Class: MarkdownVideos::Renderer
- Inherits:
-
Object
- Object
- MarkdownVideos::Renderer
- Defined in:
- lib/markdown_videos/renderer.rb
Instance Attribute Summary collapse
-
#markdown_text ⇒ Object
readonly
Returns the value of attribute markdown_text.
Instance Method Summary collapse
- #find_service_for(url) ⇒ Object
-
#initialize(markdown_text, options = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
Constructor Details
#initialize(markdown_text, options = {}) ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 12 13 14 15 |
# File 'lib/markdown_videos/renderer.rb', line 9 def initialize(markdown_text, = {}) @markdown_text = markdown_text @options = { wrapper: MarkdownVideos.defaults.wrapper, class_name: MarkdownVideos.defaults.class_name }.merge( || {}) end |
Instance Attribute Details
#markdown_text ⇒ Object (readonly)
Returns the value of attribute markdown_text.
7 8 9 |
# File 'lib/markdown_videos/renderer.rb', line 7 def markdown_text @markdown_text end |
Instance Method Details
#find_service_for(url) ⇒ Object
36 37 38 |
# File 'lib/markdown_videos/renderer.rb', line 36 def find_service_for(url) MarkdownVideos::SERVICES.find { |service_class| service_class.support(url) } end |
#render ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/markdown_videos/renderer.rb', line 17 def render @markdown_text.gsub(/!\[([^\]]*)\]\(([^)]+)\)/) do rendered = nil match_data = Regexp.last_match markdown = { alt_text: match_data[1], url: match_data[2].strip } service_class = find_service_for(markdown[:url]) if service_class service_class.new(markdown[:alt_text], markdown[:url], @options).render else match_data.string end end end |