Module: Daru::View::Display
- Included in:
- DataTable
- Defined in:
- lib/daru/data_tables/display/display.rb
Instance Method Summary collapse
-
#show_in_iruby(dom = SecureRandom.uuid) ⇒ void
Shows the datatable in IRuby notebook.
-
#show_script(dom = SecureRandom.uuid, options = {}) ⇒ String
Js script to render the table.
-
#to_html(id = nil, options = {}) ⇒ String
If table_options is not present then it will assume that table tag is already present in the web page source, where we are pasting the html code.
-
#to_js(element_id) ⇒ String
Returns the javascript of the DataTable.
Instance Method Details
#show_in_iruby(dom = SecureRandom.uuid) ⇒ void
This method returns an undefined value.
Returns shows the datatable in IRuby notebook.
96 97 98 |
# File 'lib/daru/data_tables/display/display.rb', line 96 def show_in_iruby(dom=SecureRandom.uuid) IRuby.html(to_html(dom)) end |
#show_script(dom = SecureRandom.uuid, options = {}) ⇒ String
Returns js script to render the table.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/daru/data_tables/display/display.rb', line 59 def show_script(dom=SecureRandom.uuid, ={}) script_tag = .fetch(:script_tag) { true } if script_tag to_js(dom) else html = '' html << draw_js(dom) html end end |
#to_html(id = nil, options = {}) ⇒ String
If table_options is not present then it will assume that table tag is already present in the web page source, where we are pasting the html code.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/daru/data_tables/display/display.rb', line 78 def to_html(id=nil, ={}) # More things can be added into table_script.erb path = File.('../templates/table_script.erb', __dir__) template = File.read(path) id ||= SecureRandom.uuid # TODO: remove it or Use it for table tag. element_id ||= id table_script = show_script(element_id, script_tag: false) html_code = ERB.new(template).result(binding) # table_options is given. That means table html code is not present in # the webpage. So it must generate table code with given options. table_thead = extract_table draw_table_thead(element_id, html_code, table_thead) html_code end |
#to_js(element_id) ⇒ String
Returns the javascript of the DataTable
103 104 105 106 107 108 109 |
# File 'lib/daru/data_tables/display/display.rb', line 103 def to_js(element_id) js = '' js << "\n<script type='text/javascript'>" js << draw_js(element_id) js << "\n</script>" js end |