Class: Sibu::DynamicStyle
- Inherits:
-
Object
- Object
- Sibu::DynamicStyle
- Defined in:
- app/models/sibu/dynamic_style.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#scss_file ⇒ Object
readonly
Returns the value of attribute scss_file.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Class Method Summary collapse
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(site_id) ⇒ DynamicStyle
constructor
A new instance of DynamicStyle.
Constructor Details
#initialize(site_id) ⇒ DynamicStyle
Returns a new instance of DynamicStyle.
6 7 8 9 10 11 12 |
# File 'app/models/sibu/dynamic_style.rb', line 6 def initialize(site_id) @site = Sibu::Site.find(site_id) @filename = "#{site_id}_#{Time.current.to_i}" @scss_file = File.new(scss_file_path, 'w') @body = ERB.new(File.read(template_file_path)).result(binding) @env = Rails.application.assets end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'app/models/sibu/dynamic_style.rb', line 4 def body @body end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
4 5 6 |
# File 'app/models/sibu/dynamic_style.rb', line 4 def env @env end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'app/models/sibu/dynamic_style.rb', line 4 def filename @filename end |
#scss_file ⇒ Object (readonly)
Returns the value of attribute scss_file.
4 5 6 |
# File 'app/models/sibu/dynamic_style.rb', line 4 def scss_file @scss_file end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
4 5 6 |
# File 'app/models/sibu/dynamic_style.rb', line 4 def site @site end |
Class Method Details
Instance Method Details
#compile ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/sibu/dynamic_style.rb', line 14 def compile find_or_create_scss begin scss_file.write generate_css scss_file.flush scss_file.close css_file_path = scss_file_path.gsub('scss', 'css') File.rename(scss_file_path, css_file_path) site.update(style: File.new(css_file_path)) rescue Exception => ex Rails.logger.error(ex) ensure File.delete(scss_file_path) if scss_file_path && File.exist?(scss_file_path) File.delete(css_file_path) if css_file_path && File.exist?(css_file_path) end end |