Class: Trenni::Formatters::HTML::TableSelect
- Inherits:
-
Object
- Object
- Trenni::Formatters::HTML::TableSelect
- 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
- #call(options = {}, &block) ⇒ Object
-
#initialize(formatter, options, builder) ⇒ TableSelect
constructor
A new instance of TableSelect.
- #item(options = {}, &block) ⇒ Object
- #name_for(options) ⇒ Object
- #radio_attributes_for(options) ⇒ Object
- #title_for(options) ⇒ Object
- #value_for(options) ⇒ Object
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, , builder) @formatter = formatter @object = formatter.object @field = [: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, , builder, &block) instance = self.new(formatter, , builder) instance.call(, &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( = {}, &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( = {}, &block) fragment = Builder.fragment do |builder| builder.tag :tr do builder.inline(:td, :class => :handle) do builder.tag :input, radio_attributes_for() end builder.inline(:td, :class => :item) do if block_given? builder.append Trenni::Template.capture(self, &block) else builder.text title_for() 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() @formatter.name_for() 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() return { :type => :radio, :name => @field, :value => value_for(), :selected => [:selected], } end |
#title_for(options) ⇒ Object
50 51 52 |
# File 'lib/trenni/formatters/html/table_select.rb', line 50 def title_for() @formatter.title_for() end |
#value_for(options) ⇒ Object
46 47 48 |
# File 'lib/trenni/formatters/html/table_select.rb', line 46 def value_for() @formatter.value_for() end |