Class: DynamicStyles::AssetCompiler
- Inherits:
-
Object
- Object
- DynamicStyles::AssetCompiler
- Defined in:
- lib/dynamic_styles/asset_compiler.rb
Instance Method Summary collapse
- #compile! ⇒ Object
- #compiled? ⇒ Boolean
- #digest ⇒ Object
-
#initialize(asset_path, scss_path = nil) ⇒ AssetCompiler
constructor
A new instance of AssetCompiler.
- #manifest_path ⇒ Object
- #precompilation? ⇒ Boolean
- #write_template!(string) ⇒ Object
Constructor Details
#initialize(asset_path, scss_path = nil) ⇒ AssetCompiler
Returns a new instance of AssetCompiler.
3 4 5 6 7 |
# File 'lib/dynamic_styles/asset_compiler.rb', line 3 def initialize(asset_path, scss_path=nil) @asset_path = asset_path @scss_path = Rails.root.join('app', 'assets', 'stylesheets', scss_path) @env = Rails.application.assets.instance_variable_get('@environment') if precompilation? end |
Instance Method Details
#compile! ⇒ Object
29 30 31 32 33 |
# File 'lib/dynamic_styles/asset_compiler.rb', line 29 def compile! if precompilation? Sprockets::Manifest.new(@env, self.manifest_path).compile(@asset_path) end end |
#compiled? ⇒ Boolean
13 14 15 16 17 18 19 |
# File 'lib/dynamic_styles/asset_compiler.rb', line 13 def compiled? if precompilation? @env.find_asset(@asset_path).present? else File.exists?(@scss_path) && !File.zero?(@scss_path) end end |
#digest ⇒ Object
21 22 23 |
# File 'lib/dynamic_styles/asset_compiler.rb', line 21 def digest @env.find_asset(@asset_path).digest end |
#manifest_path ⇒ Object
25 26 27 |
# File 'lib/dynamic_styles/asset_compiler.rb', line 25 def manifest_path File.join(Rails.public_path, Rails.application.config.assets.prefix) end |
#precompilation? ⇒ Boolean
9 10 11 |
# File 'lib/dynamic_styles/asset_compiler.rb', line 9 def precompilation? !Rails.application.config.assets.compile end |
#write_template!(string) ⇒ Object
35 36 37 |
# File 'lib/dynamic_styles/asset_compiler.rb', line 35 def write_template!(string) File.open(@scss_path, 'w') { |f| f.write(string) } end |