rslt 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/.travis.yml +10 -0
  2. data/Gemfile +14 -0
  3. data/Gemfile.lock +53 -0
  4. data/History.txt +4 -0
  5. data/PostInstall.txt +1 -0
  6. data/README.md +67 -0
  7. data/Rakefile +55 -0
  8. data/TODO +3 -0
  9. data/lib/rslt/element_wrapper.rb +37 -0
  10. data/lib/rslt/rule.rb +45 -0
  11. data/lib/rslt/stylesheet.rb +94 -0
  12. data/lib/rslt.rb +9 -0
  13. data/rdoc/RSLT/ElementWrapper.html +357 -0
  14. data/rdoc/RSLT/Rule.html +379 -0
  15. data/rdoc/RSLT/Stylesheet.html +311 -0
  16. data/rdoc/RSLT.html +132 -0
  17. data/rdoc/created.rid +6 -0
  18. data/rdoc/images/add.png +0 -0
  19. data/rdoc/images/brick.png +0 -0
  20. data/rdoc/images/brick_link.png +0 -0
  21. data/rdoc/images/bug.png +0 -0
  22. data/rdoc/images/bullet_black.png +0 -0
  23. data/rdoc/images/bullet_toggle_minus.png +0 -0
  24. data/rdoc/images/bullet_toggle_plus.png +0 -0
  25. data/rdoc/images/date.png +0 -0
  26. data/rdoc/images/delete.png +0 -0
  27. data/rdoc/images/find.png +0 -0
  28. data/rdoc/images/loadingAnimation.gif +0 -0
  29. data/rdoc/images/macFFBgHack.png +0 -0
  30. data/rdoc/images/package.png +0 -0
  31. data/rdoc/images/page_green.png +0 -0
  32. data/rdoc/images/page_white_text.png +0 -0
  33. data/rdoc/images/page_white_width.png +0 -0
  34. data/rdoc/images/plugin.png +0 -0
  35. data/rdoc/images/ruby.png +0 -0
  36. data/rdoc/images/tag_blue.png +0 -0
  37. data/rdoc/images/tag_green.png +0 -0
  38. data/rdoc/images/transparent.png +0 -0
  39. data/rdoc/images/wrench.png +0 -0
  40. data/rdoc/images/wrench_orange.png +0 -0
  41. data/rdoc/images/zoom.png +0 -0
  42. data/rdoc/index.html +75 -0
  43. data/rdoc/js/darkfish.js +153 -0
  44. data/rdoc/js/jquery.js +18 -0
  45. data/rdoc/js/navigation.js +142 -0
  46. data/rdoc/js/search.js +94 -0
  47. data/rdoc/js/search_index.js +1 -0
  48. data/rdoc/js/searcher.js +228 -0
  49. data/rdoc/rdoc.css +543 -0
  50. data/rdoc/table_of_contents.html +83 -0
  51. data/rslt.gemspec +150 -0
  52. data/script/console +10 -0
  53. data/script/destroy +14 -0
  54. data/script/generate +14 -0
  55. data/spec/element_wrapper_spec.rb +22 -0
  56. data/spec/excesselt_spec.rb +112 -0
  57. data/spec/spec_helper.rb +6 -0
  58. data/spec/support/matchers/dom_matcher.rb +45 -0
  59. data/tasks/rspec.rake +13 -0
  60. metadata +307 -0
