Class: Liquid::ParseEnvironment
- Inherits:
-
Object
- Object
- Liquid::ParseEnvironment
- Includes:
- Singleton
- Defined in:
- app/lib/liquid/parse_environment.rb
Overview
Library code: parse environment.
Defined Under Namespace
Classes: RawFallbackTemplate
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ ParseEnvironment
constructor
A new instance of ParseEnvironment.
-
#parse(content) ⇒ Object
Forgiving parse for the RENDER path — a template already in the database must still send, so a syntax error degrades to RawFallbackTemplate rather than blowing up an order confirmation.
-
#parse!(content) ⇒ Object
Strict parse for the SAVE path — raises Liquid::SyntaxError so a validation can surface it to whoever is editing the template.
Constructor Details
#initialize ⇒ ParseEnvironment
Returns a new instance of ParseEnvironment.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/lib/liquid/parse_environment.rb', line 11 def initialize @environment = Liquid::Environment.new @environment.error_mode = :warn @environment.register_filter(Liquid::Filters::Helpers) @environment.register_tag('image_tag', Liquid::Tags::Image) @environment.register_tag('partial', Liquid::Tags::Partial) @environment.register_tag('floor_heating_calculator', Liquid::Tags::FloorHeatingCalculator) @environment.register_tag('snow_melting_calculator', Liquid::Tags::SnowMeltingCalculator) @environment.register_tag('electricity_cost', Liquid::Tags::ElectricityCost) @environment.register_tag('product_price', Liquid::Tags::ProductPrice) end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
9 10 11 |
# File 'app/lib/liquid/parse_environment.rb', line 9 def environment @environment end |
Class Method Details
.parse(content) ⇒ Object
46 47 48 |
# File 'app/lib/liquid/parse_environment.rb', line 46 def self.parse(content) instance.parse(content) end |
.parse!(content) ⇒ Object
50 51 52 |
# File 'app/lib/liquid/parse_environment.rb', line 50 def self.parse!(content) instance.parse!(content) end |
Instance Method Details
#parse(content) ⇒ Object
Forgiving parse for the RENDER path — a template already in the database
must still send, so a syntax error degrades to RawFallbackTemplate
rather than blowing up an order confirmation.
Use #parse! on the SAVE path instead. Rescuing here means callers that
write rescue Liquid::SyntaxError around this method are unreachable.
31 32 33 34 35 36 |
# File 'app/lib/liquid/parse_environment.rb', line 31 def parse(content) parse!(content) rescue Liquid::SyntaxError => e ErrorReporting.error(e, context: "Liquid parse failed for content (#{content.to_s[0, 80]}...)") RawFallbackTemplate.new(content) end |
#parse!(content) ⇒ Object
Strict parse for the SAVE path — raises Liquid::SyntaxError so a
validation can surface it to whoever is editing the template.
42 43 44 |
# File 'app/lib/liquid/parse_environment.rb', line 42 def parse!(content) Liquid::Template.parse(content, environment: @environment) end |