haml 2.2.15 → 2.2.16

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.15
1
+ 2.2.16
@@ -15,7 +15,7 @@ module Haml
15
15
 
16
16
  # The options hash passed in from {Haml::Engine}.
17
17
  #
18
- # @return [Hash<String, Object>]
18
+ # @return [{String => Object}]
19
19
  # @see Haml::Engine#options_for_buffer
20
20
  attr_accessor :options
21
21
 
@@ -85,7 +85,7 @@ module Haml
85
85
  end
86
86
 
87
87
  # @param upper [Buffer] The parent buffer
88
- # @param options [Hash<Symbol, Object>] An options hash.
88
+ # @param options [{Symbol => Object}] An options hash.
89
89
  # See {Haml::Engine#options\_for\_buffer}
90
90
  def initialize(upper = nil, options = {})
91
91
  @active = true
@@ -240,9 +240,9 @@ RUBY
240
240
  #
241
241
  # Destructively modifies both `to` and `from`.
242
242
  #
243
- # @param to [Hash<String, String>] The attribute hash to merge into
244
- # @param from [Hash<String, String>] The attribute hash to merge from
245
- # @return [Hash<String, String>] `to`, after being merged
243
+ # @param to [{String => String}] The attribute hash to merge into
244
+ # @param from [{String => String}] The attribute hash to merge from
245
+ # @return [{String => String}] `to`, after being merged
246
246
  def self.merge_attrs(to, from)
247
247
  if to['id'] && from['id']
248
248
  to['id'] << '_' << from.delete('id').to_s
@@ -20,7 +20,7 @@ module Haml
20
20
  # The options hash.
21
21
  # See {file:HAML_REFERENCE.md#haml_options the Haml options documentation}.
22
22
  #
23
- # @return [Hash<Symbol, Object>]
23
+ # @return [{Symbol => Object}]
24
24
  attr_accessor :options
25
25
 
26
26
  # The indentation used in the Haml document,
@@ -66,7 +66,7 @@ module Haml
66
66
  # Precompiles the Haml template.
67
67
  #
68
68
  # @param template [String] The Haml template
69
- # @param options [Hash<Symbol, Object>] An options hash;
69
+ # @param options [{Symbol => Object}] An options hash;
70
70
  # see {file:HAML_REFERENCE.md#haml_options the Haml options documentation}
71
71
  # @raise [Haml::Error] if there's a Haml syntax error in the template
72
72
  def initialize(template, options = {})
@@ -154,7 +154,7 @@ module Haml
154
154
  # they won't work.
155
155
  #
156
156
  # @param scope [Binding, Proc, Object] The context in which the template is evaluated
157
- # @param locals [Hash<Symbol, Object>] Local variables that will be made available
157
+ # @param locals [{Symbol => Object}] Local variables that will be made available
158
158
  # to the template
159
159
  # @param block [#to_proc] A block that can be yielded to within the template
160
160
  # @return [String] The rendered template
@@ -275,7 +275,7 @@ module Haml
275
275
  #
276
276
  # See {file:HAML_REFERENCE.md#haml_options the Haml options documentation}.
277
277
  #
278
- # @return [Hash<Symbol, Object>] The options hash
278
+ # @return [{Symbol => Object}] The options hash
279
279
  def options_for_buffer
