Permalink
Browse files

updated haml

  • Loading branch information...
1 parent b0b99d0 commit 55e5030cb367054847b917a8c546882a44772bc0 @saturnflyer saturnflyer committed Nov 3, 2010
Showing with 760 additions and 362 deletions.
  1. +1 −0 CHANGELOG
  2. +12 −42 vendor/plugins/haml/Rakefile
  3. +1 −1 vendor/plugins/haml/VERSION
  4. +44 −0 vendor/plugins/haml/doc-src/HAML_CHANGELOG.md
  5. +83 −0 vendor/plugins/haml/doc-src/SASS_CHANGELOG.md
  6. +17 −0 vendor/plugins/haml/doc-src/SASS_REFERENCE.md
  7. +2 −2 vendor/plugins/haml/extra/haml-mode.el
  8. +1 −1 vendor/plugins/haml/extra/sass-mode.el
  9. +1 −1 vendor/plugins/haml/haml.gemspec
  10. +1 −1 vendor/plugins/haml/lib/haml/engine.rb
  11. +4 −6 vendor/plugins/haml/lib/haml/exec.rb
  12. +41 −34 vendor/plugins/haml/lib/haml/precompiler.rb
  13. +16 −6 vendor/plugins/haml/lib/haml/template/plugin.rb
  14. +13 −0 vendor/plugins/haml/lib/haml/util.rb
  15. +15 −1 vendor/plugins/haml/lib/sass/engine.rb
  16. +31 −12 vendor/plugins/haml/lib/sass/less.rb
  17. +4 −1 vendor/plugins/haml/lib/sass/plugin.rb
  18. +2 −1 vendor/plugins/haml/lib/sass/script/color.rb
  19. +5 −6 vendor/plugins/haml/lib/sass/script/funcall.rb
  20. +1 −1 vendor/plugins/haml/lib/sass/script/interpolation.rb
  21. +1 −1 vendor/plugins/haml/lib/sass/script/literal.rb
  22. +11 −0 vendor/plugins/haml/lib/sass/script/node.rb
  23. +12 −9 vendor/plugins/haml/lib/sass/script/number.rb
  24. +11 −8 vendor/plugins/haml/lib/sass/script/operation.rb
  25. +10 −1 vendor/plugins/haml/lib/sass/script/parser.rb
  26. +1 −1 vendor/plugins/haml/lib/sass/script/string_interpolation.rb
  27. +0 −5 vendor/plugins/haml/lib/sass/scss/css_parser.rb
  28. +9 −1 vendor/plugins/haml/lib/sass/scss/parser.rb
  29. +1 −1 vendor/plugins/haml/lib/sass/scss/static_parser.rb
  30. +37 −0 vendor/plugins/haml/lib/sass/tree/charset_node.rb
  31. +2 −2 vendor/plugins/haml/lib/sass/tree/directive_node.rb
  32. +34 −2 vendor/plugins/haml/lib/sass/tree/root_node.rb
  33. +1 −1 vendor/plugins/haml/lib/sass/tree/rule_node.rb
  34. +89 −192 vendor/plugins/haml/test/haml/engine_test.rb
  35. +8 −0 vendor/plugins/haml/test/sass/conversion_test.rb
  36. +43 −7 vendor/plugins/haml/test/sass/engine_test.rb
  37. +24 −3 vendor/plugins/haml/test/sass/less_conversion_test.rb
  38. +12 −3 vendor/plugins/haml/test/sass/plugin_test.rb
  39. +4 −0 vendor/plugins/haml/test/sass/results/import_charset.css
  40. +4 −0 vendor/plugins/haml/test/sass/results/import_charset_1_8.css
  41. +4 −0 vendor/plugins/haml/test/sass/results/import_charset_ibm866.css
  42. +60 −0 vendor/plugins/haml/test/sass/script_conversion_test.rb
  43. +18 −1 vendor/plugins/haml/test/sass/script_test.rb
  44. +27 −8 vendor/plugins/haml/test/sass/scss/css_test.rb
  45. +14 −0 vendor/plugins/haml/test/sass/scss/scss_test.rb
  46. +4 −0 vendor/plugins/haml/test/sass/templates/_imported_charset_ibm866.sass
  47. +4 −0 vendor/plugins/haml/test/sass/templates/_imported_charset_utf8.sass
  48. +7 −0 vendor/plugins/haml/test/sass/templates/import_charset.sass
  49. +4 −0 vendor/plugins/haml/test/sass/templates/import_charset_1_8.sass
  50. +9 −0 vendor/plugins/haml/test/sass/templates/import_charset_ibm866.sass
