Module: ViewComponent::Styles::Component
- Defined in:
- lib/view_component/styles/component.rb
Instance Method Summary collapse
Instance Method Details
#asset_exists?(path) ⇒ Boolean
6 7 8 9 10 11 12 13 14 |
# File 'lib/view_component/styles/component.rb', line 6 def asset_exists?(path) if Rails.configuration.assets.compile # Dynamic compilation Rails.application.assets.find_asset(path).present? else # Pre-compiled Rails.application.assets_manifest.assets[path].present? end end |
#component_stylesheet_name ⇒ Object
16 17 18 |
# File 'lib/view_component/styles/component.rb', line 16 def component_stylesheet_name "#{name.underscore}.css" end |
#inherited(subclass) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/view_component/styles/component.rb', line 20 def inherited(subclass) super subclass.include(ViewComponent::Styles::Helper) component_stylesheet_name = subclass.component_stylesheet_name subclass.prepend(Module.new.tap do |m| m.class_eval(" # def before_render\n # super\n # return unless self.class.asset_exists?(\"example\")\n # singleton_stylesheet_link_tag(\"example\")\n # end\n def before_render\n super\n return unless self.class.asset_exists?(\#{component_stylesheet_name.inspect})\n singleton_stylesheet_link_tag(\#{component_stylesheet_name.inspect})\n end\n RUBY\n end)\nend\n", __FILE__, __LINE__ + 1) |