Sha256: c518340ffdaf4d41b1adc0cb6af8cf044bf4c71649f28b06c17596ceb517927b

Contents?: true

Size: 1.44 KB

Versions: 164

Compression:

Stored size: 1.44 KB

Contents

module Lalala::Markdown::Preview

  def self.hookup
    d = ActiveAdmin::Event
    e = ActiveAdmin::Resource::RegisterEvent

    d.subscribe e do |resource|
      Lalala::Markdown::Preview.add_preview_action(resource)
    end
  end

  def self.add_preview_action(resource_spec)
    resource_spec.dsl.run_registration_block do
      member_action :preview, :method => :post do

        if resource_params.size > 1
          raise "Expects exactly 1 param"
        end

        instance_params = resource_params.first

        if instance_params.size > 1
          raise "Expects exactly 1 param"
        end

        key = instance_params.keys.first
        val = instance_params[key]

        if key.to_s == 'translations_writer'
          instance_params = val

          if instance_params.size > 1
            raise "Expects exactly 1 param"
          end

          key = instance_params.keys.first
          val = instance_params[key]

          instance_params = val

          if instance_params.size > 1
            raise "Expects exactly 1 param"
          end

          key = instance_params.keys.first
          val = instance_params[key]
        end

        resource[key] = val

        unless resource.respond_to?("#{key}_html")
          raise "Column (#{key}) is not a markdown column"
        end

        @content = resource.send("#{key}_html")

        render layout: 'lalala/markdown', template: 'lalala/markdown/preview'

      end
    end
  end

end

Version data entries

164 entries across 164 versions & 1 rubygems

Version Path
lalala-4.1.0.dev.425 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.420 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.419 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.418 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.417 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.416 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.415 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.414 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.413 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.412 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.411 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.410 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.409 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.407 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.408 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.398 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.397 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.396 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.395 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.394 lib/lalala/markdown/preview.rb