Permalink
Browse files

Merge branch 'master' of git@github.com:tobi/liquid

Conflicts:
	lib/liquid.rb
	lib/liquid/context.rb
	lib/liquid/variable.rb
	test/standard_tag_test.rb
  • Loading branch information...
2 parents 8ac4d6a + 37e913f commit a65bd76e726c3a4b50a25df8289a77c3945d0b78 @tobi tobi committed Jun 15, 2009
Showing with 3,809 additions and 401 deletions.
  1. +10 −6 CHANGELOG
  2. +7 −0 Rakefile
  3. +27 −16 lib/extras/liquid_view.rb
  4. +15 −27 lib/liquid.rb
  5. +23 −23 lib/liquid/block.rb
  6. +30 −33 lib/liquid/condition.rb
  7. +7 −11 lib/liquid/context.rb
  8. +7 −7 lib/liquid/document.rb
  9. +17 −16 lib/liquid/drop.rb
  10. +27 −27 lib/liquid/htmltags.rb
  11. +4 −4 lib/liquid/module_ex.rb
  12. +17 −18 lib/liquid/strainer.rb
  13. +8 −8 lib/liquid/tag.rb
  14. +9 −9 lib/liquid/tags/capture.rb
  15. +54 −53 lib/liquid/template.rb
  16. +3 −6 lib/liquid/variable.rb
  17. +14 −4 liquid.gemspec
  18. +92 −0 performance/shopify.rb
  19. +33 −0 performance/shopify/comment_form.rb
  20. +45 −0 performance/shopify/database.rb
  21. +7 −0 performance/shopify/json_filter.rb
  22. +18 −0 performance/shopify/liquid.rb
  23. +18 −0 performance/shopify/money_filter.rb
  24. +93 −0 performance/shopify/paginate.rb
  25. +98 −0 performance/shopify/shop_filter.rb
  26. +25 −0 performance/shopify/tag_filter.rb
  27. +945 −0 performance/shopify/vision.database.yml
  28. +11 −0 performance/shopify/weight_filter.rb
  29. +74 −0 performance/tests/dropify/article.liquid
  30. +33 −0 performance/tests/dropify/blog.liquid
  31. +66 −0 performance/tests/dropify/cart.liquid
  32. +22 −0 performance/tests/dropify/collection.liquid
  33. +47 −0 performance/tests/dropify/index.liquid
  34. +8 −0 performance/tests/dropify/page.liquid
  35. +68 −0 performance/tests/dropify/product.liquid
  36. +105 −0 performance/tests/dropify/theme.liquid
  37. +74 −0 performance/tests/ripen/article.liquid
  38. +13 −0 performance/tests/ripen/blog.liquid
  39. +54 −0 performance/tests/ripen/cart.liquid
  40. +29 −0 performance/tests/ripen/collection.liquid
  41. +32 −0 performance/tests/ripen/index.liquid
  42. +4 −0 performance/tests/ripen/page.liquid
  43. +75 −0 performance/tests/ripen/product.liquid
  44. +85 −0 performance/tests/ripen/theme.liquid
  45. +56 −0 performance/tests/tribble/404.liquid
  46. +98 −0 performance/tests/tribble/article.liquid
  47. +41 −0 performance/tests/tribble/blog.liquid
  48. +134 −0 performance/tests/tribble/cart.liquid
  49. +70 −0 performance/tests/tribble/collection.liquid
  50. +94 −0 performance/tests/tribble/index.liquid
  51. +56 −0 performance/tests/tribble/page.liquid
  52. +116 −0 performance/tests/tribble/product.liquid
  53. +51 −0 performance/tests/tribble/search.liquid
  54. +90 −0 performance/tests/tribble/theme.liquid
  55. +66 −0 performance/tests/vogue/article.liquid
  56. +32 −0 performance/tests/vogue/blog.liquid
  57. +58 −0 performance/tests/vogue/cart.liquid
  58. +19 −0 performance/tests/vogue/collection.liquid
  59. +22 −0 performance/tests/vogue/index.liquid
  60. +3 −0 performance/tests/vogue/page.liquid
  61. +62 −0 performance/tests/vogue/product.liquid
  62. +122 −0 performance/tests/vogue/theme.liquid
  63. +13 −12 test/context_test.rb
  64. +4 −4 test/security_test.rb
  65. +112 −117 test/standard_tag_test.rb
  66. +37 −0 test/variable_test.rb