280
280
  {
281
281
  :autoclose => @options[:autoclose],
@@ -4,7 +4,7 @@ module Haml
4
4
  #
5
5
  # @see Haml::Filters::Base
6
6
  module Filters
7
- # @return [Hash<String, Haml::Filters::Base>] a hash of filter names to classes
7
+ # @return [{String => Haml::Filters::Base}] a hash of filter names to classes
8
8
  def self.defined
9
9
  @defined ||= {}
10
10
  end
@@ -198,7 +198,7 @@ MESSAGE
198
198
  # <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-US' lang='en-US'>
199
199
  #
200
200
  # @param lang [String] The value of `xml:lang` and `lang`
201
- # @return [Hash<#to_s, String>] The attribute hash
201
+ # @return [{#to_s => String}] The attribute hash
202
202
  def html_attrs(lang = 'en-US')
203
203
  {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang}
204
204
  end
@@ -9,7 +9,7 @@ module Haml
9
9
  # The options hash for Haml when used within Rails.
10
10
  # See {file:HAML_REFERENCE.md#haml_options the Haml options documentation}.
11
11
  #
12
- # @return [Hash<Symbol, Object>]
12
+ # @return [{Symbol => Object}]
13
13
  attr_accessor :options
14
14
 
15
15
  # Enables integration with the Rails 2.2.5+ XSS protection,
@@ -46,7 +46,7 @@ end
46
46
  # Decide how we want to load Haml into Rails.
47
47
  # Patching was necessary for versions <= 2.0.1,
48
48
  # but we can make it a normal handler for higher versions.
49
- if defined?(ActionView::TemplateHandler)
49
+ if defined?(ActionView::TemplateHandler) || defined?(ActionView::Template::Handler)
50
50
  require 'haml/template/plugin'
51
51
  else
52
52
  require 'haml/template/patch'
@@ -2,8 +2,11 @@
2
2
  # using the > 2.0.1 template handler API.
3
3
 
4
4
  module Haml
5
- class Plugin < ActionView::TemplateHandler
6
- include ActionView::TemplateHandlers::Compilable if defined?(ActionView::TemplateHandlers::Compilable)
5
+ class Plugin < Haml::Util.av_template_class(:Handler)
6
+ if defined?(ActionView::TemplateHandlers::Compilable) ||
7
+ defined?(ActionView::Template::Handlers::Compilable)
8
+ include Haml::Util.av_template_class(:Handlers)::Compilable
9
+ end
7
10
 
8
11
  def compile(template)
9
12
  options = Haml::Template.options.dup
@@ -38,7 +41,8 @@ end.register_template_handler(:haml, Haml::Plugin)
38
41
  # In Rails 2.0.2, ActionView::TemplateError took arguments
39
42
  # that we can't fill in from the Haml::Plugin context.
40
43
  # Thus, we've got to monkeypatch ActionView::Base to catch the error.
41
- if ActionView::TemplateError.instance_method(:initialize).arity == 5
44
+ if defined?(ActionView::TemplateError) &&
45
+ ActionView::TemplateError.instance_method(:initialize).arity == 5
42
46
  class ActionView::Base
43
47
  def compile_template(handler, template, file_name, local_assigns)
44
48
  render_symbol = assign_method_name(handler, template, file_name)
@@ -146,6 +146,19 @@ module Haml
146
146
  return nil
147
147
  end
148
148
 
149
+ # Returns an ActionView::Template* class.
150
+ # In pre-3.0 versions of Rails, most of these classes
151
+ # were of the form `ActionView::TemplateFoo`,
152
+ # while afterwards they were of the form `ActionView;:Template::Foo`.
153
+ #
154
+ # @param name [#to_s] The name of the class to get.
155
+ # For example, `:Error` will return `ActionView::TemplateError`
156
+ # or `ActionView::Template::Error`.
157
+ def av_template_class(name)
158
+ return ActionView.const_get("Template#{name}") if ActionView.const_defined?("Template#{name}")
159
+ return ActionView::Template.const_get(name.to_s)
160
+ end
161
+
149
162
  ## Rails XSS Safety
150
163
 
151
164
  # Whether or not ActionView's XSS protection is available and enabled,
@@ -23,7 +23,7 @@ module Haml
23
23
  # :major => 2, :minor => 1, :teeny => 0
24
24
  # }
25
25
  #
26
- # @return [Hash<Symbol, String/Fixnum>] The version hash
26
+ # @return [{Symbol => String/Fixnum}] The version hash
27
27
  def version
28
28
  return @@version if defined?(@@version)
29
29
 
@@ -8,7 +8,7 @@ module Sass
8
8
  # Converts a node to Sass code that will generate it.
9
9
  #
10
10
  # @param tabs [Fixnum] The amount of tabulation to use for the Sass code
11
- # @param opts [Hash<Symbol, Object>] An options hash (see {Sass::CSS#initialize})
11
+ # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
12
12
  # @return [String] The Sass code corresponding to the node
13
13
  def to_sass(tabs = 0, opts = {})
14
14
  result = ''
@@ -126,7 +126,7 @@ module Sass
126
126
  }.freeze
