Compare commits

...

8 Commits

Author SHA1 Message Date
Tobias Lütke
6831eac902 Released gem 2.1.3 2010-08-05 18:07:05 -04:00
Dennis Theisen
13f98de7f3 Change behavior of capture tag to use existing variables if they already have been initialized in an outer scope. 2010-08-06 06:02:37 +08:00
Dennis Theisen
e26f509277 Fixed minor typos in inline documentation for assign and capture 2010-08-06 06:02:37 +08:00
James MacAulay
0417c9e723 Gem v2.1.2 2010-07-09 09:17:10 -04:00
James MacAulay
ffd48880e2 Gem v2.1.1 2010-07-09 09:11:49 -04:00
James MacAulay
6b79f25c87 rake release 2010-07-09 09:11:41 -04:00
James MacAulay
ff829e7996 fix if tag parsing with expressions starting with and/or 2010-07-07 16:48:23 -04:00
James MacAulay
d53a4e1834 rake default task is 'test' 2010-07-06 16:01:15 -04:00
10 changed files with 71 additions and 8 deletions

BIN
.CHANGELOG.swp Normal file

Binary file not shown.

BIN
.liquid.gemspec.swp Normal file

Binary file not shown.

View File

@@ -1,3 +1,5 @@
* Make context and assign work the same
* Ruby 1.9.1 bugfixes
* Fix LiquidView for Rails 2.2. Fix local assigns for all versions of Rails

View File

@@ -4,6 +4,8 @@ require 'rake'
require 'rake/testtask'
require 'rake/gempackagetask'
task :default => 'test'
Rake::TestTask.new(:test) do |t|
t.libs << "lib"
t.libs << "test"
@@ -16,6 +18,11 @@ 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"
end
namespace :profile do

View File

@@ -6,7 +6,7 @@ module Liquid
#
# You can then use the variable later in the page.
#
# {{ monkey }}
# {{ foo }}
#
class Assign < Tag
Syntax = /(#{VariableSignature}+)\s*=\s*(#{QuotedFragment}+)/
@@ -23,11 +23,11 @@ module Liquid
end
def render(context)
context.scopes.last[@to.to_s] = context[@from]
context.scopes.last[@to] = context[@from]
''
end
end
Template.register_tag('assign', Assign)
end
end

View File

@@ -6,7 +6,7 @@ module Liquid
# Monkeys!
# {% endcapture %}
# ...
# <h1>{{ monkeys }}</h1>
# <h1>{{ heading }}</h1>
#
# Capture is useful for saving content for use later in your template, such as
# in a sidebar or footer.
@@ -26,7 +26,7 @@ module Liquid
def render(context)
output = super
context[@to] = output.join
context.scopes.last[@to] = output.join
''
end
end

View File

@@ -14,7 +14,7 @@ module Liquid
class If < Block
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/
ExpressionsAndOperators = /(?:and|or|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
ExpressionsAndOperators = /(?:\b(?:and|or)\b|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
def initialize(tag_name, markup, tokens)

View File

@@ -1,10 +1,9 @@
Gem::Specification.new do |s|
s.name = %q{liquid}
s.version = "2.1.0"
s.version = "2.1.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Tobias Luetke"]
s.date = %q{2009-04-13}
s.description = %q{A secure, non-evaling end user template engine with aesthetic markup.}
s.email = %q{tobi@leetsoft.com}
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]

41
test/capture_test.rb Normal file
View File

@@ -0,0 +1,41 @@
require File.dirname(__FILE__) + '/helper'
class CaptureTest < Test::Unit::TestCase
include Liquid
def test_captures_block_content_in_variable
assert_template_result("test string", "{% capture 'var' %}test string{% endcapture %}{{var}}", {})
end
def test_capture_to_variable_from_outer_scope_if_existing
template_source = <<-END_TEMPLATE
{% assign var = '' %}
{% if true %}
{% capture var %}first-block-string{% endcapture %}
{% endif %}
{% if true %}
{% capture var %}test-string{% endcapture %}
{% endif %}
{{var}}
END_TEMPLATE
template = Template.parse(template_source)
rendered = template.render
assert_equal "test-string", rendered.gsub(/\s/, '')
end
def test_assigning_from_capture
template_source = <<-END_TEMPLATE
{% assign first = '' %}
{% assign second = '' %}
{% for number in (1..3) %}
{% capture first %}{{number}}{% endcapture %}
{% assign second = first %}
{% endfor %}
{{ first }}-{{ second }}
END_TEMPLATE
template = Template.parse(template_source)
rendered = template.render
assert_equal "3-3", rendered.gsub(/\s/, '')
end
end

View File

@@ -44,6 +44,20 @@ class IfElseTest < Test::Unit::TestCase
end
end
def test_comparison_of_expressions_starting_with_and_or_or
assigns = {'order' => {'items_count' => 0}, 'android' => {'name' => 'Roy'}}
assert_nothing_raised do
assert_template_result( "YES",
"{% if android.name == 'Roy' %}YES{% endif %}",
assigns)
end
assert_nothing_raised do
assert_template_result( "YES",
"{% if order.items_count == 0 %}YES{% endif %}",
assigns)
end
end
def test_if_and
assert_template_result(' YES ','{% if true and true %} YES {% endif %}')
assert_template_result('','{% if false and true %} YES {% endif %}')