Class: Proscenium::SideLoad
- Inherits:
-
Object
- Object
- Proscenium::SideLoad
- Defined in:
- lib/proscenium/side_load.rb
Defined Under Namespace
Modules: Controller
Constant Summary collapse
- JS_COMMENT =
'<!-- [PROSCENIUM_JAVASCRIPTS] -->'- CSS_COMMENT =
'<!-- [PROSCENIUM_STYLESHEETS] -->'
Class Method Summary collapse
-
.sideload_inheritance_chain(obj, options) ⇒ Object
Side loads assets for the class, and its super classes that respond to ‘.source_path`, which should return a Pathname of the class source file.
Class Method Details
.sideload_inheritance_chain(obj, options) ⇒ Object
Side loads assets for the class, and its super classes that respond to ‘.source_path`, which should return a Pathname of the class source file.
Set the ‘abstract_class` class variable to true in any class, and it will not be side loaded.
If the class responds to ‘.sideload`, it will be called after the regular side loading. You can use this to customise what is side loaded.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/proscenium/side_load.rb', line 91 def sideload_inheritance_chain(obj, ) return unless Proscenium.config.side_load = {} if .nil? = { js: , css: } unless .is_a?(Hash) unless obj..nil? = obj. = if .is_a?(Hash) .deep_merge else { js: , css: } end end i[css js].each do |k| [k] = obj.instance_eval(&[k]) if [k].is_a?(Proc) end css_imports = [] klass = obj.class while klass.respond_to?(:source_path) && klass.source_path && (klass.respond_to?(:abstract_class) ? !klass.abstract_class : true) if [:css] == false Importer.sideload klass.source_path, ** else Importer.sideload_js klass.source_path, ** css_imports << klass.source_path end klass.sideload if klass.respond_to?(:sideload) klass = klass.superclass end # All regular CSS files (*.css) are ancestrally sideloaded. However, the first CSS module # in the ancestry is also sideloaded in addition to the regular CSS files. This is because # the CSS module digest will be different for each file, so we only sideload the first CSS # module. css_imports.each do |it| # rubocop:disable Style/ItAssignment break if Importer.sideload_css_module(it, **).present? end # Sideload regular CSS files in reverse order. # # The reason why we sideload CSS after JS is because the order of CSS is important. # Basically, the layout should be loaded before the view so that CSS cascading works in the # right direction. css_imports.reverse_each do |it| # rubocop:disable Style/ItAssignment Importer.sideload_css it, ** end end |