haml-edge 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/EDGE_GEM_VERSION +1 -1
- data/VERSION +1 -1
- data/lib/haml/engine.rb +3 -3
- data/lib/haml/helpers.rb +3 -3
- data/lib/haml/html.rb +29 -32
- data/lib/haml/template.rb +1 -1
- data/lib/haml/util.rb +5 -0
- data/lib/haml/version.rb +4 -5
- data/test/haml/helper_test.rb +5 -0
- data/test/haml/util_test.rb +5 -0
- metadata +2 -2
data/EDGE_GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.3
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.3
|
data/lib/haml/engine.rb
CHANGED
@@ -17,16 +17,16 @@ module Haml
|
|
17
17
|
include Precompiler
|
18
18
|
|
19
19
|
# Allow reading and writing of the options hash
|
20
|
-
|
20
|
+
attr_accessor :options
|
21
21
|
|
22
22
|
# This string contains the source code that is evaluated
|
23
23
|
# to produce the Haml document.
|
24
|
-
|
24
|
+
attr_accessor :precompiled
|
25
25
|
|
26
26
|
# A string containing the indentation used for the Haml document.
|
27
27
|
# nil if the indentation is ambiguous
|
28
28
|
# (for example, for a single-level document).
|
29
|
-
|
29
|
+
attr_accessor :indentation
|
30
30
|
|
31
31
|
# True if the format is XHTML
|
32
32
|
def xhtml?
|
data/lib/haml/helpers.rb
CHANGED
@@ -78,14 +78,14 @@ module Haml
|
|
78
78
|
|
79
79
|
# call-seq:
|
80
80
|
# find_and_preserve(input, tags = haml_buffer.options[:preserve])
|
81
|
-
# find_and_preserve {...}
|
81
|
+
# find_and_preserve(tags = haml_buffer.options[:preserve]) {...}
|
82
82
|
#
|
83
83
|
# Uses preserve to convert any newlines inside whitespace-sensitive tags
|
84
84
|
# into the HTML entities for endlines.
|
85
85
|
# +tags+ is an array of tags to preserve.
|
86
86
|
# It defaults to the value of the <tt>:preserve</tt> option.
|
87
|
-
def find_and_preserve(input =
|
88
|
-
return find_and_preserve(capture_haml(&block)) if block
|
87
|
+
def find_and_preserve(input = nil, tags = haml_buffer.options[:preserve], &block)
|
88
|
+
return find_and_preserve(capture_haml(&block), input || tags) if block
|
89
89
|
|
90
90
|
input = input.to_s
|
91
91
|
input.gsub(/<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im) do
|
data/lib/haml/html.rb
CHANGED
@@ -14,7 +14,7 @@ module Haml
|
|
14
14
|
# which can either be a string containing HTML or an Hpricot node,
|
15
15
|
# to a Haml string when +render+ is called.
|
16
16
|
def initialize(template, options = {})
|
17
|
-
|
17
|
+
@options = options
|
18
18
|
|
19
19
|
if template.is_a? Hpricot::Node
|
20
20
|
@template = template
|
@@ -23,12 +23,12 @@ module Haml
|
|
23
23
|
template = template.read
|
24
24
|
end
|
25
25
|
|
26
|
-
if
|
26
|
+
if @options[:rhtml]
|
27
27
|
match_to_html(template, /<%=(.*?)-?%>/m, 'loud')
|
28
28
|
match_to_html(template, /<%-?(.*?)-?%>/m, 'silent')
|
29
29
|
end
|
30
30
|
|
31
|
-
method =
|
31
|
+
method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot)
|
32
32
|
@template = method.call(template.gsub('&', '&'))
|
33
33
|
end
|
34
34
|
end
|
@@ -36,14 +36,14 @@ module Haml
|
|
36
36
|
# Processes the document and returns the result as a string
|
37
37
|
# containing the Haml template.
|
38
38
|
def render
|
39
|
-
@template.to_haml(0)
|
39
|
+
@template.to_haml(0, @options)
|
40
40
|
end
|
41
41
|
alias_method :to_haml, :render
|
42
42
|
|
43
43
|
module ::Hpricot::Node
|
44
44
|
# Returns the Haml representation of the given node,
|
45
45
|
# at the given tabulation.
|
46
|
-
def to_haml(tabs
|
46
|
+
def to_haml(tabs, options)
|
47
47
|
parse_text(self.to_s, tabs)
|
48
48
|
end
|
49
49
|
|
@@ -70,32 +70,28 @@ module Haml
|
|
70
70
|
|
71
71
|
# :stopdoc:
|
72
72
|
|
73
|
-
def self.options
|
74
|
-
@@options
|
75
|
-
end
|
76
|
-
|
77
73
|
TEXT_REGEXP = /^(\s*).*$/
|
78
74
|
|
79
75
|
class ::Hpricot::Doc
|
80
|
-
def to_haml(tabs
|
81
|
-
(children || []).inject('') {|s, c| s << c.to_haml(0)}
|
76
|
+
def to_haml(tabs, options)
|
77
|
+
(children || []).inject('') {|s, c| s << c.to_haml(0, options)}
|
82
78
|
end
|
83
79
|
end
|
84
80
|
|
85
81
|
class ::Hpricot::XMLDecl
|
86
|
-
def to_haml(tabs
|
82
|
+
def to_haml(tabs, options)
|
87
83
|
"#{tabulate(tabs)}!!! XML\n"
|
88
84
|
end
|
89
85
|
end
|
90
86
|
|
91
87
|
class ::Hpricot::CData
|
92
|
-
def to_haml(tabs
|
88
|
+
def to_haml(tabs, options)
|
93
89
|
"#{tabulate(tabs)}:cdata\n#{parse_text(self.content, tabs + 1)}"
|
94
90
|
end
|
95
91
|
end
|
96
92
|
|
97
93
|
class ::Hpricot::DocType
|
98
|
-
def to_haml(tabs
|
94
|
+
def to_haml(tabs, options)
|
99
95
|
attrs = public_id.scan(/DTD\s+([^\s]+)\s*([^\s]*)\s*([^\s]*)\s*\/\//)[0]
|
100
96
|
if attrs == nil
|
101
97
|
raise Exception.new("Invalid doctype")
|
@@ -126,34 +122,35 @@ module Haml
|
|
126
122
|
end
|
127
123
|
|
128
124
|
class ::Hpricot::Comment
|
129
|
-
def to_haml(tabs
|
125
|
+
def to_haml(tabs, options)
|
130
126
|
"#{tabulate(tabs)}/\n#{parse_text(self.content, tabs + 1)}"
|
131
127
|
end
|
132
128
|
end
|
133
129
|
|
134
130
|
class ::Hpricot::Elem
|
135
|
-
def to_haml(tabs
|
131
|
+
def to_haml(tabs, options)
|
136
132
|
output = "#{tabulate(tabs)}"
|
137
|
-
if
|
133
|
+
if options[:rhtml] && name[0...5] == 'haml:'
|
138
134
|
return output + HTML.send("haml_tag_#{name[5..-1]}", CGI.unescapeHTML(self.inner_text))
|
139
135
|
end
|
140
136
|
|
141
|
-
output += "%#{name}" unless name == 'div' &&
|
137
|
+
output += "%#{name}" unless name == 'div' &&
|
138
|
+
(static_id?(options) || static_classname?(options))
|
142
139
|
|
143
140
|
if attributes
|
144
|
-
if static_id?
|
141
|
+
if static_id?(options)
|
145
142
|
output += "##{attributes['id']}"
|
146
143
|
remove_attribute('id')
|
147
144
|
end
|
148
|
-
if static_classname?
|
145
|
+
if static_classname?(options)
|
149
146
|
attributes['class'].split(' ').each { |c| output += ".#{c}" }
|
150
147
|
remove_attribute('class')
|
151
148
|
end
|
152
|
-
output += haml_attributes if attributes.length > 0
|
149
|
+
output += haml_attributes(options) if attributes.length > 0
|
153
150
|
end
|
154
151
|
|
155
152
|
(self.children || []).inject(output + "\n") do |output, child|
|
156
|
-
output + child.to_haml(tabs + 1)
|
153
|
+
output + child.to_haml(tabs + 1, options)
|
157
154
|
end
|
158
155
|
end
|
159
156
|
|
@@ -174,27 +171,27 @@ module Haml
|
|
174
171
|
end
|
175
172
|
end
|
176
173
|
|
177
|
-
def static_attribute?(name)
|
178
|
-
attributes[name] and !dynamic_attribute?(name)
|
174
|
+
def static_attribute?(name, options)
|
175
|
+
attributes[name] and !dynamic_attribute?(name, options)
|
179
176
|
end
|
180
177
|
|
181
|
-
def dynamic_attribute?(name)
|
182
|
-
|
178
|
+
def dynamic_attribute?(name, options)
|
179
|
+
options[:rhtml] and dynamic_attributes.key?(name)
|
183
180
|
end
|
184
181
|
|
185
|
-
def static_id?
|
186
|
-
static_attribute?
|
182
|
+
def static_id?(options)
|
183
|
+
static_attribute?('id', options)
|
187
184
|
end
|
188
185
|
|
189
|
-
def static_classname?
|
190
|
-
static_attribute?
|
186
|
+
def static_classname?(options)
|
187
|
+
static_attribute?('class', options)
|
191
188
|
end
|
192
189
|
|
193
190
|
# Returns a string representation of an attributes hash
|
194
191
|
# that's prettier than that produced by Hash#inspect
|
195
|
-
def haml_attributes
|
192
|
+
def haml_attributes(options)
|
196
193
|
attrs = attributes.map do |name, value|
|
197
|
-
value = dynamic_attribute?(name) ? dynamic_attributes[name] : value.inspect
|
194
|
+
value = dynamic_attribute?(name, options) ? dynamic_attributes[name] : value.inspect
|
198
195
|
name = name.index(/\W/) ? name.inspect : ":#{name}"
|
199
196
|
"#{name} => #{value}"
|
200
197
|
end
|
data/lib/haml/template.rb
CHANGED
@@ -26,7 +26,7 @@ if defined?(RAILS_ROOT)
|
|
26
26
|
# because the new init file is sufficiently flexible
|
27
27
|
# to not need updating.
|
28
28
|
rails_init_file = File.join(RAILS_ROOT, 'vendor', 'plugins', 'haml', 'init.rb')
|
29
|
-
haml_init_file = Haml.scope('init.rb')
|
29
|
+
haml_init_file = Haml::Util.scope('init.rb')
|
30
30
|
begin
|
31
31
|
if File.exists?(rails_init_file)
|
32
32
|
require 'fileutils'
|
data/lib/haml/util.rb
CHANGED
@@ -8,6 +8,11 @@ module Haml
|
|
8
8
|
|
9
9
|
RUBY_VERSION = ::RUBY_VERSION.split(".").map {|s| s.to_i}
|
10
10
|
|
11
|
+
# Returns the path of file relative to the Haml root.
|
12
|
+
def scope(file)
|
13
|
+
File.expand_path File.join(File.dirname(__FILE__), '..', '..', file)
|
14
|
+
end
|
15
|
+
|
11
16
|
def to_hash(arr)
|
12
17
|
arr.compact.inject({}) {|h, (k, v)| h[k] = v; h}
|
13
18
|
end
|
data/lib/haml/version.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
require 'haml/util'
|
2
|
+
|
1
3
|
module Haml
|
2
4
|
module Version
|
5
|
+
include Haml::Util
|
6
|
+
|
3
7
|
# Returns a hash representing the version of Haml.
|
4
8
|
# The :major, :minor, and :teeny keys have their respective numbers.
|
5
9
|
# The :string key contains a human-readable string representation of the version.
|
@@ -38,10 +42,5 @@ module Haml
|
|
38
42
|
|
39
43
|
@@version
|
40
44
|
end
|
41
|
-
|
42
|
-
# Returns the path of file relative to the Haml root.
|
43
|
-
def scope(file) # :nodoc:
|
44
|
-
File.expand_path File.join(File.dirname(__FILE__), '..', '..', file)
|
45
|
-
end
|
46
45
|
end
|
47
46
|
end
|
data/test/haml/helper_test.rb
CHANGED
@@ -182,6 +182,11 @@ HAML
|
|
182
182
|
render("= find_and_preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
|
183
183
|
end
|
184
184
|
|
185
|
+
def test_find_and_preserve_with_block_and_tags
|
186
|
+
assert_equal("<pre>Foo\nBar</pre>\nFoo\nBar\n",
|
187
|
+
render("= find_and_preserve([]) do\n %pre\n Foo\n Bar\n Foo\n Bar"))
|
188
|
+
end
|
189
|
+
|
185
190
|
def test_preserve_with_block
|
186
191
|
assert_equal("<pre>Foo
Bar</pre>
Foo
Bar\n",
|
187
192
|
render("= preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
|
data/test/haml/util_test.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
require 'pathname'
|
3
4
|
|
4
5
|
class UtilTest < Test::Unit::TestCase
|
5
6
|
include Haml::Util
|
6
7
|
|
8
|
+
def test_scope
|
9
|
+
assert(File.exist?(scope("Rakefile")))
|
10
|
+
end
|
11
|
+
|
7
12
|
def test_to_hash
|
8
13
|
assert_equal({
|
9
14
|
:foo => 1,
|
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.1.
|
4
|
+
version: 2.1.3
|
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-
|
13
|
+
date: 2009-05-02 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|