Class: Mjml::Cache
- Inherits:
-
Object
- Object
- Mjml::Cache
- Defined in:
- lib/mjml/cache.rb
Instance Attribute Summary collapse
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
Instance Method Summary collapse
- #cache { ... } ⇒ String
-
#initialize(template_path) ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(template_path) ⇒ Cache
Returns a new instance of Cache.
7 8 9 |
# File 'lib/mjml/cache.rb', line 7 def initialize(template_path) @template_path = template_path end |
Instance Attribute Details
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
5 6 7 |
# File 'lib/mjml/cache.rb', line 5 def template_path @template_path end |
Instance Method Details
#cache { ... } ⇒ String
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mjml/cache.rb', line 13 def cache(&block) return yield if !Mjml.cache_mjml && block cached_path = cached_file_path if File.exist?(cached_path) File.read(cached_path) else html_content = yield if block File.write(cached_path, html_content) html_content end end |