Class: LuxAssets::Element
- Inherits:
-
Object
- Object
- LuxAssets::Element
- Defined in:
- lib/lux_assets/element.rb
Overview
One file that can be scss, js, coffee, ts, etc…
Instance Method Summary collapse
-
#compile(force: nil, production: nil) ⇒ Object
use LuxAsset.compile if possible.
- #content_type ⇒ Object
-
#initialize(source) ⇒ Element
constructor
A new instance of Element.
Constructor Details
#initialize(source) ⇒ Element
Returns a new instance of Element.
5 6 7 8 9 10 11 |
# File 'lib/lux_assets/element.rb', line 5 def initialize source @source = Pathname.new source source = source.sub(/^\.\//, '').sub(/^\//, '').gsub('/', '-') source = '%s-%s' % [@production ? :p : :d, source] if content_type == 'text/css' @cache = Pathname.new './tmp/assets/%s' % source end |
Instance Method Details
#compile(force: nil, production: nil) ⇒ Object
use LuxAsset.compile if possible
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lux_assets/element.rb', line 19 def compile force:nil, production:nil @production = production || false method_name = 'compile_%s' % @source.to_s.split('.').last.downcase if respond_to?(method_name, true) (!force && cached) || send(method_name) else @source.read end end |
#content_type ⇒ Object
13 14 15 16 |
# File 'lib/lux_assets/element.rb', line 13 def content_type @ext ||= @source.to_s.split('.').last.to_sym [:css, :scss].include?(@ext) ? 'text/css' : 'text/javascript' end |