haml 3.1.0.alpha.36 → 3.1.0.alpha.37

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.

Files changed (5) hide show
  1. data/EDGE_GEM_VERSION +1 -1
  2. data/REVISION +1 -0
  3. data/VERSION +1 -1
  4. data/lib/haml/html.rb +69 -62
  5. metadata +8 -7
@@ -1 +1 @@
1
- 3.1.0.alpha.36
1
+ 3.1.0.alpha.37
@@ -0,0 +1 @@
1
+ (release)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.36
1
+ 3.1.0.alpha.37
@@ -3,81 +3,90 @@ require File.dirname(__FILE__) + '/../haml'
3
3
  require 'haml/engine'
4
4
  require 'rubygems'
5
5
  require 'cgi'
6
+ require 'hpricot'
6
7
 
7
8
  module Haml
8
9
  class HTML
9
10
  # A module containing utility methods that every Hpricot node
10
11
  # should have.
11
12
  module Node
12
- # Whether this node has already been converted to Haml.
13
- # Only used for text nodes and elements.
14
- #
15
- # @return [Boolean]
16
- attr_accessor :converted_to_haml
17
-
18
- # Returns the Haml representation of the given node.
19
- #
20
- # @param tabs [Fixnum] The indentation level of the resulting Haml.
21
- # @option options (see Haml::HTML#initialize)
22
- def to_haml(tabs, options)
23
- return "" if converted_to_haml || to_s.strip.empty?
24
- text = uninterp(self.to_s)
25
- node = next_node
26
- while node.is_a?(::Hpricot::Elem) && node.name == "haml:loud"
27
- node.converted_to_haml = true
28
- text << '#{' <<
29
- CGI.unescapeHTML(node.inner_text).gsub(/\n\s*/, ' ').strip << '}'
30
-
31
- if node.next_node.is_a?(::Hpricot::Text)
32
- node = node.next_node
33
- text << uninterp(node.to_s)
34
- node.converted_to_haml = true
35
- end
36
-
37
- node = node.next_node
38
- end
39
- return parse_text_with_interpolation(text, tabs)
40
- end
13
+ # We have to do everything in `#included`
14
+ # rather than including the methods in the module itself
15
+ # because if we do that, they don't propagate to the already-defined subclasses
16
+ # of the modules including this.
17
+ def self.included(base)
18
+ base.class_eval do
19
+ # Whether this node has already been converted to Haml.
20
+ # Only used for text nodes and elements.
21
+ #
22
+ # @return [Boolean]
23
+ attr_accessor :converted_to_haml
24
+
25
+ # Returns the Haml representation of the given node.
26
+ #
27
+ # @param tabs [Fixnum] The indentation level of the resulting Haml.
28
+ # @option options (see Haml::HTML#initialize)
29
+ def to_haml(tabs, options)
30
+ return "" if converted_to_haml || to_s.strip.empty?
31
+ text = uninterp(self.to_s)
32
+ node = next_node
33
+ while node.is_a?(::Hpricot::Elem) && node.name == "haml:loud"
34
+ node.converted_to_haml = true
35
+ text << '#{' <<
36
+ CGI.unescapeHTML(node.inner_text).gsub(/\n\s*/, ' ').strip << '}'
37
+
38
+ if node.next_node.is_a?(::Hpricot::Text)
39
+ node = node.next_node
40
+ text << uninterp(node.to_s)
41
+ node.converted_to_haml = true
42
+ end
41
43
 
42
- private
44
+ node = node.next_node
45
+ end
46
+ return parse_text_with_interpolation(text, tabs)
47
+ end
43
48
 
44
- def erb_to_interpolation(text, options)
45
- return text unless options[:erb]
46
- text = CGI.escapeHTML(uninterp(text))
47
- %w[<haml:loud> </haml:loud>].each {|str| text.gsub!(CGI.escapeHTML(str), str)}
48
- ::Hpricot::XML(text).children.inject("") do |str, elem|
49
- if elem.is_a?(::Hpricot::Text)
50
- str + CGI.unescapeHTML(elem.to_s)
51
- else # <haml:loud> element
52
- str + '#{' + CGI.unescapeHTML(elem.innerText.strip) + '}'
49
+ private
50
+
51
+ def erb_to_interpolation(text, options)
52
+ return text unless options[:erb]
53
+ text = CGI.escapeHTML(uninterp(text))
54
+ %w[<haml:loud> </haml:loud>].each {|str| text.gsub!(CGI.escapeHTML(str), str)}
55
+ ::Hpricot::XML(text).children.inject("") do |str, elem|
56
+ if elem.is_a?(::Hpricot::Text)
57
+ str + CGI.unescapeHTML(elem.to_s)
58
+ else # <haml:loud> element
59
+ str + '#{' + CGI.unescapeHTML(elem.innerText.strip) + '}'
60
+ end
61
+ end
53
62
  end
