Module: HelperExtensions::InstanceMethods
- Defined in:
- lib/helper_extensions.rb
Instance Method Summary (collapse)
-
- (Object) asset_scopes
:nodoc:.
-
- (Object) with_directory(*dirs)
Sets directory scope for asset tag helpers within the given block.
Instance Method Details
- (Object) asset_scopes
:nodoc:
12 13 14 |
# File 'lib/helper_extensions.rb', line 12 def asset_scopes #:nodoc: @asset_scopes ||= [] end |
- (Object) with_directory(*dirs)
Sets directory scope for asset tag helpers within the given block.
Affects any helper using compute_public_path among which are: javascript_include_tag, stylesheet_include_tag and image_tag.
Arguments
- dir:
-
Either a string, array or number of strings to define the containing directory.
Examples
<% with_directory 'ext' do %>
<%= javascript_include_tag 'adapter/ext/ext-base.js', 'ext-all.js' %>
<%= stylesheet_include_tag 'ext-all.css' %>
<% end %>
Will generate:
<script ... src="/javascripts/ext/adapter/ext/ext-base.js" ...></script>
<script ... src="/javascripts/ext/ext-all.js" ...></script>
<link ... href="/stylesheets/ext/ext-all.css" .../>
Multiple containing directories:
<% with_directory 'ext/ux' do %>
<%= javascript_include_tag 'Sorter', 'Sortlet' %>
<% end %>
or with seperate arguments:
<% with_directory 'ext', 'ux' do %>
<%= javascript_include_tag 'Sorter', 'Sortlet' %>
<% end %>
or with an array of directory names:
<% with_directory %w(ext ux) do %>
<%= javascript_include_tag 'Sorter', 'Sortlet' %>
<% end %>
or by nesting:
<% with_directory 'ext' do %>
<% with_directory 'ux' do %>
<%= javascript_include_tag 'Sorter', 'Sortlet' %>
<% end %>
<% end %>
Will generate:
<script ... src="/javascripts/ext/ux/Sorter.js" ...></script>
<script ... src="/javascripts/ext/ux/Sortlet.js" ...></script>
70 71 72 73 74 75 76 77 |
# File 'lib/helper_extensions.rb', line 70 def with_directory(*dirs) self.asset_scopes << dirs begin yield ensure self.asset_scopes.pop end end |