Class: Interview::Grid
- Includes:
- HasControls
- Defined in:
- lib/interview/grid.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#objects ⇒ Object
Returns the value of attribute objects.
-
#sortable ⇒ Object
Returns the value of attribute sortable.
Attributes included from HasControls
Attributes inherited from Control
Instance Method Summary collapse
Methods included from HasControls
#add_control, #add_controls, included, #initialize, #siblings
Methods inherited from Control
#ancestors, build, definition, #find_attribute, #find_attribute!, inherited, #initialize, #set_attributes, #set_defaults
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
6 7 8 |
# File 'lib/interview/grid.rb', line 6 def object @object end |
#objects ⇒ Object
Returns the value of attribute objects.
5 6 7 |
# File 'lib/interview/grid.rb', line 5 def objects @objects end |
#sortable ⇒ Object
Returns the value of attribute sortable.
5 6 7 |
# File 'lib/interview/grid.rb', line 5 def sortable @sortable end |
Instance Method Details
#render ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/interview/grid.rb', line 8 def render objects = @objects || find_attribute!(:objects) @object = find_attribute!(:object) sortable_id = "sortable_#{@object.class.model_name.plural}" if @sortable html = Builder::XmlMarkup.new html.table class: 'table' do html.thead do html.tr do html.th '' if @sortable @controls.each do |control| html.th do html << control.caption end end end end html_opts = {} html_opts[:id] = sortable_id if @sortable html.tbody html_opts do objects.each do |object| @object = object html_opts = {} html_opts[:id] = "#{sortable_id}_#{object.id}" if @sortable html.tr html_opts do if @sortable html.td do html.span '', class: 'handle glyphicon glyphicon-resize-vertical' end end @controls.each do |control| html.td do html << control.render end end end end end end if objects.empty? html.p "Keine #{@object.class.human_name(count: 2)} vorhanden.", class: 'text-center text-muted' end return html.target! end |