Class: LuxAssets::Element
- Inherits:
-
Object
- Object
- LuxAssets::Element
- Defined in:
- lib/lux_assets/element.rb
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.
7 8 9 10 11 12 13 |
# File 'lib/lux_assets/element.rb', line 7 def initialize source @source = @cache_source = Pathname.new source @target = source.sub(/^\.\//, '').sub(/^\//, '').gsub('/', '-') @target = '%s-%s' % [@production ? :p : :d, @target] if content_type == 'text/css' @cache = Pathname.new './tmp/assets/%s' % @target end |
Instance Method Details
#compile(force: nil, production: nil) ⇒ Object
use LuxAsset.compile if possible
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lux_assets/element.rb', line 21 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) || ( process_erb; send(method_name)) else @source.read end end |
#content_type ⇒ Object
15 16 17 18 |
# File 'lib/lux_assets/element.rb', line 15 def content_type @ext ||= @source.to_s.split('.').last.to_sym [:css, :scss].include?(@ext) ? 'text/css' : 'text/javascript' end |