haml 3.1.0.alpha.141 → 3.1.0.alpha.144

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 (4) hide show
  1. data/REVISION +1 -1
  2. data/VERSION +1 -1
  3. data/lib/haml/html.rb +67 -90
  4. metadata +1 -1
data/REVISION CHANGED
@@ -1 +1 @@
1
- 2ddf27942c8145f06fcc021ddeb11b06093c8c62
1
+ 391004898bc81800e98a3801e5efafbf1dd42d64
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.141
1
+ 3.1.0.alpha.144
@@ -5,105 +5,82 @@ require 'rubygems'
5
5
  require 'cgi'
6
6
  require 'hpricot'
7
7
 
8
- module Haml
9
- class HTML
10
- # A module containing utility methods that every Hpricot node
11
- # should have.
12
- module Node
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
43
-
44
- node = node.next_node
45
- end
46
- return parse_text_with_interpolation(text, tabs)
47
- end
48
-
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
62
- end
8
+ # Haml monkeypatches various Hpricot classes
9
+ # to add methods for conversion to Haml.
10
+ # @private
11
+ module Hpricot
12
+ # @see Hpricot
13
+ module Node
14
+ # Whether this node has already been converted to Haml.
15
+ # Only used for text nodes and elements.
16
+ #
17
+ # @return [Boolean]
18
+ attr_accessor :converted_to_haml
19
+
20
+ # Returns the Haml representation of the given node.
21
+ #
22
+ # @param tabs [Fixnum] The indentation level of the resulting Haml.
23
+ # @option options (see Haml::HTML#initialize)
24
+ def to_haml(tabs, options)
25
+ return "" if converted_to_haml || to_s.strip.empty?
26
+ text = uninterp(self.to_s)
27
+ node = next_node
28
+ while node.is_a?(::Hpricot::Elem) && node.name == "haml:loud"
29
+ node.converted_to_haml = true
30
+ text << '#{' <<
31
+ CGI.unescapeHTML(node.inner_text).gsub(/\n\s*/, ' ').strip << '}'
32
+
33
+ if node.next_node.is_a?(::Hpricot::Text)
34
+ node = node.next_node
35
+ text << uninterp(node.to_s)
36
+ node.converted_to_haml = true
37
+ end
63
38
 
64
- def tabulate(tabs)
65
- ' ' * tabs
66
- end
39
+ node = node.next_node
40
+ end
41
+ return parse_text_with_interpolation(text, tabs)
42
+ end
67
43
 
68
- def uninterp(text)
69
- text.gsub('#{', '\#{') #'
70
- end
44
+ private
45
+
46
+ def erb_to_interpolation(text, options)
47
+ return text unless options[:erb]
48
+ text = CGI.escapeHTML(uninterp(text))
49
+ %w[<haml:loud> </haml:loud>].each {|str| text.gsub!(CGI.escapeHTML(str), str)}
50
+ ::Hpricot::XML(text).children.inject("") do |str, elem|
51
+ if elem.is_a?(::Hpricot::Text)
52
+ str + CGI.unescapeHTML(elem.to_s)
53
+ else # <haml:loud> element
54
+ str + '#{' + CGI.unescapeHTML(elem.innerText.strip) + '}'
55
+ end
56
+ end
57
+ end
71
58
 
72
- def attr_hash
73
- attributes.to_hash
74
- end
59
+ def tabulate(tabs)
60
+ ' ' * tabs
61
+ end
75
62
 
76
- def parse_text(text, tabs)
77
- parse_text_with_interpolation(uninterp(text), tabs)
78
- end
63
+ def uninterp(text)
64
+ text.gsub('#{', '\#{') #'
65
+ end
79
66
 
80
- def parse_text_with_interpolation(text, tabs)
81
- text.strip!
82
- return "" if text.empty?
67
+ def attr_hash
68
+ attributes.to_hash
69
+ end
83
70
 
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
90
- end
71
+ def parse_text(text, tabs)
72
+ parse_text_with_interpolation(uninterp(text), tabs)
91
73
  end
92
- end
93
- end
94
74
 
95
- # Haml monkeypatches various Hpricot classes
96
- # to add methods for conversion to Haml.
97
- # @private
98
- module Hpricot
99
- # @see Hpricot
100
- module Node
101
- include Haml::HTML::Node
102
- end
75
+ def parse_text_with_interpolation(text, tabs)
76
+ text.strip!
77
+ return "" if text.empty?
103
78
 
104
- # @see Hpricot
105
- class BaseEle
106
- include Haml::HTML::Node
79
+ text.split("\n").map do |line|
80
+ line.strip!
81
+ "#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
82
+ end.join
83
+ end
107
84
  end
108
85
  end
109
86
 
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.141
4
+ version: 3.1.0.alpha.144
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum