Sha256: 348677d6c3cdc2ed059be9233f4815371f85dbb06e40ca5a0fb7e7aabae0ca28

Contents?: true

Size: 1008 Bytes

Versions: 18

Compression:

Stored size: 1008 Bytes

Contents

require 'redcarpet'

module PushType
  class MarkdownField < PushType::FieldType

    options form_helper:    :text_area,
            renderer:       Redcarpet::Render::HTML,
            render_options: {},
            extensions: {
              autolink:             true,
              fenced_code_blocks:   true,
              no_intra_emphasis:    true,
              space_after_headers:  true,
              strikethrough:        true,
              tables:               true,
              underline:            true
            }

    def compiled_value
      markdown.render value unless value.nil?
    end

    private

    def markdown
      @markdown ||= Redcarpet::Markdown.new(renderer, @opts[:extensions])
    end

    def renderer
      @opts[:renderer].new @opts[:render_options]
    end

    on_instance do |object, field|
      object.presenter_class.class_eval do
        define_method(field.name) { field.compiled_value } unless method_defined?(field.name)
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
push_type_core-0.9.1 app/fields/push_type/markdown_field.rb
push_type_core-0.9.0 app/fields/push_type/markdown_field.rb
push_type_core-0.9.0.beta.4 app/fields/push_type/markdown_field.rb
push_type_core-0.9.0.beta.3 app/fields/push_type/markdown_field.rb
push_type_core-0.9.0.beta.2 app/fields/push_type/markdown_field.rb
push_type_core-0.8.2 app/fields/push_type/markdown_field.rb
push_type_core-0.8.1 app/fields/push_type/markdown_field.rb
push_type_core-0.8.0 app/fields/push_type/markdown_field.rb
push_type_core-0.8.0.beta.3 app/fields/push_type/markdown_field.rb
push_type_core-0.8.0.beta.2 app/fields/push_type/markdown_field.rb
push_type_core-0.8.0.beta.1 app/fields/push_type/markdown_field.rb
push_type_core-0.7.0 app/fields/push_type/markdown_field.rb
push_type_core-0.7.0.beta.1 app/fields/push_type/markdown_field.rb
push_type_core-0.6.0 app/fields/push_type/markdown_field.rb
push_type_core-0.6.0.beta.4 app/fields/push_type/markdown_field.rb
push_type_core-0.6.0.beta.3 app/fields/push_type/markdown_field.rb
push_type_core-0.6.0.beta.2 app/fields/push_type/markdown_field.rb
push_type_core-0.6.0.beta.1 app/fields/push_type/markdown_field.rb