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.392 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.393 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.391 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.390 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.389 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.388 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.387 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.386 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.385 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.384 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.382 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.381 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.376 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.375 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.374 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.372 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.368 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.367 lib/lalala/markdown/preview.rb
lalala-4.0.0.dev.366 lib/lalala/markdown/preview.rb
lalala-4.1.0.dev.360 lib/lalala/markdown/preview.rb