haml 3.2.0.beta.3 → 3.2.0.rc.1

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.

@@ -30,6 +30,12 @@
30
30
  a language change from 3.1 and is enabled by default.
31
31
  (thanks to [Andrew Smith](https://github.com/fullsailor))
32
32
 
33
+ * All Hash attribute values are now treated as HTML5 data, regardless of key.
34
+ Previously only the "data" key was treated this way. Allowing arbitrary keys
35
+ means you can now easily use this feauture for Aria attributes, among other
36
+ uses.
37
+ (thanks to [Elvin Efendi](https://github.com/ElvinEfendi))
38
+
33
39
  * Added `remove_whitespace` option to always remove all whitespace around Haml
34
40
  tags. (thanks to [Tim van der Horst](https://github.com/vdh))
35
41
 
@@ -86,6 +92,11 @@
86
92
  * Fix multiline silent comments: Haml previously did not allow free indentation
87
93
  inside multline silent comments.
88
94
 
95
+ * Fix ordering bug with partial layouts on Rails.
96
+ (thanks [Sam Pohlenz](https://github.com/spohlenz))
97
+
98
+ * Add command-line option to suppress script evaluation.
99
+
89
100
  ## 3.1.6
90
101
 
91
102
  * In indented mode, don't reindent buffers that contain preserved tags, and
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require "rubygems/package_task"
4
4
 
5
5
  task :default => :test
6
6
 
7
- CLEAN.replace %w(pkg doc coverage .yardoc)
7
+ CLEAN.replace %w(pkg doc coverage .yardoc test/haml vendor)
8
8
 
9
9
  def silence_warnings
10
10
  the_real_stderr, $stderr = $stderr, StringIO.new
@@ -6,7 +6,6 @@ require 'haml/version'
6
6
  # * {Haml::Compiler} is Haml's compiler.
7
7
  # * {Haml::Engine} is the class used to render Haml within Ruby code.
8
8
  # * {Haml::Options} is where Haml's runtime options are defined.
9
- # * {Haml::Engine} is the class used to render Haml within Ruby code.
10
9
  # * {Haml::Error} is raised when Haml encounters an error.
11
10
  #
12
11
  # Also see the {file:REFERENCE.md full Haml reference}.
@@ -47,13 +47,18 @@ module Haml
47
47
  precompiled + ";" + precompiled_method_return_value
48
48
  end
49
49
 
50
- # Returns the precompiled string with the preamble and postamble
50
+ # Returns the precompiled string with the preamble and postamble.
51
+ #
52
+ # Initializes to ActionView::OutputBuffer when available; this is necessary
53
+ # to avoid ordering issues with partial layouts in Rails. If not available,
54
+ # initializes to nil.
51
55
  def precompiled_with_ambles(local_names)
52
56
  preamble = <<END.gsub("\n", ";")
53
57
  begin
54
58
  extend Haml::Helpers
55
59
  _hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{options.for_buffer.inspect})
56
60
  _erbout = _hamlout.buffer
61
+ @output_buffer = output_buffer ||= ActionView::OutputBuffer.new rescue nil
57
62
  END
58
63
  postamble = <<END.gsub("\n", ";")
59
64
  #{precompiled_method_return_value}
@@ -410,12 +415,14 @@ END
410
415
  other_quote_char = attr_wrapper == '"' ? "'" : '"'
411
416
  join_char = hyphenate_data_attrs ? '-' : '_'
412
417
 
413
- if attributes['data'].is_a?(Hash)
414
- data_attributes = attributes.delete('data')
415
- data_attributes = flatten_data_attributes(data_attributes, '', join_char)
416
- data_attributes = build_data_keys(data_attributes, hyphenate_data_attrs)
417
- attributes = data_attributes.merge(attributes)
418
- end
418
+ attributes.each do |key, value|
419
+ if value.is_a?(Hash)
420
+ data_attributes = attributes.delete(key)
421
+ data_attributes = flatten_data_attributes(data_attributes, '', join_char)
422
+ data_attributes = build_data_keys(data_attributes, hyphenate_data_attrs, key)
423
+ attributes = data_attributes.merge(attributes)
424
+ end
425
+ end
419
426
 
420
427
  result = attributes.collect do |attr, value|
421
428
  next if value.nil?
@@ -465,14 +472,14 @@ END
465
472
  return !value.empty? && value
466
473
  end
467
474
 
468
- def self.build_data_keys(data_hash, hyphenate)
475
+ def self.build_data_keys(data_hash, hyphenate, attr_name="data")
469
476
  Hash[data_hash.map do |name, value|
470
477
  if name == nil
471
- ["data", value]
478
+ [attr_name, value]
472
479
  elsif hyphenate
473
- ["data-#{name.to_s.gsub(/_/, '-')}", value]
480
+ ["#{attr_name}-#{name.to_s.gsub(/_/, '-')}", value]
474
481
  else
475
- ["data-#{name}", value]
482
+ ["#{attr_name}-#{name}", value]
476
483
  end
477
484
  end]
478
485
  end
@@ -241,6 +241,11 @@ END
241
241
  'Always add CDATA sections to javascript and css blocks.') do
242
242
  @options[:for_engine][:cdata] = true
243
243
  end
244
+
245
+ opts.on('--suppress-eval',
246
+ 'Don\'t evaluate Ruby scripts.') do
247
+ @options[:for_engine][:suppress_eval] = true
248
+ end
244
249
 
245
250
  opts.on('-r', '--require FILE', "Same as 'ruby -r'.") do |file|
246
251
  @options[:requires] << file
@@ -611,8 +611,8 @@ MESSAGE
611
611
  # @return [Proc] A new proc with the new variables bound
612
612
  def haml_bind_proc(&proc)
613
613
  _hamlout = haml_buffer
614
- _erbout = _hamlout.buffer
615
- _erbout.to_s #"use" the variable to silence warnings
614
+ #double assignment is to avoid warnings
615
+ _erbout = _erbout = _hamlout.buffer
616
616
  proc { |*args| proc.call(*args) }
617
617
  end
618
618
  end
@@ -39,7 +39,8 @@ module ActionView
39
39
  module CaptureHelper
40
40
  def capture_with_haml(*args, &block)
41
41
  if Haml::Helpers.block_is_haml?(block)
42
- _hamlout = eval('_hamlout', block.binding) # Necessary since capture_haml checks _hamlout
42
+ #double assignment is to avoid warnings
43
+ _hamlout = _hamlout = eval('_hamlout', block.binding) # Necessary since capture_haml checks _hamlout
43
44
  value = nil
44
45
  buffer = capture_haml(*args) { value = yield(*args) }
45
46
  str =
@@ -16,7 +16,11 @@ module Haml
16
16
 
17
17
  def compile(template)
18
18
  options = Haml::Template.options.dup
19
- options[:mime_type] = template.mime_type if template.respond_to? :mime_type
19
+ if template.respond_to? :type
20
+ options[:mime_type] = template.type
21
+ elsif template.respond_to? :mime_type
22
+ options[:mime_type] = template.mime_type
23
+ end
20
24
  options[:filename] = template.identifier
21
25
  Haml::Engine.new(template.source, options).compiler.precompiled_with_ambles([])
22
26
  end
@@ -1,3 +1,3 @@
1
1
  module Haml
2
- VERSION = "3.2.0.beta.3"
2
+ VERSION = "3.2.0.rc.1"
3
3
  end
@@ -92,19 +92,23 @@ class EngineTest < MiniTest::Unit::TestCase
92
92
  end
93
93
  end
94
94
 
95
- def render(text, options = {}, &block)
96
- scope = options.delete(:scope) || Object.new
97
- locals = options.delete(:locals) || {}
98
- engine(text, options).to_html(scope, locals, &block)
99
- end
100
-
101
- def engine(text, options = {})
95
+ def use_test_tracing(options)
102
96
  unless options[:filename]
103
97
  # use caller method name as fake filename. useful for debugging
104
98
  i = -1
105
99
  caller[i+=1] =~ /`(.+?)'/ until $1 and $1.index('test_') == 0
106
100
  options[:filename] = "(#{$1})"
107
101
  end
102
+ options
103
+ end
104
+
105
+ def render(text, options = {}, &block)
106
+ options = use_test_tracing(options)
107
+ super
108
+ end
109
+
110
+ def engine(text, options = {})
111
+ options = use_test_tracing(options)
108
112
  Haml::Engine.new(text, options)
109
113
  end
110
114
 
@@ -1430,6 +1434,13 @@ HAML
1430
1434
  render("%div{:data => {:foo_bar => 'blip', :baz => 'bang'}}"))
1431
1435
  end
1432
1436
 
1437
+ def test_html5_arbitrary_hash_valued_attributes_with
1438
+ assert_equal("<div aria-foo='blip'></div>\n",
1439
+ render("%div{:aria => {:foo => 'blip'}}"))
1440
+ assert_equal("<div foo-baz='bang'></div>\n",
1441
+ render("%div{:foo => {:baz => 'bang'}}"))
1442
+ end
1443
+
1433
1444
  def test_html5_data_attributes_with_nested_hash
1434
1445
  assert_equal("<div data-a-b='c'></div>\n", render(<<-HAML))
1435
1446
  - hash = {:a => {:b => 'c'}}
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', git: 'git://github.com/rails/rails.git'
4
+ gem 'journey', git: 'git://github.com/rails/journey.git'
5
+ gem 'activerecord-deprecated_finders', git: 'git://github.com/rails/activerecord-deprecated_finders.git'
6
+ gemspec :path => "../.."
7
+
@@ -0,0 +1,111 @@
1
+ GIT
2
+ remote: git://github.com/rails/activerecord-deprecated_finders.git
3
+ revision: fe150f26f009cef370658b7c19db1629b2448952
4
+ specs:
5
+ activerecord-deprecated_finders (0.0.1)
6
+
7
+ GIT
8
+ remote: git://github.com/rails/journey.git
9
+ revision: 850267edd7f19633a6868110d523f86f147c1653
10
+ specs:
11
+ journey (2.0.0.20120723141804)
12
+
13
+ GIT
14
+ remote: git://github.com/rails/rails.git
15
+ revision: 8815de7b427196f00bd9f3406377928c2c269e22
16
+ specs:
17
+ actionmailer (4.0.0.beta)
18
+ actionpack (= 4.0.0.beta)
19
+ mail (~> 2.4.4)
20
+ actionpack (4.0.0.beta)
21
+ activesupport (= 4.0.0.beta)
22
+ builder (~> 3.1.0)
23
+ erubis (~> 2.7.0)
24
+ journey (~> 2.0.0)
25
+ rack (~> 1.4.1)
26
+ rack-test (~> 0.6.1)
27
+ activemodel (4.0.0.beta)
28
+ activesupport (= 4.0.0.beta)
29
+ builder (~> 3.1.0)
30
+ activerecord (4.0.0.beta)
31
+ activemodel (= 4.0.0.beta)
32
+ activerecord-deprecated_finders (= 0.0.1)
33
+ activesupport (= 4.0.0.beta)
34
+ arel (~> 3.0.2)
35
+ activesupport (4.0.0.beta)
36
+ i18n (~> 0.6)
37
+ minitest (~> 4.1)
38
+ multi_json (~> 1.3)
39
+ tzinfo (~> 0.3.33)
40
+ rails (4.0.0.beta)
41
+ actionmailer (= 4.0.0.beta)
42
+ actionpack (= 4.0.0.beta)
43
+ activerecord (= 4.0.0.beta)
44
+ activesupport (= 4.0.0.beta)
45
+ bundler (~> 1.2)
46
+ railties (= 4.0.0.beta)
47
+ sprockets-rails (~> 1.0)
48
+ railties (4.0.0.beta)
49
+ actionpack (= 4.0.0.beta)
50
+ activesupport (= 4.0.0.beta)
51
+ rake (>= 0.8.7)
52
+ rdoc (~> 3.4)
53
+ thor (>= 0.15.4, < 2.0)
54
+
55
+ PATH
56
+ remote: /Users/norman/work/haml/haml
57
+ specs:
58
+ haml (4.0.0.alpha.0)
59
+ tilt
60
+
61
+ GEM
62
+ remote: http://rubygems.org/
63
+ specs:
64
+ arel (3.0.2)
65
+ builder (3.1.3)
66
+ erubis (2.7.0)
67
+ hike (1.2.1)
68
+ i18n (0.6.1)
69
+ json (1.7.5)
70
+ mail (2.4.4)
71
+ i18n (>= 0.4.0)
72
+ mime-types (~> 1.16)
73
+ treetop (~> 1.4.8)
74
+ mime-types (1.19)
75
+ minitest (4.1.0)
76
+ multi_json (1.3.6)
77
+ nokogiri (1.5.5)
78
+ polyglot (0.3.3)
79
+ rack (1.4.1)
80
+ rack-test (0.6.2)
81
+ rack (>= 1.0)
82
+ rake (0.9.2.2)
83
+ rbench (0.2.3)
84
+ rdoc (3.12)
85
+ json (~> 1.4)
86
+ sprockets (2.3.2)
87
+ hike (~> 1.2)
88
+ multi_json (~> 1.0)
89
+ rack (~> 1.0)
90
+ tilt (~> 1.1, != 1.3.0)
91
+ sprockets-rails (1.0.0)
92
+ railties (>= 4.0.0.beta, < 5.0)
93
+ sprockets (~> 2.3.1)
94
+ thor (0.16.0)
95
+ tilt (1.3.3)
96
+ treetop (1.4.10)
97
+ polyglot
98
+ polyglot (>= 0.3.1)
99
+ tzinfo (0.3.33)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ activerecord-deprecated_finders!
106
+ haml!
107
+ journey!
108
+ minitest
109
+ nokogiri
110
+ rails!
111
+ rbench
@@ -43,12 +43,8 @@ class HelperTest < MiniTest::Unit::TestCase
43
43
  end
44
44
 
45
45
  def render(text, options = {})
46
- if options == :action_view
47
- @base.render :inline => text, :type => :haml
48
- else
49
- scope = options.delete :scope_object
50
- Haml::Engine.new(text, options).to_html(scope ? scope : Object.new)
51
- end
46
+ return @base.render :inline => text, :type => :haml if options == :action_view
47
+ super
52
48
  end
53
49
 
54
50
  def test_flatten
@@ -185,14 +181,12 @@ HAML
185
181
 
186
182
  def test_content_tag_error_wrapping
187
183
  def @base.protect_against_forgery?; false; end
188
- assert_equal(<<HTML, render(<<HAML, :action_view))
189
- <form accept-charset="UTF-8" action="" method="post">#{rails_form_opener}
190
- <div class="field_with_errors"><label for="post_error_field">Error field</label></div>
191
- </form>
192
- HTML
184
+ output = render(<<HAML, :action_view)
193
185
  = form_for @post, :as => :post, :html => {:class => nil, :id => nil}, :url => '' do |f|
194
186
  = f.label 'error_field'
195
187
  HAML
188
+ fragment = Nokogiri::HTML.fragment(output)
189
+ refute_nil fragment.css('form div.field_with_errors label[for=post_error_field]').first
196
190
  end
197
191
 
198
192
  def test_form_tag_in_helper_with_string_block
@@ -350,7 +344,7 @@ HAML
350
344
  def test_page_class
351
345
  controller = Struct.new(:controller_name, :action_name).new('troller', 'tion')
352
346
  scope = Struct.new(:controller).new(controller)
353
- result = render("%div{:class => page_class} MyDiv", :scope_object => scope)
347
+ result = render("%div{:class => page_class} MyDiv", :scope => scope)
354
348
  expected = "<div class='troller tion'>MyDiv</div>\n"
355
349
  assert_equal expected, result
356
350
  end
@@ -0,0 +1,5 @@
1
+ <h1>Partial layout used with for block:</h1>
2
+ <div class='partial-layout'>
3
+ <h2>This is inside a partial layout</h2>
4
+ <p>Some content within a layout</p>
5
+ </div>
@@ -44,7 +44,7 @@ class TemplateTest < MiniTest::Unit::TestCase
44
44
  whitespace_handling original_engine list helpful
45
45
  silent_script tag_parsing just_stuff partials
46
46
  nuke_outer_whitespace nuke_inner_whitespace
47
- render_layout partial_layout}
47
+ render_layout partial_layout partial_layout_erb}
48
48
 
49
49
  def setup
50
50
  @base = create_base
@@ -68,10 +68,10 @@ class TemplateTest < MiniTest::Unit::TestCase
68
68
  base
69
69
  end
70
70
 
71
- def render(text, opts = {})
72
- return @base.render(:inline => text, :type => :haml) if opts == :action_view
73
- opts = opts.merge(:format => :xhtml)
74
- Haml::Engine.new(text, opts).to_html(@base)
71
+ def render(text, options = {})
72
+ return @base.render(:inline => text, :type => :haml) if options == :action_view
73
+ options = options.merge(:format => :xhtml)
74
+ super(text, options, @base)
75
75
  end
76
76
 
77
77
  def load_result(name)
@@ -216,16 +216,13 @@ END
216
216
  end
217
217
 
218
218
  def test_form_builder_label_with_block
219
- assert_equal(<<HTML, render(<<HAML, :action_view))
220
- <form accept-charset="UTF-8" action="" method="post">#{rails_form_opener}
221
- <label for="article_title">Block content
222
- </label>
223
- </form>
224
- HTML
219
+ output = render(<<HAML, :action_view)
225
220
  = form_for @article, :as => :article, :html => {:class => nil, :id => nil}, :url => '' do |f|
226
221
  = f.label :title do
227
222
  Block content
228
223
  HAML
224
+ fragment = Nokogiri::HTML.fragment output
225
+ assert_equal "Block content", fragment.css('form label').first.content.strip
229
226
  end
230
227
 
231
228
  ## XSS Protection Tests
@@ -310,23 +307,6 @@ HTML
310
307
  HAML
311
308
  end
312
309
 
313
- def test_xss_protection_with_form_for
314
- assert_equal(<<HTML, render(<<HAML, :action_view))
315
- <form accept-charset="UTF-8" action="" method="post">#{rails_form_opener}
316
- Title:
317
- <input id="article_title" name="article[title]" size="30" type="text" value="Hello" />
318
- Body:
319
- <input id="article_body" name="article[body]" size="30" type="text" value="World" />
320
- </form>
321
- HTML
322
- = form_for @article, :as => :article, :html => {:class => nil, :id => nil}, :url => '' do |f|
323
- Title:
324
- = f.text_field :title
325
- Body:
326
- = f.text_field :body
327
- HAML
328
- end
329
-
330
310
  if defined?(ActionView::Helpers::PrototypeHelper)
331
311
  def test_rjs
332
312
  assert_equal(<<HTML, render(<<HAML, :action_view))
@@ -0,0 +1,4 @@
1
+ <h1>Partial layout used with for block:</h1>
2
+ <%= render :layout => 'layout_for_partial' do -%>
3
+ <p>Some content within a layout</p>
4
+ <% end %>
@@ -10,6 +10,7 @@ require 'minitest/autorun'
10
10
  require 'action_pack'
11
11
  require 'action_controller'
12
12
  require 'action_view'
13
+ require 'nokogiri'
13
14
 
14
15
  require 'rails'
15
16
  class TestApp < Rails::Application
@@ -39,10 +40,12 @@ class MiniTest::Unit::TestCase
39
40
 
40
41
  extend Declarative
41
42
 
42
- def render(text, options = {}, &block)
43
+ def render(text, options = {}, base = nil, &block)
43
44
  scope = options.delete(:scope) || Object.new
44
45
  locals = options.delete(:locals) || {}
45
- Haml::Engine.new(text, options).to_html(scope, locals, &block)
46
+ engine = Haml::Engine.new(text, options)
47
+ return engine.to_html(base) if base
48
+ engine.to_html(scope, locals, &block)
46
49
  end
47
50
 
48
51
  def assert_warning(message)
@@ -79,4 +82,4 @@ class MiniTest::Unit::TestCase
79
82
  Haml::Error.message(*args)
80
83
  end
81
84
 
82
- end
85
+ end
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: 3.2.0.beta.3
4
+ version: 3.2.0.rc.1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-08-19 00:00:00.000000000 Z
14
+ date: 2012-10-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: tilt
@@ -77,6 +77,22 @@ dependencies:
77
77
  - - ! '>='
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: nokogiri
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
80
96
  description: ! 'Haml (HTML Abstraction Markup Language) is a layer on top of HTML
81
97
  or XML that''s
82
98
 
@@ -97,7 +113,6 @@ executables:
97
113
  extensions: []
98
114
  extra_rdoc_files: []
99
115
  files:
100
- - rails/init.rb
101
116
  - lib/haml/buffer.rb
102
117
  - lib/haml/compiler.rb
103
118
  - lib/haml/engine.rb
@@ -129,6 +144,8 @@ files:
129
144
  - test/gemfiles/Gemfile.rails-3.0.x
130
145
  - test/gemfiles/Gemfile.rails-3.1.x
131
146
  - test/gemfiles/Gemfile.rails-3.2.x
147
+ - test/gemfiles/Gemfile.rails-master
148
+ - test/gemfiles/Gemfile.rails-master.lock
132
149
  - test/haml-spec/LICENSE
133
150
  - test/haml-spec/lua_haml_spec.lua
134
151
  - test/haml-spec/perl_haml_test.pl
@@ -149,6 +166,7 @@ files:
149
166
  - test/results/nuke_outer_whitespace.xhtml
150
167
  - test/results/original_engine.xhtml
151
168
  - test/results/partial_layout.xhtml
169
+ - test/results/partial_layout_erb.xhtml
152
170
  - test/results/partials.xhtml
153
171
  - test/results/render_layout.xhtml
154
172
  - test/results/silent_script.xhtml
@@ -178,6 +196,7 @@ files:
178
196
  - test/templates/nuke_outer_whitespace.haml
179
197
  - test/templates/original_engine.haml
180
198
  - test/templates/partial_layout.haml
199
+ - test/templates/partial_layout_erb.erb
181
200
  - test/templates/partialize.haml
182
201
  - test/templates/partials.haml
183
202
  - test/templates/render_layout.haml
@@ -190,7 +209,6 @@ files:
190
209
  - test/test_helper.rb
191
210
  - test/util_test.rb
192
211
  - Rakefile
193
- - init.rb
194
212
  - .yardopts
195
213
  - CHANGELOG.md
196
214
  - FAQ.md
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require "haml"
@@ -1 +0,0 @@
1
- Kernel.load File.join(File.dirname(__FILE__), '..', 'init.rb')