Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly support of non-ascii strings by filters #4

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
39e7810
pass a hash as context when parsing
did Aug 19, 2010
6150705
implementation of template inheritance + tests
did Aug 19, 2010
92aad46
clean code
did Aug 19, 2010
a41213c
change find_blocks method visibility + fix bug
did Aug 19, 2010
ba44b85
keep current block in context during parsing
did Aug 24, 2010
dbcc0b1
a bit of refactoring
did Aug 24, 2010
0c1cf77
a bit of refactoring
did Aug 24, 2010
9e35d06
add the name method in block drops
did Aug 25, 2010
f299f8b
context used in the parsing time was not the same instance all the ti…
did Aug 26, 2010
7ce591f
split the end_tag method for InheritedBlock
did Aug 27, 2010
9ec5709
new algorithm for the inheritance module. This one is much more simpl…
did Aug 30, 2010
b03cdc2
current block pushed in a stack during parsing
did Aug 31, 2010
7a06126
Repackage liquid gem for locomotive
Sep 28, 2010
8c2132d
reorganizing gemspec
Sep 28, 2010
3691796
Cleanup Readme and gemspec
Sep 28, 2010
a9345c4
RSpec environment setup
Sep 28, 2010
49e718e
Converting Block, Assign, and Capture to specs
Sep 28, 2010
9ecb9ff
Converting Condition Test
Sep 28, 2010
f0d0cc8
Converting Context Spec
Sep 28, 2010
876972d
Refactoring specs
Sep 28, 2010
ac1a7bd
Converting drop test
Sep 29, 2010
1fdfc2f
Convert error handling spec
Sep 29, 2010
f3be5a6
Convert template inheritance spec
Sep 29, 2010
bb978e0
spec cleanup and reorg
Sep 29, 2010
67062a4
converting filesystem test
Sep 29, 2010
232645a
Converting filter test
Sep 29, 2010
98eacaf
Reorganizing fixtures
Sep 29, 2010
9ddce08
Converting additional tests to specs
Sep 29, 2010
01a1bfc
include tag spec, and cleanup
Sep 29, 2010
57149f9
Converting some additional output specs
Sep 29, 2010
4e40056
reorganize specs
Sep 29, 2010
d0c109c
Remove money_filter
Sep 29, 2010
508d542
Additional spec refactoring
Sep 29, 2010
ec77241
cleaning out template etsts
Sep 29, 2010
31727bc
Converting filter specs
Sep 29, 2010
bcbc997
reorganize filter spec
Sep 29, 2010
f3affdb
Rspec
Sep 29, 2010
6f20154
Adding output and tag specs
Sep 29, 2010
5276a7b
Refactor tag specs
Sep 30, 2010
893a5f9
Adding RSpec to Rakefile
Sep 30, 2010
448ba2f
cleaning test folder
Sep 30, 2010
cd5e7b7
Additional specs and cleanup
Oct 1, 2010
78d5dad
cleanup whitespace
Oct 1, 2010
093fe3e
Adding strainger spec
Oct 1, 2010
ff43af8
Strainer
Oct 1, 2010
3dada41
Fix up filters for Ruby 1.9.2
Oct 1, 2010
bbab7be
Fix context for Ruby 1.9.2
Oct 1, 2010
fd63553
Additional fixes from master
Oct 1, 2010
89985bc
Adding Literal support + Specs
Oct 1, 2010
8b7b27d
Updating history and readme
Oct 1, 2010
1b27b1a
fixing gemspec
Oct 1, 2010
cd7d7e1
Adding release rake task
Oct 1, 2010
eaee027
Reorgnaize specs a bit
Oct 1, 2010
b107cd2
Add pending default content tag / spec
Oct 1, 2010
5e51d05
raw tag
Jul 26, 2012
fc155be
fix broken tests with ruby 1.9.x + upgrade libs
Jul 26, 2012
566fca9
allow assign with filters
rpmessner Sep 29, 2012
3a637bd
Merge pull request #2 from Liquidthread/master
did Nov 20, 2012
69e3c07
merging
did Nov 20, 2012
f8e6ee7
fixed broken tests
did Nov 20, 2012
a84b052
releasing version 2.4.1
did Nov 20, 2012
bc3c0ba
move some methods from LocomotiveCMS to Liquid
did Dec 16, 2012
55d3974
Properly support of non-ascii strings for downcase, upcase, capitaliz…
dimonzozo Apr 9, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
*.gem
*.swp
pkg
.rvmrc
.bundle/config
*.rbc
.rvmrc
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--colour
--backtrace
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source :rubygems

gem 'rake', '~> 0.9.2'
gem 'rspec', '~> 2.6' #>= 2.0.0.beta.22"
gem 'cucumber', '~> 1.1.9' #'> 0.9.0'
gem 'activesupport'

