Class: SimpleDataPresentation::SimpleTable::Head
- Defined in:
- lib/simple_data_presentation/simple_table/head.rb
Instance Method Summary collapse
-
#initialize(context, resource_class, options = {}, &content_block) ⇒ Head
constructor
A new instance of Head.
- #render! ⇒ Object
- #title(*args, &block) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(context, resource_class, options = {}, &content_block) ⇒ Head
Returns a new instance of Head.
2 3 4 5 6 7 8 |
# File 'lib/simple_data_presentation/simple_table/head.rb', line 2 def initialize(context, resource_class, = {}, &content_block) @context = context @options = @resource_class = resource_class @search = @context.instance_variable_get(:"@search") if @context.instance_variable_get(:"@search").present? && @context.instance_variable_get(:"@search").klass == @resource_class @content_block = content_block end |
Instance Method Details
#render! ⇒ Object
30 31 32 33 |
# File 'lib/simple_data_presentation/simple_table/head.rb', line 30 def render! content = @context.capture self, &@content_block @context.raw @context.content_tag :thead, @context.content_tag(:tr, content, (@options[:row_html])), @options[:html] end |
#title(*args, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/simple_data_presentation/simple_table/head.rb', line 10 def title(*args, &block) = args. content = if block.present? @context.capture(@resource_class, &block) else sort_attribute = [:sort_by] || (args.any? ? args.join("_").to_sym : nil) label = if [:label].is_a?(Symbol) @resource_class.human_attribute_name [:label] elsif ![:label].nil? [:label] elsif sort_attribute.present? label = @resource_class.human_attribute_name sort_attribute abbr_label = @resource_class.human_attribute_name "#{sort_attribute}_abbr", default: "" abbr_label.present? ? @context.content_tag(:abbr, abbr_label, title: label) : label end !@search.nil? && [:sortable] != false ? @context.sort_link(@search, sort_attribute, label) : label end @context.content_tag :th, content, [:html] end |