Class: HtmlTable

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#attributesObject

Virtual attributes



20
21
22
# File 'lib/html_table.rb', line 20

def attributes
  @attributes
end

#base_urlObject

Virtual attributes



20
21
22
# File 'lib/html_table.rb', line 20

def base_url
  @base_url
end

#pagination_optionsObject

Virtual attributes



20
21
22
# File 'lib/html_table.rb', line 20

def pagination_options
  @pagination_options
end

#primary_colorObject

Virtual attributes



20
21
22
# File 'lib/html_table.rb', line 20

def primary_color
  @primary_color
end

#resourcesObject

Virtual attributes



20
21
22
# File 'lib/html_table.rb', line 20

def resources
  @resources
end

#resources_classObject

Virtual attributes



20
21
22
# File 'lib/html_table.rb', line 20

def resources_class
  @resources_class
end

#resources_countObject

Virtual attributes



20
21
22
# File 'lib/html_table.rb', line 20

def resources_count
  @resources_count
end

#secondary_colorObject

Virtual attributes



20
21
22
# File 'lib/html_table.rb', line 20

def secondary_color
  @secondary_color
end

Virtual attributes



20
21
22
# File 'lib/html_table.rb', line 20

def show_resource_link
  @show_resource_link
end

#table_idObject

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