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
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
Constants inherited from Block
Block::ContentOfVariable, Block::FullToken, Block::IsTag, Block::IsVariable
Instance Attribute Summary
Attributes inherited from Tag
#line, #nodelist, #options, #warnings
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens, options) ⇒ If
constructor
A new instance of If.
- #render(context) ⇒ Object
- #unknown_tag(tag, markup, tokens) ⇒ Object
Methods inherited from Block
#blank?, #block_delimiter, #block_name, #create_variable, #end_tag, #parse, #warnings
Methods inherited from Tag
#blank?, #name, new_with_options, #parse, #parse_with_selected_parser
Constructor Details
#initialize(tag_name, markup, tokens, options) ⇒ If
Returns a new instance of If.
16 17 18 19 20 |
# File 'lib/liquid/tags/if.rb', line 16 def initialize(tag_name, markup, tokens, ) @blocks = [] push_block('if', markup) super end |
Instance Method Details
#render(context) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/liquid/tags/if.rb', line 30 def render(context) context.stack do @blocks.each do |block| if block.evaluate(context) return render_all(block., context) end end '' end end |
#unknown_tag(tag, markup, tokens) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/liquid/tags/if.rb', line 22 def unknown_tag(tag, markup, tokens) if ['elsif', 'else'].include?(tag) push_block(tag, markup) else super end end |