Class: Newsly::LiquidModel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Newsly::LiquidModel
- Defined in:
- app/models/newsly/liquid_model.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#after_validation ⇒ Object
Puts the parse error from Liquid on the error list if parsing failed.
-
#body=(text) ⇒ Object
body contains the raw internal_template.
-
#render(options = {}) ⇒ Object
Methods.
Instance Method Details
#after_validation ⇒ Object
Puts the parse error from Liquid on the error list if parsing failed
9 10 11 |
# File 'app/models/newsly/liquid_model.rb', line 9 def after_validation errors.add :internal_template, @syntax_error unless @syntax_error.nil? end |
#body=(text) ⇒ Object
body contains the raw internal_template. When updating this attribute, the template parses the internal_template and stores the serialized object for quicker rendering.
23 24 25 26 27 28 29 30 31 |
# File 'app/models/newsly/liquid_model.rb', line 23 def body=(text) self[:body] = text begin @internal_template = Liquid::Template.parse(text) self[:internal_template] = [Marshal.dump(@internal_template)].pack('m*') rescue Liquid::SyntaxError => error @syntax_error = error. end end |
#render(options = {}) ⇒ Object
Methods
Renders body as Liquid Markup template
37 38 39 |
# File 'app/models/newsly/liquid_model.rb', line 37 def render( = {}) internal_template.render end |