Class: DynamicStyles::Stylesheet
- Inherits:
-
Object
- Object
- DynamicStyles::Stylesheet
- Defined in:
- lib/dynamic_styles/stylesheet.rb
Instance Method Summary collapse
- #asset_path ⇒ Object
- #base_filename ⇒ Object
- #base_path ⇒ Object
- #compile ⇒ Object
- #compiler ⇒ Object
- #digested_path ⇒ Object
-
#initialize(layout) ⇒ Stylesheet
constructor
A new instance of Stylesheet.
- #path ⇒ Object
- #public_path ⇒ Object
- #render_template ⇒ Object
- #scss_path ⇒ Object
- #template_name ⇒ Object
- #undigested_path ⇒ Object
Constructor Details
#initialize(layout) ⇒ Stylesheet
Returns a new instance of Stylesheet.
8 9 10 |
# File 'lib/dynamic_styles/stylesheet.rb', line 8 def initialize(layout) @layout = layout end |
Instance Method Details
#asset_path ⇒ Object
24 25 26 |
# File 'lib/dynamic_styles/stylesheet.rb', line 24 def asset_path "#{base_path}.css" end |
#base_filename ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/dynamic_styles/stylesheet.rb', line 44 def base_filename [ @layout.id, @layout.updated_at.to_s(:number), template_name ].join('-') end |
#base_path ⇒ Object
20 21 22 |
# File 'lib/dynamic_styles/stylesheet.rb', line 20 def base_path "#{template_name.pluralize}/#{base_filename}" end |
#compile ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/dynamic_styles/stylesheet.rb', line 57 def compile unless compiled? write_template!(render_template) compile! # cleanup end end |
#compiler ⇒ Object
12 13 14 |
# File 'lib/dynamic_styles/stylesheet.rb', line 12 def compiler AssetCompiler.new(asset_path, scss_path) end |
#digested_path ⇒ Object
36 37 38 |
# File 'lib/dynamic_styles/stylesheet.rb', line 36 def digested_path "/assets/#{base_path}-#{digest}.css" end |
#path ⇒ Object
52 53 54 55 |
# File 'lib/dynamic_styles/stylesheet.rb', line 52 def path compile public_path end |
#public_path ⇒ Object
16 17 18 |
# File 'lib/dynamic_styles/stylesheet.rb', line 16 def public_path precompilation? ? digested_path : undigested_path end |
#render_template ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/dynamic_styles/stylesheet.rb', line 65 def render_template class_name = @layout.class.to_s controller = (class_name.pluralize + "Controller").constantize controller.new.render_to_string template_name, formats: [:scss], layout: false, locals: { :"#{class_name.downcase}" => @layout } end |
#scss_path ⇒ Object
28 29 30 |
# File 'lib/dynamic_styles/stylesheet.rb', line 28 def scss_path "#{base_path}.scss" end |
#template_name ⇒ Object
40 41 42 |
# File 'lib/dynamic_styles/stylesheet.rb', line 40 def template_name @layout.class.to_s.downcase.split('::').last end |
#undigested_path ⇒ Object
32 33 34 |
# File 'lib/dynamic_styles/stylesheet.rb', line 32 def undigested_path "/assets/#{base_path}.css" end |