liquid 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/Manifest.txt +1 -1
- data/README.md +42 -0
- data/lib/liquid.rb +1 -0
- data/lib/liquid/tag.rb +3 -3
- data/lib/liquid/tags/comment.rb +5 -5
- data/lib/liquid/tags/if.rb +41 -42
- data/lib/liquid/template.rb +1 -1
- metadata +7 -7
- data/README.txt +0 -38
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Liquid template engine
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
Liquid is a template engine which I wrote for very specific requirements
|
6
|
+
|
7
|
+
* It has to have beautiful and simple markup. Template engines which don't produce good looking markup are no fun to use.
|
8
|
+
* It needs to be non evaling and secure. Liquid templates are made so that users can edit them. You don't want to run code on your server which your users wrote.
|
9
|
+
* It has to be stateless. Compile and render steps have to be seperate so that the expensive parsing and compiling can be done once and later on you can just render it passing in a hash with local variables and objects.
|
10
|
+
|
11
|
+
## Why should I use Liquid
|
12
|
+
|
13
|
+
* You want to allow your users to edit the appearance of your application but don't want them to run **insecure code on your server**.
|
14
|
+
* You want to render templates directly from the database
|
15
|
+
* You like smarty (PHP) style template engines
|
16
|
+
* You need a template engine which does HTML just as well as emails
|
17
|
+
* You don't like the markup of your current templating engine
|
18
|
+
|
19
|
+
## What does it look like?
|
20
|
+
|
21
|
+
<code>
|
22
|
+
<ul id="products">
|
23
|
+
{% for product in products %}
|
24
|
+
<li>
|
25
|
+
<h2>{{product.name}}</h2>
|
26
|
+
Only {{product.price | price }}
|
27
|
+
|
28
|
+
{{product.description | prettyprint | paragraph }}
|
29
|
+
</li>
|
30
|
+
{% endfor %}
|
31
|
+
</ul>
|
32
|
+
</code>
|
33
|
+
|
34
|
+
## Howto use Liquid
|
35
|
+
|
36
|
+
Liquid supports a very simple API based around the Liquid::Template class.
|
37
|
+
For standard use you can just pass it the content of a file and call render with a parameters hash.
|
38
|
+
|
39
|
+
<pre>
|
40
|
+
@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
|
41
|
+
@template.render( 'name' => 'tobi' ) # => "hi tobi"
|
42
|
+
</pre>
|
data/lib/liquid.rb
CHANGED
@@ -45,6 +45,7 @@ module Liquid
|
|
45
45
|
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/
|
46
46
|
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/
|
47
47
|
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/
|
48
|
+
LiteralShorthand = /^(?:\{\{\{\s?)(.*?)(?:\s*\}\}\})$/
|
48
49
|
end
|
49
50
|
|
50
51
|
require 'liquid/drop'
|
data/lib/liquid/tag.rb
CHANGED
data/lib/liquid/tags/comment.rb
CHANGED
data/lib/liquid/tags/if.rb
CHANGED
@@ -14,17 +14,16 @@ module Liquid
|
|
14
14
|
class If < Block
|
15
15
|
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
|
16
16
|
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/
|
17
|
-
ExpressionsAndOperators = /(?:\b(
|
18
|
-
|
19
|
-
def initialize(tag_name, markup, tokens)
|
20
|
-
|
17
|
+
ExpressionsAndOperators = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
|
18
|
+
|
19
|
+
def initialize(tag_name, markup, tokens)
|
21
20
|
@blocks = []
|
22
|
-
|
21
|
+
|
23
22
|
push_block('if', markup)
|
24
|
-
|
25
|
-
super
|
23
|
+
|
24
|
+
super
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
def unknown_tag(tag, markup, tokens)
|
29
28
|
if ['elsif', 'else'].include?(tag)
|
30
29
|
push_block(tag, markup)
|
@@ -32,49 +31,49 @@ module Liquid
|
|
32
31
|
super
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
def render(context)
|
37
36
|
context.stack do
|
38
37
|
@blocks.each do |block|
|
39
|
-
if block.evaluate(context)
|
40
|
-
return render_all(block.attachment, context)
|
38
|
+
if block.evaluate(context)
|
39
|
+
return render_all(block.attachment, context)
|
41
40
|
end
|
42
|
-
end
|
41
|
+
end
|
43
42
|
''
|
44
43
|
end
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
private
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
47
|
+
|
48
|
+
def push_block(tag, markup)
|
49
|
+
block = if tag == 'else'
|
50
|
+
ElseCondition.new
|
51
|
+
else
|
52
|
+
|
53
|
+
expressions = markup.scan(ExpressionsAndOperators).reverse
|
54
|
+
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
55
|
+
|
56
|
+
condition = Condition.new($1, $2, $3)
|
57
|
+
|
58
|
+
while not expressions.empty?
|
59
|
+
operator = (expressions.shift).to_s.strip
|
60
|
+
|
61
|
+
raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax
|
62
|
+
|
63
|
+
new_condition = Condition.new($1, $2, $3)
|
64
|
+
new_condition.send(operator.to_sym, condition)
|
65
|
+
condition = new_condition
|
66
|
+
end
|
67
|
+
|
68
|
+
condition
|
69
|
+
end
|
70
|
+
|
71
|
+
@blocks.push(block)
|
72
|
+
@nodelist = block.attach(Array.new)
|
70
73
|
end
|
71
|
-
|
72
|
-
|
73
|
-
@nodelist = block.attach(Array.new)
|
74
|
-
end
|
75
|
-
|
76
|
-
|
74
|
+
|
75
|
+
|
77
76
|
end
|
78
77
|
|
79
78
|
Template.register_tag('if', If)
|
80
|
-
end
|
79
|
+
end
|
data/lib/liquid/template.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 2.2.
|
9
|
+
- 1
|
10
|
+
version: 2.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Luetke
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-23 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -28,13 +28,13 @@ extensions: []
|
|
28
28
|
extra_rdoc_files:
|
29
29
|
- History.txt
|
30
30
|
- Manifest.txt
|
31
|
-
- README.
|
31
|
+
- README.md
|
32
32
|
files:
|
33
33
|
- CHANGELOG
|
34
34
|
- History.txt
|
35
35
|
- MIT-LICENSE
|
36
36
|
- Manifest.txt
|
37
|
-
- README.
|
37
|
+
- README.md
|
38
38
|
- Rakefile
|
39
39
|
- lib/extras/liquid_view.rb
|
40
40
|
- lib/liquid.rb
|
@@ -70,7 +70,7 @@ licenses: []
|
|
70
70
|
post_install_message:
|
71
71
|
rdoc_options:
|
72
72
|
- --main
|
73
|
-
- README.
|
73
|
+
- README.md
|
74
74
|
require_paths:
|
75
75
|
- lib
|
76
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/README.txt
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
= Liquid template engine
|
2
|
-
|
3
|
-
Liquid is a template engine which I wrote for very specific requirements
|
4
|
-
|
5
|
-
* It has to have beautiful and simple markup.
|
6
|
-
Template engines which don't produce good looking markup are no fun to use.
|
7
|
-
* It needs to be non evaling and secure. Liquid templates are made so that users can edit them. You don't want to run code on your server which your users wrote.
|
8
|
-
* It has to be stateless. Compile and render steps have to be seperate so that the expensive parsing and compiling can be done once and later on you can
|
9
|
-
just render it passing in a hash with local variables and objects.
|
10
|
-
|
11
|
-
== Why should i use Liquid
|
12
|
-
|
13
|
-
* You want to allow your users to edit the appearance of your application but don't want them to run insecure code on your server.
|
14
|
-
* You want to render templates directly from the database
|
15
|
-
* You like smarty style template engines
|
16
|
-
* You need a template engine which does HTML just as well as Emails
|
17
|
-
* You don't like the markup of your current one
|
18
|
-
|
19
|
-
== What does it look like?
|
20
|
-
|
21
|
-
<ul id="products">
|
22
|
-
{% for product in products %}
|
23
|
-
<li>
|
24
|
-
<h2>{{product.name}}</h2>
|
25
|
-
Only {{product.price | price }}
|
26
|
-
|
27
|
-
{{product.description | prettyprint | paragraph }}
|
28
|
-
</li>
|
29
|
-
{% endfor %}
|
30
|
-
</ul>
|
31
|
-
|
32
|
-
== Howto use Liquid
|
33
|
-
|
34
|
-
Liquid supports a very simple API based around the Liquid::Template class.
|
35
|
-
For standard use you can just pass it the content of a file and call render with a parameters hash.
|
36
|
-
|
37
|
-
@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
|
38
|
-
@template.render( 'name' => 'tobi' ) # => "hi tobi"
|