Module: Rack::Webconsole::AssetHelpers
- Included in:
- Assets
- Defined in:
- lib/rack/webconsole/asset_helpers.rb
Overview
Helper module to encapsulate the asset loading logic used by the Assets middleware.
For now, the strategy is reading the files from disk. In the future, we should come up with a somewhat more sophisticated strategy, although Rack::Webconsole is used only in development environments, where performance isn’t usually a concern.
Instance Method Summary collapse
-
#css_code ⇒ String
Loads the CSS from a file in ‘/public`.
-
#html_code ⇒ String
Loads the HTML from a file in ‘/public`.
-
#js_code ⇒ String
Loads the JavaScript from a file in ‘/public`.
-
#render(javascript, variables = {}) ⇒ String
Inteprolates the given variables inside the javascrpt code.
Instance Method Details
#css_code ⇒ String
Loads the CSS from a file in ‘/public`.
It contains the styles for the console.
30 31 32 33 34 |
# File 'lib/rack/webconsole/asset_helpers.rb', line 30 def css_code '<style type="text/css">' << asset('webconsole.css') << '</style>' end |
#html_code ⇒ String
Loads the HTML from a file in ‘/public`.
It contains a form and the needed divs to render the console.
18 19 20 21 22 23 |
# File 'lib/rack/webconsole/asset_helpers.rb', line 18 def html_code out = "" out << asset('jquery.html') if Webconsole.inject_jquery out << asset('webconsole.html') out end |
#js_code ⇒ String
Loads the JavaScript from a file in ‘/public`.
It contains the JavaScript logic of the webconsole.
41 42 43 44 45 |
# File 'lib/rack/webconsole/asset_helpers.rb', line 41 def js_code '<script type="text/javascript">' << asset('webconsole.js') << '</script>' end |
#render(javascript, variables = {}) ⇒ String
Inteprolates the given variables inside the javascrpt code
and its values
54 55 56 57 58 59 60 |
# File 'lib/rack/webconsole/asset_helpers.rb', line 54 def render(javascript, variables = {}) javascript_with_variables = javascript.dup variables.each_pair do |variable, value| javascript_with_variables.gsub!("$#{variable}", value) end javascript_with_variables end |