127
127
 
128
128
  # @param template [String] The Sass template.
129
- # @param options [Hash<Symbol, Object>] An options hash;
129
+ # @param options [{Symbol => Object}] An options hash;
130
130
  # see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
131
131
  def initialize(template, options={})
132
132
  @options = DEFAULT_OPTIONS.merge(options)
@@ -30,7 +30,7 @@ module Sass
30
30
  # The options hash.
31
31
  # See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
32
32
  #
33
- # @return [Hash<Symbol, Object>]
33
+ # @return [{Symbol => Object}]
34
34
  def options
35
35
  @options || (parent && parent.options) || {}
36
36
  end
@@ -12,7 +12,7 @@ module Sass
12
12
  # reading it from the Sass cache if possible.
13
13
  #
14
14
  # @param filename [String] The path to the Sass file
15
- # @param options [Hash<Symbol, Object>] The options hash.
15
+ # @param options [{Symbol => Object}] The options hash.
16
16
  # Only the {file:SASS_REFERENCE.md#cache-option `:cache_location`} option is used
17
17
  # @raise [Sass::SyntaxError] if there's an error in the document
18
18
  def tree_for(filename, options)
@@ -30,21 +30,21 @@ module Sass
30
30
  # An options hash.
31
31
  # See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
32
32
  #
33
- # @return [Hash<Symbol, Object>]
33
+ # @return [{Symbol => Object}]
34
34
  attr_reader :options
35
35
 
36
36
  # Sets the options hash.
37
37
  # See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
38
38
  #
39
- # @param value [Hash<Symbol, Object>] The options hash
39
+ # @param value [{Symbol => Object}] The options hash
40
40
  def options=(value)
41
41
  @options.merge!(value)
42
42
  end
43
43
 
44
44
  # Non-destructively modifies \{#options} so that default values are properly set.
45
45
  #
46
- # @param additional_options [Hash<Symbol, Object>] An options hash with which to merge \{#options}
47
- # @return [Hash<Symbol, Object>] The modified options hash
46
+ # @param additional_options [{Symbol => Object}] An options hash with which to merge \{#options}
47
+ # @return [{Symbol => Object}] The modified options hash
48
48
  def engine_options(additional_options = {})
49
49
  opts = options.dup.merge(additional_options)
50
50
  opts[:load_paths] = load_paths(opts)
@@ -38,7 +38,7 @@ module Sass
38
38
  # and updating them if necessary.
39
39
  #
40
40
  # @param env The Rack request environment
41
- # @return [(#to_i, Hash<String, String>, Object)] The Rack response
41
+ # @return [(#to_i, {String => String}, Object)] The Rack response
42
42
  def call(env)
43
43
  Sass::Plugin.check_for_updates
44
44
  @app.call(env)
@@ -7,7 +7,7 @@ module Sass
7
7
  # evaluates them,
8
8
  # and prints the result.
9
9
  class Repl
10
- # @param options [Hash<Symbol, Object>] An options hash.
10
+ # @param options [{Symbol => Object}] An options hash.
11
11
  def initialize(options = {})
12
12
  @options = options
13
13
  end
@@ -69,7 +69,7 @@ END
69
69
  # Color.new([126, 126, 126]).with(:red => 0, :green => 255)
70
70
  # #=> rgb(0, 255, 126)
71
71
  #
72
- # @param attrs [Hash<Symbol, Fixnum>]
72
+ # @param attrs [{Symbol => Fixnum}]
73
73
  # A map of channel names (`:red`, `:green`, or `:blue`) to values
