haml-edge 2.3.11 → 2.3.12

Sign up to get free protection for your applications and to get access to all the features.
data/EDGE_GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.11
1
+ 2.3.12
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.11
1
+ 2.3.12
data/lib/haml/html.rb CHANGED
@@ -2,9 +2,60 @@ require File.dirname(__FILE__) + '/../haml'
2
2
 
3
3
  require 'haml/engine'
4
4
  require 'rubygems'
5
- require 'hpricot'
6
5
  require 'cgi'
7
6
 
7
+ module Haml
8
+ class HTML
9
+ # A module containing utility methods that every Hpricot node
10
+ # should have.
11
+ module Node
12
+ # Returns the Haml representation of the given node.
13
+ #
14
+ # @param tabs [Fixnum] The indentation level of the resulting Haml.
15
+ # @option options (see Haml::HTML#initialize)
16
+ def to_haml(tabs, options)
17
+ parse_text(self.to_s, tabs)
18
+ end
19
+
20
+ private
21
+
22
+ def tabulate(tabs)
23
+ ' ' * tabs
24
+ end
25
+
26
+ def parse_text(text, tabs)
27
+ text.strip!
28
+ if text.empty?
29
+ String.new
30
+ else
31
+ lines = text.split("\n")
32
+
33
+ lines.map do |line|
34
+ line.strip!
35
+ "#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
36
+ end.join
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ # Haml monkeypatches various Hpricot classes
44
+ # to add methods for conversion to Haml.
45
+ module Hpricot
46
+ # @see Hpricot
47
+ module Node
48
+ include Haml::HTML::Node
49
+ end
50
+
51
+ # @see Hpricot
52
+ class BaseEle
53
+ include Haml::HTML::Node
54
+ end
55
+ end
56
+
57
+ require 'hpricot'
58
+
8
59
  module Haml
9
60
  # Converts HTML documents into Haml templates.
10
61
  # Depends on [Hpricot](http://code.whytheluckystiff.net/hpricot/) for HTML parsing.
@@ -46,67 +97,35 @@ module Haml
46
97
  end
47
98
  alias_method :to_haml, :render
48
99
 
49
- # Haml monkeypatches various Hpricot classes
50
- # to add methods for conversion to Haml.
51
- module ::Hpricot::Node
52
- # Returns the Haml representation of the given node.
53
- #
54
- # @param tabs [Fixnum] The indentation level of the resulting Haml.
55
- # @option options (see Haml::HTML#initialize)
56
- def to_haml(tabs, options)
57
- parse_text(self.to_s, tabs)
58
- end
59
-
60
- private
61
-
62
- def tabulate(tabs)
63
- ' ' * tabs
64
- end
65
-
66
- def parse_text(text, tabs)
67
- text.strip!
68
- if text.empty?
69
- String.new
70
- else
71
- lines = text.split("\n")
72
-
73
- lines.map do |line|
74
- line.strip!
75
- "#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
76
- end.join
77
- end
78
- end
79
- end
80
-
81
100
  TEXT_REGEXP = /^(\s*).*$/
82
101
 
83
- # @see Hpricot::Node
102
+ # @see Hpricot
84
103
  class ::Hpricot::Doc
85
- # @see Hpricot::Node#to_haml
104
+ # @see Haml::HTML::Node#to_haml
86
105
  def to_haml(tabs, options)
87
106
  (children || []).inject('') {|s, c| s << c.to_haml(0, options)}
88
107
  end
89
108
  end
90
109
 
91
- # @see Hpricot::Node
110
+ # @see Hpricot
92
111
  class ::Hpricot::XMLDecl
93
- # @see Hpricot::Node#to_haml
112
+ # @see Haml::HTML::Node#to_haml
94
113
  def to_haml(tabs, options)
95
114
  "#{tabulate(tabs)}!!! XML\n"
96
115
  end
97
116
  end
98
117
 
99
- # @see Hpricot::Node
118
+ # @see Hpricot
100
119
  class ::Hpricot::CData
