Class: ContentfulRails::MarkdownRenderer
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- ContentfulRails::MarkdownRenderer
- Includes:
- ActionView::Context, ActionView::Helpers::TagHelper
- Defined in:
- lib/contentful_rails/markdown_renderer.rb
Overview
You can subclass this in your application, to add or manipulate specific markup to elements in the markdown.
Instance Method Summary collapse
- #image(link, title, alt_text) ⇒ Object
-
#initialize(opts) ⇒ MarkdownRenderer
constructor
A new instance of MarkdownRenderer.
Constructor Details
#initialize(opts) ⇒ MarkdownRenderer
Returns a new instance of MarkdownRenderer.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/contentful_rails/markdown_renderer.rb', line 9 def initialize(opts) @options = opts @image_parameters = { w: @options[:image_options][:width], #width in px h: @options[:image_options][:height], #height in px fit: @options[:image_options][:fit], #crop, scale, pad, thumb f: @options[:image_options][:focus], #top, right, bottom, left, top_right, top_left, bottom_right, bottom_left, face fm: @options[:image_options][:format], #jpg, png bg: @options[:image_options][:background_colour], #no idea what the options are, but 'transparent' works for pngs r: @options[:image_options][:corner_radius], #corner radius in px q: @options[:image_options][:quality] }.delete_if {|k,v| v.nil?} super end |
Instance Method Details
#image(link, title, alt_text) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/contentful_rails/markdown_renderer.rb', line 24 def image(link, title, alt_text) # add the querystring to the image link += "?#{@image_parameters.to_query}" # return a content tag content_tag(:img, nil, src: link.to_s, alt: alt_text, title: title) end |