Class: Zable::View

Inherits:
Object
  • Object
show all
Includes:
Html
Defined in:
lib/zable/view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Html

#body_cell_id, #body_row_class, #body_row_id, #current_url, #empty_table_body_row, #header_cell_content, #header_cell_href, #header_cell_link_text, #header_cell_sort_image, #param, #search_params, #sort_arrow_image_file, #sort_params, #table_body, #table_body_row, #table_body_row_cell, #table_body_row_cells, #table_body_rows, #table_header, #table_header_cell, #table_header_cells, #table_header_row

Constructor Details

#initialize(collection, template, options = {}, &block) ⇒ View

Returns a new instance of View.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/zable/view.rb', line 8

def initialize(collection, template, options={}, &block)
  @collection = collection

  @template = template # this refers to the view context
  raise "Must pass in valid view context" unless @template.kind_of? ActionView::Context
  @search = @template.controller.request.params[:search]
  @_extra_params = options[:params]

  @options = options
  @columns = []
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object (private)



50
51
52
53
# File 'lib/zable/view.rb', line 50

def method_missing(*args, &block)
  # missing methods will be sent to the view context - these will generally be rails helper methods
  h.send(*args, &block)
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



6
7
8
# File 'lib/zable/view.rb', line 6

def columns
  @columns
end

Instance Method Details

#column(name, options = {}, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zable/view.rb', line 31

def column(name, options={}, &block)
  col = {
    :name       => name,
    :title      => options[:title],
    :sort       => options.has_key?(:sort) ? options[:sort] : true,
    :block      => block,
    :sorted?    => sorted_column?(name),
    :sort_order => link_sort_order(name)
  }

  @columns << col
end

#renderObject



21
22
23
24
25
26
27
28
29
# File 'lib/zable/view.rb', line 21

def render
  reset_cycle("zable_cycle")

  html = ''.html_safe #stylesheet_link_tag("zable")
  html << pagination_element if @options[:paginate]
  html << zable_element
  html << pagination_element if @options[:paginate]
  html
end