Class: Pakunok::AssetRenderers::ScriptRenderer
- Inherits:
-
Object
- Object
- Pakunok::AssetRenderers::ScriptRenderer
- Defined in:
- lib/pakunok/renderers/script_renderer.rb
Instance Method Summary collapse
-
#initialize(pakunok) ⇒ ScriptRenderer
constructor
A new instance of ScriptRenderer.
- #render(context, path) ⇒ Object
- #render_asset(context, asset) ⇒ Object
- #separator ⇒ Object
Constructor Details
#initialize(pakunok) ⇒ ScriptRenderer
Returns a new instance of ScriptRenderer.
5 6 7 |
# File 'lib/pakunok/renderers/script_renderer.rb', line 5 def initialize(pakunok) @pakunok = pakunok end |
Instance Method Details
#render(context, path) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/pakunok/renderers/script_renderer.rb', line 9 def render(context, path) asset = @pakunok.asset(path) parts = asset.full_dependencies.map do |dep| render_asset(context, dep) end + [render_asset(context, asset)] parts.join(separator) end |
#render_asset(context, asset) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pakunok/renderers/script_renderer.rb', line 21 def render_asset(context, asset) resource = context.asset_paths.asset_environment[asset.path] raise "Asset #{asset.path} is not available in rails. Check the pakunok configuration, you could misspell something." unless resource async_attr = asset.async? ? " async='async'" : '' if asset. "<script type='text/javascript'#{async_attr}>\n" + resource.to_s + "\n</script>" else "<script type='text/javascript' src='#{asset.url(context)}'#{async_attr}></script>" end end |
#separator ⇒ Object
17 18 19 |
# File 'lib/pakunok/renderers/script_renderer.rb', line 17 def separator "\n" end |