drnic-liquid 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +44 -0
- data/History.txt +44 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +34 -0
- data/README.rdoc +44 -0
- data/Rakefile +30 -0
- data/example/server/example_servlet.rb +37 -0
- data/example/server/liquid_servlet.rb +28 -0
- data/example/server/server.rb +12 -0
- data/example/server/templates/index.liquid +6 -0
- data/example/server/templates/products.liquid +45 -0
- data/init.rb +8 -0
- data/lib/extras/liquid_view.rb +51 -0
- data/lib/liquid.rb +70 -0
- data/lib/liquid/block.rb +102 -0
- data/lib/liquid/condition.rb +120 -0
- data/lib/liquid/context.rb +221 -0
- data/lib/liquid/document.rb +17 -0
- data/lib/liquid/drop.rb +51 -0
- data/lib/liquid/errors.rb +11 -0
- data/lib/liquid/extensions.rb +56 -0
- data/lib/liquid/file_system.rb +62 -0
- data/lib/liquid/htmltags.rb +74 -0
- data/lib/liquid/module_ex.rb +62 -0
- data/lib/liquid/standardfilters.rb +209 -0
- data/lib/liquid/strainer.rb +51 -0
- data/lib/liquid/tag.rb +26 -0
- data/lib/liquid/tags/assign.rb +33 -0
- data/lib/liquid/tags/capture.rb +35 -0
- data/lib/liquid/tags/case.rb +83 -0
- data/lib/liquid/tags/comment.rb +9 -0
- data/lib/liquid/tags/cycle.rb +59 -0
- data/lib/liquid/tags/for.rb +136 -0
- data/lib/liquid/tags/if.rb +79 -0
- data/lib/liquid/tags/ifchanged.rb +20 -0
- data/lib/liquid/tags/include.rb +55 -0
- data/lib/liquid/tags/unless.rb +33 -0
- data/lib/liquid/template.rb +147 -0
- data/lib/liquid/variable.rb +49 -0
- data/liquid.gemspec +40 -0
- data/performance/shopify.rb +92 -0
- data/performance/shopify/comment_form.rb +33 -0
- data/performance/shopify/database.rb +45 -0
- data/performance/shopify/json_filter.rb +7 -0
- data/performance/shopify/liquid.rb +18 -0
- data/performance/shopify/money_filter.rb +18 -0
- data/performance/shopify/paginate.rb +93 -0
- data/performance/shopify/shop_filter.rb +98 -0
- data/performance/shopify/tag_filter.rb +25 -0
- data/performance/shopify/vision.database.yml +945 -0
- data/performance/shopify/weight_filter.rb +11 -0
- data/performance/tests/dropify/article.liquid +74 -0
- data/performance/tests/dropify/blog.liquid +33 -0
- data/performance/tests/dropify/cart.liquid +66 -0
- data/performance/tests/dropify/collection.liquid +22 -0
- data/performance/tests/dropify/index.liquid +47 -0
- data/performance/tests/dropify/page.liquid +8 -0
- data/performance/tests/dropify/product.liquid +68 -0
- data/performance/tests/dropify/theme.liquid +105 -0
- data/performance/tests/ripen/article.liquid +74 -0
- data/performance/tests/ripen/blog.liquid +13 -0
- data/performance/tests/ripen/cart.liquid +54 -0
- data/performance/tests/ripen/collection.liquid +29 -0
- data/performance/tests/ripen/index.liquid +32 -0
- data/performance/tests/ripen/page.liquid +4 -0
- data/performance/tests/ripen/product.liquid +75 -0
- data/performance/tests/ripen/theme.liquid +85 -0
- data/performance/tests/tribble/404.liquid +56 -0
- data/performance/tests/tribble/article.liquid +98 -0
- data/performance/tests/tribble/blog.liquid +41 -0
- data/performance/tests/tribble/cart.liquid +134 -0
- data/performance/tests/tribble/collection.liquid +70 -0
- data/performance/tests/tribble/index.liquid +94 -0
- data/performance/tests/tribble/page.liquid +56 -0
- data/performance/tests/tribble/product.liquid +116 -0
- data/performance/tests/tribble/search.liquid +51 -0
- data/performance/tests/tribble/theme.liquid +90 -0
- data/performance/tests/vogue/article.liquid +66 -0
- data/performance/tests/vogue/blog.liquid +32 -0
- data/performance/tests/vogue/cart.liquid +58 -0
- data/performance/tests/vogue/collection.liquid +19 -0
- data/performance/tests/vogue/index.liquid +22 -0
- data/performance/tests/vogue/page.liquid +3 -0
- data/performance/tests/vogue/product.liquid +62 -0
- data/performance/tests/vogue/theme.liquid +122 -0
- data/test/assign_test.rb +11 -0
- data/test/block_test.rb +58 -0
- data/test/condition_test.rb +109 -0
- data/test/context_test.rb +482 -0
- data/test/drop_test.rb +162 -0
- data/test/error_handling_test.rb +89 -0
- data/test/extra/breakpoint.rb +547 -0
- data/test/extra/caller.rb +80 -0
- data/test/file_system_test.rb +30 -0
- data/test/filter_test.rb +95 -0
- data/test/helper.rb +20 -0
- data/test/html_tag_test.rb +31 -0
- data/test/if_else_test.rb +131 -0
- data/test/include_tag_test.rb +115 -0
- data/test/module_ex_test.rb +89 -0
- data/test/output_test.rb +121 -0
- data/test/parsing_quirks_test.rb +41 -0
- data/test/regexp_test.rb +45 -0
- data/test/security_test.rb +41 -0
- data/test/standard_filter_test.rb +161 -0
- data/test/standard_tag_test.rb +400 -0
- data/test/statements_test.rb +137 -0
- data/test/strainer_test.rb +21 -0
- data/test/template_test.rb +26 -0
- data/test/test_helper.rb +20 -0
- data/test/unless_else_test.rb +27 -0
- data/test/variable_test.rb +172 -0
- metadata +187 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
* Ruby 1.9.1 bugfixes
|
2
|
+
|
3
|
+
* Fix LiquidView for Rails 2.2. Fix local assigns for all versions of Rails
|
4
|
+
|
5
|
+
* Fixed gem install rake task
|
6
|
+
* Improve Error encapsulation in liquid by maintaining a own set of exceptions instead of relying on ruby build ins
|
7
|
+
|
8
|
+
* Added If with or / and expressions
|
9
|
+
|
10
|
+
* Implemented .to_liquid for all objects which can be passed to liquid like Strings Arrays Hashes Numerics and Booleans. To export new objects to liquid just implement .to_liquid on them and return objects which themselves have .to_liquid methods.
|
11
|
+
|
12
|
+
* Added more tags to standard library
|
13
|
+
|
14
|
+
* Added include tag ( like partials in rails )
|
15
|
+
|
16
|
+
* [...] Gazillion of detail improvements
|
17
|
+
|
18
|
+
* Added strainers as filter hosts for better security [Tobias Luetke]
|
19
|
+
|
20
|
+
* Fixed that rails integration would call filter with the wrong "self" [Michael Geary]
|
21
|
+
|
22
|
+
* Fixed bad error reporting when a filter called a method which doesn't exist. Liquid told you that it couldn't find the filter which was obviously misleading [Tobias Luetke]
|
23
|
+
|
24
|
+
* Removed count helper from standard lib. use size [Tobias Luetke]
|
25
|
+
|
26
|
+
* Fixed bug with string filter parameters failing to tolerate commas in strings. [Paul Hammond]
|
27
|
+
|
28
|
+
* Improved filter parameters. Filter parameters are now context sensitive; Types are resolved according to the rules of the context. Multiple parameters are now separated by the Liquid::ArgumentSeparator: , by default [Paul Hammond]
|
29
|
+
|
30
|
+
{{ 'Typo' | link_to: 'http://typo.leetsoft.com', 'Typo - a modern weblog engine' }}
|
31
|
+
|
32
|
+
|
33
|
+
* Added Liquid::Drop. A base class which you can use for exporting proxy objects to liquid which can acquire more data when used in liquid. [Tobias Luetke]
|
34
|
+
|
35
|
+
class ProductDrop < Liquid::Drop
|
36
|
+
def top_sales
|
37
|
+
Shop.current.products.find(:all, :order => 'sales', :limit => 10 )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
t = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {% end %} ' )
|
41
|
+
t.render('product' => ProductDrop.new )
|
42
|
+
|
43
|
+
|
44
|
+
* Added filter parameters support. Example: {{ date | format_date: "%Y" }} [Paul Hammond]
|
data/History.txt
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
1.9.0 / 2008-03-04
|
2
|
+
|
3
|
+
* Fixed gem install rake task
|
4
|
+
* Improve Error encapsulation in liquid by maintaining a own set of exceptions instead of relying on ruby build ins
|
5
|
+
|
6
|
+
Before 1.9.0
|
7
|
+
|
8
|
+
* Added If with or / and expressions
|
9
|
+
|
10
|
+
* Implemented .to_liquid for all objects which can be passed to liquid like Strings Arrays Hashes Numerics and Booleans. To export new objects to liquid just implement .to_liquid on them and return objects which themselves have .to_liquid methods.
|
11
|
+
|
12
|
+
* Added more tags to standard library
|
13
|
+
|
14
|
+
* Added include tag ( like partials in rails )
|
15
|
+
|
16
|
+
* [...] Gazillion of detail improvements
|
17
|
+
|
18
|
+
* Added strainers as filter hosts for better security [Tobias Luetke]
|
19
|
+
|
20
|
+
* Fixed that rails integration would call filter with the wrong "self" [Michael Geary]
|
21
|
+
|
22
|
+
* Fixed bad error reporting when a filter called a method which doesn't exist. Liquid told you that it couldn't find the filter which was obviously misleading [Tobias Luetke]
|
23
|
+
|
24
|
+
* Removed count helper from standard lib. use size [Tobias Luetke]
|
25
|
+
|
26
|
+
* Fixed bug with string filter parameters failing to tolerate commas in strings. [Paul Hammond]
|
27
|
+
|
28
|
+
* Improved filter parameters. Filter parameters are now context sensitive; Types are resolved according to the rules of the context. Multiple parameters are now separated by the Liquid::ArgumentSeparator: , by default [Paul Hammond]
|
29
|
+
|
30
|
+
{{ 'Typo' | link_to: 'http://typo.leetsoft.com', 'Typo - a modern weblog engine' }}
|
31
|
+
|
32
|
+
|
33
|
+
* Added Liquid::Drop. A base class which you can use for exporting proxy objects to liquid which can acquire more data when used in liquid. [Tobias Luetke]
|
34
|
+
|
35
|
+
class ProductDrop < Liquid::Drop
|
36
|
+
def top_sales
|
37
|
+
Shop.current.products.find(:all, :order => 'sales', :limit => 10 )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
t = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {% end %} ' )
|
41
|
+
t.render('product' => ProductDrop.new )
|
42
|
+
|
43
|
+
|
44
|
+
* Added filter parameters support. Example: {{ date | format_date: "%Y" }} [Paul Hammond]
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2005, 2006 Tobias Luetke
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
History.txt
|
3
|
+
MIT-LICENSE
|
4
|
+
Manifest.txt
|
5
|
+
README.rdoc
|
6
|
+
Rakefile
|
7
|
+
init.rb
|
8
|
+
lib/extras/liquid_view.rb
|
9
|
+
lib/liquid.rb
|
10
|
+
lib/liquid/block.rb
|
11
|
+
lib/liquid/condition.rb
|
12
|
+
lib/liquid/context.rb
|
13
|
+
lib/liquid/document.rb
|
14
|
+
lib/liquid/drop.rb
|
15
|
+
lib/liquid/errors.rb
|
16
|
+
lib/liquid/extensions.rb
|
17
|
+
lib/liquid/file_system.rb
|
18
|
+
lib/liquid/htmltags.rb
|
19
|
+
lib/liquid/module_ex.rb
|
20
|
+
lib/liquid/standardfilters.rb
|
21
|
+
lib/liquid/strainer.rb
|
22
|
+
lib/liquid/tag.rb
|
23
|
+
lib/liquid/tags/assign.rb
|
24
|
+
lib/liquid/tags/capture.rb
|
25
|
+
lib/liquid/tags/case.rb
|
26
|
+
lib/liquid/tags/comment.rb
|
27
|
+
lib/liquid/tags/cycle.rb
|
28
|
+
lib/liquid/tags/for.rb
|
29
|
+
lib/liquid/tags/if.rb
|
30
|
+
lib/liquid/tags/ifchanged.rb
|
31
|
+
lib/liquid/tags/include.rb
|
32
|
+
lib/liquid/tags/unless.rb
|
33
|
+
lib/liquid/template.rb
|
34
|
+
lib/liquid/variable.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= Liquid template engine
|
2
|
+
|
3
|
+
* http://www.liquidmarkup.org
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
A secure non evaling end user template engine with aesthetic markup.
|
8
|
+
|
9
|
+
Liquid is a template engine which I wrote for very specific requirements.
|
10
|
+
|
11
|
+
* It has to have beautiful and simple markup.
|
12
|
+
Template engines which don't produce good looking markup are no fun to use.
|
13
|
+
* 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.
|
14
|
+
* 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
|
15
|
+
just render it passing in a hash with local variables and objects.
|
16
|
+
|
17
|
+
== Why should i use Liquid
|
18
|
+
|
19
|
+
* 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.
|
20
|
+
* You want to render templates directly from the database
|
21
|
+
* You like smarty style template engines
|
22
|
+
* You need a template engine which does HTML just as well as Emails
|
23
|
+
* You don't like the markup of your current one
|
24
|
+
|
25
|
+
== What does it look like?
|
26
|
+
|
27
|
+
<ul id="products">
|
28
|
+
{% for product in products %}
|
29
|
+
<li>
|
30
|
+
<h2>{{product.name}}</h2>
|
31
|
+
Only {{product.price | price }}
|
32
|
+
|
33
|
+
{{product.description | prettyprint | paragraph }}
|
34
|
+
</li>
|
35
|
+
{% end %}
|
36
|
+
</ul>
|
37
|
+
|
38
|
+
== Howto use Liquid
|
39
|
+
|
40
|
+
Liquid supports a very simple API based around the Liquid::Template class.
|
41
|
+
For standard use you can just pass it the content of a file and call render with a parameters hash.
|
42
|
+
|
43
|
+
@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
|
44
|
+
@template.render( 'name' => 'tobi' ) # => "hi tobi"
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
Hoe.spec "liquid" do
|
7
|
+
developer("Tobias Luetke", "tobi@leetsoft.com")
|
8
|
+
self.readme_file = "README.rdoc"
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
namespace :profile do
|
13
|
+
|
14
|
+
|
15
|
+
task :default => [:run]
|
16
|
+
|
17
|
+
desc "Run the liquid profile/perforamce coverage"
|
18
|
+
task :run do
|
19
|
+
|
20
|
+
ruby "performance/shopify.rb"
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Run KCacheGrind"
|
25
|
+
task :grind => :run do
|
26
|
+
system "kcachegrind /tmp/liquid.rubyprof_calltreeprinter.txt"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ProductsFilter
|
2
|
+
def price(integer)
|
3
|
+
sprintf("$%.2d USD", integer / 100.0)
|
4
|
+
end
|
5
|
+
|
6
|
+
def prettyprint(text)
|
7
|
+
text.gsub( /\*(.*)\*/, '<b>\1</b>' )
|
8
|
+
end
|
9
|
+
|
10
|
+
def count(array)
|
11
|
+
array.size
|
12
|
+
end
|
13
|
+
|
14
|
+
def paragraph(p)
|
15
|
+
"<p>#{p}</p>"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Servlet < LiquidServlet
|
20
|
+
|
21
|
+
def index
|
22
|
+
{ 'date' => Time.now }
|
23
|
+
end
|
24
|
+
|
25
|
+
def products
|
26
|
+
{ 'products' => products_list, 'section' => 'Snowboards', 'cool_products' => true}
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def products_list
|
32
|
+
[{'name' => 'Arbor Draft', 'price' => 39900, 'description' => 'the *arbor draft* is a excellent product' },
|
33
|
+
{'name' => 'Arbor Element', 'price' => 40000, 'description' => 'the *arbor element* rocks for freestyling'},
|
34
|
+
{'name' => 'Arbor Diamond', 'price' => 59900, 'description' => 'the *arbor diamond* is a made up product because im obsessed with arbor and have no creativity'}]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class LiquidServlet < WEBrick::HTTPServlet::AbstractServlet
|
2
|
+
|
3
|
+
def do_GET(req, res)
|
4
|
+
handle(:get, req, res)
|
5
|
+
end
|
6
|
+
|
7
|
+
def do_POST(req, res)
|
8
|
+
handle(:post, req, res)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def handle(type, req, res)
|
14
|
+
@request, @response = req, res
|
15
|
+
|
16
|
+
@request.path_info =~ /(\w+)$/
|
17
|
+
@action = $1 || 'index'
|
18
|
+
@assigns = send(@action) if respond_to?(@action)
|
19
|
+
|
20
|
+
@response['Content-Type'] = "text/html"
|
21
|
+
@response.status = 200
|
22
|
+
@response.body = Liquid::Template.parse(read_template).render(@assigns, :filters => [ProductsFilter])
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_template(filename = @action)
|
26
|
+
File.read( File.dirname(__FILE__) + "/templates/#{filename}.liquid" )
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'rexml/document'
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../../lib/liquid'
|
5
|
+
require File.dirname(__FILE__) + '/liquid_servlet'
|
6
|
+
require File.dirname(__FILE__) + '/example_servlet'
|
7
|
+
|
8
|
+
# Setup webrick
|
9
|
+
server = WEBrick::HTTPServer.new( :Port => ARGV[1] || 3000 )
|
10
|
+
server.mount('/', Servlet)
|
11
|
+
trap("INT"){ server.shutdown }
|
12
|
+
server.start
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
7
|
+
<meta http-equiv="Content-Language" content="en-us" />
|
8
|
+
|
9
|
+
<title>products</title>
|
10
|
+
|
11
|
+
<meta name="ROBOTS" content="ALL" />
|
12
|
+
<meta http-equiv="imagetoolbar" content="no" />
|
13
|
+
<meta name="MSSmartTagsPreventParsing" content="true" />
|
14
|
+
<meta name="Copyright" content="(c) 2005 Copyright content: Copyright design: Tobias Luetke" />
|
15
|
+
<!-- (c) Copyright 2005 by Tobias Luetke All Rights Reserved. -->
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
|
20
|
+
<h1>There are currently {{products | count}} products in the {{section}} catalog</h1>
|
21
|
+
|
22
|
+
{% if cool_products %}
|
23
|
+
Cool products :)
|
24
|
+
{% else %}
|
25
|
+
Uncool products :(
|
26
|
+
{% end %}
|
27
|
+
|
28
|
+
<ul id="products">
|
29
|
+
|
30
|
+
{% for product in products %}
|
31
|
+
<li>
|
32
|
+
<h2>{{product.name}}</h2>
|
33
|
+
Only {{product.price | price }}
|
34
|
+
|
35
|
+
{{product.description | prettyprint | paragraph }}
|
36
|
+
|
37
|
+
{{ 'it rocks!' | paragraph }}
|
38
|
+
|
39
|
+
</li>
|
40
|
+
{% end %}
|
41
|
+
|
42
|
+
</ul>
|
43
|
+
|
44
|
+
</body>
|
45
|
+
</html>
|
data/init.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# LiquidView is a action view extension class. You can register it with rails
|
2
|
+
# and use liquid as an template system for .liquid files
|
3
|
+
#
|
4
|
+
# Example
|
5
|
+
#
|
6
|
+
# ActionView::Base::register_template_handler :liquid, LiquidView
|
7
|
+
class LiquidView
|
8
|
+
PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
|
9
|
+
_response url _request _cookies variables_added _flash params _headers request cookies
|
10
|
+
ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
|
11
|
+
PROTECTED_INSTANCE_VARIABLES = %w( @_request @controller @_first_render @_memoized__pick_template @view_paths
|
12
|
+
@helpers @assigns_added @template @_render_stack @template_format @assigns )
|
13
|
+
|
14
|
+
def self.call(template)
|
15
|
+
"LiquidView.new(self).render(template, local_assigns)"
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(view)
|
19
|
+
@view = view
|
20
|
+
end
|
21
|
+
|
22
|
+
def render(template, local_assigns = nil)
|
23
|
+
@view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
|
24
|
+
|
25
|
+
# Rails 2.2 Template has source, but not locals
|
26
|
+
if template.respond_to?(:source) && !template.respond_to?(:locals)
|
27
|
+
assigns = (@view.instance_variables - PROTECTED_INSTANCE_VARIABLES).inject({}) do |hash, ivar|
|
28
|
+
hash[ivar[1..-1]] = @view.instance_variable_get(ivar)
|
29
|
+
hash
|
30
|
+
end
|
31
|
+
else
|
32
|
+
assigns = @view.assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
|
33
|
+
end
|
34
|
+
|
35
|
+
source = template.respond_to?(:source) ? template.source : template
|
36
|
+
local_assigns = (template.respond_to?(:locals) ? template.locals : local_assigns) || {}
|
37
|
+
|
38
|
+
if content_for_layout = @view.instance_variable_get("@content_for_layout")
|
39
|
+
assigns['content_for_layout'] = content_for_layout
|
40
|
+
end
|
41
|
+
assigns.merge!(local_assigns.stringify_keys)
|
42
|
+
|
43
|
+
liquid = Liquid::Template.parse(source)
|
44
|
+
liquid.render(assigns, :filters => [@view.controller.master_helper_module], :registers => {:action_view => @view, :controller => @view.controller})
|
45
|
+
end
|
46
|
+
|
47
|
+
def compilable?
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/liquid.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Copyright (c) 2005 Tobias Luetke
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
23
|
+
|
24
|
+
module Liquid
|
25
|
+
VERSION = "2.1.0"
|
26
|
+
|
27
|
+
FilterSeparator = /\|/
|
28
|
+
ArgumentSeparator = ','
|
29
|
+
FilterArgumentSeparator = ':'
|
30
|
+
VariableAttributeSeparator = '.'
|
31
|
+
TagStart = /\{\%/
|
32
|
+
TagEnd = /\%\}/
|
33
|
+
VariableSignature = /\(?[\w\-\.\[\]]\)?/
|
34
|
+
VariableSegment = /[\w\-]/
|
35
|
+
VariableStart = /\{\{/
|
36
|
+
VariableEnd = /\}\}/
|
37
|
+
VariableIncompleteEnd = /\}\}?/
|
38
|
+
QuotedString = /"[^"]+"|'[^']+'/
|
39
|
+
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/
|
40
|
+
StrictQuotedFragment = /"[^"]+"|'[^']+'|[^\s,\|,\:,\,]+/
|
41
|
+
FirstFilterArgument = /#{FilterArgumentSeparator}(?:#{StrictQuotedFragment})/
|
42
|
+
OtherFilterArgument = /#{ArgumentSeparator}(?:#{StrictQuotedFragment})/
|
43
|
+
SpacelessFilter = /#{FilterSeparator}(?:#{StrictQuotedFragment})(?:#{FirstFilterArgument}(?:#{OtherFilterArgument})*)?/
|
44
|
+
Expression = /(?:#{QuotedFragment}(?:#{SpacelessFilter})*)/
|
45
|
+
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/
|
46
|
+
AnyStartingTag = /\{\{|\{\%/
|
47
|
+
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/
|
48
|
+
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/
|
49
|
+
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/
|
50
|
+
end
|
51
|
+
|
52
|
+
require 'liquid/drop'
|
53
|
+
require 'liquid/extensions'
|
54
|
+
require 'liquid/errors'
|
55
|
+
require 'liquid/strainer'
|
56
|
+
require 'liquid/context'
|
57
|
+
require 'liquid/tag'
|
58
|
+
require 'liquid/block'
|
59
|
+
require 'liquid/document'
|
60
|
+
require 'liquid/variable'
|
61
|
+
require 'liquid/file_system'
|
62
|
+
require 'liquid/template'
|
63
|
+
require 'liquid/htmltags'
|
64
|
+
require 'liquid/standardfilters'
|
65
|
+
require 'liquid/condition'
|
66
|
+
require 'liquid/module_ex'
|
67
|
+
|
68
|
+
# Load all the tags of the standard library
|
69
|
+
#
|
70
|
+
Dir[File.dirname(__FILE__) + '/liquid/tags/*.rb'].each { |f| require f }
|