Class: Liquid::If
Overview
If is the conditional block
{% if user.admin %}
Admin user!
{% else %}
Not admin user
{% endif %}
There are {% if count < 5 %} less {% else %} more {% endif %} items than you need.
Direct Known Subclasses
Defined Under Namespace
Classes: ParseTreeVisitor
Constant Summary collapse
- Syntax =
/(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/o
- ExpressionsAndOperators =
/(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/o
- BOOLEAN_OPERATORS =
%w(and or)
Constants inherited from Block
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
Attributes inherited from Tag
#line_number, #parse_context, #tag_name
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ If
constructor
A new instance of If.
- #nodelist ⇒ Object
- #parse(tokens) ⇒ Object
- #render(context) ⇒ Object
- #unknown_tag(tag, markup, tokens) ⇒ Object
Methods inherited from Block
#blank?, #block_delimiter, #block_name
Methods inherited from Tag
Methods included from ParserSwitching
Constructor Details
#initialize(tag_name, markup, options) ⇒ If
Returns a new instance of If.
19 20 21 22 23 |
# File 'lib/liquid/tags/if.rb', line 19 def initialize(tag_name, markup, ) super @blocks = [] push_block('if'.freeze, markup) end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
17 18 19 |
# File 'lib/liquid/tags/if.rb', line 17 def blocks @blocks end |
Instance Method Details
#nodelist ⇒ Object
25 26 27 |
# File 'lib/liquid/tags/if.rb', line 25 def nodelist @blocks.map(&:attachment) end |
#parse(tokens) ⇒ Object
29 30 31 32 |
# File 'lib/liquid/tags/if.rb', line 29 def parse(tokens) while parse_body(@blocks.last., tokens) end end |
#render(context) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/liquid/tags/if.rb', line 42 def render(context) context.stack do @blocks.each do |block| if block.evaluate(context) return block..render(context) end end ''.freeze end end |
#unknown_tag(tag, markup, tokens) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/liquid/tags/if.rb', line 34 def unknown_tag(tag, markup, tokens) if ['elsif'.freeze, 'else'.freeze].include?(tag) push_block(tag, markup) else super end end |