Sha256: f043df3007ba1345e026d45ebab1ccdae3deaf756533108101f7a08fe0be7c0d

Contents?: true

Size: 769 Bytes

Versions: 2

Compression:

Stored size: 769 Bytes

Contents

module SimpleFormMarkdownEditor
  class PreviewsController < ActionController::Base
    protect_from_forgery with: :exception
    respond_to :html

    def preview
      respond_to do |format|
        format.html { render text: text_preview }
      end
    end

    private # =============================================================

    # overwrite this in your own controller
    def text_preview
      Renderer.call(text, { render_class: render_class, extensions: extensions })
    end

    def text
      params.require(:text)
    end

    def options
      params.fetch(:options, {})
    end

    def render_class
      options.fetch(:render_class, nil).to_s.safe_constantize
    end

    def extensions
      options.fetch(:extensions, {})
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_form_markdown_editor-0.0.9 app/controllers/simple_form_markdown_editor/previews_controller.rb
simple_form_markdown_editor-0.0.8 app/controllers/simple_form_markdown_editor/previews_controller.rb