Sha256: cff49fb0d669e7e851418133efd93b19d093e0146b83b2cc5c966e865838bc63

Contents?: true

Size: 854 Bytes

Versions: 5

Compression:

Stored size: 854 Bytes

Contents

require 'redcarpet'

module ActiveAdminAddons
  class MarkdownBuilder < CustomBuilder
    def render
      return if data.blank?

      Redcarpet::Markdown.new(renderer, extensions).render(@data).html_safe
    end

    private

    def extensions_default
      { fenced_code_blocks: true,
        no_intra_emphasis: true,
        strikethrough: true,
        superscript: true }
    end

    def renderer_options_default
      { filter_html: true, hard_wrap: true }
    end

    def extensions
      @extensions ||= extensions_default.merge(options[:extensions] || {})
    end

    def render_options
      @render_options ||= renderer_options_default.merge(options[:render_options] || {})
    end

    def renderer
      @renderer ||= Redcarpet::Render::HTML.new(render_options)
    end
  end
end

ActiveAdminAddons::MarkdownBuilder.create_view_methods

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activeadmin_addons-2.0.0.beta.3 lib/activeadmin_addons/addons/markdown_builder.rb
activeadmin_addons-1.10.1 lib/activeadmin_addons/addons/markdown_builder.rb
activeadmin_addons-2.0.0.beta.2 lib/activeadmin_addons/addons/markdown_builder.rb
activeadmin_addons-2.0.0.beta.0 lib/activeadmin_addons/addons/markdown_builder.rb
activeadmin_addons-1.10.0 lib/activeadmin_addons/addons/markdown_builder.rb