liquor 0.1.1 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -9
- data/Gemfile +7 -0
- data/Guardfile +11 -0
- data/MIT-LICENSE +6 -2
- data/README.md +4 -122
- data/Rakefile +20 -23
- data/doc/language-spec.html +768 -0
- data/doc/language-spec.md +698 -0
- data/lib/liquor.rb +39 -68
- data/lib/liquor/ast_tools.rb +28 -0
- data/lib/liquor/compiler.rb +110 -0
- data/lib/liquor/context.rb +76 -254
- data/lib/liquor/diagnostics.rb +151 -0
- data/lib/liquor/drop/drop.rb +168 -0
- data/lib/liquor/drop/drop_delegation.rb +24 -0
- data/lib/liquor/drop/drop_scope.rb +118 -0
- data/lib/liquor/drop/dropable.rb +17 -0
- data/lib/liquor/emitter.rb +313 -0
- data/lib/liquor/extensions/kaminari.rb +14 -0
- data/lib/liquor/extensions/pagination.rb +235 -0
- data/lib/liquor/extensions/rails.rb +97 -0
- data/lib/liquor/extensions/thinking_sphinx.rb +14 -0
- data/lib/liquor/extensions/tire.rb +30 -0
- data/lib/liquor/external.rb +79 -0
- data/lib/liquor/function.rb +94 -0
- data/lib/liquor/grammar/lexer.rb +1223 -0
- data/lib/liquor/grammar/lexer.rl +297 -0
- data/lib/liquor/grammar/parser.racc +288 -0
- data/lib/liquor/grammar/parser.rb +885 -0
- data/lib/liquor/library.rb +41 -0
- data/lib/liquor/manager.rb +146 -0
- data/lib/liquor/runtime.rb +167 -0
- data/lib/liquor/stdlib/builtin_functions.rb +315 -0
- data/lib/liquor/stdlib/builtin_tags.rb +228 -0
- data/lib/liquor/stdlib/html_truncater.rb +162 -0
- data/lib/liquor/stdlib/partial_tags.rb +76 -0
- data/lib/liquor/tag.rb +83 -14
- data/lib/liquor/version.rb +1 -1
- data/liquor.gemspec +29 -6
- data/spec/builtins_spec.rb +264 -0
- data/spec/compiler_spec.rb +136 -0
- data/spec/context_spec.rb +49 -0
- data/spec/drop_delegation_spec.rb +21 -0
- data/spec/drop_spec.rb +222 -0
- data/spec/errors_spec.rb +40 -0
- data/spec/external_spec.rb +207 -0
- data/spec/function_spec.rb +80 -0
- data/spec/lexer_spec.rb +173 -0
- data/spec/library_spec.rb +18 -0
- data/spec/manager_spec.rb +84 -0
- data/spec/parser_spec.rb +381 -0
- data/spec/partials_spec.rb +74 -0
- data/spec/runtime_spec.rb +97 -0
- data/spec/spec_helper.rb +94 -0
- data/spec/tag_spec.rb +7 -0
- metadata +216 -173
- data/AUTHORS +0 -2
- data/CHANGELOG +0 -48
- data/Gemfile.lock +0 -91
- data/History.txt +0 -44
- data/LICENSE +0 -23
- data/example/server/example_servlet.rb +0 -37
- data/example/server/liquid_servlet.rb +0 -28
- data/example/server/liquor_servlet.rb +0 -28
- data/example/server/server.rb +0 -12
- data/example/server/templates/index.liquid +0 -6
- data/example/server/templates/index.liquor +0 -6
- data/example/server/templates/products.liquid +0 -45
- data/example/server/templates/products.liquor +0 -45
- data/init.rb +0 -8
- data/lib/extras/liquid_view.rb +0 -51
- data/lib/extras/liquor_view.rb +0 -51
- data/lib/liquor/block.rb +0 -101
- data/lib/liquor/condition.rb +0 -120
- data/lib/liquor/document.rb +0 -17
- data/lib/liquor/drop.rb +0 -256
- data/lib/liquor/errors.rb +0 -11
- data/lib/liquor/extensions.rb +0 -72
- data/lib/liquor/file_system.rb +0 -62
- data/lib/liquor/htmltags.rb +0 -74
- data/lib/liquor/module_ex.rb +0 -60
- data/lib/liquor/standardfilters.rb +0 -315
- data/lib/liquor/strainer.rb +0 -58
- data/lib/liquor/tags/assign.rb +0 -33
- data/lib/liquor/tags/capture.rb +0 -35
- data/lib/liquor/tags/case.rb +0 -83
- data/lib/liquor/tags/comment.rb +0 -9
- data/lib/liquor/tags/content_for.rb +0 -54
- data/lib/liquor/tags/cycle.rb +0 -59
- data/lib/liquor/tags/for.rb +0 -136
- data/lib/liquor/tags/if.rb +0 -80
- data/lib/liquor/tags/ifchanged.rb +0 -20
- data/lib/liquor/tags/include.rb +0 -56
- data/lib/liquor/tags/unless.rb +0 -33
- data/lib/liquor/tags/yield.rb +0 -49
- data/lib/liquor/template.rb +0 -181
- data/lib/liquor/variable.rb +0 -52
- data/performance/shopify.rb +0 -92
- data/performance/shopify/comment_form.rb +0 -33
- data/performance/shopify/database.rb +0 -45
- data/performance/shopify/json_filter.rb +0 -7
- data/performance/shopify/liquid.rb +0 -18
- data/performance/shopify/liquor.rb +0 -18
- data/performance/shopify/money_filter.rb +0 -18
- data/performance/shopify/paginate.rb +0 -93
- data/performance/shopify/shop_filter.rb +0 -98
- data/performance/shopify/tag_filter.rb +0 -25
- data/performance/shopify/vision.database.yml +0 -945
- data/performance/shopify/weight_filter.rb +0 -11
- data/performance/tests/dropify/article.liquid +0 -74
- data/performance/tests/dropify/blog.liquid +0 -33
- data/performance/tests/dropify/cart.liquid +0 -66
- data/performance/tests/dropify/collection.liquid +0 -22
- data/performance/tests/dropify/index.liquid +0 -47
- data/performance/tests/dropify/page.liquid +0 -8
- data/performance/tests/dropify/product.liquid +0 -68
- data/performance/tests/dropify/theme.liquid +0 -105
- data/performance/tests/ripen/article.liquid +0 -74
- data/performance/tests/ripen/blog.liquid +0 -13
- data/performance/tests/ripen/cart.liquid +0 -54
- data/performance/tests/ripen/collection.liquid +0 -29
- data/performance/tests/ripen/index.liquid +0 -32
- data/performance/tests/ripen/page.liquid +0 -4
- data/performance/tests/ripen/product.liquid +0 -75
- data/performance/tests/ripen/theme.liquid +0 -85
- data/performance/tests/tribble/404.liquid +0 -56
- data/performance/tests/tribble/article.liquid +0 -98
- data/performance/tests/tribble/blog.liquid +0 -41
- data/performance/tests/tribble/cart.liquid +0 -134
- data/performance/tests/tribble/collection.liquid +0 -70
- data/performance/tests/tribble/index.liquid +0 -94
- data/performance/tests/tribble/page.liquid +0 -56
- data/performance/tests/tribble/product.liquid +0 -116
- data/performance/tests/tribble/search.liquid +0 -51
- data/performance/tests/tribble/theme.liquid +0 -90
- data/performance/tests/vogue/article.liquid +0 -66
- data/performance/tests/vogue/blog.liquid +0 -32
- data/performance/tests/vogue/cart.liquid +0 -58
- data/performance/tests/vogue/collection.liquid +0 -19
- data/performance/tests/vogue/index.liquid +0 -22
- data/performance/tests/vogue/page.liquid +0 -3
- data/performance/tests/vogue/product.liquid +0 -62
- data/performance/tests/vogue/theme.liquid +0 -122
- data/test/assign_test.rb +0 -11
- data/test/block_test.rb +0 -58
- data/test/capture_test.rb +0 -41
- data/test/condition_test.rb +0 -115
- data/test/content_for_test.rb +0 -15
- data/test/context_test.rb +0 -479
- data/test/drop_test.rb +0 -162
- data/test/error_handling_test.rb +0 -89
- data/test/extra/breakpoint.rb +0 -547
- data/test/extra/caller.rb +0 -80
- data/test/file_system_test.rb +0 -30
- data/test/filter_test.rb +0 -147
- data/test/helper.rb +0 -24
- data/test/html_tag_test.rb +0 -31
- data/test/if_else_test.rb +0 -139
- data/test/include_tag_test.rb +0 -129
- data/test/module_ex_test.rb +0 -89
- data/test/output_test.rb +0 -121
- data/test/parsing_quirks_test.rb +0 -54
- data/test/regexp_test.rb +0 -45
- data/test/security_test.rb +0 -41
- data/test/standard_filter_test.rb +0 -170
- data/test/standard_tag_test.rb +0 -405
- data/test/statements_test.rb +0 -137
- data/test/strainer_test.rb +0 -27
- data/test/template_test.rb +0 -82
- data/test/test_helper.rb +0 -28
- data/test/unless_else_test.rb +0 -27
- data/test/variable_test.rb +0 -173
- data/test/yield_test.rb +0 -24
data/lib/liquor/tags/if.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
module Liquor
|
2
|
-
|
3
|
-
# If is the conditional block
|
4
|
-
#
|
5
|
-
# {% if user.admin %}
|
6
|
-
# Admin user!
|
7
|
-
# {% else %}
|
8
|
-
# Not admin user
|
9
|
-
# {% endif %}
|
10
|
-
#
|
11
|
-
# There are {% if count < 5 %} less {% else %} more {% endif %} items than you need.
|
12
|
-
#
|
13
|
-
#
|
14
|
-
class If < Block
|
15
|
-
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
|
16
|
-
Syntax = /(#{Expression})\s*([=!<>a-z_]+)?\s*(#{Expression})?/
|
17
|
-
ExpressionsAndOperators = /(?:and|or|(?:\s*(?!\b(?:and|or)\b)(?:#{Expression}|\S+)\s*)+)/
|
18
|
-
|
19
|
-
def initialize(tag_name, markup, tokens)
|
20
|
-
|
21
|
-
@blocks = []
|
22
|
-
|
23
|
-
push_block('if', markup)
|
24
|
-
|
25
|
-
super
|
26
|
-
end
|
27
|
-
|
28
|
-
def unknown_tag(tag, markup, tokens)
|
29
|
-
if ['elsif', 'else'].include?(tag)
|
30
|
-
push_block(tag, markup)
|
31
|
-
else
|
32
|
-
super
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def render(context)
|
37
|
-
context.stack do
|
38
|
-
@blocks.each do |block|
|
39
|
-
if block.evaluate(context)
|
40
|
-
return render_all(block.attachment, context)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
''
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def push_block(tag, markup)
|
50
|
-
block = if tag == 'else'
|
51
|
-
ElseCondition.new
|
52
|
-
else
|
53
|
-
|
54
|
-
expressions = markup.scan(ExpressionsAndOperators).reverse
|
55
|
-
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
56
|
-
|
57
|
-
condition = Condition.new($1, $2, $3)
|
58
|
-
|
59
|
-
while not expressions.empty?
|
60
|
-
operator = expressions.shift
|
61
|
-
|
62
|
-
raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax
|
63
|
-
|
64
|
-
new_condition = Condition.new($1, $2, $3)
|
65
|
-
new_condition.send(operator.to_sym, condition)
|
66
|
-
condition = new_condition
|
67
|
-
end
|
68
|
-
|
69
|
-
condition
|
70
|
-
end
|
71
|
-
|
72
|
-
@blocks.push(block)
|
73
|
-
@nodelist = block.attach(Array.new)
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
Template.register_tag('if', If)
|
80
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Liquor
|
2
|
-
class Ifchanged < Block
|
3
|
-
|
4
|
-
def render(context)
|
5
|
-
context.stack do
|
6
|
-
|
7
|
-
output = render_all(@nodelist, context)
|
8
|
-
|
9
|
-
if output != context.registers[:ifchanged]
|
10
|
-
context.registers[:ifchanged] = output
|
11
|
-
output
|
12
|
-
else
|
13
|
-
''
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Template.register_tag('ifchanged', Ifchanged)
|
20
|
-
end
|
data/lib/liquor/tags/include.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
module Liquor
|
2
|
-
class Include < Tag
|
3
|
-
Syntax = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?/
|
4
|
-
|
5
|
-
def initialize(tag_name, markup, tokens)
|
6
|
-
if markup =~ Syntax
|
7
|
-
|
8
|
-
@template_name = $1
|
9
|
-
@variable_name = $3
|
10
|
-
@attributes = {}
|
11
|
-
|
12
|
-
markup.scan(TagAttributes) do |key, value|
|
13
|
-
@attributes[key] = value
|
14
|
-
end
|
15
|
-
|
16
|
-
else
|
17
|
-
raise SyntaxError.new("Error in tag 'include' - Valid syntax: include '[template]' (with|for) [object|collection]")
|
18
|
-
end
|
19
|
-
|
20
|
-
super
|
21
|
-
end
|
22
|
-
|
23
|
-
def parse(tokens)
|
24
|
-
end
|
25
|
-
|
26
|
-
def render(context)
|
27
|
-
file_system = context.registers[:file_system] || Liquor::Template.file_system
|
28
|
-
source = file_system.read_template_file(context[@template_name])
|
29
|
-
partial = Liquor::Template.parse(source)
|
30
|
-
|
31
|
-
variable = context[@variable_name || @template_name[1..-2]]
|
32
|
-
|
33
|
-
context.stack do
|
34
|
-
@attributes.each do |key, value|
|
35
|
-
context[key] = context[value]
|
36
|
-
end
|
37
|
-
|
38
|
-
if variable.is_a?(Array)
|
39
|
-
|
40
|
-
variable.collect do |variable|
|
41
|
-
context[@template_name[1..-2]] = variable
|
42
|
-
partial.render(context)
|
43
|
-
end
|
44
|
-
|
45
|
-
else
|
46
|
-
|
47
|
-
context[@template_name[1..-2]] = variable
|
48
|
-
partial.render(context)
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
Template.register_tag('include', Include)
|
56
|
-
end
|
data/lib/liquor/tags/unless.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/if'
|
2
|
-
|
3
|
-
module Liquor
|
4
|
-
|
5
|
-
# Unless is a conditional just like 'if' but works on the inverse logic.
|
6
|
-
#
|
7
|
-
# {% unless x < 0 %} x is greater than zero {% end %}
|
8
|
-
#
|
9
|
-
class Unless < If
|
10
|
-
def render(context)
|
11
|
-
context.stack do
|
12
|
-
|
13
|
-
# First condition is interpreted backwards ( if not )
|
14
|
-
block = @blocks.first
|
15
|
-
unless block.evaluate(context)
|
16
|
-
return render_all(block.attachment, context)
|
17
|
-
end
|
18
|
-
|
19
|
-
# After the first condition unless works just like if
|
20
|
-
@blocks[1..-1].each do |block|
|
21
|
-
if block.evaluate(context)
|
22
|
-
return render_all(block.attachment, context)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
''
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
Template.register_tag('unless', Unless)
|
33
|
-
end
|
data/lib/liquor/tags/yield.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
module Liquor
|
2
|
-
|
3
|
-
# Within the context of a layout, yield identifies a section where content from the view should be inserted.
|
4
|
-
# The simplest way to use this is to have a single yield, into which the entire contents of the view currently
|
5
|
-
# being rendered is inserted.
|
6
|
-
#
|
7
|
-
# In your layout:
|
8
|
-
# <title>{% yield title %}</title>
|
9
|
-
# <body>{% yield %}</body>
|
10
|
-
#
|
11
|
-
# In the view:
|
12
|
-
# {% content_for title %} The title {% end_content_for %}
|
13
|
-
# The body
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# Will produce:
|
17
|
-
# <title>The title</title>
|
18
|
-
# <body>The body</body>
|
19
|
-
#
|
20
|
-
#
|
21
|
-
class Yield < Tag
|
22
|
-
Syntax = /(#{VariableSignature}+){0,1}/
|
23
|
-
|
24
|
-
def initialize(tag_name, markup, tokens)
|
25
|
-
if markup =~ Syntax
|
26
|
-
@what = $1
|
27
|
-
@what = "_rendered_template_" if @what.blank?
|
28
|
-
else
|
29
|
-
raise SyntaxError.new("Syntax Error in 'yield' - Valid syntax: yield [name]")
|
30
|
-
end
|
31
|
-
|
32
|
-
super
|
33
|
-
end
|
34
|
-
|
35
|
-
def render(context)
|
36
|
-
res = context["content_for"][@what]
|
37
|
-
if res.present? && res.is_a?(Array)
|
38
|
-
res = res.first
|
39
|
-
elsif res.blank?
|
40
|
-
res = ''
|
41
|
-
end
|
42
|
-
|
43
|
-
res
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
Template.register_tag('yield', Yield)
|
49
|
-
end
|
data/lib/liquor/template.rb
DELETED
@@ -1,181 +0,0 @@
|
|
1
|
-
module Liquor
|
2
|
-
|
3
|
-
# Templates are central to liquor.
|
4
|
-
# Interpretating templates is a two step process. First you compile the
|
5
|
-
# source code you got. During compile time some extensive error checking is performed.
|
6
|
-
# your code should expect to get some SyntaxErrors.
|
7
|
-
#
|
8
|
-
# After you have a compiled template you can then <tt>render</tt> it.
|
9
|
-
# You can use a compiled template over and over again and keep it cached.
|
10
|
-
#
|
11
|
-
# Example:
|
12
|
-
#
|
13
|
-
# template = Liquor::Template.parse(source)
|
14
|
-
# template.render('user_name' => 'bob')
|
15
|
-
#
|
16
|
-
class Template
|
17
|
-
attr_accessor :root
|
18
|
-
@@file_system = BlankFileSystem.new
|
19
|
-
|
20
|
-
class << self
|
21
|
-
def file_system
|
22
|
-
@@file_system
|
23
|
-
end
|
24
|
-
|
25
|
-
def file_system=(obj)
|
26
|
-
@@file_system = obj
|
27
|
-
end
|
28
|
-
|
29
|
-
def register_tag(name, klass)
|
30
|
-
tags[name.to_s] = klass
|
31
|
-
end
|
32
|
-
|
33
|
-
def tags
|
34
|
-
@tags ||= {}
|
35
|
-
end
|
36
|
-
|
37
|
-
# Pass a module with filter methods which should be available
|
38
|
-
# to all liquor views. Good for registering the standard library
|
39
|
-
def register_filter(mod)
|
40
|
-
Strainer.global_filter(mod)
|
41
|
-
end
|
42
|
-
|
43
|
-
def get_filters
|
44
|
-
Strainer.get_filters
|
45
|
-
end
|
46
|
-
|
47
|
-
# creates a new <tt>Template</tt> object from liquor source code
|
48
|
-
def parse(source)
|
49
|
-
template = Template.new
|
50
|
-
template.parse(source)
|
51
|
-
template
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# creates a new <tt>Template</tt> from an array of tokens. Use <tt>Template.parse</tt> instead
|
56
|
-
def initialize
|
57
|
-
end
|
58
|
-
|
59
|
-
# Parse source code.
|
60
|
-
# Returns self for easy chaining
|
61
|
-
def parse(source)
|
62
|
-
@root = Document.new(tokenize(source))
|
63
|
-
self
|
64
|
-
end
|
65
|
-
|
66
|
-
def registers
|
67
|
-
@registers ||= {}
|
68
|
-
end
|
69
|
-
|
70
|
-
def assigns
|
71
|
-
@assigns ||= {}
|
72
|
-
end
|
73
|
-
|
74
|
-
def instance_assigns
|
75
|
-
@instance_assigns ||= {}
|
76
|
-
end
|
77
|
-
|
78
|
-
def errors
|
79
|
-
@errors ||= []
|
80
|
-
end
|
81
|
-
|
82
|
-
# Render takes a hash with local variables.
|
83
|
-
#
|
84
|
-
# if you use the same filters over and over again consider registering them globally
|
85
|
-
# with <tt>Template.register_filter</tt>
|
86
|
-
#
|
87
|
-
# Following options can be passed:
|
88
|
-
#
|
89
|
-
# * <tt>filters</tt> : array with local filters
|
90
|
-
# * <tt>registers</tt> : hash with register variables. Those can be accessed from
|
91
|
-
# filters and tags and might be useful to integrate liquor more with its host application
|
92
|
-
# * <tt>layout</tt>: Liquor::Template object which describes layout for this template
|
93
|
-
#
|
94
|
-
|
95
|
-
def render(*args)
|
96
|
-
return '' if @root.nil?
|
97
|
-
|
98
|
-
context = case args.first
|
99
|
-
when Liquor::Context
|
100
|
-
args.first
|
101
|
-
when Hash
|
102
|
-
Context.new([args.first, assigns], instance_assigns, registers, @rethrow_errors)
|
103
|
-
when nil
|
104
|
-
Context.new(assigns, instance_assigns, registers, @rethrow_errors)
|
105
|
-
else
|
106
|
-
raise ArgumentError, "Expect Hash or Liquor::Context as parameter"
|
107
|
-
end
|
108
|
-
|
109
|
-
options = nil
|
110
|
-
case args.last
|
111
|
-
when Hash
|
112
|
-
options = args.last
|
113
|
-
|
114
|
-
if options[:registers].is_a?(Hash)
|
115
|
-
self.registers.merge!(options[:registers])
|
116
|
-
end
|
117
|
-
|
118
|
-
if options[:filters]
|
119
|
-
context.add_filters(options[:filters])
|
120
|
-
end
|
121
|
-
|
122
|
-
if options[:layout]
|
123
|
-
raise ArgumentError, "Expected Liquor::Template as layout argument" unless options[:layout].is_a? Liquor::Template
|
124
|
-
end
|
125
|
-
|
126
|
-
when Module
|
127
|
-
context.add_filters(args.last)
|
128
|
-
when Array
|
129
|
-
context.add_filters(args.last)
|
130
|
-
end
|
131
|
-
|
132
|
-
begin
|
133
|
-
# render the nodelist.
|
134
|
-
# for performance reasons we get a array back here. join will make a string out of it
|
135
|
-
res = @root.render(context).join
|
136
|
-
|
137
|
-
if options && options[:layout]
|
138
|
-
content_for_assigns = (context.has_key?("content_for") ? context["content_for"] : {})
|
139
|
-
content_for_assigns = content_for_assigns.merge({ "_rendered_template_" => res })
|
140
|
-
|
141
|
-
case args.first
|
142
|
-
when Liquor::Context
|
143
|
-
args.first["content_for"] = content_for_assigns
|
144
|
-
when Hash
|
145
|
-
args.first.merge!({ "content_for" => content_for_assigns })
|
146
|
-
end
|
147
|
-
|
148
|
-
layout_template = args.last.delete(:layout)
|
149
|
-
|
150
|
-
# Here we execute render method of the Liquor::Template object (we execute _this_ method)
|
151
|
-
# It is not the @root.render method. It is a result of the @root.render(context).join
|
152
|
-
# so we don't need to call join here.
|
153
|
-
res = layout_template.render(*args)
|
154
|
-
end
|
155
|
-
|
156
|
-
res
|
157
|
-
ensure
|
158
|
-
@errors = context.errors
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def render!(*args)
|
163
|
-
@rethrow_errors = true; render(*args)
|
164
|
-
end
|
165
|
-
|
166
|
-
private
|
167
|
-
|
168
|
-
# Uses the <tt>Liquor::TemplateParser</tt> regexp to tokenize the passed source
|
169
|
-
def tokenize(source)
|
170
|
-
source = source.source if source.respond_to?(:source)
|
171
|
-
return [] if source.to_s.empty?
|
172
|
-
tokens = source.split(TemplateParser)
|
173
|
-
|
174
|
-
# removes the rogue empty element at the beginning of the array
|
175
|
-
tokens.shift if tokens[0] and tokens[0].empty?
|
176
|
-
|
177
|
-
tokens
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
end
|
data/lib/liquor/variable.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
module Liquor
|
2
|
-
|
3
|
-
# Holds variables. Variables are only loaded "just in time"
|
4
|
-
# and are not evaluated as part of the render stage
|
5
|
-
#
|
6
|
-
# {{ monkey }}
|
7
|
-
# {{ user.name }}
|
8
|
-
#
|
9
|
-
# Variables can be combined with filters:
|
10
|
-
#
|
11
|
-
# {{ user | link }}
|
12
|
-
#
|
13
|
-
class Variable
|
14
|
-
FilterParser = /(?:#{FilterSeparator}|(?:\s*(?!(?:#{FilterSeparator}))(?:(?:#{StrictQuotedFragment})(?:#{FirstFilterArgument}(?:#{OtherFilterArgument})*)?|\S+)\s*)+)/
|
15
|
-
attr_accessor :filters, :name
|
16
|
-
|
17
|
-
def initialize(markup)
|
18
|
-
@markup = markup
|
19
|
-
@name = nil
|
20
|
-
@filters = []
|
21
|
-
if match = markup.match(/\s*(#{QuotedFragment})(.*)/)
|
22
|
-
@name = match[1]
|
23
|
-
if match[2].match(/#{FilterSeparator}\s*(.*)/)
|
24
|
-
filters = Regexp.last_match(1).scan(FilterParser)
|
25
|
-
filters.each do |f|
|
26
|
-
if matches = f.match(/\s*(\w+)/)
|
27
|
-
filtername = matches[1]
|
28
|
-
filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten
|
29
|
-
@filters << [filtername.to_sym, filterargs]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def render(context)
|
37
|
-
return '' if @name.nil?
|
38
|
-
@filters.inject(context[@name]) do |output, filter|
|
39
|
-
filterargs = filter[1].to_a.collect do |a|
|
40
|
-
context[a]
|
41
|
-
end
|
42
|
-
begin
|
43
|
-
context.invoke(filter[0], output, *filterargs)
|
44
|
-
rescue FilterNotFound
|
45
|
-
raise FilterNotFound, "Error - filter '#{filter[0]}' in '#{@markup.strip}' could not be found."
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|