mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 00:05:42 +03:00
Compare commits
5 Commits
experiment
...
render-for
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
baf21ec3cc | ||
|
|
7f1e25005b | ||
|
|
938ca78be6 | ||
|
|
03a5375c8c | ||
|
|
a46610065a |
@@ -7,6 +7,7 @@ module Liquid
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
@blank = true
|
||||
@body = nil
|
||||
end
|
||||
|
||||
def parse(tokens)
|
||||
@@ -17,7 +18,7 @@ module Liquid
|
||||
|
||||
# For backwards compatibility
|
||||
def render(context)
|
||||
@body.render(context)
|
||||
@body&.render(context)
|
||||
end
|
||||
|
||||
def blank?
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
module Liquid
|
||||
class Tag
|
||||
attr_reader :nodelist, :tag_name, :line_number, :parse_context
|
||||
attr_reader :nodelist, :tag_name, :line_number, :parse_context, :markup
|
||||
alias_method :options, :parse_context
|
||||
include ParserSwitching
|
||||
|
||||
@@ -17,8 +17,6 @@ module Liquid
|
||||
disabled_tags.push(*tags)
|
||||
end
|
||||
|
||||
private :new
|
||||
|
||||
def disabled_tags
|
||||
@disabled_tags ||= []
|
||||
end
|
||||
|
||||
@@ -18,8 +18,7 @@ module Liquid
|
||||
|
||||
attr_reader :to, :from
|
||||
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
def parse(_tokens)
|
||||
if markup =~ Syntax
|
||||
@to = Regexp.last_match(1)
|
||||
@from = Variable.new(Regexp.last_match(2), options)
|
||||
|
||||
@@ -15,13 +15,13 @@ module Liquid
|
||||
class Capture < Block
|
||||
Syntax = /(#{VariableSignature}+)/o
|
||||
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
def parse(_tokens)
|
||||
if markup =~ Syntax
|
||||
@to = Regexp.last_match(1)
|
||||
else
|
||||
raise SyntaxError, options[:locale].t("errors.syntax.capture")
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
def render_to_output_buffer(context, output)
|
||||
|
||||
@@ -7,8 +7,7 @@ module Liquid
|
||||
|
||||
attr_reader :blocks, :left
|
||||
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
def parse(tokens)
|
||||
@blocks = []
|
||||
|
||||
if markup =~ Syntax
|
||||
@@ -16,9 +15,7 @@ module Liquid
|
||||
else
|
||||
raise SyntaxError, options[:locale].t("errors.syntax.case")
|
||||
end
|
||||
end
|
||||
|
||||
def parse(tokens)
|
||||
body = BlockBody.new
|
||||
body = @blocks.last.attachment while parse_body(body, tokens)
|
||||
end
|
||||
|
||||
@@ -19,8 +19,7 @@ module Liquid
|
||||
|
||||
attr_reader :variables
|
||||
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
def parse(_tokens)
|
||||
case markup
|
||||
when NamedSyntax
|
||||
@variables = variables_from_string(Regexp.last_match(2))
|
||||
|
||||
@@ -20,8 +20,7 @@ module Liquid
|
||||
# Hello: -3
|
||||
#
|
||||
class Decrement < Tag
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
def parse(_tokens)
|
||||
@variable = markup.strip
|
||||
end
|
||||
|
||||
|
||||
@@ -12,13 +12,14 @@ module Liquid
|
||||
# {% echo user | link %}
|
||||
#
|
||||
class Echo < Tag
|
||||
def initialize(tag_name, markup, parse_context)
|
||||
super
|
||||
attr_reader :variable
|
||||
|
||||
def parse(_tokens)
|
||||
@variable = Variable.new(markup, parse_context)
|
||||
end
|
||||
|
||||
def render(context)
|
||||
@variable.render_to_output_buffer(context, +'')
|
||||
variable&.render_to_output_buffer(context, +'')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -50,15 +50,11 @@ module Liquid
|
||||
|
||||
attr_reader :collection_name, :variable_name, :limit, :from
|
||||
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
def parse(tokens)
|
||||
@from = @limit = nil
|
||||
parse_with_selected_parser(markup)
|
||||
@for_block = BlockBody.new
|
||||
@else_block = nil
|
||||
end
|
||||
|
||||
def parse(tokens)
|
||||
return unless parse_body(@for_block, tokens)
|
||||
parse_body(@else_block, tokens)
|
||||
end
|
||||
|
||||
@@ -18,17 +18,13 @@ module Liquid
|
||||
|
||||
attr_reader :blocks
|
||||
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
@blocks = []
|
||||
push_block('if', markup)
|
||||
end
|
||||
|
||||
def nodelist
|
||||
@blocks.map(&:attachment)
|
||||
end
|
||||
|
||||
def parse(tokens)
|
||||
@blocks = []
|
||||
push_block('if', markup)
|
||||
while parse_body(@blocks.last.attachment, tokens)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,9 +21,7 @@ module Liquid
|
||||
|
||||
attr_reader :template_name_expr, :variable_name_expr, :attributes
|
||||
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
|
||||
def parse(_tokens)
|
||||
if markup =~ SYNTAX
|
||||
|
||||
template_name = Regexp.last_match(1)
|
||||
@@ -43,9 +41,6 @@ module Liquid
|
||||
end
|
||||
end
|
||||
|
||||
def parse(_tokens)
|
||||
end
|
||||
|
||||
def render_to_output_buffer(context, output)
|
||||
template_name = context.evaluate(@template_name_expr)
|
||||
raise ArgumentError, options[:locale].t("errors.argument.include") unless template_name
|
||||
|
||||
@@ -17,8 +17,7 @@ module Liquid
|
||||
# Hello: 2
|
||||
#
|
||||
class Increment < Tag
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
def parse(_tokens)
|
||||
@variable = markup.strip
|
||||
end
|
||||
|
||||
|
||||
@@ -5,13 +5,8 @@ module Liquid
|
||||
Syntax = /\A\s*\z/
|
||||
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
|
||||
|
||||
def initialize(tag_name, markup, parse_context)
|
||||
super
|
||||
|
||||
ensure_valid_markup(tag_name, markup, parse_context)
|
||||
end
|
||||
|
||||
def parse(tokens)
|
||||
ensure_valid_markup(tag_name, markup, parse_context)
|
||||
@body = +''
|
||||
while (token = tokens.shift)
|
||||
if token =~ FullTokenPossiblyInvalid
|
||||
|
||||
@@ -8,9 +8,7 @@ module Liquid
|
||||
|
||||
attr_reader :template_name_expr, :attributes
|
||||
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
|
||||
def parse(_tokens)
|
||||
raise SyntaxError, options[:locale].t("errors.syntax.render") unless markup =~ SYNTAX
|
||||
|
||||
template_name = Regexp.last_match(1)
|
||||
|
||||
@@ -6,8 +6,7 @@ module Liquid
|
||||
|
||||
attr_reader :variable_name, :collection_name, :attributes
|
||||
|
||||
def initialize(tag_name, markup, options)
|
||||
super
|
||||
def parse(_tokens)
|
||||
if markup =~ Syntax
|
||||
@variable_name = Regexp.last_match(1)
|
||||
@collection_name = Expression.parse(Regexp.last_match(2))
|
||||
@@ -18,6 +17,7 @@ module Liquid
|
||||
else
|
||||
raise SyntaxError, options[:locale].t("errors.syntax.table_row")
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
def render_to_output_buffer(context, output)
|
||||
|
||||
20
test/integration/tag_test.rb
Normal file
20
test/integration/tag_test.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class TagTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_all_tags_with_no_parse_can_render
|
||||
Template.tags.each do |key, _tag|
|
||||
Template.tags[key].new(key, '', ParseContext.new).render(Context.new)
|
||||
assert_nil(nil)
|
||||
end
|
||||
end
|
||||
|
||||
def test_all_tags_are_registered
|
||||
tags = Template.tags.map { |key, _tag| key }
|
||||
expected_tags = %w(assign break capture case comment continue cycle decrement echo for if ifchanged include increment raw render tablerow unless)
|
||||
assert_equal(expected_tags, tags.sort)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user