class TheGrid::Builder

Public Class Methods

assemble(options, &block) click to toggle source
# File lib/the_grid/builder.rb, line 28
def self.assemble(options, &block)
  new(options, &block).instance_eval(&block)
end
call(template) click to toggle source
# File lib/the_grid/builder.rb, line 9
def self.call(template)
  source = if template.source.empty?
    File.read(template.identifier)
  else
    template.source
  end

  %{
    ::TheGrid::Builder.assemble(:format => #{template.formats.first.inspect}, :scope => self) {
      #{source}
    }
  }
end
detect_view(format) click to toggle source
# File lib/the_grid/builder.rb, line 23
def self.detect_view(format)
  @@view_types ||= {}
  @@view_types[format] ||= "the_grid/builder/#{format}".camelize.constantize
end
new(options, &block) click to toggle source
# File lib/the_grid/builder.rb, line 32
def initialize(options, &block)
  options.assert_valid_keys(:scope, :format)

  @_scope = options.delete(:scope)
  @_view_type = self.class.detect_view(options.delete(:format))

  copy_instance_variables_from(@_scope) if @_scope
  self.instance_eval(&block)
end

Public Instance Methods

grid_for(relation, options = {}, &block) click to toggle source
# File lib/the_grid/builder.rb, line 42
def grid_for(relation, options = {}, &block)
  context = Context.new(options.merge(:scope => @_scope), &block)
  @_view_type.assemble(context, :on => relation, :with => @_scope.params)
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/the_grid/builder.rb, line 47
def method_missing(name, *args, &block)
  if @_scope.respond_to?(name)
    @_scope.send(name, *args, &block)
  else
    super
  end
end

Private Instance Methods

copy_instance_variables_from(object) click to toggle source
# File lib/the_grid/builder.rb, line 57
def copy_instance_variables_from(object)
  vars = object.instance_variables.map(&:to_s)
  vars.each{ |name| instance_variable_set(name.to_sym, object.instance_variable_get(name)) }
end