Module: Proscenium::Helper
- Defined in:
- lib/proscenium/helper.rb
Instance Method Summary collapse
-
#class_names(*names, path: nil) ⇒ String
The transformed CSS module names concatenated as a string.
-
#compute_asset_path(path, options = {}) ⇒ Object
Overriden to allow regular use of javascript_include_tag and stylesheet_link_tag, while still building with Proscenium.
-
#css_module(*names, path: nil) ⇒ String
Accepts one or more CSS class names, and transforms them into CSS module names.
- #include_assets ⇒ Object
-
#include_javascripts ⇒ String
Includes all javascripts that have been imported and side loaded.
- #include_stylesheets ⇒ Object
- #sideload_assets(value) ⇒ Object
Instance Method Details
#class_names(*names, path: nil) ⇒ String
Returns the transformed CSS module names concatenated as a string.
46 47 48 49 50 51 52 53 |
# File 'lib/proscenium/helper.rb', line 46 def class_names(*names, path: nil) names = names.flatten.compact return if names.empty? path ||= Pathname.new(@lookup_context.find(@virtual_path).identifier).sub_ext('') CssModule::Transformer.new(path).class_names(*names).map { |name, _| name }.join(' ') end |
#compute_asset_path(path, options = {}) ⇒ Object
Overriden to allow regular use of javascript_include_tag and stylesheet_link_tag, while still building with Proscenium. It’s important to note that ‘include_assets` will not call this, as those asset paths all begin with a slash, which the Rails asset helpers do not pass through to here.
If the given ‘path` is a bare path (does not start with `./` or `../`), then we use Rails default conventions, and serve CSS from /app/assets/stylesheets and JS from /app/javascript.
22 23 24 25 26 27 28 29 |
# File 'lib/proscenium/helper.rb', line 22 def compute_asset_path(path, = {}) if %i[javascript stylesheet].include?([:type]) path.prepend DEFAULT_RAILS_ASSET_PATHS[[:type]] if !path.start_with?('./', '../') return path end super end |
#css_module(*names, path: nil) ⇒ String
Accepts one or more CSS class names, and transforms them into CSS module names.
37 38 39 40 41 |
# File 'lib/proscenium/helper.rb', line 37 def css_module(*names, path: nil) path ||= Pathname.new(@lookup_context.find(@virtual_path).identifier).sub_ext('') CssModule::Transformer.new(path).class_names(*names, require_prefix: false) .map { |name, _| name }.join(' ') end |
#include_assets ⇒ Object
55 56 57 |
# File 'lib/proscenium/helper.rb', line 55 def include_assets include_stylesheets + include_javascripts end |
#include_javascripts ⇒ String
Includes all javascripts that have been imported and side loaded.
66 67 68 |
# File 'lib/proscenium/helper.rb', line 66 def include_javascripts SideLoad::JS_COMMENT.html_safe end |
#include_stylesheets ⇒ Object
59 60 61 |
# File 'lib/proscenium/helper.rb', line 59 def include_stylesheets SideLoad::CSS_COMMENT.html_safe end |
#sideload_assets(value) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/proscenium/helper.rb', line 5 def sideload_assets(value) if value.nil? @current_template.instance_variable_defined?(:@sideload_assets_options) && @current_template.remove_instance_variable(:@sideload_assets_options) else @current_template.instance_variable_set :@sideload_assets_options, value end end |