Sha256: 9c16bac3aa51c25ce0654a56da1e16afb13c14be9b0672fe800efc3c9a073304

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Trestle
  class Table
    class Row
      attr_reader :table, :options, :block

      def initialize(table, options={}, &block)
        @table, @options = table, options
        @block = block if block_given?
      end

      def renderer(template)
        Renderer.new(self, template)
      end

      class Renderer
        delegate :table, to: :@row

        def initialize(row, template)
          @row, @template = row, template
        end

        def options(instance)
          options = Trestle::Options.new

          if table.admin && table.autolink?
            options.merge!(data: { url: admin_url_for(instance) })
            options.merge!(data: { behavior: "dialog" }) if table.admin.form.dialog?
          end

          options.merge!(@row.options)
          options.merge!(@template.instance_exec(instance, &@row.block)) if @row.block

          options
        end

      protected
        def admin_url_for(instance)
          @template.admin_url_for(instance, admin: table.admin)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trestle-0.8.6 lib/trestle/table/row.rb