mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 00:05:42 +03:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6831eac902 | ||
|
|
13f98de7f3 | ||
|
|
e26f509277 |
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{liquid}
|
||||
s.version = "2.1.2"
|
||||
s.version = "2.1.3"
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Tobias Luetke"]
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user