Sha256: 3fa9a6f4cf6c29f282c734452d7b0b01ac927a1ff4664b3bf87364056c59d823

Contents?: true

Size: 1.56 KB

Versions: 9

Compression:

Stored size: 1.56 KB

Contents

module Fancygrid  
  module View
    module Helper
      # Renders an existing fancygrid for the given name. A rendering block
      # may be passed to format column values.
      #
      def fancygrid(name, options={}, &block)#:yields: column, record, value
        instance = @fancygrid_collection && @fancygrid_collection[name]
        raise "Unknown fancygrid name: '#{name}'" if instance.nil?
        render :template => instance.options[:base_template], :locals => { :fancygrid => instance, :format_block => block }
      end
      
      # Fetches a value from given record and applies a formatter on it.
      # 
      def render_fancygrid_cell(record, column, &format_block)
        value = column.fetch_value_and_format(record)
        format_fancygrid_value(record, column, value, &format_block)
      end
      
      # Renders the given <tt>record</tt>, <tt>column</tt> and <tt>value</tt> 
      # with the formatter block.
      #
      def format_fancygrid_value(record, column, value=nil, &format_block)
        if block_given?
          if defined?(Haml::Helpers) && is_haml?
            capture_haml(column, record, value, &format_block)
          else
            capture(column, record, value, &format_block)
          end
        #elsif !column.root.cell_template.nil?
        #  render( :template => column.root.cell_template, :inline => true, :locals => { 
        #    :grid => column.root,
        #    :record => record, 
        #    :column => column, 
        #    :value => value 
        #  })
        else
          value
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fancygrid-2.0.8 lib/fancygrid/view/helper.rb
fancygrid-2.0.7 lib/fancygrid/view/helper.rb
fancygrid-2.0.6 lib/fancygrid/view/helper.rb
fancygrid-2.0.5 lib/fancygrid/view/helper.rb
fancygrid-2.0.4 lib/fancygrid/view/helper.rb
fancygrid-2.0.3 lib/fancygrid/view/helper.rb
fancygrid-2.0.2 lib/fancygrid/view/helper.rb
fancygrid-2.0.1 lib/fancygrid/view/helper.rb
fancygrid-2.0.0 lib/fancygrid/view/helper.rb