mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 00:05:42 +03:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6831eac902 | ||
|
|
13f98de7f3 | ||
|
|
e26f509277 | ||
|
|
0417c9e723 | ||
|
|
ffd48880e2 | ||
|
|
6b79f25c87 | ||
|
|
ff829e7996 | ||
|
|
d53a4e1834 |
BIN
.CHANGELOG.swp
Normal file
BIN
.CHANGELOG.swp
Normal file
Binary file not shown.
BIN
.liquid.gemspec.swp
Normal file
BIN
.liquid.gemspec.swp
Normal file
Binary file not shown.
@@ -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
|
||||
|
||||
7
Rakefile
7
Rakefile
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
41
test/capture_test.rb
Normal 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
|
||||
@@ -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 %}')
|
||||
|
||||
Reference in New Issue
Block a user