54
- end
55
- end
56
63
 
57
- def tabulate(tabs)
58
- ' ' * tabs
59
- end
64
+ def tabulate(tabs)
65
+ ' ' * tabs
66
+ end
60
67
 
61
- def uninterp(text)
62
- text.gsub('#{', '\#{') #'
63
- end
68
+ def uninterp(text)
69
+ text.gsub('#{', '\#{') #'
70
+ end
64
71
 
65
- def attr_hash
66
- attributes.to_hash
67
- end
72
+ def attr_hash
73
+ attributes.to_hash
74
+ end
68
75
 
69
- def parse_text(text, tabs)
70
- parse_text_with_interpolation(uninterp(text), tabs)
71
- end
76
+ def parse_text(text, tabs)
77
+ parse_text_with_interpolation(uninterp(text), tabs)
78
+ end
72
79
 
73
- def parse_text_with_interpolation(text, tabs)
74
- text.strip!
75
- return "" if text.empty?
80
+ def parse_text_with_interpolation(text, tabs)
81
+ text.strip!
82
+ return "" if text.empty?
76
83
 
77
- text.split("\n").map do |line|
78
- line.strip!
79
- "#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
80
- end.join
84
+ text.split("\n").map do |line|
85
+ line.strip!
86
+ "#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
87
+ end.join
88
+ end
89
+ end
81
90
  end
82
91
  end
83
92
  end
@@ -98,8 +107,6 @@ module Hpricot
98
107
  end
99
108
  end
100
109
 
101
- require 'hpricot'
102
-
103
110
  # @private
104
111
  HAML_TAGS = %w[haml:block haml:loud haml:silent]
105
112
 
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.1.0.alpha.36
4
+ version: 3.1.0.alpha.37
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: 2010-11-26 00:00:00 -05:00
13
+ date: 2010-12-06 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -46,27 +46,27 @@ files:
46
46
  - rails/init.rb
47
47
  - lib/haml.rb
48
48
  - lib/haml/buffer.rb
49
- - lib/haml/compiler.rb
50
49
  - lib/haml/engine.rb
51
- - lib/haml/error.rb
52
50
  - lib/haml/exec.rb
51
+ - lib/haml/error.rb
53
52
  - lib/haml/filters.rb
54
53
  - lib/haml/helpers.rb
54
+ - lib/haml/util.rb
55
55
  - lib/haml/helpers/action_view_extensions.rb
56
56
  - lib/haml/helpers/action_view_mods.rb
57
57
  - lib/haml/helpers/xss_mods.rb
58
58
  - lib/haml/html.rb
59
59
  - lib/haml/html/erb.rb
60
- - lib/haml/parser.rb
61
60
  - lib/haml/railtie.rb
61
+ - lib/haml/template.rb
62
62
  - lib/haml/root.rb
63
63
  - lib/haml/shared.rb
64
- - lib/haml/template.rb
64
+ - lib/haml/compiler.rb
65
65
  - lib/haml/template/options.rb
66
66
  - lib/haml/template/patch.rb
67
67
  - lib/haml/template/plugin.rb
68
- - lib/haml/util.rb
69
68
  - lib/haml/version.rb
69
+ - lib/haml/parser.rb
70
70
  - lib/sass.rb
71
71
  - lib/sass/plugin.rb
72
72
  - lib/sass/rails2_shim.rb
@@ -383,6 +383,7 @@ files:
383
383
  - VERSION
384
384
  - VERSION_NAME
385
385
  - EDGE_GEM_VERSION
386
+ - REVISION
386
387
  has_rdoc: false
387
388
  homepage: http://haml-lang.com/
388
389
  licenses: []