platforms :ruby_18 do
gem 'ruby-debug'
end
46 changes: 46 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
GEM
remote: http://rubygems.org/
specs:
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
builder (3.0.0)
columnize (0.3.1)
cucumber (1.1.9)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (~> 2.9.0)
json (>= 1.4.6)
term-ansicolor (>= 1.0.6)
diff-lcs (1.1.3)
gherkin (2.9.3)
json (>= 1.4.6)
i18n (0.6.1)
json (1.7.3)
linecache (0.43)
multi_json (1.6.1)
rake (0.9.2.2)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.1)
ruby-debug (0.10.3)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.3.0)
ruby-debug-base (0.10.3)
linecache (>= 0.3)
term-ansicolor (1.0.7)

PLATFORMS
ruby

DEPENDENCIES
activesupport
cucumber (~> 1.1.9)
rake (~> 0.9.2)
rspec (~> 2.6)
ruby-debug
57 changes: 57 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
2.2.2

* Added support for template inheritance {% extends %}

2.2.1 / 2010-08-23

* Added support for literal tags

2.2.0 / 2010-08-22

* Compatible with Ruby 1.8.7, 1.9.1 and 1.9.2-p0
* Merged some changed made by the community

1.9.0 / 2008-03-04

* Fixed gem install rake task
* Improve Error encapsulation in liquid by maintaining a own set of exceptions instead of relying on ruby build ins

Before 1.9.0

* Added If with or / and expressions

* 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.

* Added more tags to standard library

* Added include tag ( like partials in rails )

* [...] Gazillion of detail improvements

* Added strainers as filter hosts for better security [Tobias Luetke]

* Fixed that rails integration would call filter with the wrong "self" [Michael Geary]

* 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]

* Removed count helper from standard lib. use size [Tobias Luetke]

* Fixed bug with string filter parameters failing to tolerate commas in strings. [Paul Hammond]

* 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]

{{ 'Typo' | link_to: 'http://typo.leetsoft.com', 'Typo - a modern weblog engine' }}


* 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]

class ProductDrop < Liquid::Drop
def top_sales
Shop.current.products.find(:all, :order => 'sales', :limit => 10 )
end
end
t = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {% endfor %} ' )
t.render('product' => ProductDrop.new )


