Class: PostParser
- Inherits:
-
Object
- Object
- PostParser
- Defined in:
- app/services/post_parser.rb
Overview
Parser for post body
Instance Method Summary collapse
- #convert_asides ⇒ Object
- #convert_video_links ⇒ Object
- #escape_scripts ⇒ Object
-
#initialize(entity) ⇒ PostParser
constructor
A new instance of PostParser.
- #parsed_body ⇒ Object
Constructor Details
#initialize(entity) ⇒ PostParser
Returns a new instance of PostParser.
6 7 8 9 |
# File 'app/services/post_parser.rb', line 6 def initialize(entity) @entity = entity @body = entity.body.clone end |
Instance Method Details
#convert_asides ⇒ Object
33 34 35 36 37 38 |
# File 'app/services/post_parser.rb', line 33 def convert_asides pattern = %r{<p>~~\s*(.+?)</p>}i @body.gsub(pattern) do "<aside>#{$LAST_MATCH_INFO[1]}</aside>" end end |
#convert_video_links ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/services/post_parser.rb', line 25 def convert_video_links pattern = %r(<p>{video:(?<url>[^}]{1,100})}</p>)i @body.gsub(pattern) do iframe = video_url_to_iframe($LAST_MATCH_INFO[:url]) %(<div class="proportional-container r-16x9">#{iframe}</div>) end end |
#escape_scripts ⇒ Object
21 22 23 |
# File 'app/services/post_parser.rb', line 21 def escape_scripts @body.gsub(/<script/, '<script') end |
#parsed_body ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'app/services/post_parser.rb', line 11 def parsed_body unless @entity.avoid_parsing? @body = escape_scripts @body = convert_video_links @body = convert_asides end @body end |