View
@@ -1,9 +1,13 @@
+* Ruby 1.9.1 bugfixes
+
+* Fix LiquidView for Rails 2.2. Fix local assigns for all versions of Rails
+
* Fixed gem install rake task
* Improve Error encapsulation in liquid by maintaining a own set of exceptions instead of relying on ruby build ins
* 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
@@ -22,17 +26,17 @@
* 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 )
View
@@ -21,4 +21,11 @@ Hoe.new(PKG_NAME, PKG_VERSION) do |p|
p.author = "Tobias Luetke"
p.email = "tobi@leetsoft.com"
p.url = "http://www.liquidmarkup.org"
+end
+
+desc "Run the liquid profile/perforamce coverage"
+task :profile do
+
+ ruby "performance/shopify.rb"
+
end
View
@@ -5,32 +5,43 @@
#
# 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
+ @helpers @assigns_added @template @_render_stack @template_format @assigns )
+
+ def self.call(template)
+ "LiquidView.new(self).render(template, local_assigns)"
+ end
- def initialize(action_view)
- @action_view = action_view
+ def initialize(view)
+ @view = view
end
-
- def render(template, local_assigns_for_rails_less_than_2_1_0 = nil)
- @action_view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
- assigns = @action_view.assigns.dup
+ def render(template, local_assigns = nil)
+ @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
- # template is a Template object in Rails >=2.1.0, a source string previously.
- if template.respond_to? :source
- source = template.source
- local_assigns = template.locals
+ # 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|
+ hash[ivar[1..-1]] = @view.instance_variable_get(ivar)
+ hash
+ end
else
- source = template
- local_assigns = local_assigns_for_rails_less_than_2_1_0
+ assigns = @view.assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
end
-
- if content_for_layout = @action_view.instance_variable_get("@content_for_layout")
+
+ 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)
+ assigns.merge!(local_assigns.stringify_keys)
liquid = Liquid::Template.parse(source)
- liquid.render(assigns, :filters => [@action_view.controller.master_helper_module], :registers => {:action_view => @action_view, :controller => @action_view.controller})
+ liquid.render(assigns, :filters => [@view.controller.master_helper_module], :registers => {:action_view => @view, :controller => @view.controller})
end
def compilable?
View
@@ -22,41 +22,29 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
module Liquid
-
- # Basic apperence:
-
- # Tags {% look like this %}
- TagStart = /\{%/
- TagEnd = /%\}/
-
- # Variables {{look}} like {{this}}
- VariableStart = /\{\{/
- VariableEnd = /\}\}/
-
- # Arguments are passed {% like: this %}
- FilterArgumentSeparator = ':'
-
- # Hashes are separated {{ like.this }}
- VariableAttributeSeparator = '.'
-
- # Filters are piped in {{ like | this }}
- FilterSeparator = /\|/
-
- # Muliple arguments are {% separated: like, this %}
+ FilterSeparator = /\|/
ArgumentSeparator = ','
-
-
- # Lexical parsing regexped go below.
+ FilterArgumentSeparator = ':'
+ VariableAttributeSeparator = '.'
+ TagStart = /\{\%/
+ TagEnd = /\%\}/
VariableSignature = /\(?[\w\-\.\[\]]\)?/
- VariableSegment = /[\w\-]\??/
+ VariableSegment = /[\w\-]/
+ VariableStart = /\{\{/
+ VariableEnd = /\}\}/
VariableIncompleteEnd = /\}\}?/
QuotedString = /"[^"]+"|'[^']+'/
- QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/
+ QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/
+ StrictQuotedFragment = /"[^"]+"|'[^']+'|[^\s,\|,\:,\,]+/
+ FirstFilterArgument = /#{FilterArgumentSeparator}(?:#{StrictQuotedFragment})/
+ OtherFilterArgument = /#{ArgumentSeparator}(?:#{StrictQuotedFragment})/
+ SpacelessFilter = /#{FilterSeparator}(?:#{StrictQuotedFragment})(?:#{FirstFilterArgument}(?:#{OtherFilterArgument})*)?/
+ Expression = /(?:#{QuotedFragment}(?:#{SpacelessFilter})*)/
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/
AnyStartingTag = /\{\{|\{\%/
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/
- VariableParser = /\[[^\]]+\]|#{VariableSegment}+/
+ VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/
end
require 'liquid/drop'
View
@@ -1,19 +1,19 @@
module Liquid
-
+
class Block < Tag
def parse(tokens)
@nodelist ||= []
@nodelist.clear
- while token = tokens.shift
+ while token = tokens.shift
case token
- when /^#{TagStart}/
+ when /^#{TagStart}/
if token =~ /^#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}$/
# if we found the proper block delimitor just end parsing here and let the outer block
- # proceed
+ # proceed
if block_delimiter == $1
end_tag
return
@@ -23,10 +23,10 @@ def parse(tokens)
if tag = Template.tags[$1]
@nodelist << tag.new($1, $2, tokens)
else
- # this tag is not registered with the system
+ # this tag is not registered with the system
# pass it to the current block for special handling or error reporting
unknown_tag($1, $2, tokens)
- end
+ end
else
raise SyntaxError, "Tag '#{token}' was not properly terminated with regexp: #{TagEnd.inspect} "
end
@@ -37,19 +37,19 @@ def parse(tokens)
else
@nodelist << token
end
- end
-
- # Make sure that its ok to end parsing in the current block.
- # Effectively this method will throw and exception unless the current block is
- # of type Document
+ end
+
+ # Make sure that its ok to end parsing in the current block.
+ # Effectively this method will throw and exception unless the current block is
+ # of type Document
assert_missing_delimitation!
- end
-
- def end_tag
+ end
+
+ def end_tag
end
def unknown_tag(tag, params, tokens)
- case tag
+ case tag
when 'else'
raise SyntaxError, "#{block_name} tag does not expect else tag"
when 'end'
@@ -61,7 +61,7 @@ def unknown_tag(tag, params, tokens)
def block_delimiter
"end#{block_name}"
- end
+ end
def block_name
@tag_name
@@ -77,7 +77,7 @@ def create_variable(token)
def render(context)
render_all(@nodelist, context)
end
-
+
protected
def assert_missing_delimitation!
@@ -86,12 +86,12 @@ def assert_missing_delimitation!
def render_all(list, context)
list.collect do |token|
- begin
+ begin
token.respond_to?(:render) ? token.render(context) : token
- rescue Exception => e
+ rescue Exception => e
context.handle_error(e)
- end
- end
+ end
+ end
end
- end
-end
+ end
+end
Oops, something went wrong.

0 comments on commit a65bd76

Please sign in to comment.