74
74
  # @return [Color] The new Color object
75
75
  def with(attrs)
@@ -67,16 +67,18 @@ module Sass::Script
67
67
  # That means that all instance methods of {EvaluationContext}
68
68
  # are available to use in functions.
69
69
  class EvaluationContext
70
- include Sass::Script::Functions
71
-
72
70
  # The options hash for the {Sass::Engine} that is processing the function call
73
71
  #
74
- # @return [Hash<Symbol, Object>]
72
+ # @return [{Symbol => Object}]
75
73
  attr_reader :options
76
74
 
77
- # @param options [Hash<Symbol, Object>] See \{#options}
75
+ # @param options [{Symbol => Object}] See \{#options}
78
76
  def initialize(options)
79
77
  @options = options
78
+
79
+ # We need to include this individually in each instance
80
+ # because of an icky Ruby restriction
81
+ class << self; include Sass::Script::Functions; end
80
82
  end
81
83
 
82
84
  # Asserts that the type of a given SassScript value
@@ -36,7 +36,7 @@ module Sass
36
36
  # The options hash for the node.
37
37
  # See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
38
38
  #
39
- # @return [Hash<Symbol, Object>]
39
+ # @return [{Symbol => Object}]
40
40
  attr_reader :options
41
41
 
42
42
  def initialize
@@ -45,7 +45,7 @@ module Sass
45
45
 
46
46
  # Sets the options hash for the node and all its children.
47
47
  #
48
- # @param options [Hash<Symbol, Object>] The options
48
+ # @param options [{Symbol => Object}] The options
49
49
  # @see #options
50
50
  def options=(options)
51
51
  children.each {|c| c.options = options}
@@ -73,7 +73,7 @@ class HelperTest < Test::Unit::TestCase
73
73
 
74
74
  begin
75
75
  ActionView::Base.new.render(:inline => "<%= flatten('Foo\\nBar') %>")
76
- rescue NoMethodError, ActionView::TemplateError
76
+ rescue NoMethodError, Haml::Util.av_template_class(:Error)
77
77
  proper_behavior = true
78
78
  end
79
79
  assert(proper_behavior)
@@ -109,7 +109,7 @@ class TemplateTest < Test::Unit::TestCase
109
109
  message = "template: #{name}\nline: #{line}"
110
110
  assert_equal(pair.first, pair.last, message)
111
111
  end
112
- rescue ActionView::TemplateError => e
112
+ rescue Haml::Util.av_template_class(:Error) => e
113
113
  if e.message =~ /Can't run [\w:]+ filter; required (one of|file) ((?:'\w+'(?: or )?)+)(, but none were found| not found)/
114
114
  puts "\nCouldn't require #{$2}; skipping a test."
115
115
  else
@@ -2,6 +2,16 @@ require 'test/unit'
2
2
  require File.dirname(__FILE__) + '/../../lib/sass'
3
3
  require 'sass/script'
4
4
 
5
+ module UserFunctions
6
+ def user_defined
7
+ Sass::Script::String.new("I'm a user-defined string!")
8
+ end
9
+ end
10
+
11
+ module Sass::Script::Functions
12
+ include UserFunctions
13
+ end
14
+
5
15
  class SassFunctionTest < Test::Unit::TestCase
6
16
  def test_hsl
7
17
  # These tests adapted from the w3c browser tests
@@ -138,6 +148,10 @@ class SassFunctionTest < Test::Unit::TestCase
138
148
  assert_error_message("\"foo\" is not a number for `rgb'", "rgb(10, 10, \"foo\")");
139
149
  end
140
150
 
151
+ def test_user_defined_function
152
+ assert_equal("I'm a user-defined string!", evaluate("user_defined()"))
153
+ end
154
+
141
155
  private
142
156
 
143
157
  def assert_rgb_hsl(rgb, hsl)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.15
4
+ version: 2.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-12-01 00:00:00 -08:00
13
+ date: 2009-12-16 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency