Class: Trenni::Formatters::HTML::TableSelect

Inherits:
Object
  • Object
show all
Defined in:
lib/trenni/formatters/html/table_select.rb

Overview

Table based select boxes using per-row checkboxes.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter, options, builder) ⇒ TableSelect

Returns a new instance of TableSelect.



34
35
36
37
38
39
40
# File 'lib/trenni/formatters/html/table_select.rb', line 34

def initialize(formatter, options, builder)
  @formatter = formatter
  @object = formatter.object
  @field = options[:field]
  
  @builder = builder
end

Class Method Details

.call(formatter, options, builder, &block) ⇒ Object



28
29
30
31
32
# File 'lib/trenni/formatters/html/table_select.rb', line 28

def self.call(formatter, options, builder, &block)
  instance = self.new(formatter, options, builder)
  
  instance.call(options, &block)
end

Instance Method Details

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



90
91
92
93
94
95
96
97
98
# File 'lib/trenni/formatters/html/table_select.rb', line 90

def call(options = {}, &block)
  Builder.fragment(@builder) do |builder|
    builder.tag :table do
      builder.tag :tbody do
        builder.append Trenni::Template.capture(self, &block)
      end
    end
  end
end

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



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/trenni/formatters/html/table_select.rb', line 63

def item(options = {}, &block)
  fragment = Builder.fragment do |builder|
    builder.tag :tr do
      builder.inline(:td, :class => :handle) do
        builder.tag :input, radio_attributes_for(options)
      end
        
      builder.inline(:td, :class => :item) do
        if block_given?
          builder.append Trenni::Template.capture(self, &block)
        else
          builder.text title_for(options)
        end
      end
    end
  end
  
  if block_given?
    buffer = Trenni::buffer(block.binding)
    buffer << fragment
    
    return nil
  else
    return fragment
  end
end

#name_for(options) ⇒ Object



42
43
44
# File 'lib/trenni/formatters/html/table_select.rb', line 42

def name_for(options)
  @formatter.name_for(options)
end

#radio_attributes_for(options) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/trenni/formatters/html/table_select.rb', line 54

def radio_attributes_for(options)
  return {
    :type => :radio,
    :name => @field,
    :value => value_for(options),
    :selected => options[:selected],
  }
end

#title_for(options) ⇒ Object



50
51
52
# File 'lib/trenni/formatters/html/table_select.rb', line 50

def title_for(options)
  @formatter.title_for(options)
end

#value_for(options) ⇒ Object



46
47
48
# File 'lib/trenni/formatters/html/table_select.rb', line 46

def value_for(options)
  @formatter.value_for(options)
end