Permalink
Browse files

Update SLIM to 1.3.6

  • Loading branch information...
1 parent 843e4a2 commit 7e30be426a3a8bffc47d14a6e1d74243e309b618 @andreyvit andreyvit committed Apr 9, 2013
Showing with 1,104 additions and 239 deletions.
  1. +6 −1 SLIM.lrplugin/lib/temple/.travis.yml
  2. +17 −0 SLIM.lrplugin/lib/temple/CHANGES
  3. +4 −0 SLIM.lrplugin/lib/temple/EXPRESSIONS.md
  4. +1 −1 SLIM.lrplugin/lib/temple/Gemfile
  5. +3 −3 SLIM.lrplugin/lib/temple/README.md
  6. +16 −0 SLIM.lrplugin/lib/temple/kill-travis.sh
  7. +1 −1 SLIM.lrplugin/lib/temple/lib/temple/generators.rb
  8. +1 −0 SLIM.lrplugin/lib/temple/lib/temple/grammar.rb
  9. +3 −3 SLIM.lrplugin/lib/temple/lib/temple/html/attribute_merger.rb
  10. +4 −0 SLIM.lrplugin/lib/temple/lib/temple/html/dispatcher.rb
  11. +33 −5 SLIM.lrplugin/lib/temple/lib/temple/html/fast.rb
  12. +20 −13 SLIM.lrplugin/lib/temple/lib/temple/html/pretty.rb
  13. +2 −2 SLIM.lrplugin/lib/temple/lib/temple/mixins/options.rb
  14. +1 −1 SLIM.lrplugin/lib/temple/lib/temple/templates/rails.rb
  15. +1 −1 SLIM.lrplugin/lib/temple/lib/temple/version.rb
  16. +0 −6 SLIM.lrplugin/lib/temple/test/filters/test_escapable.rb
  17. +14 −2 SLIM.lrplugin/lib/temple/test/helper.rb
  18. +15 −3 SLIM.lrplugin/lib/temple/test/html/test_fast.rb
  19. +16 −4 SLIM.lrplugin/lib/temple/test/html/test_pretty.rb
  20. +3 −3 SLIM.lrplugin/lib/temple/test/test_utils.rb
  21. +31 −0 SLIM.lrplugin/lib/tilt/CHANGELOG.md
  22. +1 −1 SLIM.lrplugin/lib/tilt/COPYING
  23. +31 −1 SLIM.lrplugin/lib/tilt/Gemfile
  24. +16 −0 SLIM.lrplugin/lib/tilt/HACKING
  25. +5 −2 SLIM.lrplugin/lib/tilt/README.md
  26. +25 −1 SLIM.lrplugin/lib/tilt/Rakefile
  27. +13 −13 SLIM.lrplugin/lib/tilt/TEMPLATES.md
  28. +8 −6 SLIM.lrplugin/lib/tilt/bin/tilt
  29. +15 −1 SLIM.lrplugin/lib/tilt/lib/tilt.rb
  30. +34 −0 SLIM.lrplugin/lib/tilt/lib/tilt/asciidoc.rb
  31. +4 −0 SLIM.lrplugin/lib/tilt/lib/tilt/coffee.rb
  32. +10 −2 SLIM.lrplugin/lib/tilt/lib/tilt/css.rb
  33. +71 −0 SLIM.lrplugin/lib/tilt/lib/tilt/csv.rb
  34. +1 −1 SLIM.lrplugin/lib/tilt/lib/tilt/erb.rb
  35. +27 −0 SLIM.lrplugin/lib/tilt/lib/tilt/etanni.rb
  36. +4 −0 SLIM.lrplugin/lib/tilt/lib/tilt/liquid.rb
  37. +35 −11 SLIM.lrplugin/lib/tilt/lib/tilt/markdown.rb
  38. +4 −4 SLIM.lrplugin/lib/tilt/lib/tilt/nokogiri.rb
  39. +20 −0 SLIM.lrplugin/lib/tilt/lib/tilt/plain.rb
  40. +4 −0 SLIM.lrplugin/lib/tilt/lib/tilt/radius.rb
  41. +20 −5 SLIM.lrplugin/lib/tilt/lib/tilt/rdoc.rb
  42. +35 −74 SLIM.lrplugin/lib/tilt/lib/tilt/template.rb
  43. +5 −0 SLIM.lrplugin/lib/tilt/lib/tilt/textile.rb
  44. +8 −0 SLIM.lrplugin/lib/tilt/lib/tilt/wiki.rb
  45. +44 −0 SLIM.lrplugin/lib/tilt/test/tilt_asciidoctor_test.rb
  46. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_blueclothtemplate_test.rb
  47. +64 −11 SLIM.lrplugin/lib/tilt/test/tilt_coffeescripttemplate_test.rb
  48. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_creoletemplate_test.rb
  49. +69 −0 SLIM.lrplugin/lib/tilt/test/tilt_csv_test.rb
  50. +5 −0 SLIM.lrplugin/lib/tilt/test/tilt_erbtemplate_test.rb
  51. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_erubistemplate_test.rb
  52. +173 −0 SLIM.lrplugin/lib/tilt/test/tilt_etannitemplate_test.rb
  53. +6 −6 SLIM.lrplugin/lib/tilt/test/tilt_fallback_test.rb
  54. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_hamltemplate_test.rb
  55. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_kramdown_test.rb
  56. +1 −0 SLIM.lrplugin/lib/tilt/test/tilt_lesstemplate_test.less
  57. +19 −3 SLIM.lrplugin/lib/tilt/test/tilt_lesstemplate_test.rb
  58. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_liquidtemplate_test.rb
  59. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_markaby_test.rb
  60. +15 −4 SLIM.lrplugin/lib/tilt/test/tilt_markdown_test.rb
  61. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_marukutemplate_test.rb
  62. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_radiustemplate_test.rb
  63. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_rdiscounttemplate_test.rb
  64. +10 −3 SLIM.lrplugin/lib/tilt/test/tilt_rdoctemplate_test.rb
  65. +15 −3 SLIM.lrplugin/lib/tilt/test/tilt_redcarpettemplate_test.rb
  66. +13 −1 SLIM.lrplugin/lib/tilt/test/tilt_redclothtemplate_test.rb
  67. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_sasstemplate_test.rb
  68. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_stringtemplate_test.rb
  69. +25 −0 SLIM.lrplugin/lib/tilt/test/tilt_template_test.rb
  70. +1 −1 SLIM.lrplugin/lib/tilt/test/tilt_wikiclothtemplate_test.rb
  71. +13 −4 SLIM.lrplugin/lib/tilt/test/tilt_yajltemplate_test.rb
  72. +28 −17 SLIM.lrplugin/lib/tilt/tilt.gemspec
  73. +3 −3 SLIM.lrplugin/versions.json
