Module: Daru::View::Adapter::DatatablesAdapter
- Extended by:
- DatatablesAdapter
- Included in:
- DatatablesAdapter
- Defined in:
- lib/daru/view/adapters/datatables.rb
Instance Method Summary collapse
-
#export_html_file(table, path = './table.html') ⇒ void
Writes the html code of the datatable to the file.
-
#generate_body(table) ⇒ String
Script and table (containg thead only) tags of the datatable generated.
-
#generate_html(table) ⇒ String
Returns html code of the datatable generated.
-
#init_iruby ⇒ void
Loads the dependent JS and CSS files in IRuby notebook.
-
#init_script ⇒ String
Returns code of the dependent JS and CSS file(s).
-
#init_table(data = [], options = {}, _user_options = {}) ⇒ Daru::DataTables::DataTable
Read : datatables.net/ to understand the datatables option concept.
-
#show_in_iruby(table) ⇒ void
Shows the datatable in IRuby notebook.
Instance Method Details
#export_html_file(table, path = './table.html') ⇒ void
This method returns an undefined value.
Returns writes the html code of the datatable to the file.
85 86 87 88 89 |
# File 'lib/daru/view/adapters/datatables.rb', line 85 def export_html_file(table, path='./table.html') path = File.(path, Dir.pwd) str = generate_html(table) File.write(path, str) end |
#generate_body(table) ⇒ String
Returns script and table (containg thead only) tags of the datatable generated.
75 76 77 |
# File 'lib/daru/view/adapters/datatables.rb', line 75 def generate_body(table) table.to_html end |
#generate_html(table) ⇒ String
Returns html code of the datatable generated
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/daru/view/adapters/datatables.rb', line 104 def generate_html(table) path = File.( '../templates/datatables/static_html.erb', __dir__ ) template = File.read(path) table_script = generate_body(table) initial_script = init_script id = table.element_id ERB.new(template).result(binding) end |
#init_iruby ⇒ void
This method returns an undefined value.
Returns loads the dependent JS and CSS files in IRuby notebook.
119 120 121 |
# File 'lib/daru/view/adapters/datatables.rb', line 119 def init_iruby Daru::View::DataTables.init_iruby end |
#init_script ⇒ String
Returns code of the dependent JS and CSS file(s)
67 68 69 |
# File 'lib/daru/view/adapters/datatables.rb', line 67 def init_script Daru::View::DataTables.init_script end |
#init_table(data = [], options = {}, _user_options = {}) ⇒ Daru::DataTables::DataTable
Read : datatables.net/ to understand the datatables option concept. Along with these options, a user can provide an additional option
html_options[:table_options] to cistomize the generated table
See the specs of daru-data_tables gem.
61 62 63 64 |
# File 'lib/daru/view/adapters/datatables.rb', line 61 def init_table(data=[], ={}, ={}) @table = Daru::View::DataTable.new(data, ) @table end |
#show_in_iruby(table) ⇒ void
This method returns an undefined value.
Returns shows the datatable in IRuby notebook.
97 98 99 |
# File 'lib/daru/view/adapters/datatables.rb', line 97 def show_in_iruby(table) table.show_in_iruby end |