excesselt 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +56 -0
- data/History.txt +4 -0
- data/PostInstall.txt +1 -0
- data/README.md +67 -0
- data/Rakefile +54 -0
- data/TODO +3 -0
- data/excesselt.gemspec +102 -0
- data/lib/excesselt/element_wrapper.rb +37 -0
- data/lib/excesselt/rule.rb +45 -0
- data/lib/excesselt/stylesheet.rb +64 -0
- data/lib/excesselt.rb +9 -0
- data/rdoc/classes/Excesselt/ElementWrapper.html +276 -0
- data/rdoc/classes/Excesselt/Rule.html +290 -0
- data/rdoc/classes/Excesselt/Stylesheet.html +242 -0
- data/rdoc/classes/Excesselt.html +138 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/README_md.html +199 -0
- data/rdoc/files/lib/excesselt/element_wrapper_rb.html +101 -0
- data/rdoc/files/lib/excesselt/rule_rb.html +101 -0
- data/rdoc/files/lib/excesselt/stylesheet_rb.html +108 -0
- data/rdoc/files/lib/excesselt_rb.html +110 -0
- data/rdoc/fr_class_index.html +30 -0
- data/rdoc/fr_file_index.html +31 -0
- data/rdoc/fr_method_index.html +40 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/excesselt_spec.rb +90 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/matchers/dom_matcher.rb +45 -0
- data/tasks/rspec.rake +10 -0
- metadata +227 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "excesselt" do
|
4
|
+
|
5
|
+
describe "When a developer wants to transform their hello world xml" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
|
9
|
+
module TestHelper
|
10
|
+
def error_text_in_parent
|
11
|
+
error("Text is not allowed within a parent node!") unless (text.strip == '')
|
12
|
+
end
|
13
|
+
def uppercase_text
|
14
|
+
add text.upcase
|
15
|
+
end
|
16
|
+
def text
|
17
|
+
self.to_xml
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
@stylesheet = Class.new(Excesselt::Stylesheet) do
|
22
|
+
def rules
|
23
|
+
render('parent > child') { builder.p(:style => "child_content" ) { child_content } }
|
24
|
+
render('parent') { builder.p(:style => "parent_content") { child_content } }
|
25
|
+
helper TestHelper do
|
26
|
+
render('parent.explode > text()', :with => :a_method_that_doesnt_exist)
|
27
|
+
render('parent > text()', :with => :error_text_in_parent)
|
28
|
+
render('text()', :with => :uppercase_text)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should transform a hello world document according to a stylesheet" do
|
36
|
+
xml = <<-XML
|
37
|
+
<parent>
|
38
|
+
<child>Hello World</child>
|
39
|
+
</parent>
|
40
|
+
XML
|
41
|
+
expected = <<-EXPECTED
|
42
|
+
<p style="parent_content">
|
43
|
+
<p style="child_content">HELLO WORLD</p>
|
44
|
+
</p>
|
45
|
+
EXPECTED
|
46
|
+
@stylesheet.transform(xml).should match_the_dom_of(expected)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should transform a goodbye document according to a stylesheet" do
|
50
|
+
xml = <<-XML
|
51
|
+
<parent>
|
52
|
+
<parent>
|
53
|
+
<child>Goodbye</child>
|
54
|
+
</parent>
|
55
|
+
</parent>
|
56
|
+
XML
|
57
|
+
expected = <<-EXPECTED
|
58
|
+
<p style="parent_content" >
|
59
|
+
<p style="parent_content" >
|
60
|
+
<p style="child_content" >
|
61
|
+
GOODBYE
|
62
|
+
</p>
|
63
|
+
</p>
|
64
|
+
</p>
|
65
|
+
EXPECTED
|
66
|
+
@stylesheet.transform(xml).should match_the_dom_of(expected)
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "error handling" do
|
70
|
+
it "should record errors encountered during processing" do
|
71
|
+
xml = <<-XML
|
72
|
+
<parent>foo</parent>
|
73
|
+
XML
|
74
|
+
@instance = @stylesheet.new
|
75
|
+
@instance.transform(xml)
|
76
|
+
@instance.errors.should == ["Text is not allowed within a parent node!"]
|
77
|
+
end
|
78
|
+
it "should record errors encountered during processing" do
|
79
|
+
xml = <<-XML
|
80
|
+
<parent class="explode">foo</parent>
|
81
|
+
XML
|
82
|
+
@instance = @stylesheet.new
|
83
|
+
lambda { @instance.transform(xml) }.should raise_exception {|e| e.message.should =~ /With Included Modules: \[TestHelper\]/}
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'active_support/core_ext/hash/conversions'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :match_the_dom_of do |expected_xml_string|
|
5
|
+
|
6
|
+
def describe(string)
|
7
|
+
string ? string.to_s.gsub('"', "'").strip.inspect : 'NIL'
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_for_should_not do |actual|
|
11
|
+
"expected that #{describe(actual)} would not match the dom of #{describe(expected)}"
|
12
|
+
end
|
13
|
+
|
14
|
+
failure_message_for_should do |actual|
|
15
|
+
<<-MESSAGE
|
16
|
+
|
17
|
+
expected first, but got second:
|
18
|
+
#{describe(expected) }
|
19
|
+
#{describe(actual) }
|
20
|
+
|
21
|
+
(compared using Nokogiri::XML::Node#==)
|
22
|
+
MESSAGE
|
23
|
+
end
|
24
|
+
|
25
|
+
failure_message_for_should_not do |actual|
|
26
|
+
<<-MESSAGE
|
27
|
+
|
28
|
+
expected actual not to equal expected:
|
29
|
+
#{describe(expected) }
|
30
|
+
#{describe(actual) }
|
31
|
+
|
32
|
+
(compared using Nokogiri::XML::Node#==)
|
33
|
+
MESSAGE
|
34
|
+
end
|
35
|
+
|
36
|
+
def hash_for(string)
|
37
|
+
Hash.from_xml("<container>#{string.to_s.gsub(' ', '').gsub("\n", '')}</container>")['container']
|
38
|
+
end
|
39
|
+
|
40
|
+
match do |actual_xml_string|
|
41
|
+
expected_hash = hash_for(expected_xml_string)
|
42
|
+
actual_hash = hash_for(actual_xml_string)
|
43
|
+
expected_hash == actual_hash
|
44
|
+
end
|
45
|
+
end
|
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: excesselt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel Heath
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-08 00:00:00 +11:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
type: :runtime
|
24
|
+
name: nokogiri
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - "="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 113
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 4
|
34
|
+
- 3
|
35
|
+
- 1
|
36
|
+
version: 1.4.3.1
|
37
|
+
requirement: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
name: builder
|
42
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - "="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 15
|
48
|
+
segments:
|
49
|
+
- 2
|
50
|
+
- 1
|
51
|
+
- 2
|
52
|
+
version: 2.1.2
|
53
|
+
requirement: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
prerelease: false
|
56
|
+
type: :development
|
57
|
+
name: activesupport
|
58
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirement: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
prerelease: false
|
70
|
+
type: :development
|
71
|
+
name: rake
|
72
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirement: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
prerelease: false
|
84
|
+
type: :development
|
85
|
+
name: rspec
|
86
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 15
|
92
|
+
segments:
|
93
|
+
- 2
|
94
|
+
- 0
|
95
|
+
- 0
|
96
|
+
version: 2.0.0
|
97
|
+
requirement: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
prerelease: false
|
100
|
+
type: :development
|
101
|
+
name: rcov
|
102
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
requirement: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
prerelease: false
|
114
|
+
type: :development
|
115
|
+
name: ruby-debug
|
116
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
requirement: *id007
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
prerelease: false
|
128
|
+
type: :development
|
129
|
+
name: jeweler
|
130
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 3
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
requirement: *id008
|
140
|
+
description: I had a lot of XML transformation to do and the requirements kept changing, so I sat down and wrote something that was easy to modify.
|
141
|
+
email: daniel.r.heath@gmail.com
|
142
|
+
executables: []
|
143
|
+
|
144
|
+
extensions: []
|
145
|
+
|
146
|
+
extra_rdoc_files:
|
147
|
+
- README.md
|
148
|
+
- TODO
|
149
|
+
files:
|
150
|
+
- .gitignore
|
151
|
+
- Gemfile
|
152
|
+
- Gemfile.lock
|
153
|
+
- History.txt
|
154
|
+
- PostInstall.txt
|
155
|
+
- README.md
|
156
|
+
- Rakefile
|
157
|
+
- TODO
|
158
|
+
- excesselt.gemspec
|
159
|
+
- lib/excesselt.rb
|
160
|
+
- lib/excesselt/element_wrapper.rb
|
161
|
+
- lib/excesselt/rule.rb
|
162
|
+
- lib/excesselt/stylesheet.rb
|
163
|
+
- rdoc/classes/Excesselt.html
|
164
|
+
- rdoc/classes/Excesselt/ElementWrapper.html
|
165
|
+
- rdoc/classes/Excesselt/Rule.html
|
166
|
+
- rdoc/classes/Excesselt/Stylesheet.html
|
167
|
+
- rdoc/created.rid
|
168
|
+
- rdoc/files/README_md.html
|
169
|
+
- rdoc/files/lib/excesselt/element_wrapper_rb.html
|
170
|
+
- rdoc/files/lib/excesselt/rule_rb.html
|
171
|
+
- rdoc/files/lib/excesselt/stylesheet_rb.html
|
172
|
+
- rdoc/files/lib/excesselt_rb.html
|
173
|
+
- rdoc/fr_class_index.html
|
174
|
+
- rdoc/fr_file_index.html
|
175
|
+
- rdoc/fr_method_index.html
|
176
|
+
- rdoc/index.html
|
177
|
+
- rdoc/rdoc-style.css
|
178
|
+
- script/console
|
179
|
+
- script/destroy
|
180
|
+
- script/generate
|
181
|
+
- spec/excesselt_spec.rb
|
182
|
+
- spec/spec_helper.rb
|
183
|
+
- spec/support/matchers/dom_matcher.rb
|
184
|
+
- tasks/rspec.rake
|
185
|
+
has_rdoc: true
|
186
|
+
homepage: http://www.github.com/danielheath/excesselt
|
187
|
+
licenses: []
|
188
|
+
|
189
|
+
post_install_message:
|
190
|
+
rdoc_options:
|
191
|
+
- --charset=UTF-8
|
192
|
+
- -mREADME.md
|
193
|
+
require_paths:
|
194
|
+
- lib
|
195
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
196
|
+
none: false
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
hash: 57
|
201
|
+
segments:
|
202
|
+
- 1
|
203
|
+
- 8
|
204
|
+
- 7
|
205
|
+
version: 1.8.7
|
206
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
|
+
none: false
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
hash: 23
|
212
|
+
segments:
|
213
|
+
- 1
|
214
|
+
- 3
|
215
|
+
- 6
|
216
|
+
version: 1.3.6
|
217
|
+
requirements: []
|
218
|
+
|
219
|
+
rubyforge_project:
|
220
|
+
rubygems_version: 1.3.7
|
221
|
+
signing_key:
|
222
|
+
specification_version: 3
|
223
|
+
summary: Helps you to transform XML without using XSLT.
|
224
|
+
test_files:
|
225
|
+
- spec/excesselt_spec.rb
|
226
|
+
- spec/spec_helper.rb
|
227
|
+
- spec/support/matchers/dom_matcher.rb
|