data/rslt.gemspec ADDED
@@ -0,0 +1,150 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rslt"
8
+ s.version = "1.1.8"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Daniel Heath"]
12
+ s.date = "2012-04-05"
13
+ s.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."
14
+ s.email = ["daniel.r.heath@gmail.com"]
15
+ s.extra_rdoc_files = [
16
+ "README.md",
17
+ "TODO"
18
+ ]
19
+ s.files = [
20
+ ".travis.yml",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "History.txt",
24
+ "PostInstall.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "TODO",
28
+ "lib/rslt.rb",
29
+ "lib/rslt/element_wrapper.rb",
30
+ "lib/rslt/rule.rb",
31
+ "lib/rslt/stylesheet.rb",
32
+ "rdoc/RSLT.html",
33
+ "rdoc/RSLT/ElementWrapper.html",
34
+ "rdoc/RSLT/Rule.html",
35
+ "rdoc/RSLT/Stylesheet.html",
36
+ "rdoc/created.rid",
37
+ "rdoc/images/add.png",
38
+ "rdoc/images/brick.png",
39
+ "rdoc/images/brick_link.png",
40
+ "rdoc/images/bug.png",
41
+ "rdoc/images/bullet_black.png",
42
+ "rdoc/images/bullet_toggle_minus.png",
43
+ "rdoc/images/bullet_toggle_plus.png",
44
+ "rdoc/images/date.png",
45
+ "rdoc/images/delete.png",
46
+ "rdoc/images/find.png",
47
+ "rdoc/images/loadingAnimation.gif",
48
+ "rdoc/images/macFFBgHack.png",
49
+ "rdoc/images/package.png",
50
+ "rdoc/images/page_green.png",
51
+ "rdoc/images/page_white_text.png",
52
+ "rdoc/images/page_white_width.png",
53
+ "rdoc/images/plugin.png",
54
+ "rdoc/images/ruby.png",
55
+ "rdoc/images/tag_blue.png",
56
+ "rdoc/images/tag_green.png",
57
+ "rdoc/images/transparent.png",
58
+ "rdoc/images/wrench.png",
59
+ "rdoc/images/wrench_orange.png",
60
+ "rdoc/images/zoom.png",
61
+ "rdoc/index.html",
62
+ "rdoc/js/darkfish.js",
63
+ "rdoc/js/jquery.js",
64
+ "rdoc/js/navigation.js",
65
+ "rdoc/js/search.js",
66
+ "rdoc/js/search_index.js",
67
+ "rdoc/js/searcher.js",
68
+ "rdoc/rdoc.css",
69
+ "rdoc/table_of_contents.html",
70
+ "rslt.gemspec",
71
+ "script/console",
72
+ "script/destroy",
73
+ "script/generate",
74
+ "spec/element_wrapper_spec.rb",
75
+ "spec/excesselt_spec.rb",
76
+ "spec/spec_helper.rb",
77
+ "spec/support/matchers/dom_matcher.rb",
78
+ "tasks/rspec.rake"
79
+ ]
80
+ s.homepage = "http://www.github.com/danielheath/rslt"
81
+ s.rdoc_options = ["--charset=UTF-8", "-mREADME.md"]
82
+ s.require_paths = ["lib"]
83
+ s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
84
+ s.rubygems_version = "1.8.10"
85
+ s.summary = "Helps you to transform XML without using XSLT."
86
+
87
+ if s.respond_to? :specification_version then
88
+ s.specification_version = 3
89
+
90
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
91
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
92
+ s.add_runtime_dependency(%q<builder>, [">= 0"])
93
+ s.add_development_dependency(%q<activesupport>, [">= 0"])
94
+ s.add_development_dependency(%q<rake>, [">= 0"])
95
+ s.add_development_dependency(%q<i18n>, [">= 0"])
96
+ s.add_development_dependency(%q<rspec>, ["> 2.0.0"])
97
+ s.add_development_dependency(%q<rcov>, [">= 0"])
98
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
99
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
100
+ s.add_runtime_dependency(%q<nokogiri>, ["~> 1"])
101
+ s.add_runtime_dependency(%q<builder>, ["> 2"])
102
+ s.add_development_dependency(%q<activesupport>, [">= 0"])
103
+ s.add_development_dependency(%q<rake>, [">= 0"])
104
+ s.add_development_dependency(%q<i18n>, [">= 0"])
105
+ s.add_development_dependency(%q<rspec>, ["> 2.0.0"])
106
+ s.add_development_dependency(%q<rcov>, [">= 0"])
107
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
108
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
109
+ else
110
+ s.add_dependency(%q<nokogiri>, [">= 0"])
111
+ s.add_dependency(%q<builder>, [">= 0"])
112
+ s.add_dependency(%q<activesupport>, [">= 0"])
113
+ s.add_dependency(%q<rake>, [">= 0"])
114
+ s.add_dependency(%q<i18n>, [">= 0"])
115
+ s.add_dependency(%q<rspec>, ["> 2.0.0"])
116
+ s.add_dependency(%q<rcov>, [">= 0"])
117
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
118
+ s.add_dependency(%q<jeweler>, [">= 0"])
119
+ s.add_dependency(%q<nokogiri>, ["~> 1"])
120
+ s.add_dependency(%q<builder>, ["> 2"])
121
+ s.add_dependency(%q<activesupport>, [">= 0"])
122
+ s.add_dependency(%q<rake>, [">= 0"])
123
+ s.add_dependency(%q<i18n>, [">= 0"])
124
+ s.add_dependency(%q<rspec>, ["> 2.0.0"])
125
+ s.add_dependency(%q<rcov>, [">= 0"])
126
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
127
+ s.add_dependency(%q<jeweler>, [">= 0"])
128
+ end
129
+ else
130
+ s.add_dependency(%q<nokogiri>, [">= 0"])
131
+ s.add_dependency(%q<builder>, [">= 0"])
132
+ s.add_dependency(%q<activesupport>, [">= 0"])
133
+ s.add_dependency(%q<rake>, [">= 0"])
134
+ s.add_dependency(%q<i18n>, [">= 0"])
135
+ s.add_dependency(%q<rspec>, ["> 2.0.0"])
136
+ s.add_dependency(%q<rcov>, [">= 0"])
137
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
138
+ s.add_dependency(%q<jeweler>, [">= 0"])
139
+ s.add_dependency(%q<nokogiri>, ["~> 1"])
140
+ s.add_dependency(%q<builder>, ["> 2"])
141
+ s.add_dependency(%q<activesupport>, [">= 0"])
142
+ s.add_dependency(%q<rake>, [">= 0"])
143
+ s.add_dependency(%q<i18n>, [">= 0"])
144
+ s.add_dependency(%q<rspec>, ["> 2.0.0"])
145
+ s.add_dependency(%q<rcov>, [">= 0"])
146
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
147
+ s.add_dependency(%q<jeweler>, [">= 0"])
148
+ end
149
+ end
150
+
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/mygem.rb'}"
9
+ puts "Loading mygem gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe RSLT::ElementWrapper do
4
+
5
+ before do
6
+ @stylesheet = Object.new
7
+ @element = Object.new
8
+ @builder = Object.new
9
+ @wrapper = RSLT::ElementWrapper.new(@stylesheet, @element, @builder)
10
+ end
11
+
12
+ describe "passing through method calls" do
13
+ describe "when an error is raised in a passed through call" do
14
+ it "should raise an error" do
15
+ lambda {
16
+ @wrapper.foo
17
+ }.should raise_exception
18
+ end
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,112 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require 'json'
3
+ describe "rslt" 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(options=nil)
11
+ error("Text is not allowed within a parent node! Options were #{options.to_json}") 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(RSLT::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
+ within 'parent' do
28
+ render('> text()', :with => :error_text_in_parent, :passing => 'a custom option')
29
+ end
30
+ render('text()', :with => :uppercase_text)
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ it "should transform a hello world document according to a stylesheet" do
38
+ xml = <<-XML
39
+ <parent>
40
+ <child>Hello World</child>
41
+ </parent>
42
+ XML
43
+ expected = <<-EXPECTED
44
+ <p style="parent_content">
45
+ <p style="child_content">HELLO WORLD</p>
46
+ </p>
47
+ EXPECTED
48
+ @stylesheet.transform(xml).should match_the_dom_of(expected)
49
+ end
50
+
51
+ it "should ignore comments" do
52
+ xml = <<-XML
53
+ <parent>
54
+ <!-- Ignore me -->
55
+ </parent>
56
+ XML
57
+ expected = <<-EXPECTED
58
+ <p style="parent_content"/>
59
+ EXPECTED
60
+ @stylesheet.transform(xml).should match_the_dom_of(expected)
61
+ end
62
+
63
+ it "should transform a goodbye document according to a stylesheet" do
64
+ xml = <<-XML
65
+ <parent>
66
+ <parent>
67
+ <child>Goodbye</child>
68
+ </parent>
69
+ </parent>
70
+ XML
71
+ expected = <<-EXPECTED
72
+ <p style="parent_content" >
73
+ <p style="parent_content" >
74
+ <p style="child_content" >
75
+ GOODBYE
76
+ </p>
77
+ </p>
78
+ </p>
79
+ EXPECTED
80
+ @stylesheet.transform(xml).should match_the_dom_of(expected)
81
+ end
82
+
83
+ describe "error handling" do
84
+
85
+ it "should record errors encountered during processing" do
86
+ xml = <<-XML
87
+ <parent>foo</parent>
88
+ XML
89
+ @instance = @stylesheet.new
90
+ @instance.transform(xml)
91
+ @instance.errors.should == ['Text is not allowed within a parent node! Options were {"passing":"a custom option"}']
92
+ end
93
+
94
+ it "should record errors encountered during processing" do
95
+ xml = <<-XML
96
+ <parent><unexpected></unexpected></parent>
97
+ XML
98
+ @instance = @stylesheet.new
99
+ lambda { @instance.transform(xml) }.should raise_exception {|e|
100
+ e.message.should =~ /With selector '.*' and included modules: \[TestHelper\]/
101
+ e.message.should =~ /There is no style defined to handle this element/
102
+ e.message.should =~ /CSS Path: 'parent > unexpected'/
103
+ e.message.should =~ /Xpath: '\/parent\/unexpected'/
104
+ e.message.should =~ /Context: 'document, parent'/
105
+ }
106
+ end
107
+
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+
4
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
5
+ require 'rslt'
6
+ require 'support/matchers/dom_matcher'
@@ -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
@@ -0,0 +1,13 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ if RUBY_VERSION =~ /^1\.8/
4
+ desc "Run all specs with rcov"
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rcov = true
7
+ t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,features\/ --failure-threshold 100}
8
+ end
9
+
10
+ else
11
+ desc "Run all specs"
12
+ RSpec::Core::RakeTask.new(:spec)
13
+ end