* Added filter parameters support. Example: {{ date | format_date: "%Y" }} [Paul Hammond]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Liquid is a template engine which was written with very specific requirements:
```

## How to use Liquid
>>>>>>> upstream/master

Liquid supports a very simple API based around the Liquid::Template class.
For standard use you can just pass it the content of a file and call render with a parameters hash.
Expand Down
37 changes: 33 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'

require 'rake'
require 'rake/testtask'
require 'rspec'
require 'rspec/core/rake_task'
require 'rubygems/package_task'

task :default => 'test'
RSpec::Core::RakeTask.new("spec") do |spec|
spec.pattern = "spec/**/*_spec.rb"
end

desc "Run the Integration Specs (rendering)"
RSpec::Core::RakeTask.new("spec:integration") do |spec|
spec.pattern = "spec/unit/*_spec.rb"
end

desc "Run the Unit Specs"
RSpec::Core::RakeTask.new("spec:unit") do |spec|
spec.pattern = "spec/unit/*_spec.rb"
end

desc "Run all the specs without all the verbose spec output"
RSpec::Core::RakeTask.new('spec:progress') do |spec|
spec.rspec_opts = %w(--format progress)
spec.pattern = "spec/**/*_spec.rb"
end

Rake::TestTask.new(:test) do |t|
t.libs << '.' << 'lib' << 'test'
t.test_files = FileList['test/liquid/**/*_test.rb']
t.verbose = false
end

gemspec = eval(File.read('liquid.gemspec'))
task :default => [:spec, :test]

gemspec = eval(File.read('locomotive_liquid.gemspec'))

Gem::PackageTask.new(gemspec) do |pkg|
pkg.gem_spec = gemspec
end

desc "Build the gem and release it to rubygems.org"
task :release => :gem do
sh "gem push pkg/liquid-#{gemspec.version}.gem"
puts "Tagging #{gemspec.version}..."
system "git tag -a #{gemspec.version} -m 'Tagging #{gemspec.version}'"
puts "Pushing to Github..."
system "git push --tags"
puts "Pushing to rubygems.org..."
system "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
end

namespace :benchmark do
Expand All @@ -32,7 +62,6 @@ namespace :benchmark do

end


namespace :profile do

desc "Run the liquid profile/performance coverage"
Expand Down
1 change: 1 addition & 0 deletions autotest/discover.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Autotest.add_discovery { "rspec2" }
18 changes: 9 additions & 9 deletions example/server/example_servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ module ProductsFilter
def price(integer)
sprintf("$%.2d USD", integer / 100.0)
end

def prettyprint(text)
text.gsub( /\*(.*)\*/, '<b>\1</b>' )
end

def count(array)
array.size
end

def paragraph(p)
"<p>#{p}</p>"
end
end

class Servlet < LiquidServlet

def index
{ 'date' => Time.now }
end
def products
{ 'products' => products_list, 'section' => 'Snowboards', 'cool_products' => true}

def products
{ 'products' => products_list, 'section' => 'Snowboards', 'cool_products' => true}
end

def description
"List of Products ~ This is a list of products with price and description."
end

private

def products_list
[{'name' => 'Arbor Draft', 'price' => 39900, 'description' => 'the *arbor draft* is a excellent product' },
{'name' => 'Arbor Element', 'price' => 40000, 'description' => 'the *arbor element* rocks for freestyling'},
{'name' => 'Arbor Diamond', 'price' => 59900, 'description' => 'the *arbor diamond* is a made up product because im obsessed with arbor and have no creativity'}]
end

end
14 changes: 7 additions & 7 deletions example/server/liquid_servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ def do_GET(req, res)
def do_POST(req, res)
handle(:post, req, res)
end

private

def handle(type, req, res)
@request, @response = req, res

@request.path_info =~ /(\w+)$/
@action = $1 || 'index'
@assigns = send(@action) if respond_to?(@action)
@action = $1 || 'index'
@assigns = send(@action) if respond_to?(@action)

@response['Content-Type'] = "text/html"
@response.status = 200
@response.body = Liquid::Template.parse(read_template).render(@assigns, :filters => [ProductsFilter])
@response.body = Liquid::Template.parse(read_template).render(@assigns, :filters => [ProductsFilter])
end

def read_template(filename = @action)
File.read( File.dirname(__FILE__) + "/templates/#{filename}.liquid" )
end
Expand Down
30 changes: 15 additions & 15 deletions example/server/templates/products.liquid
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />

<title>products</title>

<meta name="ROBOTS" content="ALL" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="Copyright" content="(c) 2005 Copyright content: Copyright design: Tobias Luetke" />
<!-- (c) Copyright 2005 by Tobias Luetke All Rights Reserved. -->
</head>

<body>

<h1>{{ description | split: '~' | first }}</h1>
Expand All @@ -24,26 +24,26 @@
<h2>There are currently {{products | count}} products in the {{section}} catalog</h2>

{% if cool_products %}
Cool products :)
Cool products :)
{% else %}
Uncool products :(
Uncool products :(
{% endif %}

<ul id="products">

{% for product in products %}
<li>
<h2>{{product.name}}</h2>
Only {{product.price | price }}

{{product.description | prettyprint | paragraph }}

{{ 'it rocks!' | paragraph }}
</li>

</li>
{% endfor %}

</ul>
</body>

</body>
</html>
16 changes: 8 additions & 8 deletions lib/extras/liquid_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
# and use liquid as an template system for .liquid files
#
# Example
#
#
# ActionView::Base::register_template_handler :liquid, LiquidView
class LiquidView
PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
_response url _request _cookies variables_added _flash params _headers request cookies
ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
PROTECTED_INSTANCE_VARIABLES = %w( @_request @controller @_first_render @_memoized__pick_template @view_paths
PROTECTED_INSTANCE_VARIABLES = %w( @_request @controller @_first_render @_memoized__pick_template @view_paths
@helpers @assigns_added @template @_render_stack @template_format @assigns )

def self.call(template)
"LiquidView.new(self).render(template, local_assigns)"
end

def initialize(view)
@view = view
end

def render(template, local_assigns = nil)
@view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'

# Rails 2.2 Template has source, but not locals
if template.respond_to?(:source) && !template.respond_to?(:locals)
assigns = (@view.instance_variables - PROTECTED_INSTANCE_VARIABLES).inject({}) do |hash, ivar|
Expand All @@ -31,15 +31,15 @@ def render(template, local_assigns = nil)
else
assigns = @view.assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
end

source = template.respond_to?(:source) ? template.source : template
local_assigns = (template.respond_to?(:locals) ? template.locals : local_assigns) || {}

if content_for_layout = @view.instance_variable_get("@content_for_layout")
assigns['content_for_layout'] = content_for_layout
end
assigns.merge!(local_assigns.stringify_keys)

liquid = Liquid::Template.parse(source)
liquid.render(assigns, :filters => [@view.controller.master_helper_module], :registers => {:action_view => @view, :controller => @view.controller})
end
Expand Down
Loading