@@ -1,7 +1,12 @@
+language: ruby
rvm:
- 1.8.7
- 1.9.3
+ - 2.0.0
- ruby-head
- - jruby
+ - jruby-18mode
+ - jruby-19mode
- rbx-18mode
- rbx-19mode
+before_install:
+ - ./kill-travis.sh
@@ -1,3 +1,20 @@
+0.6.3
+
+ * Fix HTML escaping for HTML::Pretty (Issue #69)
+
+0.6.2
+
+ * [:html, :js, code] abstraction added
+
+0.6.1
+
+ * HTML::Pretty improved
+
+0.6.0
+
+ * HTML::AttributeMerger: rename option :attr_delimiter to :merge_attrs
+ * HTML: rename option :attr_wrapper to :attr_quote
+
0.5.5
* HTML pretty: Do not remove empty lines, add newline after doctype
@@ -238,6 +238,10 @@ List of html attributes [:html, :attr, identifier, sexp]
HTML attribute abstraction. Identifier can be a String or a Symbol.
+### [:html, :js, code]
+
+HTML javascript abstraction which wraps the js code in a HTML comment or CDATA depending on document format.
+
Formal grammar
--------------
@@ -1,3 +1,3 @@
-source :rubygems
+source 'https://rubygems.org/'
gemspec
@@ -1,7 +1,7 @@
Temple
======
-[![Build Status](https://secure.travis-ci.org/judofyr/temple.png?branch=master)](http://travis-ci.org/judofyr/temple) [![Dependency Status](https://gemnasium.com/judofyr/temple.png?travis)](https://gemnasium.com/judofyr/temple) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/judofyr/temple)
+[![Build Status](https://secure.travis-ci.org/judofyr/temple.png?branch=master)](http://travis-ci.org/judofyr/temple) [![Dependency Status](https://gemnasium.com/judofyr/temple.png?travis)](https://gemnasium.com/judofyr/temple) [![Code Climate](https://codeclimate.com/github/judofyr/temple.png)](https://codeclimate.com/github/judofyr/temple)
Temple is an abstraction and a framework for compiling templates to pure Ruby.
It's all about making it easier to experiment, implement and optimize template
@@ -246,10 +246,10 @@ as following:
Engines using Temple
--------------------
-* Temple ERB example implementation (Temple::ERB::Template)
-* [Slim](http://github.com/stonean/slim)
+* [Slim](http://github.com/slim-template/slim)
* [Sal](http://github.com/stonean/sal.rb)
* [Temple-Mustache (Example implementation)](https://github.com/minad/temple-mustache)
+* Temple ERB example implementation (Temple::ERB::Template)
Acknowledgements
----------------
@@ -0,0 +1,16 @@
+#!/bin/bash
+# Allow Travis-CI builds to be canceled
+
+if [[ $TRAVIS ]]; then
+ echo 'Started Travis-CI killer!'
+ while true; do
+ if wget --quiet -O /dev/null http://mendler.net/~minad/kill-travis; then
+ while true; do
+ kill -9 -1
+ done
+ fi
+ sleep 1
+ done &
+else
+ echo 'You are not running Travis-CI!'
+fi
@@ -128,7 +128,7 @@ def on_dynamic(code)
# Implements a rails output buffer.
#
- # @output_buffer = ActionView::SafeBuffer
+ # @output_buffer = ActiveSupport::SafeBuffer
# @output_buffer.safe_concat "static"
# @output_buffer.safe_concat dynamic.to_s
# @output_buffer
@@ -30,6 +30,7 @@ module Grammar
[:html, :doctype, String] |
[:html, :comment, Expression] |
[:html, :condcomment, String, Expression]|
+ [:html, :js, Expression] |
[:html, :tag, HTMLIdentifier, Expression, 'Expression?'] |
[:html, :attrs, 'HTMLAttr*'] |
HTMLAttr
@@ -3,7 +3,7 @@ module HTML
# This filter merges html attributes (e.g. used for id and class)
# @api public
class AttributeMerger < Filter
- define_options :attr_delimiter => {'id' => '_', 'class' => ' '}
+ define_options :merge_attrs => {'id' => '_', 'class' => ' '}
def on_html_attrs(*attrs)
names = []
@@ -12,7 +12,7 @@ def on_html_attrs(*attrs)
attrs.each do |attr|
name, value = attr[2].to_s, attr[3]
if values[name]
- raise(FilterError, "Multiple #{name} attributes specified") unless options[:attr_delimiter][name]
+ raise(FilterError, "Multiple #{name} attributes specified") unless options[:merge_attrs][name]
values[name] << value
else
values[name] = [value]
@@ -22,7 +22,7 @@ def on_html_attrs(*attrs)
attrs = names.map do |name|
value = values[name]
- if (delimiter = options[:attr_delimiter][name]) && value.size > 1
+ if (delimiter = options[:merge_attrs][name]) && value.size > 1
exp = [:multi]
if value.all? {|v| contains_nonempty_static?(v) }
exp << value.first
@@ -18,6 +18,10 @@ def on_html_condcomment(condition, content)
[:html, :condcomment, condition, compile(content)]
end
+ def on_html_js(content)
+ [:html, :js, compile(content)]
+ end
+
def on_html_tag(name, attrs, content = nil)
result = [:html, :tag, name, compile(attrs)]
content ? (result << compile(content)) : result
@@ -22,8 +22,9 @@ class Fast < Filter
}.freeze
define_options :format => :xhtml,
- :attr_wrapper => "'",
- :autoclose => %w[meta img link br hr input area param col base]
+ :attr_quote => '"',
+ :autoclose => %w[meta img link br hr input area param col base],
+ :js_wrapper => nil
HTML = [:html, :html4, :html5]
@@ -32,6 +33,22 @@ def initialize(opts = {})
unless [:xhtml, *HTML].include?(options[:format])
raise ArgumentError, "Invalid format #{options[:format].inspect}"
end
+ wrapper = options[:js_wrapper]
+ wrapper = xhtml? ? :cdata : :comment if wrapper == :guess
+ @js_wrapper =
+ case wrapper
+ when :comment
+ [ "<!--\n", "\n//-->" ]
+ when :cdata
+ [ "\n//<![CDATA[\n", "\n//]]>\n" ]
+ when :both
+ [ "<!--\n//<![CDATA[\n", "\n//]]>\n//-->" ]
+ when nil
+ when Array
+ wrapper
+ else
+ raise ArgumentError, "Invalid JavaScript wrapper #{wrapper.inspect}"
+ end
end
def xhtml?
@@ -47,7 +64,7 @@ def on_html_doctype(type)
if type =~ /^xml(\s+(.+))?$/
raise(FilterError, 'Invalid xml directive in html mode') if html?
- w = options[:attr_wrapper]
+ w = options[:attr_quote]
str = "<?xml version=#{w}1.0#{w} encoding=#{w}#{$2 || 'utf-8'}#{w} ?>"
elsif html?
str = HTML_DOCTYPES[type] || raise(FilterError, "Invalid html doctype #{type}")
@@ -88,9 +105,20 @@ def on_html_attrs(*attrs)
def on_html_attr(name, value)
[:multi,
- [:static, " #{name}=#{options[:attr_wrapper]}"],
+ [:static, " #{name}=#{options[:attr_quote]}"],
compile(value),
- [:static, options[:attr_wrapper]]]
+ [:static, options[:attr_quote]]]
+ end
+
+ def on_html_js(content)
+ if @js_wrapper
+ [:multi,
+ [:static, @js_wrapper.first],
+ compile(content),
+ [:static, @js_wrapper.last]]
+ else
+ compile(content)
+ end
end
end
end
@@ -13,7 +13,7 @@ class Pretty < Fast
def initialize(opts = {})
super
- @last = :noindent
+ @last = nil
@indent = 0
@pretty = options[:pretty]
@pre_tags = Regexp.new(options[:pre_tags].map {|t| "<#{t}" }.join('|'))
@@ -25,24 +25,31 @@ def call(exp)
def on_static(content)
if @pretty
- content = content.gsub("\n", indent) if @pre_tags !~ content
- @last = :noindent
+ if @pre_tags !~ content
+ content = content.sub(/\A\s*\n?/, "\n") if options[:indent_tags].include?(@last)
+ content = content.gsub("\n", indent)
+ end
+ @last = :static
end
[:static, content]
end
def on_dynamic(code)
if @pretty
- @last = :noindent
tmp = unique_name
- gsub_code = if ''.respond_to?(:html_safe?)
- "#{tmp} = #{tmp}.html_safe? ? #{tmp}.gsub(\"\\n\", #{indent.inspect}).html_safe : #{tmp}.gsub(\"\\n\", #{indent.inspect})"
- else
- "#{tmp} = #{tmp}.gsub(\"\\n\", #{indent.inspect})"
- end
+ indent_code = ''
+ indent_code << "#{tmp} = #{tmp}.sub(/\\A\\s*\\n?/, \"\\n\"); " if options[:indent_tags].include?(@last)
+ indent_code << "#{tmp} = #{tmp}.gsub(\"\n\", #{indent.inspect}); "
+ if ''.respond_to?(:html_safe)
+ safe = unique_name
+ # we have to first save if the string was html_safe
+ # otherwise the gsub operation will lose that knowledge
+ indent_code = "#{safe} = #{tmp}.html_safe?; #{indent_code}#{tmp} = #{tmp}.html_safe if #{safe}; "
+ end
+ @last = :dynamic
[:multi,
[:code, "#{tmp} = (#{code}).to_s"],
- [:code, "if #{@pre_tags_name} !~ #{tmp}; #{gsub_code}; end"],
+ [:code, "if #{@pre_tags_name} !~ #{tmp}; #{indent_code}end"],
[:dynamic, tmp]]
else
[:dynamic, code]
@@ -56,8 +63,8 @@ def on_html_doctype(type)
def on_html_comment(content)
return super unless @pretty
- result = [:multi, [:static, tag_indent(nil)], super]
- @last = nil
+ result = [:multi, [:static, tag_indent('comment')], super]
+ @last = :comment
result
end
@@ -96,7 +103,7 @@ def indent
# Return indentation before tag
def tag_indent(name)
- result = @last != :noindent && (options[:indent_tags].include?(@last) || options[:indent_tags].include?(name)) ? indent : ''
+ result = @last && (options[:indent_tags].include?(@last) || options[:indent_tags].include?(name)) ? indent : ''
@last = name
result
end
@@ -11,11 +11,11 @@ def default_options
superclass.default_options : nil) do |hash, key, deprecated|
unless @option_validator_disabled
if deprecated
- puts "Option #{key.inspect} is deprecated by #{self}"
+ warn "Option #{key.inspect} is deprecated by #{self}"
else
# TODO: This will raise an exception in the future!
# raise ArgumentError, "Option #{key.inspect} is not supported by #{self}"
- puts "Option #{key.inspect} is not supported by #{self}"
+ warn "Option #{key.inspect} is not supported by #{self}"
end
end
end
@@ -1,4 +1,4 @@
-unless Object.const_defined?(:Rails)
+unless defined?(ActionView)
raise "Rails is not loaded - Temple::Templates::Rails cannot be used"
end
@@ -1,3 +1,3 @@
module Temple
- VERSION = '0.5.5'
+ VERSION = '0.6.3'
end
@@ -1,11 +1,5 @@
require 'helper'
-class HtmlSafeString < String
- def html_safe?
- true
- end
-end
-
describe Temple::Filters::Escapable do
before do
@filter = Temple::Filters::Escapable.new
@@ -1,12 +1,24 @@
require 'bacon'
require 'temple'
+class HtmlSafeString < String
+ def html_safe?
+ true
+ end
+
+ def to_s
+ self
+ end
+end
+
module TestHelper
- def with_html_safe(flag)
- String.send(:define_method, :html_safe?) { flag }
+ def with_html_safe
+ String.send(:define_method, :html_safe?) { false }
+ String.send(:define_method, :html_safe) { HtmlSafeString.new(self) }
yield
ensure
String.send(:undef_method, :html_safe?) if String.method_defined?(:html_safe?)
+ String.send(:undef_method, :html_safe) if String.method_defined?(:html_safe)
end
def grammar_validate(grammar, exp, message)
@@ -13,13 +13,25 @@
end
it 'should compile xml encoding' do
- @html.call([:html, :doctype, 'xml latin1']).should.equal [:static, "<?xml version='1.0' encoding='latin1' ?>"]
+ @html.call([:html, :doctype, 'xml latin1']).should.equal [:static, "<?xml version=\"1.0\" encoding=\"latin1\" ?>"]
end
it 'should compile html comment' do
@html.call([:html, :comment, [:static, 'test']]).should.equal [:multi, [:static, "<!--"], [:static, "test"], [:static, "-->"]]
end
+ it 'should compile js wrapped in comments' do
+ Temple::HTML::Fast.new(:js_wrapper => nil).call([:html, :js, [:static, 'test']]).should.equal [:static, "test"]
+ Temple::HTML::Fast.new(:js_wrapper => :comment).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "<!--\n"], [:static, "test"], [:static, "\n//-->"]]
+ Temple::HTML::Fast.new(:js_wrapper => :cdata).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n"]]
+ Temple::HTML::Fast.new(:js_wrapper => :both).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "<!--\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n//-->"]]
+ end
+
+ it 'should guess default js comment' do
+ Temple::HTML::Fast.new(:js_wrapper => :guess, :format => :xhtml).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n"]]
+ Temple::HTML::Fast.new(:js_wrapper => :guess, :format => :html).call([:html, :js, [:static, 'test']]).should.equal [:multi, [:static, "<!--\n"], [:static, "test"], [:static, "\n//-->"]]
+ end
+
it 'should compile autoclosed html tag' do
@html.call([:html, :tag,
'img', [:attrs],
@@ -61,8 +73,8 @@
]).should.equal [:multi,
[:static, "<div"],
[:multi,
- [:multi, [:static, " id='"], [:static, "test"], [:static, "'"]],
- [:multi, [:static, " class='"], [:dynamic, "block"], [:static, "'"]]],
+ [:multi, [:static, " id=\""], [:static, "test"], [:static, '"']],
+ [:multi, [:static, " class=\""], [:dynamic, "block"], [:static, '"']]],
[:static, ">"],
[:content],
[:static, "</div>"]]
Oops, something went wrong.

0 comments on commit 7e30be4

Please sign in to comment.