liquid 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,12 @@
1
+ 2.2.1 / 2010-08-23
2
+
3
+ * Added support for literal tags
4
+
5
+ 2.2.0 / 2010-08-22
6
+
7
+ * Compatible with Ruby 1.8.7, 1.9.1 and 1.9.2-p0
8
+ * Merged some changed made by the community
9
+
1
10
  1.9.0 / 2008-03-04
2
11
 
3
12
  * Fixed gem install rake task
@@ -2,7 +2,7 @@ CHANGELOG
2
2
  History.txt
3
3
  MIT-LICENSE
4
4
  Manifest.txt
5
- README.txt
5
+ README.md
6
6
  Rakefile
7
7
  init.rb
8
8
  lib/extras/liquid_view.rb
@@ -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>
@@ -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'
@@ -1,6 +1,7 @@
1
1
  module Liquid
2
2
 
3
3
  class Tag
4
+
4
5
  attr_accessor :nodelist
5
6
 
6
7
  def initialize(tag_name, markup, tokens)
@@ -19,8 +20,7 @@ module Liquid
19
20
  def render(context)
20
21
  ''
21
22
  end
22
- end
23
-
24
23
 
25
- end
24
+ end # Tag
26
25
 
26
+ end # Tag
@@ -1,9 +1,9 @@
1
1
  module Liquid
2
- class Comment < Block
2
+ class Comment < Block
3
3
  def render(context)
4
4
  ''
5
- end
5
+ end
6
6
  end
7
-
8
- Template.register_tag('comment', Comment)
9
- end
7
+
8
+ Template.register_tag('comment', Comment)
9
+ end
@@ -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(?:and|or)\b|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
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
- 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
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
- @blocks.push(block)
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
@@ -55,7 +55,7 @@ module Liquid
55
55
  # Parse source code.
56
56
  # Returns self for easy chaining
57
57
  def parse(source)
58
- @root = Document.new(tokenize(source))
58
+ @root = Document.new(tokenize(Liquid::Literal.from_shorthand(source)))
59
59
  self
60
60
  end
61
61
 
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: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 0
10
- version: 2.2.0
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-22 00:00:00 -04:00
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.txt
31
+ - README.md
32
32
  files:
33
33
  - CHANGELOG
34
34
  - History.txt
35
35
  - MIT-LICENSE
36
36
  - Manifest.txt
37
- - README.txt
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.txt
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"