class Administrate::Field::SimpleMarkdown

Public Instance Methods

data() click to toggle source
# File lib/administrate/field/simple_markdown.rb, line 15
def data
  @data || ''
end
easymde_options() click to toggle source
# File lib/administrate/field/simple_markdown.rb, line 19
def easymde_options
  options.fetch(:easymde_options, {})
    .transform_keys { |key| key.to_s.camelize(:lower) }
    .to_json
end
html_id() click to toggle source
# File lib/administrate/field/simple_markdown.rb, line 33
def html_id
  [
    resource.class.name.underscore.gsub('/', '_'),
    attribute
  ].join('_')
end
to_html() click to toggle source
# File lib/administrate/field/simple_markdown.rb, line 25
def to_html
  markdown(html_renderer).render(data).html_safe
end
to_s() click to toggle source
# File lib/administrate/field/simple_markdown.rb, line 29
def to_s
  markdown(plaintext_renderer).render(data)
end

Private Instance Methods

html_renderer() click to toggle source
# File lib/administrate/field/simple_markdown.rb, line 42
def html_renderer
  @html_renderer ||= Redcarpet::Render::HTML.new({
    safe_links_only: options.fetch(:safe_links_only, true),
    filter_html: options.fetch(:filter_html, true),
    with_toc_data: options.fetch(:with_toc_data, true),
    hard_wrap: options.fetch(:hard_wrap, true),
    link_attributes: options.fetch(:link_attributes, { rel: 'nofollow' })
  })
end
markdown(renderer) click to toggle source
# File lib/administrate/field/simple_markdown.rb, line 56
def markdown(renderer)
  @markdown ||= Redcarpet::Markdown.new(renderer, {
    autolink: options.fetch(:autolink, true),
    tables: options.fetch(:tables, true),
    no_intra_emphasis: options.fetch(:no_intra_emphasis, true),
    strikethrough: options.fetch(:strikethrough, true),
    highlight: options.fetch(:highlight, true),
    space_after_headers: options.fetch(:space_after_headers, true)
  })
end
plaintext_renderer() click to toggle source
# File lib/administrate/field/simple_markdown.rb, line 52
def plaintext_renderer
  @plaintext_renderer ||= Redcarpet::Render::StripDown
end