101
- # @see Hpricot::Node#to_haml
120
+ # @see Haml::HTML::Node#to_haml
102
121
  def to_haml(tabs, options)
103
122
  "#{tabulate(tabs)}:cdata\n#{parse_text(self.content, tabs + 1)}"
104
123
  end
105
124
  end
106
125
 
107
- # @see Hpricot::Node
126
+ # @see Hpricot
108
127
  class ::Hpricot::DocType
109
- # @see Hpricot::Node#to_haml
128
+ # @see Haml::HTML::Node#to_haml
110
129
  def to_haml(tabs, options)
111
130
  attrs = public_id.scan(/DTD\s+([^\s]+)\s*([^\s]*)\s*([^\s]*)\s*\/\//)[0]
112
131
  if attrs == nil
@@ -137,17 +156,17 @@ module Haml
137
156
  end
138
157
  end
139
158
 
140
- # @see Hpricot::Node
159
+ # @see Hpricot
141
160
  class ::Hpricot::Comment
142
- # @see Hpricot::Node#to_haml
161
+ # @see Haml::HTML::Node#to_haml
143
162
  def to_haml(tabs, options)
144
163
  "#{tabulate(tabs)}/\n#{parse_text(self.content, tabs + 1)}"
145
164
  end
146
165
  end
147
166
 
148
- # @see Hpricot::Node
167
+ # @see Hpricot
149
168
  class ::Hpricot::Elem
150
- # @see Hpricot::Node#to_haml
169
+ # @see Haml::HTML::Node#to_haml
151
170
  def to_haml(tabs, options)
152
171
  output = "#{tabulate(tabs)}"
153
172
  if options[:rhtml] && name[0...5] == 'haml:'
@@ -571,7 +571,10 @@ END
571
571
  attributes = {}
572
572
 
573
573
  scanner.scan(/\(\s*/)
574
- until (name, value = parse_new_attribute(scanner)).first.nil?
574
+ loop do
575
+ name, value = parse_new_attribute(scanner)
576
+ break if name.nil?
577
+
575
578
  if name == false
576
579
  text = (Haml::Shared.balance(line, ?(, ?)) || [line]).first
577
580
  raise Haml::SyntaxError.new("Invalid attribute list: #{text.inspect}.", last_line - 1)
@@ -42,7 +42,7 @@ module Sass
42
42
 
43
43
  return Functions::EvaluationContext.new(environment.options).send(name, *args)
44
44
  rescue ArgumentError => e
45
- raise e unless e.backtrace.first =~ /:in `(#{name}|perform)'$/
45
+ raise e unless e.backtrace.first =~ /:in `(block in )?(#{name}|perform)'$/
46
46
  raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
47
47
  end
48
48
  end
@@ -140,8 +140,10 @@ class TemplateTest < Test::Unit::TestCase
140
140
  end
141
141
 
142
142
  def test_action_view_templates_render_correctly
143
- @base.content_for(:layout) {'Lorem ipsum dolor sit amet'}
144
- assert_renders_correctly 'content_for_layout'
143
+ @base.with_output_buffer("") do
144
+ @base.content_for(:layout) {'Lorem ipsum dolor sit amet'}
145
+ assert_renders_correctly 'content_for_layout'
146
+ end
145
147
  end
146
148
 
147
149
  def test_instance_variables_should_work_inside_templates
data/test/test_helper.rb CHANGED
@@ -7,7 +7,7 @@ $:.unshift lib_dir unless $:.include?(lib_dir)
7
7
  require 'haml'
8
8
  require 'sass'
9
9
 
10
- Sass::RAILS_LOADED = true
10
+ Sass::RAILS_LOADED = true unless defined?(Sass::RAILS_LOADED)
11
11
 
12
12
  # required because of Sass::Plugin
13
13
  unless defined? RAILS_ROOT
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-edge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.11
4
+ version: 2.3.12
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-07-12 00:00:00 -04:00
13
+ date: 2009-07-14 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency