Class: Diaspora::MessageRenderer::Processor
- Inherits:
-
Object
- Object
- Diaspora::MessageRenderer::Processor
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/diaspora/message_renderer.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #append_and_truncate ⇒ Object
- #escape ⇒ Object
-
#initialize(message, options) ⇒ Processor
constructor
A new instance of Processor.
- #make_mentions_plain_text ⇒ Object
- #markdownify ⇒ Object
-
#process_newlines ⇒ Object
In very clear cases, let newlines become <br /> tags Grabbed from Github flavored Markdown.
- #render_mentions ⇒ Object
- #render_tags ⇒ Object
- #squish ⇒ Object
- #strip_markdown ⇒ Object
Constructor Details
#initialize(message, options) ⇒ Processor
21 22 23 24 |
# File 'lib/diaspora/message_renderer.rb', line 21 def initialize , = = end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message
19 20 21 |
# File 'lib/diaspora/message_renderer.rb', line 19 def end |
#options ⇒ Object (readonly)
Returns the value of attribute options
19 20 21 |
# File 'lib/diaspora/message_renderer.rb', line 19 def end |
Class Method Details
.process(message, options, &block) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/diaspora/message_renderer.rb', line 11 def process , , &block return '' if .blank? # Optimize for empty message processor = new , processor.instance_exec(&block) processor. end |
Instance Method Details
#append_and_truncate ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/diaspora/message_renderer.rb', line 30 def append_and_truncate if [:truncate] = .truncate [:truncate]-[:append].to_s.size end << [:append].to_s << [:append_after_truncate].to_s end |
#escape ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/diaspora/message_renderer.rb', line 40 def escape if [:escape] # TODO: On Rails 4 port change this to ERB::Util.html_escape_once # and remove the include = escape_once # Special case Hex entities since escape_once # doesn't catch them. # TODO: Watch for https://github.com/rails/rails/pull/9102 # on whether this can be removed = .gsub(/&(#[xX][\dA-Fa-f]{1,4});/, '&\1;') end end |
#make_mentions_plain_text ⇒ Object
86 87 88 |
# File 'lib/diaspora/message_renderer.rb', line 86 def make_mentions_plain_text = Diaspora::Mentionable.format , [], plain_text: true end |
#markdownify ⇒ Object
59 60 61 62 63 64 |
# File 'lib/diaspora/message_renderer.rb', line 59 def markdownify renderer = Diaspora::Markdownify::HTML.new [:markdown_render_options] markdown = Redcarpet::Markdown.new renderer, [:markdown_options] = markdown.render end |
#process_newlines ⇒ Object
In very clear cases, let newlines become <br /> tags Grabbed from Github flavored Markdown
68 69 70 71 72 |
# File 'lib/diaspora/message_renderer.rb', line 68 def process_newlines .gsub(/^[\w\<][^\n]*\n+/) do |x| x =~ /\n{2}/ ? x : (x.strip!; x << " \n") end end |
#render_mentions ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/diaspora/message_renderer.rb', line 74 def render_mentions unless [:disable_hovercards] || [:mentioned_people].empty? = Diaspora::Mentionable.format , [:mentioned_people] end if [:disable_hovercards] || [:link_all_mentions] = Diaspora::Mentionable.filter_for_aspects , nil else make_mentions_plain_text end end |
#render_tags ⇒ Object
90 91 92 |
# File 'lib/diaspora/message_renderer.rb', line 90 def = Diaspora::Taggable. , no_escape: ![:escape_tags] end |
#squish ⇒ Object
26 27 28 |
# File 'lib/diaspora/message_renderer.rb', line 26 def squish = .squish if [:squish] end |
#strip_markdown ⇒ Object
54 55 56 57 |
# File 'lib/diaspora/message_renderer.rb', line 54 def strip_markdown renderer = Redcarpet::Markdown.new Redcarpet::Render::StripDown, [:markdown_options] = renderer.render().strip end |