Class: HtmlTable
- Inherits:
-
Object
- Object
- HtmlTable
- Defined in:
- lib/html_table.rb
Overview
Manage HTML table
Constant Summary collapse
- DEFAULT_COLOR =
Constants
'#5bc0de'
- DEFAULT_PAGINATION_OPTIONS =
[5, 10, 20, 40].freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Virtual attributes.
-
#base_url ⇒ Object
Virtual attributes.
-
#pagination_options ⇒ Object
Virtual attributes.
-
#primary_color ⇒ Object
Virtual attributes.
-
#resources ⇒ Object
Virtual attributes.
-
#resources_class ⇒ Object
Virtual attributes.
-
#resources_count ⇒ Object
Virtual attributes.
-
#secondary_color ⇒ Object
Virtual attributes.
-
#show_resource_link ⇒ Object
Virtual attributes.
-
#table_id ⇒ Object
Virtual attributes.
Instance Method Summary collapse
-
#generate! ⇒ Object
Generate HTML table.
-
#initialize(resources_class, resources, attributes, params = {}) ⇒ HtmlTable
constructor
Initialize class.
Constructor Details
#initialize(resources_class, resources, attributes, params = {}) ⇒ HtmlTable
Initialize class
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/html_table.rb', line 26 def initialize(resources_class, resources, attributes, params = {}) @attributes = attributes&.to_a @resources = resources&.to_a @resources_class = resources_class @resources_count = resources.size @base_url = params[:base_url] @table_id = params[:table_id] || "table#{SecureRandom.hex}" @show_resource_link = params[:show_resource_link] != false && resources_class.method_defined?('id') @pagination_options = params[:pagination_options] || DEFAULT_PAGINATION_OPTIONS @primary_color = params[:primary_color] || DEFAULT_COLOR @secondary_color = params[:secondary_color] || DEFAULT_COLOR end |
Instance Attribute Details
#attributes ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def attributes @attributes end |
#base_url ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def base_url @base_url end |
#pagination_options ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def @pagination_options end |
#primary_color ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def primary_color @primary_color end |
#resources ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def resources @resources end |
#resources_class ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def resources_class @resources_class end |
#resources_count ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def resources_count @resources_count end |
#secondary_color ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def secondary_color @secondary_color end |
#show_resource_link ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def show_resource_link @show_resource_link end |
#table_id ⇒ Object
Virtual attributes
20 21 22 |
# File 'lib/html_table.rb', line 20 def table_id @table_id end |
Instance Method Details
#generate! ⇒ Object
Generate HTML table
42 43 44 45 46 |
# File 'lib/html_table.rb', line 42 def generate! return '' if invalid_data complete_css + complete_div + complete_js end |