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

Updated for tag to use sort_by and order_by tags to allow sorting #1

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 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
d61e77f
Updated for tag to use sort_by and order_by tags to allow sorting and…
waynegerard May 24, 2012
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
@@ -1,2 +1,4 @@
*.gem
pkg
.rvmrc
.bundle/config
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source :rubygems

gem "rake"
gem "rspec", ">= 2.0.0.beta.22"
gem "cucumber", ">= 0.9.0"

platforms :ruby_18 do
gem "ruby-debug"
end
45 changes: 45 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
GEM
remote: http://rubygems.org/
specs:
builder (2.1.2)
columnize (0.3.1)
cucumber (0.9.0)
builder (~> 2.1.2)
diff-lcs (~> 1.1.2)
gherkin (~> 2.2.2)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
diff-lcs (1.1.2)
gherkin (2.2.4)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
trollop (~> 1.16.2)
json (1.4.6)
linecache (0.43)
rake (0.8.7)
rspec (2.0.0.beta.22)
rspec-core (= 2.0.0.beta.22)
rspec-expectations (= 2.0.0.beta.22)
rspec-mocks (= 2.0.0.beta.22)
rspec-core (2.0.0.beta.22)
rspec-expectations (2.0.0.beta.22)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.0.beta.22)
rspec-core (= 2.0.0.beta.22)
rspec-expectations (= 2.0.0.beta.22)
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.5)
trollop (1.16.2)

PLATFORMS
ruby

DEPENDENCIES
cucumber (>= 0.9.0)
rake
rspec (>= 2.0.0.beta.22)
ruby-debug
25 changes: 19 additions & 6 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
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
Expand All @@ -7,7 +20,7 @@ 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.
* 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

Expand All @@ -26,17 +39,17 @@ Before 1.9.0
* 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]
{{ '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
end
t = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {% endfor %} ' )
t.render('product' => ProductDrop.new )

Expand Down
34 changes: 0 additions & 34 deletions Manifest.txt

This file was deleted.

39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Liquid template engine

## Introduction

Liquid is a template engine which I wrote for very specific requirements

* It has to have beautiful and simple markup. Template engines which don't produce good looking markup are no fun to use.
* 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.
* 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.

## Why should I use Liquid

* 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**.
* You want to render templates directly from the database
* You like smarty (PHP) style template engines
* You need a template engine which does HTML just as well as emails
* You don't like the markup of your current templating engine

## What does it look like?

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

{{product.description | prettyprint | paragraph }}
</li>
{% endfor %}
</ul>

## Howto use Liquid

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.


@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
@template.render( 'name' => 'tobi' ) # => "hi tobi"
38 changes: 0 additions & 38 deletions README.txt

This file was deleted.

56 changes: 39 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,66 @@
#!/usr/bin/env ruby
require 'rubygems'

require "bundler"
Bundler.setup

require 'rake'
require 'rake/testtask'
require 'rake/gempackagetask'

task :default => 'test'
require "rspec"
require "rspec/core/rake_task"

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

Rake::TestTask.new(:test) do |t|
t.libs << "lib"
t.libs << "test"
t.pattern = 'test/*_test.rb'
t.verbose = false
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

gemspec = eval(File.read('liquid.gemspec'))
task :default => :spec

gemspec = eval(File.read('locomotive_liquid.gemspec'))
Rake::GemPackageTask.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 :profile do


task :default => [:run]

desc "Run the liquid profile/perforamce coverage"
task :run do

ruby "performance/shopify.rb"

end
desc "Run KCacheGrind"

desc "Run KCacheGrind"
task :grind => :run do
system "kcachegrind /tmp/liquid.rubyprof_calltreeprinter.txt"
end
end



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" }
20 changes: 10 additions & 10 deletions example/server/example_servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ 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

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
Loading