View
1 CHANGELOG
@@ -2,6 +2,7 @@
=== Edge
+* Update Haml to 3.0.23 [Jim Gay]
* Localize <r:date> [Jim Gay]
* Make any date column a valid value for <r:date /> [Jim Gay]
* Move url methods to path [Jim Gay]
View
54 vendor/plugins/haml/Rakefile
@@ -42,7 +42,7 @@ END
# Don't use Rake::GemPackageTast because we want prerequisites to run
# before we load the gemspec.
desc "Build all the packages."
-task :package => [:revision_file, :submodules] do
+task :package => [:revision_file, :submodules, :permissions] do
load scope('haml.gemspec')
Gem::Builder.new(HAML_GEMSPEC).build
pkg = "#{HAML_GEMSPEC.name}-#{HAML_GEMSPEC.version}"
@@ -54,6 +54,16 @@ task :package => [:revision_file, :submodules] do
sh %{gzip pkg/#{pkg}.tar}
end
+task :permissions do
+ sh %{chmod -R a+rx bin}
+ sh %{chmod -R a+r .}
+ require 'shellwords'
+ Dir.glob('test/**/*_test.rb') do |file|
+ next if file =~ %r{^test/haml/spec/}
+ sh %{chmod a+rx #{file}}
+ end
+end
+
task :revision_file do
require 'lib/haml'
@@ -77,54 +87,14 @@ task :install => [:package] do
end
desc "Release a new Haml package to Rubyforge."
-task :release => [:check_release, :release_elpa, :package] do
+task :release => [:check_release, :package] do
name = File.read(scope("VERSION_NAME")).strip
version = File.read(scope("VERSION")).strip
sh %{rubyforge add_release haml haml "#{name} (v#{version})" pkg/haml-#{version}.gem}
sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.gz}
sh %{gem push pkg/haml-#{version}.gem}
end
-# Releases haml-mode.el and sass-mode.el to ELPA.
-task :release_elpa do
- require 'tlsmail'
- require 'time'
- require scope('lib/haml')
-
- next if Haml.version[:prerelease]
- version = Haml.version[:number]
-
- haml_unchanged = mode_unchanged?(:haml, version)
- sass_unchanged = mode_unchanged?(:sass, version)
- next if haml_unchanged && sass_unchanged
- raise "haml-mode.el and sass-mode.el are out of sync." if (!!haml_unchanged) ^ (!!sass_unchanged)
-
- if sass_unchanged && File.read(scope("extra/sass-mode.el")).
- include?(";; Package-Requires: ((haml-mode #{sass_unchanged.inspect}))")
- raise "sass-mode.el doesn't require the same version of haml-mode."
- end
-
- from = `git config user.email`.strip
- raise "Don't know how to send emails except via Gmail" unless from =~ /@gmail.com$/
-
- to = "elpa@tromey.com"
- Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
- Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', from, read_password("GMail Password"), :login) do |smtp|
- smtp.send_message(<<CONTENT, from, to)
-From: Nathan Weizenbaum <#{from}>
-To: #{to}
-Subject: Submitting haml-mode and sass-mode #{version}
-Date: #{Time.now.rfc2822}
-
-haml-mode and sass-mode #{version} are packaged and ready to be included in ELPA.
-They can be downloaded from:
-
- http://github.com/nex3/haml/raw/#{Haml.version[:rev]}/extra/haml-mode.el
- http://github.com/nex3/haml/raw/#{Haml.version[:rev]}/extra/sass-mode.el
-CONTENT
- end
-end
-
# Ensures that the version have been updated for a new release.
task :check_release do
version = File.read(scope("VERSION")).strip
View
2 vendor/plugins/haml/VERSION
@@ -1 +1 @@
-3.0.18
+3.0.23
View
44 vendor/plugins/haml/doc-src/HAML_CHANGELOG.md
@@ -3,6 +3,47 @@
* Table of contents
{:toc}
+## 3.0.23
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.23).
+
+* Fix the error message for unloadable modules when running the executables under Ruby 1.9.2.
+
+* Fix an error when combining old-style and new-style attributes.
+
+## 3.0.22
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.22).
+
+* Allow an empty line after `case` but before `when`.
+
+* Remove `vendor/sass`, which snuck into the gem by mistake
+ and was causing trouble for Heroku users (thanks to [Jacques Crocker](http://railsjedi.com/)).
+
+* Support the Rails 3.1 template handler API.
+
+## 3.0.21
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.21).
+
+* Fix the permissions errors for good.
+
+## 3.0.20
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.20).
+
+* Fix some permissions errors.
+
+## 3.0.19
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.19).
+
+* Fix the `:encoding` option under Ruby 1.9.2.
+
+* Fix interpolated if statement when HTML escaping is enabled.
+
+* Allow the `--unix-newlines` flag to work on Unix, where it's a no-op.
+
## 3.0.18
[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.18).
@@ -14,6 +55,9 @@
* Disambiguate references to the `Rails` module when `haml-rails` is installed.
+* Fix a bug in `haml_tag` that would allow duplicate attributes to be added
+ and make `data-` attributes not work.
+
* Compatibility with Rails 3 final.
## 3.0.17
View
83 vendor/plugins/haml/doc-src/SASS_CHANGELOG.md
@@ -3,6 +3,89 @@
* Table of contents
{:toc}
+## 3.0.23
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.23).
+
+* Fix the error message for unloadable modules when running the executables under Ruby 1.9.2.
+
+### `@charset` Change
+
+The behavior of `@charset` has changed in version 3.0.23
+in order to work around a bug in Safari,
+where `@charset` declarations placed anywhere other than the beginning of the document
+cause some CSS rules to be ignored.
+This change also makes `@charset`s in imported files behave in a more useful way.
+
+#### Ruby 1.9
+
+When using Ruby 1.9, which keeps track of the character encoding of the Sass document internally,
+`@charset` directive in the Sass stylesheet and any stylesheets it imports
+are no longer directly output to the generated CSS.
+They're still used for determining the encoding of the input and output stylesheets,
+but they aren't rendered in the same way other directives are.
+
+Instead, Sass adds a single `@charset` directive at the beginning of the output stylesheet
+if necessary, whether or not the input stylesheet had a `@charset` directive.
+It will add this directive if and only if the output stylesheet contains non-ASCII characters.
+By default, the declared charset will be UTF-8,
+but if the Sass stylesheet declares a different charset then that will be used instead if possible.
+
+One important consequence of this scheme is that it's possible for a Sass file
+to import partials with different encodings (e.g. one encoded as UTF-8 and one as IBM866).
+The output will then be UTF-8, unless the importing stylesheet
+declares a different charset.
+
+#### Ruby 1.8
+
+Ruby 1.8 doesn't have good support for encodings, so it uses a simpler but less accurate
+scheme for figuring out what `@charset` declaration to use for the output stylesheet.
+It just takes the first `@charset` declaration to appear in the stylesheet
+or any of its imports and moves it to the beginning of the document.
+This means that under Ruby 1.8 it's *not* safe to import files with different encodings.
+
+## 3.0.22
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.22).
+
+* Remove `vendor/sass`, which snuck into the gem by mistake
+ and was causing trouble for Heroku users (thanks to [Jacques Crocker](http://railsjedi.com/)).
+
+* `sass-convert` now understands better when it's acceptable
+ to remove parentheses from expressions.
+
+## 3.0.21
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.21).
+
+* Fix the permissions errors for good.
+
+* Fix more `#options` attribute errors.
+
+## 3.0.20
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.20).
+
+* Fix some permissions errors.
+
+* Fix `#options` attribute errors when CSS functions were used with commas.
+
+## 3.0.19
+
+[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.19).
+
+* Make the alpha value for `rgba` colors respect {Sass::Script::Number::PRECISION}.
+
+* Remove all newlines in selectors in `:compressed` mode.
+
+* Make color names case-insensitive.
+
+* Properly detect SCSS files when using `sass -c`.
+
+* Remove spaces after commas in `:compressed` mode.
+
+* Allow the `--unix-newlines` flag to work on Unix, where it's a no-op.
+
## 3.0.18
[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.18).
View
17 vendor/plugins/haml/doc-src/SASS_REFERENCE.md
@@ -329,6 +329,23 @@ Note that Sass does not support the obscure `UTF-32-2143`,
since Ruby does not have support for them
and they're highly unlikely to ever be used in practice.
+#### Output Encoding
+
+In general, Sass will try to encode the output stylesheet
+using the same encoding as the input stylesheet.
+In order for it to do this, though, the input stylesheet must have a `@charset` declaration;
+otherwise, Sass will default to encoding the output stylesheet as UTF-8.
+In addition, it will add a `@charset` declaration to the output
+if it's not plain ASCII.
+
+When other stylesheets with `@charset` declarations are `@import`ed,
+Sass will convert them to the same encoding as the main stylesheet.
+
+Note that Ruby 1.8 does not have good support for character encodings,
+and so Sass behaves somewhat differently when running under it than under Ruby 1.9 and later.
+In Ruby 1.8, Sass simply uses the first `@charset` declaration in the stylesheet
+or any of the other stylesheets it `@import`s.
+
## CSS Extensions
### Nested Rules
View
4 vendor/plugins/haml/extra/haml-mode.el
@@ -4,7 +4,7 @@
;; Author: Nathan Weizenbaum
;; URL: http://github.com/nex3/haml/tree/master
-;; Version: 3.0.14
+;; Version: 3.0.19
;; Created: 2007-03-08
;; By: Nathan Weizenbaum
;; Keywords: markup, language, html
@@ -73,7 +73,7 @@ a specific level to which the current line could be indented.")
`(,(concat haml-tag-beg-re "[><]*[ \t]*$")
"^[ \t]*[&!]?[-=~].*do[ \t]*\\(|.*|[ \t]*\\)?$"
,(concat "^[ \t]*[&!]?[-=~][ \t]*\\("
- (regexp-opt '("if" "unless" "while" "until" "else"
+ (regexp-opt '("if" "unless" "while" "until" "else" "for"
"begin" "elsif" "rescue" "ensure" "when"))
"\\)")
"^[ \t]*/\\(\\[.*\\]\\)?[ \t]*$"
View
2 vendor/plugins/haml/extra/sass-mode.el
@@ -4,7 +4,7 @@
;; Author: Nathan Weizenbaum
;; URL: http://github.com/nex3/haml/tree/master
-;; Version: 3.0.14
+;; Version: 3.0.19
;; Created: 2007-03-15
;; By: Nathan Weizenbaum
;; Keywords: markup, language, css
View
2 vendor/plugins/haml/haml.gemspec
@@ -26,7 +26,7 @@ HAML_GEMSPEC = Gem::Specification.new do |spec|
readmes = Dir['*'].reject{ |x| x =~ /(^|[^.a-z])[a-z]+/ || x == "TODO" }
spec.executables = ['haml', 'html2haml', 'sass', 'css2sass', 'sass-convert']
- spec.files = Dir['rails/init.rb', 'lib/**/*', 'vendor/**/*',
+ spec.files = Dir['rails/init.rb', 'lib/**/*', 'vendor/fssm/**/*',
'bin/*', 'test/**/*', 'extra/**/*', 'Rakefile', 'init.rb',
'.yardopts'] + readmes
spec.homepage = 'http://haml-lang.com/'
View
2 vendor/plugins/haml/lib/haml/engine.rb
@@ -190,7 +190,7 @@ def render(scope = Object.new, locals = {}, &block)
ensure
# Get rid of the current buffer
scope_object.instance_eval do
- @haml_buffer = buffer.upper
+ @haml_buffer = buffer.upper if buffer
end
end
alias_method :to_html, :render
View
10 vendor/plugins/haml/lib/haml/exec.rb
@@ -79,10 +79,8 @@ def set_opts(opts)
@options[:trace] = true
end
- if ::Haml::Util.windows?
- opts.on('--unix-newlines', 'Use Unix-style newlines in written files.') do
- @options[:unix_newlines] = true
- end
+ opts.on('--unix-newlines', 'Use Unix-style newlines in written files.') do
+ @options[:unix_newlines] = true if ::Haml::Util.windows?
end
opts.on_tail("-?", "-h", "--help", "Show this message") do
@@ -157,7 +155,7 @@ def open_file(filename, flag = 'r')
end
def handle_load_error(err)
- dep = err.message.scan(/^no such file to load -- (.*)/)[0]
+ dep = err.message[/^no such file to load -- (.*)/, 1]
raise err if @options[:trace] || dep.nil? || dep.empty?
$stderr.puts <<MESSAGE
Required dependency #{dep} not found!
@@ -357,7 +355,7 @@ def process_result
input = @options[:input]
output = @options[:output]
- @options[:syntax] ||= :scss if input.is_a?(File) && input.path =~ /\.scss$/
+ @options[:for_engine][:syntax] ||= :scss if input.is_a?(File) && input.path =~ /\.scss$/
tree =
if input.is_a?(File) && !@options[:check_syntax]
::Sass::Files.tree_for(input.path, @options[:for_engine])
View
75 vendor/plugins/haml/lib/haml/precompiler.rb
@@ -118,8 +118,8 @@ def locals_code(names)
names.map do |name|
# Can't use || because someone might explicitly pass in false with a symbol
- sym_local = "_haml_locals[#{name.to_sym.inspect}]"
- str_local = "_haml_locals[#{name.to_s.inspect}]"
+ sym_local = "_haml_locals[#{inspect_obj(name.to_sym)}]"
+ str_local = "_haml_locals[#{inspect_obj(name.to_s)}]"
"#{name} = #{sym_local}.nil? ? #{str_local} : #{sym_local}"
end.join(';') + ';'
end
@@ -320,7 +320,7 @@ def flush_merged_text
@to_merge.each do |type, val, tabs|
case type
when :text
- str << val.inspect[1...-1]
+ str << inspect_obj(val)[1...-1]
mtabs += tabs
when :script
if mtabs != 0 && !@options[:ugly]
@@ -336,12 +336,14 @@ def flush_merged_text
end
end
- @precompiled <<
- if @options[:ugly]
- "_hamlout.buffer << \"#{str}\";"
- else
- "_hamlout.push_text(\"#{str}\", #{mtabs}, #{@dont_tab_up_next_text.inspect});"
- end
+ unless str.empty?
+ @precompiled <<
+ if @options[:ugly]
+ "_hamlout.buffer << \"#{str}\";"
+ else
+ "_hamlout.push_text(\"#{str}\", #{mtabs}, #{@dont_tab_up_next_text.inspect});"
+ end
+ end
@precompiled << "\n" * newlines
@to_merge = []
@dont_tab_up_next_text = false
@@ -577,17 +579,17 @@ def parse_tag(line)
raise SyntaxError.new("Invalid tag: \"#{line}\".") unless match = line.scan(/%([-:\w]+)([-:\w\.\#]*)(.*)/)[0]
tag_name, attributes, rest = match
new_attributes_hash = old_attributes_hash = last_line = object_ref = nil
- attributes_hashes = []
+ attributes_hashes = {}
while rest
case rest[0]
when ?{
break if old_attributes_hash
old_attributes_hash, rest, last_line = parse_old_attributes(rest)
- attributes_hashes << [:old, old_attributes_hash]
+ attributes_hashes[:old] = old_attributes_hash
when ?(
break if new_attributes_hash
new_attributes_hash, rest, last_line = parse_new_attributes(rest)
- attributes_hashes << [:new, new_attributes_hash]
+ attributes_hashes[:new] = new_attributes_hash
when ?[
break if object_ref
object_ref, rest = balance(rest, ?[, ?])
@@ -660,7 +662,7 @@ def parse_new_attributes(line)
if type == :static
static_attributes[name] = val
else
- dynamic_attributes << name.inspect << " => " << val << ","
+ dynamic_attributes << inspect_obj(name) << " => " << val << ","
end
end
dynamic_attributes << "}"
@@ -695,7 +697,7 @@ def parse_new_attribute(scanner)
return name, [:static, content.first[1]] if content.size == 1
return name, [:dynamic,
- '"' + content.map {|(t, v)| t == :str ? v.inspect[1...-1] : "\#{#{v}}"}.join + '"']
+ '"' + content.map {|(t, v)| t == :str ? inspect_obj(v)[1...-1] : "\#{#{v}}"}.join + '"']
end
# Parses a line that will render as an XHTML tag, and adds the code that will
@@ -755,16 +757,21 @@ def render_tag(line)
object_ref = "nil" if object_ref.nil? || @options[:suppress_eval]
attributes = Precompiler.parse_class_and_id(attributes)
- attributes_hashes.map! do |syntax, attributes_hash|
- if syntax == :old
- static_attributes = parse_static_hash(attributes_hash)
- attributes_hash = nil if static_attributes || @options[:suppress_eval]
- else
- static_attributes, attributes_hash = attributes_hash
- end
+ attributes_list = []
+
+ if attributes_hashes[:new]
+ static_attributes, attributes_hash = attributes_hashes[:new]
+ Buffer.merge_attrs(attributes, static_attributes) if static_attributes
+ attributes_list << attributes_hash
+ end
+
+ if attributes_hashes[:old]
+ static_attributes = parse_static_hash(attributes_hashes[:old])
Buffer.merge_attrs(attributes, static_attributes) if static_attributes
- attributes_hash
- end.compact!
+ attributes_list << attributes_hashes[:old] unless static_attributes || @options[:suppress_eval]
+ end
+
+ attributes_list.compact!
raise SyntaxError.new("Illegal nesting: nesting within a self-closing tag is illegal.", @next_line.index) if block_opened? && self_closing
raise SyntaxError.new("There's no Ruby code for #{action} to evaluate.", last_line - 1) if parse && value.empty?
@@ -782,7 +789,7 @@ def render_tag(line)
(nuke_inner_whitespace && block_opened?)
# Check if we can render the tag directly to text and not process it in the buffer
- if object_ref == "nil" && attributes_hashes.empty? && !preserve_script
+ if object_ref == "nil" && attributes_list.empty? && !preserve_script
tag_closed = !block_opened? && !self_closing && !parse
open_tag = prerender_tag(tag_name, self_closing, attributes)
@@ -800,19 +807,19 @@ def render_tag(line)
return if tag_closed
else
flush_merged_text
- content = parse ? 'nil' : value.inspect
- if attributes_hashes.empty?
- attributes_hashes = ''
- elsif attributes_hashes.size == 1
- attributes_hashes = ", #{attributes_hashes.first}"
+ content = parse ? 'nil' : inspect_obj(value)
+ if attributes_list.empty?
+ attributes_list = ''
+ elsif attributes_list.size == 1
+ attributes_list = ", #{attributes_list.first}"
else
- attributes_hashes = ", (#{attributes_hashes.join(").merge(")})"
+ attributes_list = ", (#{attributes_list.join(").merge(")})"
end
args = [tag_name, self_closing, !block_opened?, preserve_tag, escape_html,
attributes, nuke_outer_whitespace, nuke_inner_whitespace
- ].map { |v| v.inspect }.join(', ')
- push_silent "_hamlout.open_tag(#{args}, #{object_ref}, #{content}#{attributes_hashes})"
+ ].map {|v| inspect_obj(v)}.join(', ')
+ push_silent "_hamlout.open_tag(#{args}, #{object_ref}, #{content}#{attributes_list})"
@dont_tab_up_next_text = @dont_indent_next_line = dont_indent_next_line
end
@@ -1017,14 +1024,14 @@ def contains_interpolation?(str)
def unescape_interpolation(str, opts = {})
res = ''
- rest = Haml::Shared.handle_interpolation str.dump do |scan|
+ rest = Haml::Shared.handle_interpolation inspect_obj(str) do |scan|
escapes = (scan[2].size - 1) / 2
res << scan.matched[0...-3 - escapes]
if escapes % 2 == 1
res << '#{'
else
content = eval('"' + balance(scan, ?{, ?}, 1)[0][0...-1] + '"')
- content = "Haml::Helpers.html_escape(#{content})" if opts[:escape_html]
+ content = "Haml::Helpers.html_escape((#{content}))" if opts[:escape_html]
res << '#{' + content + "}"# Use eval to get rid of string escapes
end
end
View
22 vendor/plugins/haml/lib/haml/template/plugin.rb
@@ -2,12 +2,17 @@
# using the > 2.0.1 template handler API.
module Haml
- class Plugin < Haml::Util.av_template_class(:Handler)
- if (defined?(ActionView::TemplateHandlers) &&
- defined?(ActionView::TemplateHandlers::Compilable)) ||
- (defined?(ActionView::Template) &&
- defined?(ActionView::Template::Handlers) &&
- defined?(ActionView::Template::Handlers::Compilable))
+ # In Rails 3.1+, template handlers don't inherit from anything. In <= 3.0, they do.
+ # To avoid messy logic figuring this out, we just inherit from whatever the ERB handler does.
+ class Plugin < Haml::Util.av_template_class(:Handlers)::ERB.superclass
+ if ((defined?(ActionView::TemplateHandlers) &&
+ defined?(ActionView::TemplateHandlers::Compilable)) ||
+ (defined?(ActionView::Template) &&
+ defined?(ActionView::Template::Handlers) &&
+ defined?(ActionView::Template::Handlers::Compilable))) &&
+ # In Rails 3.1+, we don't need to include Compilable.
+ Haml::Util.av_template_class(:Handlers)::ERB.include?(
+ Haml::Util.av_template_class(:Handlers)::Compilable)
include Haml::Util.av_template_class(:Handlers)::Compilable
end
@@ -29,6 +34,11 @@ def compile(template)
Haml::Engine.new(source, options).send(:precompiled_with_ambles, [])
end
+ # In Rails 3.1+, #call takes the place of #compile
+ def self.call(template)
+ new.compile(template)
+ end
+
def cache_fragment(block, name = {}, options = nil)
@view.fragment_for(block, name, options) do
eval("_hamlout.buffer", block.binding)
View
13 vendor/plugins/haml/lib/haml/util.rb
@@ -656,6 +656,19 @@ def set_eql?(set1, set2)
set1.to_a.uniq.sort_by {|e| e.hash}.eql?(set2.to_a.uniq.sort_by {|e| e.hash})
end
+ # Like `Object#inspect`, but preserves non-ASCII characters rather than escaping them under Ruby 1.9.2.
+ # This is necessary so that the precompiled Haml template can be `#encode`d into `@options[:encoding]`
+ # before being evaluated.
+ #
+ # @param obj {Object}
+ # @return {String}
+ def inspect_obj(obj)
+ return obj.inspect unless version_geq(::RUBY_VERSION, "1.9.2")
+ return ':' + inspect_obj(obj.to_s) if obj.is_a?(Symbol)
+ return obj.inspect unless obj.is_a?(String)
+ '"' + obj.gsub(/[\x00-\x7F]+/) {|s| s.inspect[1...-1]} + '"'
+ end
+
## Static Method Stuff
# The context in which the ERB for \{#def\_static\_method} will be run.
View
16 vendor/plugins/haml/lib/sass/engine.rb
@@ -16,6 +16,7 @@
require 'sass/tree/debug_node'
require 'sass/tree/warn_node'
require 'sass/tree/import_node'
+require 'sass/tree/charset_node'
require 'sass/selector'
require 'sass/environment'
require 'sass/script'
@@ -195,7 +196,14 @@ def source_encoding
def _render
rendered = _to_tree.render
return rendered if ruby1_8?
- return rendered.encode(source_encoding)
+ begin
+ # Try to convert the result to the original encoding,
+ # but if that doesn't work fall back on UTF-8
+ rendered = rendered.encode(source_encoding)
+ rescue EncodingError
+ end
+ rendered.gsub(Regexp.new('\A@charset "(.*?)"'.encode(source_encoding)),
+ "@charset \"#{source_encoding.name}\"".encode(source_encoding))
end
def _to_tree
@@ -542,6 +550,12 @@ def parse_directive(parent, line, root)
:line => @line + 1) unless line.children.empty?
offset = line.offset + line.text.index(value).to_i
Tree::WarnNode.new(parse_script(value, :offset => offset))
+ elsif directive == "charset"
+ name = value && value[/\A(["'])(.*)\1\Z/, 2] #"
+ raise SyntaxError.new("Invalid charset directive '@charset': expected string.") unless name
+ raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath charset directives.",
+ :line => @line + 1) unless line.children.empty?
+ Tree::CharsetNode.new(name)
else
Tree::DirectiveNode.new(line.text)
end
View
43 vendor/plugins/haml/lib/sass/less.rb
@@ -246,24 +246,43 @@ def to_sass_tree
private
LESS_TO_SASS_OPERATORS = {"-" => :minus, "+" => :plus, "*" => :times, "/" => :div, "=" => :single_eq}
+
def _to_sass_tree(arr)
- return Sass::Script::UnaryOperation.new(_to_sass_tree(arr[1..-1]), :minus) if arr[0] == "-"
- _to_sass_tree2(*_sass_split(arr))
+ e, rest = _to_sass_tree_plus_minus_eq(arr)
+ until rest.empty?
+ e2, rest = _to_sass_tree_plus_minus_eq(rest)
+ e = Sass::Script::Operation.new(e, e2, :concat)
+ end
+ return e
end
- def _to_sass_tree2(first, rest)
- return first if rest.empty?
- if rest[0].is_a?(Operator)
+ def _to_sass_tree_plus_minus_eq(arr)
+ e, rest = _to_sass_tree_times_div(arr)
+ while rest[0] && rest[0].is_a?(Operator) && %w[+ - =].include?(rest[0])
op = LESS_TO_SASS_OPERATORS[rest[0]]
- if op == :times || op == :div
- second, rest = _sass_split(rest[1..-1])
- return _to_sass_tree2(Sass::Script::Operation.new(first, second, op), rest)
- else
- return Sass::Script::Operation.new(first, _to_sass_tree(rest[1..-1]), op)
- end
+ e2, rest = _to_sass_tree_times_div(rest[1..-1])
+ e = Sass::Script::Operation.new(e, e2, op)
end
+ return e, rest
+ end
- Sass::Script::Operation.new(first, _to_sass_tree(rest), :concat)
+ def _to_sass_tree_times_div(arr)
+ e, rest = _to_sass_tree_unary(arr)
+ while rest[0] && rest[0].is_a?(Operator) && %w[* /].include?(rest[0])
+ op = LESS_TO_SASS_OPERATORS[rest[0]]
+ e2, rest = _to_sass_tree_unary(rest[1..-1])
+ e = Sass::Script::Operation.new(e, e2, op)
+ end
+ return e, rest
+ end
+
+ def _to_sass_tree_unary(arr)
+ if arr[0] == "-"
+ first, rest = _sass_split(arr[1..-1])
+ return Sass::Script::UnaryOperation.new(first, :minus), rest
+ else
+ return _sass_split(arr[0..-1])
+ end
end
def _sass_split(arr)
View
5 vendor/plugins/haml/lib/sass/plugin.rb
@@ -228,7 +228,10 @@ def update_stylesheet(filename, css)
# Finally, write the file
flag = 'w'
flag = 'wb' if Haml::Util.windows? && options[:unix_newlines]
- File.open(css, flag) {|file| file.print(result)}
+ File.open(css, flag) do |file|
+ file.set_encoding(result.encoding) unless Haml::Util.ruby1_8?
+ file.print(result)
+ end
end
def try_delete_css(css)
View
3 vendor/plugins/haml/lib/sass/script/color.rb
@@ -401,7 +401,8 @@ def smallest
end
def rgba_str
- "rgba(#{rgb.join(', ')}, #{alpha % 1 == 0.0 ? alpha.to_i : alpha})"
+ split = options[:style] == :compressed ? ',' : ', '
+ "rgba(#{rgb.join(split)}#{split}#{Number.round(alpha)})"
end
def hex_str
View
11 vendor/plugins/haml/lib/sass/script/funcall.rb
@@ -1,4 +1,5 @@
-require File.join(File.dirname(__FILE__), 'functions')
+require 'sass/script/functions'
+
module Sass
module Script
# A SassScript parse node representing a function call.
@@ -63,12 +64,10 @@ def _perform(environment)
args = self.args.map {|a| a.perform(environment)}
ruby_name = name.gsub('-', '_')
unless Haml::Util.has?(:public_instance_method, Functions, ruby_name) && ruby_name !~ /^__/
- return Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})")
+ opts(Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})"))
+ else
+ opts(Functions::EvaluationContext.new(environment.options).send(ruby_name, *args))
end
-
- result = Functions::EvaluationContext.new(environment.options).send(ruby_name, *args)
- result.options = environment.options
- return result
rescue ArgumentError => e
raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/}
raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
View
2 vendor/plugins/haml/lib/sass/script/interpolation.rb
@@ -64,7 +64,7 @@ def _perform(environment)
res << (val.is_a?(Sass::Script::String) ? val.value : val.to_s)
res << " " if @after && @whitespace_after
res << @after.perform(environment).to_s if @after
- Sass::Script::String.new(res)
+ opts(Sass::Script::String.new(res))
end
end
end
View
2 vendor/plugins/haml/lib/sass/script/literal.rb
@@ -117,7 +117,7 @@ def concat(other)
# @return [Script::String] A string containing both literals
# separated by `", "`
def comma(other)
- Sass::Script::String.new("#{self.to_s}, #{other.to_s}")
+ Sass::Script::String.new("#{self.to_s},#{' ' unless options[:style] == :compressed}#{other.to_s}")
end
# The SassScript `=` operation
View
11 vendor/plugins/haml/lib/sass/script/node.rb
@@ -90,12 +90,23 @@ def dasherize(s, opts)
end
# Evaluates this node.
+ # Note that all {Literal} objects created within this method
+ # should have their \{#options} attribute set, probably via \{#opts}.
#
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
# @return [Literal] The SassScript object that is the value of the SassScript
# @see #perform
def _perform(environment)
raise NotImplementedError.new("All subclasses of Sass::Script::Node must override #_perform.")
end
+
+ # Sets the \{#options} field on the given literal and returns it
+ #
+ # @param literal [Literal]
+ # @return [Literal]
+ def opts(literal)
+ literal.options = options
+ literal
+ end
end
end
View
21 vendor/plugins/haml/lib/sass/script/number.rb
@@ -248,15 +248,7 @@ def to_s
#
# @return [String] The representation
def inspect(opts = {})
- value =
- if self.value.is_a?(Float) && (self.value.infinite? || self.value.nan?)
- self.value
- elsif int?
- self.value.to_i
- else
- (self.value * PRECISION).round / PRECISION
- end
- "#{value}#{unit_str}"
+ "#{self.class.round(self.value)}#{unit_str}"
end
alias_method :to_sass, :inspect
@@ -334,6 +326,17 @@ def unit_str
private
+ # @private
+ def self.round(num)
+ if num.is_a?(Float) && (num.infinite? || num.nan?)
+ num
+ elsif num % 1 == 0.0
+ num.to_i
+ else
+ (num * PRECISION).round / PRECISION
+ end
+ end
+
def operate(other, operation)
this = self
if [:+, :-, :<=, :<, :>, :>=].include?(operation)
View
19 vendor/plugins/haml/lib/sass/script/operation.rb
@@ -36,8 +36,8 @@ def inspect
# @see Node#to_sass
def to_sass(opts = {})
pred = Sass::Script::Parser.precedence_of(@operator)
- o1 = operand_to_sass pred, @operand1, opts
- o2 = operand_to_sass pred, @operand2, opts
+ o1 = operand_to_sass @operand1, :left, opts
+ o2 = operand_to_sass @operand2, :right, opts
sep =
case @operator
when :comma; ", "
@@ -72,9 +72,7 @@ def _perform(environment)
end
begin
- res = literal1.send(@operator, literal2)
- res.options = environment.options
- res
+ opts(literal1.send(@operator, literal2))
rescue NoMethodError => e
raise e unless e.name.to_s == @operator.to_s
raise Sass::SyntaxError.new("Undefined operation: \"#{literal1} #{@operator} #{literal2}\".")
@@ -83,9 +81,14 @@ def _perform(environment)
private
- def operand_to_sass(pred, op, opts = {})
- return "(#{op.to_sass(opts)})" if op.is_a?(Operation) &&
- Sass::Script::Parser.precedence_of(op.operator) < pred
+ def operand_to_sass(op, side, opts)
+ return op.to_sass(opts) unless op.is_a?(Operation)
+
+ pred = Sass::Script::Parser.precedence_of(@operator)
+ sub_pred = Sass::Script::Parser.precedence_of(op.operator)
+ assoc = Sass::Script::Parser.associative?(@operator)
+ return "(#{op.to_sass(opts)})" if sub_pred < pred ||
+ (side == :right && sub_pred == pred && !assoc)
op.to_sass(opts)
end
end
View
11 vendor/plugins/haml/lib/sass/script/parser.rb
@@ -128,6 +128,8 @@ def self.parse(*args)
[:times, :div, :mod],
]
+ ASSOCIATIVE = [:comma, :concat, :plus, :times]
+
class << self
# Returns an integer representing the precedence
# of the given operator.
@@ -141,6 +143,13 @@ def precedence_of(op)
raise "[BUG] Unknown operator #{op}"
end
+ # Returns whether or not the given operation is associative.
+ #
+ # @private
+ def associative?(op)
+ ASSOCIATIVE.include?(op)
+ end
+
private
# Defines a simple left-associative production.
@@ -246,7 +255,7 @@ def ident
return if @stop_at && @stop_at.include?(@lexer.peek.value)
name = @lexer.next
- if color = Color::HTML4_COLORS[name.value]
+ if color = Color::HTML4_COLORS[name.value.downcase]
return node(Color.new(color))
end
node(Script::String.new(name.value, :identifier))
View
2 vendor/plugins/haml/lib/sass/script/string_interpolation.rb
@@ -72,7 +72,7 @@ def _perform(environment)
mid = @mid.perform(environment)
res << (mid.is_a?(Sass::Script::String) ? mid.value : mid.to_s)
res << @after.perform(environment).value
- Sass::Script::String.new(res, before.type)
+ opts(Sass::Script::String.new(res, before.type))
end
private
View
5 vendor/plugins/haml/lib/sass/scss/css_parser.rb
@@ -24,11 +24,6 @@ def interp_string; tok(STRING); end
def interp_ident(ident = IDENT); tok(ident); end
def use_css_import?; true; end
- def special_directive(name)
- return unless name == 'media' || name == 'import'
- super
- end
-
def block_child(context)
case context
when :ruleset
View
10 vendor/plugins/haml/lib/sass/scss/parser.rb
@@ -98,7 +98,8 @@ def process_comment(text, node)
node << comment
end
- DIRECTIVES = Set[:mixin, :include, :debug, :warn, :for, :while, :if, :extend, :import, :media]
+ DIRECTIVES = Set[:mixin, :include, :debug, :warn, :for, :while, :if, :extend, :import,
+ :media, :charset]
def directive
return unless tok(/@/)
@@ -289,6 +290,13 @@ def media_expr
true
end
+ def charset_directive
+ tok! STRING
+ name = @scanner[1] || @scanner[2]
+ ss
+ node(Sass::Tree::CharsetNode.new(name))
+ end
+
def variable
return unless tok(/\$/)
name = tok!(IDENT)
View
2 vendor/plugins/haml/lib/sass/scss/static_parser.rb
@@ -32,7 +32,7 @@ def interp_ident(ident = IDENT); s = tok(ident) and [s]; end
def use_css_import?; true; end
def special_directive(name)
- return unless name == 'media' || name == 'import'
+ return unless %w[media import charset].include?(name)
super
end
end
View
37 vendor/plugins/haml/lib/sass/tree/charset_node.rb
@@ -0,0 +1,37 @@
+module Sass::Tree
+ # A static node representing an unproccessed Sass `@charset` directive.
+ #
+ # @see Sass::Tree
+ class CharsetNode < Node
+ # The name of the charset.
+ #
+ # @return [String]
+ attr_accessor :name
+
+ # @param name [String] see \{#name}
+ def initialize(name)
+ @name = name
+ super()
+ end
+
+ # @see Node#invisible?
+ def invisible?
+ !Haml::Util.ruby1_8?
+ end
+
+ protected
+
+ # @see Node#to_src
+ def to_src(tabs, opts, fmt)
+ "#{' ' * tabs}@charset \"#{name}\"#{semi fmt}\n"
+ end
+
+ # Computes the CSS for the directive.
+ #
+ # @param tabs [Fixnum] The level of indentation for the CSS
+ # @return [String] The resulting CSS
+ def _to_s(tabs)
+ "@charset \"#{name}\";"
+ end
+ end
+end
View
4 vendor/plugins/haml/lib/sass/tree/directive_node.rb
@@ -4,8 +4,8 @@ module Sass::Tree
# are handled by their own nodes;
# only CSS directives like `@media` and `@font-face` become {DirectiveNode}s.
#
- # `@import` is a bit of a weird case;
- # it becomes an {ImportNode}.
+ # `@import` and `@charset` are special cases;
+ # they become {ImportNode}s and {CharsetNode}s, respectively.
#
# @see Sass::Tree
class DirectiveNode < Node
View
36 vendor/plugins/haml/lib/sass/tree/root_node.rb
@@ -47,7 +47,7 @@ def perform(environment)
# @return [(Tree::Node, Haml::Util::SubsetMap)] The resulting tree of static nodes
# *and* the extensions defined for this tree
def cssize(extends = Haml::Util::SubsetMap.new, parent = nil)
- return super(extends), extends
+ return super(extends, parent), extends
rescue Sass::SyntaxError => e
e.sass_template = @template
raise e
@@ -106,7 +106,39 @@ def _to_s(*args)
end
result.rstrip!
return "" if result.empty?
- return result + "\n"
+ result << "\n"
+ unless Haml::Util.ruby1_8? || result.ascii_only?
+ if children.first.is_a?(CharsetNode)
+ begin
+ encoding = children.first.name
+ # Default to big-endian encoding, because we have to decide somehow
+ encoding << 'BE' if encoding =~ /\Autf-(16|32)\Z/i
+ result = result.encode(Encoding.find(encoding))
+ rescue EncodingError
+ end
+ end
+
+ result = "@charset \"#{result.encoding.name}\";#{
+ style == :compressed ? '' : "\n"
+ }".encode(result.encoding) + result
+ end
+ result
+ end
+
+ # In Ruby 1.8, ensures that there's only one @charset directive
+ # and that it's at the top of the document.
+ #
+ # @see Node#cssize
+ def cssize!(extends, parent)
+ super
+
+ # In Ruby 1.9 we can make all @charset nodes invisible
+ # and infer the final @charset from the encoding of the final string.
+ if Haml::Util.ruby1_8? && parent.nil?
+ charset = self.children.find {|c| c.is_a?(CharsetNode)}
+ self.children.reject! {|c| c.is_a?(CharsetNode)}
+ self.children.unshift charset if charset
+ end
end
# Returns an error message if the given child node is invalid,
View
2 vendor/plugins/haml/lib/sass/tree/rule_node.rb
@@ -134,7 +134,7 @@ def _to_s(tabs)
per_rule_indent, total_indent = [:nested, :expanded].include?(style) ? [rule_indent, ''] : ['', rule_indent]
total_rule = total_indent + resolved_rules.members.
- map {|seq| seq.to_a.join}.
+ map {|seq| seq.to_a.join.gsub(/([^,])\n/m, style == :compressed ? '\1 ' : "\\1\n")}.
join(rule_separator).split("\n").map do |line|
per_rule_indent + line.strip
end.join(line_separator)
View
281 vendor/plugins/haml/test/haml/engine_test.rb
@@ -86,6 +86,7 @@ class EngineTest < Test::Unit::TestCase
"foo\n:plain\n 1\n 2\n 3\#{''}\n4\n- raise 'foo'" => ["foo", 7],
"foo\n:plain\n 1\n 2\n \#{raise 'foo'}" => ["foo", 5],
"= raise 'foo'\nfoo\nbar\nbaz\nbang" => ["foo", 1],
+ "- case 1\n\n- when 1\n - raise 'foo'" => ["foo", 4],
}
User = Struct.new('User', :id)
@@ -111,6 +112,17 @@ def engine(text, options = {})
Haml::Engine.new(text, options)
end
+ def setup
+ return if Haml::Util.ruby1_8?
+ @old_default_internal = Encoding.default_internal
+ Encoding.default_internal = nil
+ end
+
+ def teardown
+ return if Haml::Util.ruby1_8?
+ Encoding.default_internal = @old_default_internal
+ end
+
def test_empty_render
assert_equal "", render("")
end
@@ -763,6 +775,38 @@ def test_if_assigned_to_var
HAML
end
+ def test_case_with_newline_after_case
+ assert_equal(<<HTML, render(<<HAML))
+foo
+HTML
+- case 1
+
+ - when 1
+ foo
+ - when 2
+ bar
+HAML
+
+ assert_equal(<<HTML, render(<<HAML))
+bar
+HTML
+- case 2
+
+- when 1
+ foo
+- when 2
+ bar
+HAML
+ end
+
+ def test_escape_html_with_interpolated_if_statement
+ assert_equal(<<HTML, render(<<HAML, :escape_html => true))
+foo,
+HTML
+foo\#{"," if true}
+HAML
+ end
+
# HTML escaping tests
def test_ampersand_equals_should_escape
@@ -1345,7 +1389,7 @@ def test_basic_new_attributes
def test_new_attribute_ids
assert_equal("<div id='foo_bar'></div>\n", render("#foo(id='bar')"))
- assert_equal("<div id='foo_bar_baz'></div>\n", render("#foo{:id => 'bar'}(id='baz')"))
+ assert_equal("<div id='foo_baz_bar'></div>\n", render("#foo{:id => 'bar'}(id='baz')"))
assert_equal("<div id='foo_baz_bar'></div>\n", render("#foo(id='baz'){:id => 'bar'}"))
foo = User.new(42)
assert_equal("<div class='struct_user' id='foo_baz_bar_struct_user_42'></div>\n",
@@ -1354,7 +1398,7 @@ def test_new_attribute_ids
render("#foo(id='baz')[foo]{:id => 'bar'}", :locals => {:foo => foo}))
assert_equal("<div class='struct_user' id='foo_baz_bar_struct_user_42'></div>\n",
render("#foo[foo](id='baz'){:id => 'bar'}", :locals => {:foo => foo}))
- assert_equal("<div class='struct_user' id='foo_bar_baz_struct_user_42'></div>\n",
+ assert_equal("<div class='struct_user' id='foo_baz_bar_struct_user_42'></div>\n",
render("#foo[foo]{:id => 'bar'}(id='baz')", :locals => {:foo => foo}))
end
@@ -1426,11 +1470,17 @@ def test_new_and_old_attributes
assert_equal("<a a='b' c='d'>bar</a>\n", render("%a(c='d'){:a => 'b'} bar"))
assert_equal("<a a='b' c='d'>bar</a>\n", render("%a{:a => 'b'}(c='d') bar"))
- assert_equal("<a a='d'>bar</a>\n", render("%a{:a => 'b'}(a='d') bar"))
+ # Old-style always takes precedence over new-style,
+ # because theoretically old-style could have arbitrary end-of-method-call syntax.
+ assert_equal("<a a='b'>bar</a>\n", render("%a{:a => 'b'}(a='d') bar"))
assert_equal("<a a='b'>bar</a>\n", render("%a(a='d'){:a => 'b'} bar"))
assert_equal("<a a='b' b='c' c='d' d='e'>bar</a>\n",
render("%a{:a => 'b',\n:b => 'c'}(c='d'\nd='e') bar"))
+
+ locals = {:b => 'b', :d => 'd'}
+ assert_equal("<p a='b' c='d'></p>\n", render("%p{:a => b}(c=d)", :locals => locals))
+ assert_equal("<p a='b' c='d'></p>\n", render("%p(a=b){:c => d}", :locals => locals))
end
# Ruby Multiline
@@ -1506,7 +1556,7 @@ def test_flattened_loud_ruby_multiline
def test_loud_ruby_multiline_with_block
assert_equal(<<HTML, render(<<HAML))
-farfazfang
+#{%w[far faz fang]}
<p>foo</p>
<p>bar</p>
HTML
@@ -1636,18 +1686,8 @@ def test_default_encoding
HAML
end
- def test_convert_template_render
- assert_equal(<<HTML, render(<<HAML.encode("iso-8859-1"), :encoding => "utf-8"))
-<p>bâr</p>
-<p>föö</p>
-HTML
-%p bâr
-%p föö
-HAML
- end
-
def test_fake_ascii_encoding
- assert_equal(<<HTML.force_encoding("ascii-8bit"), render(<<HAML, :encoding => "ascii-8bit"))
+ assert_encoded_equal(<<HTML.force_encoding("ascii-8bit"), render(<<HAML, :encoding => "ascii-8bit"))
<p>bâr</p>
<p>föö</p>
HTML
@@ -1701,15 +1741,23 @@ def test_same_coding_comment_as_encoding
HAML
end
- def test_different_coding_comment_than_encoding
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# coding: ibm866
-%p bâr
-%p föö
-HAML
+ def test_coding_comments
+ assert_valid_encoding_comment("-# coding: ibm866")
+ assert_valid_encoding_comment("-# CodINg: IbM866")
+ assert_valid_encoding_comment("-#coding:ibm866")
+ assert_valid_encoding_comment("-# CodINg= ibm866")
+ assert_valid_encoding_comment("-# foo BAR FAOJcoding: ibm866")
+ assert_valid_encoding_comment("-# coding: ibm866 ASFJ (&(&#!$")
+ assert_valid_encoding_comment("-# -*- coding: ibm866")
+ assert_valid_encoding_comment("-# coding: ibm866 -*- coding: blah")
+ assert_valid_encoding_comment("-# -*- coding: ibm866 -*-")
+ assert_valid_encoding_comment("-# -*- encoding: ibm866 -*-")
+ assert_valid_encoding_comment('-# -*- coding: "ibm866" -*-')
+ assert_valid_encoding_comment("-#-*-coding:ibm866-*-")
+ assert_valid_encoding_comment("-#-*-coding:ibm866-*-")
+ assert_valid_encoding_comment("-# -*- foo: bar; coding: ibm866; baz: bang -*-")
+ assert_valid_encoding_comment("-# foo bar coding: baz -*- coding: ibm866 -*-")
+ assert_valid_encoding_comment("-# -*- coding: ibm866 -*- foo bar coding: baz")
end
def test_different_coding_than_system
@@ -1719,190 +1767,39 @@ def test_different_coding_than_system
%p тАЬ
HAML
end
+ end
- def test_case_insensitive_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# CodINg: IbM866
-%p bâr
-%p föö
-HAML
- end
-
- def test_whitespace_insensitive_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--#coding:ibm866
-%p bâr
-%p föö
-HAML
- end
-
- def test_equals_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# CodINg= ibm866
-%p bâr
-%p föö
-HAML
- end
-
- def test_prefixed_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# foo BAR FAOJcoding: ibm866
-%p bâr
-%p föö
-HAML
- end
-
- def test_suffixed_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# coding: ibm866 ASFJ (&(&#!$
-%p bâr
-%p föö
-HAML
- end
-
- def test_emacs_prefixed_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# -*- coding: ibm866
-%p bâr
-%p föö
-HAML
- end
-
- def test_emacs_suffixed_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# coding: ibm866 -*- coding: blah
-%p bâr
-%p föö
-HAML
- end
-
- def test_emacs_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# -*- coding: ibm866 -*-
-%p bâr
-%p föö
-HAML
- end
-
- def test_emacs_encoding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# -*- encoding: ibm866 -*-
-%p bâr
-%p föö
-HAML
- end
-
- def test_quoted_emacs_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# -*- coding: "ibm866" -*-
-%p bâr
-%p föö
-HAML
- end
-
- def test_whitespace_insensitive_emacs_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--#-*-coding:ibm866-*-
-%p bâr
-%p föö
-HAML
- end
-
- def test_whitespace_insensitive_emacs_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--#-*-coding:ibm866-*-
-%p bâr
-%p föö
-HAML
- end
-
- def test_one_of_several_emacs_comments
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# -*- foo: bar; coding: ibm866; baz: bang -*-
-%p bâr
-%p föö
-HAML
- end
-
- def test_prefixed_emacs_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
-HTML
--# foo bar coding: baz -*- coding: ibm866 -*-
-%p bâr
-%p föö
-HAML
- end
+ private
- def test_suffixed_emacs_coding_comment
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
-<p>bâr</p>
-<p>föö</p>
+ def assert_valid_encoding_comment(comment)
+ assert_renders_encoded(<<HTML.encode("IBM866"), <<HAML.encode("IBM866").force_encoding("UTF-8"))
+<p>ЖЛЫ</p>
+<p>тАЬ</p>
HTML
--# -*- coding: ibm866 -*- foo bar coding: baz
-%p bâr
-%p föö
+#{comment}
+%p ЖЛЫ
+%p тАЬ
HAML
- end
-
end
- private
-
def assert_converts_template_properly
- engine = Haml::Engine.new(<<HAML.encode("iso-8859-1"), :encoding => "utf-8")
+ engine = Haml::Engine.new(<<HAML.encode("iso-8859-1"), :encoding => "macRoman")
%p bâr
%p föö
HAML
- assert_equal(<<HTML, yield(engine))
+ assert_encoded_equal(<<HTML.encode("macRoman"), yield(engine))
<p>bâr</p>
<p>föö</p>
HTML
end
def assert_renders_encoded(html, haml)
result = render(haml)
- assert_equal html.encoding, result.encoding
- assert_equal html, result
+ assert_encoded_equal html, result
+ end
+
+ def assert_encoded_equal(expected, actual)
+ assert_equal expected.encoding, actual.encoding
+ assert_equal expected, actual
end
end
View
8 vendor/plugins/haml/test/sass/conversion_test.rb
@@ -607,6 +607,14 @@ def test_directive_with_rule_and_prop_children
SCSS
end
+ def test_charset
+ assert_renders <<SASS, <<SCSS
+@charset "utf-8"
+SASS
+@charset "utf-8";
+SCSS
+ end
+
def test_for
assert_renders <<SASS, <<SCSS
foo
View
50 vendor/plugins/haml/test/sass/engine_test.rb
@@ -2073,6 +2073,38 @@ def test_import_with_commas_in_url
SASS
end
+ def test_function_output_with_comma
+ assert_equal <<CSS, render(<<SASS)
+foo {
+ a: b(c), d(e); }
+CSS
+foo
+ a: b(c), d(e)
+SASS
+ end
+
+ def test_interpolation_with_comma
+ assert_equal <<CSS, render(<<SASS)
+foo {
+ a: foo, bar; }
+CSS
+$foo: foo
+foo
+ a: \#{$foo}, bar
+SASS
+ end
+
+ def test_string_interpolation_with_comma
+ assert_equal <<CSS, render(<<SASS)
+foo {
+ a: "bip foo bap", bar; }
+CSS
+$foo: foo
+foo
+ a: "bip \#{$foo} bap", bar
+SASS
+ end
+
# Encodings
unless Haml::Util.ruby1_8?
@@ -2096,7 +2128,7 @@ def test_ascii_incompatible_encoding_error
def test_same_charset_as_encoding
assert_renders_encoded(<<CSS, <<SASS)
-@charset "utf-8";
+@charset "UTF-8";
fóó {
a: b; }
CSS
@@ -2108,7 +2140,7 @@ def test_same_charset_as_encoding
def test_different_charset_than_encoding
assert_renders_encoded(<<CSS.force_encoding("IBM866"), <<SASS)
-@charset "ibm866";
+@charset "IBM866";
fóó {
a: b; }
CSS
@@ -2120,6 +2152,7 @@ def test_different_charset_than_encoding
def test_different_encoding_than_system
assert_renders_encoded(<<CSS.encode("IBM866"), <<SASS.encode("IBM866"))
+@charset "IBM866";
тАЬ {
a: b; }
CSS
@@ -2129,20 +2162,20 @@ def test_different_encoding_than_system
end
def test_multibyte_charset
- assert_renders_encoded(<<CSS.encode("UTF-16BE"), <<SASS.encode("UTF-16BE").force_encoding("UTF-8"))
-@charset "utf-16be";
+ assert_renders_encoded(<<CSS.encode("UTF-16LE"), <<SASS.encode("UTF-16LE").force_encoding("UTF-8"))
+@charset "UTF-16LE";
fóó {
a: b; }
CSS
-@charset "utf-16be"
+@charset "utf-16le"
fóó
a: b
SASS
end
def test_multibyte_charset_without_endian_specifier
- assert_renders_encoded(<<CSS.encode("UTF-32LE"), <<SASS.encode("UTF-32LE").force_encoding("UTF-8"))
-@charset "utf-32";
+ assert_renders_encoded(<<CSS.encode("UTF-32BE"), <<SASS.encode("UTF-32BE").force_encoding("UTF-8"))
+@charset "UTF-32BE";
fóó {
a: b; }
CSS
@@ -2154,6 +2187,7 @@ def test_multibyte_charset_without_endian_specifier
def test_utf8_bom
assert_renders_encoded(<<CSS, <<SASS.force_encoding("BINARY"))
+@charset "UTF-8";
fóó {
a: b; }
CSS
@@ -2164,6 +2198,7 @@ def test_utf8_bom
def test_utf16le_bom
assert_renders_encoded(<<CSS.encode("UTF-16LE"), <<SASS.encode("UTF-16LE").force_encoding("BINARY"))
+@charset "UTF-16LE";
fóó {
a: b; }
CSS
@@ -2174,6 +2209,7 @@ def test_utf16le_bom
def test_utf32be_bom
assert_renders_encoded(<<CSS.encode("UTF-32BE"), <<SASS.encode("UTF-32BE").force_encoding("BINARY"))
+@charset "UTF-32BE";
fóó {
a: b; }
CSS
View
27 vendor/plugins/haml/test/sass/less_conversion_test.rb
@@ -326,7 +326,14 @@ def test_operator_precedence
d: 1 + 2 - 3 + 4;
e: 1 / 2 - 3 / 4;
f: 1 - 2 / 3 - 4;
- g: 1 / 2 * 3 / 4; }
+ g: 1 / 2 * 3 / 4;
+ h: (1 + 2) * (3 + 4);
+ i: 1 * (2 + 3) * 4;
+ j: 1 - (2 + 2) - 4;
+ k: 1 + 2 - (3 + 4);
+ l: 1 / (2 - 3) / 4;
+ m: (1 - 2) / (3 - 4);
+ n: 1 / (2 * 3) / 4; }
SCSS
foo {
a: 1 + 2 * 3 + 4;
@@ -335,7 +342,14 @@ def test_operator_precedence
d: 1 + 2 - 3 + 4;
e: 1 / 2 - 3 / 4;
f: 1 - 2 / 3 - 4;
- g: 1 / 2 * 3 / 4; }
+ g: 1 / 2 * 3 / 4;
+ h: (1 + 2) * (3 + 4);
+ i: 1 * (2 + 3) * 4;
+ j: 1 - (2 + 2) - 4;
+ k: 1 + 2 - (3 + 4);
+ l: 1 / (2 - 3) / 4;
+ m: (1 - 2) / (3 - 4);
+ n: 1 / (2 * 3) / 4; }
LESS
end
@@ -628,5 +642,12 @@ def relative_path_to(file)
end
rescue LoadError => e
-puts "\nCouldn't require less, skipping some tests."
+ unless defined?(Gem)
+ begin
+ require 'rubygems'
+ retry
+ rescue Exception
+ end
+ end
+ puts "\nCouldn't require less, skipping some tests."
end
View
15 vendor/plugins/haml/test/sass/plugin_test.rb
@@ -9,6 +9,8 @@ class SassPluginTest < Test::Unit::TestCase
subdir/subdir subdir/nested_subdir/nested_subdir
options
}
+ @@templates += %w[import_charset import_charset_ibm866] unless Haml::Util.ruby1_8?
+ @@templates << 'import_charset_1_8' if Haml::Util.ruby1_8?
def setup
FileUtils.mkdir tempfile_loc
@@ -267,11 +269,18 @@ def assert_renders_correctly(*arguments)
prefix = options[:prefix]
result_name = arguments.shift
tempfile_name = arguments.shift || result_name
- expected_lines = File.read(result_loc(result_name, prefix)).split("\n")
- actual_lines = File.read(tempfile_loc(tempfile_name, prefix)).split("\n")
+
+ expected_str = File.read(result_loc(result_name, prefix))
+ actual_str = File.read(tempfile_loc(tempfile_name, prefix))
+ unless Haml::Util.ruby1_8?
+ expected_str = expected_str.force_encoding('IBM866') if result_name == 'import_charset_ibm866'
+ actual_str = actual_str.force_encoding('IBM866') if tempfile_name == 'import_charset_ibm866'
+ end
+ expected_lines = expected_str.split("\n")
+ actual_lines = actual_str.split("\n")
if actual_lines.first == "/*" && expected_lines.first != "/*"
- assert(false, actual_lines[0..actual_lines.enum_with_index.find {|l, i| l == "*/"}.last].join("\n"))
+ assert(false, actual_lines[0..Haml::Util.enum_with_index(actual_lines).find {|l, i| l == "*/"}.last].join("\n"))
end
expected_lines.zip(actual_lines).each_with_index do |pair, line|
View
4 vendor/plugins/haml/test/sass/results/import_charset.css
@@ -0,0 +1,4 @@
+@charset "UTF-8";
+.foo { a: b; }
+
+.bar { a: щ; }
View
4 vendor/plugins/haml/test/sass/results/import_charset_1_8.css
@@ -0,0 +1,4 @@
+@charset "IBM866";
+.foo { a: b; }
+
+.bar { a: é; }
View
4 vendor/plugins/haml/test/sass/results/import_charset_ibm866.css
@@ -0,0 +1,4 @@
+@charset "IBM866";
+.foo { a: b; }
+
+.bar { a: é; }
View
60 vendor/plugins/haml/test/sass/script_conversion_test.rb
@@ -118,6 +118,52 @@ def test_precedence_#{outer}_#{inner}
RUBY
end
+ def self.assert_associative(op_name, sibling_name)
+ op = separator_for(op_name)
+ sibling = separator_for(sibling_name)
+ class_eval <<RUBY
+ def test_associative_#{op_name}_#{sibling_name}
+ assert_renders "$foo#{op}$bar#{op}$baz"
+
+ assert_equal "$foo#{op}$bar#{op}$baz",
+ render("$foo#{op}($bar#{op}$baz)")
+ assert_equal "$foo#{op}$bar#{op}$baz",
+ render("($foo#{op}$bar)#{op}$baz")
+
+ assert_equal "$foo#{op}$bar#{sibling}$baz",
+ render("$foo#{op}($bar#{sibling}$baz)")
+ assert_equal "$foo#{sibling}$bar#{op}$baz",
+ render("($foo#{sibling}$bar)#{op}$baz")
+ end
+RUBY
+ end
+
+ def self.separator_for(op_name)
+ case op_name
+ when :comma; ", "
+ when :concat; " "
+ else; " #{Sass::Script::Lexer::OPERATORS_REVERSE[op_name]} "
+ end
+ end
+
+ def self.assert_non_associative(op_name, sibling_name)
+ op = Sass::Script::Lexer::OPERATORS_REVERSE[op_name]
+ sibling = Sass::Script::Lexer::OPERATORS_REVERSE[sibling_name]
+ class_eval <<RUBY
+ def test_non_associative_#{op_name}_#{sibling_name}
+ assert_renders "$foo #{op} $bar #{op} $baz"
+
+ assert_renders "$foo #{op} ($bar #{op} $baz)"
+ assert_equal "$foo #{op} $bar #{op} $baz",
+ render("($foo #{op} $bar) #{op} $baz")
+
+ assert_renders "$foo #{op} ($bar #{sibling} $baz)"
+ assert_equal "$foo #{sibling} $bar #{op} $baz",
+ render("($foo #{sibling} $bar) #{op} $baz")
+ end
+RUBY
+ end
+
test_precedence :or, :and
test_precedence :and, :eq
test_precedence :and, :neq
@@ -131,6 +177,20 @@ def test_precedence_#{outer}_#{inner}
test_precedence :plus, :div
test_precedence :plus, :mod
+ assert_associative :comma, :concat
+ assert_associative :concat, :or
+ assert_associative :plus, :minus
+ assert_associative :times, :div
+ assert_associative :times, :mod
+
+ assert_non_associative :minus, :plus
+ assert_non_associative :div, :times
+ assert_non_associative :mod, :times
+ assert_non_associative :gt, :gte
+ assert_non_associative :gte, :lt
+ assert_non_associative :lt, :lte
+ assert_non_associative :lte, :gt
+
def test_unary_op
assert_renders "-12px"
assert_renders '/"foo"'
View
19 vendor/plugins/haml/test/sass/script_test.rb
@@ -79,9 +79,13 @@ def test_rgba_number_math
assert_equal "rgba(100, 100, 100, 0.75)", resolve("rgba(50, 50, 50, 0.75) * 2")
end
+ def test_rgba_rounding
+ assert_equal "rgba(10, 1, 0, 0.123)", resolve("rgba(10.0, 1.23456789, 0.0, 0.1234567)")
+ end
+
def test_compressed_colors
assert_equal "#123456", resolve("#123456", :style => :compressed)
- assert_equal "rgba(1, 2, 3, 0.5)", resolve("rgba(1, 2, 3, 0.5)", :style => :compressed)
+ assert_equal "rgba(1,2,3,0.5)", resolve("rgba(1, 2, 3, 0.5)", :style => :compressed)
assert_equal "#123", resolve("#112233", :style => :compressed)
assert_equal "#000", resolve("black", :style => :compressed)
assert_equal "red", resolve("#f00", :style => :compressed)
@@ -91,6 +95,12 @@ def test_compressed_colors
assert_equal "This color is #fff", resolve('"This color is #{ white }"', :style => :compressed)
end
+ def test_compressed_comma
+ # assert_equal "foo,bar,baz", resolve("foo, bar, baz", :style => :compressed)
+ # assert_equal "foo,#baf,baz", resolve("foo, #baf, baz", :style => :compressed)
+ assert_equal "foo,#baf,red", resolve("foo, #baf, #f00", :style => :compressed)
+ end
+
def test_implicit_strings
assert_equal Sass::Script::String.new("foo"), eval("foo")
assert_equal Sass::Script::String.new("foo bar"), eval("foo bar")
@@ -372,6 +382,12 @@ def test_colors_with_wrong_number_of_digits
"Colors must have either three or six digits: '#abcdEFA'") {eval("#abcdEFA")}
end
+ def test_case_insensitive_color_names
+ assert_equal "blue", resolve("BLUE")
+ assert_equal "red", resolve("rEd")
+ assert_equal "#7f4000", resolve("mix(GrEeN, ReD)")
+ end
+
# Regression Tests
def test_funcall_has_higher_precedence_than_color_name
@@ -426,6 +442,7 @@ def assert_quoted(str, opts = {}, environment = env)
def eval(str, opts = {}, environment = env)
munge_filename opts
+ environment.options = opts
Sass::Script.parse(str, opts.delete(:line) || 1,
opts.delete(:offset) || 0, opts).perform(environment)
end
View
35 vendor/plugins/haml/test/sass/scss/css_test.rb
@@ -49,11 +49,34 @@ def test_cdo_and_cdc_ignored_at_toplevel
SCSS
end
- def test_unicode
- assert_parses <<SCSS
+ if Haml::Util.ruby1_8?
+ def test_unicode
+ assert_parses <<SCSS
+@charset "UTF-8";
+foo {
+ bar: föö bâr; }
+SCSS
+ assert_parses <<SCSS
foo {
bar: föö bâr; }
SCSS
+ end
+ else