Class: Proscenium::SideLoad
Defined Under Namespace
Modules: Controller
Class Method Summary collapse
-
.sideload_inheritance_chain(obj, options) ⇒ Object
Side loads the class, and its super classes that respond to ‘.source_path`.
Class Method Details
.sideload_inheritance_chain(obj, options) ⇒ Object
Side loads the class, and its super classes that respond to ‘.source_path`.
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 instead of the regular side loading. You can use this to customise what is side loaded.
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 144 145 146 147 148 149 150 151 152 |
# File 'lib/proscenium/side_load.rb', line 111 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.abstract_class if klass.respond_to?(:sideload) klass.sideload elsif [:css] == false Importer.sideload klass.source_path, ** else Importer.sideload_js klass.source_path, ** css_imports << klass.source_path end klass = klass.superclass end # 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 i9n the # right direction. css_imports.reverse_each do |it| Importer.sideload_css it, ** end end |