Module: Showbuilder::ShowModelTable

Included in:
Showbuilder
Defined in:
lib/showbuilder/show_model_table.rb

Instance Method Summary collapse

Instance Method Details

#get_show_model_table_column_count(block) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/showbuilder/show_model_table.rb', line 67

def get_show_model_table_column_count(block)
  row = Object.new
  class << row
    attr_accessor :column_count

    def increament_column_count
      self.column_count ||= 0
      self.column_count += 1
    end

    def method_missing(meth, *args, &block)
      if meth.to_s =~ /^show_(.+)_column$/
        self.increament_column_count
      else
        super
      end
    end
  end

  capture row, &block

  return row.column_count
end

#show_model_table(models, itext_base = nil, &block) ⇒ Object

show_model_table @sale do |row|

= row.show_date_link_column     :created_at
= row.show_text_link_column     :number
= row.show_text_link_column     :customer, :name, :link => :customer
= row.show_currency_link_column :total


14
15
16
17
18
19
# File 'lib/showbuilder/show_model_table.rb', line 14

def show_model_table(models, itext_base = nil, &block)
  contents_tag(:table, :class => "table table-bordered table-striped") do |contents|
    contents << show_model_table_header(itext_base, &block)
    contents << show_model_table_body(models, &block)
  end
end

#show_model_table_body(models, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/showbuilder/show_model_table.rb', line 27

def show_model_table_body(models, &block)
  SequenceManager.initialize_sequence(params)

  contents_tag :tbody do |contents|
    models.each do |model|
      contents << show_model_table_body_row(model, &block)
    end
    contents << show_model_table_no_record_row(block) if models.count == 0
  end
end

#show_model_table_body_row(model, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/showbuilder/show_model_table.rb', line 57

def show_model_table_body_row(model, &block)
  row           = Showbuilder::Builders::ShowModelTableRowBuilder.new(self)
  row.is_header = false
  row.model     = model

   :tr do
    capture row, &block
  end
end

#show_model_table_header(itext_base, &block) ⇒ Object



21
22
23
24
25
# File 'lib/showbuilder/show_model_table.rb', line 21

def show_model_table_header(itext_base, &block)
   :thead do
    show_model_table_header_row itext_base, &block
  end
end

#show_model_table_header_row(itext_base, &block) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/showbuilder/show_model_table.rb', line 47

def show_model_table_header_row(itext_base, &block)
  row            = Showbuilder::Builders::ShowModelTableRowBuilder.new(self)
  row.is_header  = true
  row.itext_base = itext_base

   :tr do
    capture row, &block
  end
end

#show_model_table_no_record_row(block) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/showbuilder/show_model_table.rb', line 38

def show_model_table_no_record_row(block)
  column_count = get_show_model_table_column_count(block)
   :tr do
     :td, :colspan => column_count do
      show_itext 'no_record'
    end
  end
end