Class: WCC::Contentful::App::CustomMarkdownRender
- Inherits:
- 
      Redcarpet::Render::HTML
      
        - Object
- Redcarpet::Render::HTML
- WCC::Contentful::App::CustomMarkdownRender
 
- Defined in:
- lib/wcc/contentful/app/custom_markdown_render.rb
Instance Method Summary collapse
- #hyperlink_attributes(title, url, link_class = nil) ⇒ Object
- 
  
    
      #initialize(options)  ⇒ CustomMarkdownRender 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of CustomMarkdownRender. 
- #link(link, title, content) ⇒ Object
- #table(header, body) ⇒ Object
- #use_target_blank?(url) ⇒ Boolean
Constructor Details
#initialize(options) ⇒ CustomMarkdownRender
Returns a new instance of CustomMarkdownRender.
| 7 8 9 10 | # File 'lib/wcc/contentful/app/custom_markdown_render.rb', line 7 def initialize() super @options = end | 
Instance Method Details
#hyperlink_attributes(title, url, link_class = nil) ⇒ Object
| 27 28 29 30 31 32 33 34 35 | # File 'lib/wcc/contentful/app/custom_markdown_render.rb', line 27 def hyperlink_attributes(title, url, link_class = nil) link_attrs = { title: title, class: link_class } link_attrs[:target] = use_target_blank?(url) ? '_blank' : nil return link_attrs unless @options[:link_attributes] @options[:link_attributes].merge(link_attrs) end | 
#link(link, title, content) ⇒ Object
| 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # File 'lib/wcc/contentful/app/custom_markdown_render.rb', line 12 def link(link, title, content) link_with_class_data = @options[:links_with_classes]&.find do |link_with_class| link_with_class[0] == link && link_with_class[2] == CGI.unescape_html(content) end link_class = link_with_class_data ? link_with_class_data[3] : nil ActionController::Base.helpers.link_to( content, link, hyperlink_attributes(title, link, link_class) ) end | 
#table(header, body) ⇒ Object
| 41 42 43 | # File 'lib/wcc/contentful/app/custom_markdown_render.rb', line 41 def table(header, body) "<table class=\"table\">#{header}#{body}</table>" end | 
#use_target_blank?(url) ⇒ Boolean
| 37 38 39 | # File 'lib/wcc/contentful/app/custom_markdown_render.rb', line 37 def use_target_blank?(url) url.scan(/(\s|^)(https?:\/\/\S*)/).present? end |