wdd-ruby-ext 0.2.3 → 0.3.0
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/.rvmrc +1 -0
- data/Gemfile.lock +1 -1
- data/README.rdoc +1 -16
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/wdd-ruby-ext/resources/pretty_xml.xsl +46 -0
- data/lib/wdd-ruby-ext/utils.rb +2 -1
- data/lib/wdd-ruby-ext/utils/helpers.rb +1 -1
- data/lib/wdd-ruby-ext/utils/pretty_xml.rb +27 -0
- data/lib/wdd-ruby-ext/utils/simpledebug.rb +1 -1
- data/lib/wdd-ruby-ext/utils/time_gate.rb +1 -1
- data/spec/lib/utils/pretty_xml_spec.rb +18 -0
- data/wdd-ruby-ext.gemspec +10 -2
- metadata +25 -4
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use system
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -8,21 +8,6 @@ credit where credit is due. I will try to give credit for new additions
|
|
8
8
|
added in the future and will happily give proper credit if I am alerted to
|
9
9
|
such.
|
10
10
|
|
11
|
-
== Note on Patches/Pull Requests
|
12
|
-
|
13
|
-
* Fork the project.
|
14
|
-
* Make your feature addition or bug fix.
|
15
|
-
* Add tests for it. This is important so I don't break it in a
|
16
|
-
future version unintentionally.
|
17
|
-
* Commit, do not mess with rakefile, version, or history.
|
18
|
-
(if you want to have your own version, that is fine but
|
19
|
-
bump version in a commit by itself I can ignore when I pull)
|
20
|
-
* Send me a pull request. Bonus points for topic branches.
|
21
|
-
|
22
11
|
== Copyright
|
23
12
|
|
24
|
-
Copyright (c)
|
25
|
-
<<<<<<< HEAD:README.rdoc
|
26
|
-
|
27
|
-
=======
|
28
|
-
>>>>>>> 0aa60a70e9983277e4d0ac757d74b7fde91aa1bf:README.rdoc
|
13
|
+
Copyright (c) 2010 shock. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/shock/wdd-ruby-ext"
|
12
12
|
gem.authors = ["shock"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_dependency "nokogiri", "~> 1.4.4"
|
14
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
2
|
+
<xsl:output method="xml" encoding="ISO-8859-1"/>
|
3
|
+
<xsl:param name="indent-increment" select="' '"/>
|
4
|
+
|
5
|
+
<xsl:template name="newline">
|
6
|
+
<xsl:text disable-output-escaping="yes">
|
7
|
+
</xsl:text>
|
8
|
+
</xsl:template>
|
9
|
+
|
10
|
+
<xsl:template match="comment() | processing-instruction()">
|
11
|
+
<xsl:param name="indent" select="''"/>
|
12
|
+
<xsl:call-template name="newline"/>
|
13
|
+
<xsl:value-of select="$indent"/>
|
14
|
+
<xsl:copy />
|
15
|
+
</xsl:template>
|
16
|
+
|
17
|
+
<xsl:template match="text()">
|
18
|
+
<xsl:param name="indent" select="''"/>
|
19
|
+
<xsl:call-template name="newline"/>
|
20
|
+
<xsl:value-of select="$indent"/>
|
21
|
+
<xsl:value-of select="normalize-space(.)"/>
|
22
|
+
</xsl:template>
|
23
|
+
|
24
|
+
<xsl:template match="text()[normalize-space(.)='']"/>
|
25
|
+
|
26
|
+
<xsl:template match="*">
|
27
|
+
<xsl:param name="indent" select="''"/>
|
28
|
+
<xsl:call-template name="newline"/>
|
29
|
+
<xsl:value-of select="$indent"/>
|
30
|
+
<xsl:choose>
|
31
|
+
<xsl:when test="count(child::*) > 0">
|
32
|
+
<xsl:copy>
|
33
|
+
<xsl:copy-of select="@*"/>
|
34
|
+
<xsl:apply-templates select="*|text()">
|
35
|
+
<xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
|
36
|
+
</xsl:apply-templates>
|
37
|
+
<xsl:call-template name="newline"/>
|
38
|
+
<xsl:value-of select="$indent"/>
|
39
|
+
</xsl:copy>
|
40
|
+
</xsl:when>
|
41
|
+
<xsl:otherwise>
|
42
|
+
<xsl:copy-of select="."/>
|
43
|
+
</xsl:otherwise>
|
44
|
+
</xsl:choose>
|
45
|
+
</xsl:template>
|
46
|
+
</xsl:stylesheet>
|
data/lib/wdd-ruby-ext/utils.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
# Formats XML with standard indention.
|
5
|
+
# Credit: http://stackoverflow.com/questions/1898829/nokogiri-pretty-printing
|
6
|
+
module WDD
|
7
|
+
module Utils
|
8
|
+
class PrettyXml
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@xsl ||= Nokogiri::XSLT(File.open(File.expand_path('../../resources/pretty_xml.xsl', __FILE__)))
|
13
|
+
end
|
14
|
+
|
15
|
+
def format source
|
16
|
+
source = Nokogiri(source) if source.is_a? String
|
17
|
+
@xsl.apply_to(source).to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def format source
|
22
|
+
PrettyXml.instance.format( source )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# wait on the gate to ensure that a certain amount of time has passed before continuing.
|
7
7
|
# This is specifically useful for throttling API calls.
|
8
8
|
module WDD
|
9
|
-
module
|
9
|
+
module Utils
|
10
10
|
class TimeGate
|
11
11
|
def set seconds
|
12
12
|
@gate_time = Time.now + seconds
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec/autorun'
|
2
|
+
require 'spec/runner/formatter/text_mate_formatter'
|
3
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
|
+
|
5
|
+
describe WDD::Utils::PrettyXml do
|
6
|
+
it "works for string" do
|
7
|
+
source = "<html><body>Hello</body></html>"
|
8
|
+
pretty = WDD::Utils::PrettyXml.format(source)
|
9
|
+
pretty.should == "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<html>\n <body>Hello</body>\n</html>\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "works for Nokogiri doc" do
|
13
|
+
source = Nokogiri::HTML("<html><body>Hello</body></html>")
|
14
|
+
pretty = WDD::Utils::PrettyXml.format(source)
|
15
|
+
pretty.should == "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<html>\n <body>Hello</body>\n</html>\n"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/wdd-ruby-ext.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wdd-ruby-ext}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["shock"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-16}
|
13
13
|
s.description = %q{Some of these are borrowed. Some are original. This gem simply provides a single place to source control them all for incorporation into other projects.}
|
14
14
|
s.email = %q{billdoughty@capitalthought.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
|
+
".rvmrc",
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"LICENSE",
|
@@ -31,6 +32,7 @@ Gem::Specification.new do |s|
|
|
31
32
|
"lib/wdd-ruby-ext/http.rb",
|
32
33
|
"lib/wdd-ruby-ext/numbers.rb",
|
33
34
|
"lib/wdd-ruby-ext/object.rb",
|
35
|
+
"lib/wdd-ruby-ext/resources/pretty_xml.xsl",
|
34
36
|
"lib/wdd-ruby-ext/string.rb",
|
35
37
|
"lib/wdd-ruby-ext/system.rb",
|
36
38
|
"lib/wdd-ruby-ext/time.rb",
|
@@ -38,9 +40,11 @@ Gem::Specification.new do |s|
|
|
38
40
|
"lib/wdd-ruby-ext/utils/fixed_point.rb",
|
39
41
|
"lib/wdd-ruby-ext/utils/hash_object.rb",
|
40
42
|
"lib/wdd-ruby-ext/utils/helpers.rb",
|
43
|
+
"lib/wdd-ruby-ext/utils/pretty_xml.rb",
|
41
44
|
"lib/wdd-ruby-ext/utils/simpledebug.rb",
|
42
45
|
"lib/wdd-ruby-ext/utils/time_gate.rb",
|
43
46
|
"spec/lib/utils/fixed_point_spec.rb",
|
47
|
+
"spec/lib/utils/pretty_xml_spec.rb",
|
44
48
|
"spec/spec.opts",
|
45
49
|
"spec/spec_helper.rb",
|
46
50
|
"spec/wdd-ruby-ext_spec.rb",
|
@@ -53,6 +57,7 @@ Gem::Specification.new do |s|
|
|
53
57
|
s.summary = %q{Handy extensions to the Ruby base classes and other utilities.}
|
54
58
|
s.test_files = [
|
55
59
|
"spec/lib/utils/fixed_point_spec.rb",
|
60
|
+
"spec/lib/utils/pretty_xml_spec.rb",
|
56
61
|
"spec/spec_helper.rb",
|
57
62
|
"spec/wdd-ruby-ext_spec.rb"
|
58
63
|
]
|
@@ -63,11 +68,14 @@ Gem::Specification.new do |s|
|
|
63
68
|
|
64
69
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
65
70
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
71
|
+
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.4.4"])
|
66
72
|
else
|
67
73
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
74
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.4.4"])
|
68
75
|
end
|
69
76
|
else
|
70
77
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
78
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.4.4"])
|
71
79
|
end
|
72
80
|
end
|
73
81
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wdd-ruby-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 2
|
9
8
|
- 3
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- shock
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-16 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -34,6 +34,22 @@ dependencies:
|
|
34
34
|
version: 1.2.9
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: nokogiri
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 4
|
50
|
+
version: 1.4.4
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
37
53
|
description: Some of these are borrowed. Some are original. This gem simply provides a single place to source control them all for incorporation into other projects.
|
38
54
|
email: billdoughty@capitalthought.com
|
39
55
|
executables: []
|
@@ -46,6 +62,7 @@ extra_rdoc_files:
|
|
46
62
|
files:
|
47
63
|
- .document
|
48
64
|
- .gitignore
|
65
|
+
- .rvmrc
|
49
66
|
- Gemfile
|
50
67
|
- Gemfile.lock
|
51
68
|
- LICENSE
|
@@ -58,6 +75,7 @@ files:
|
|
58
75
|
- lib/wdd-ruby-ext/http.rb
|
59
76
|
- lib/wdd-ruby-ext/numbers.rb
|
60
77
|
- lib/wdd-ruby-ext/object.rb
|
78
|
+
- lib/wdd-ruby-ext/resources/pretty_xml.xsl
|
61
79
|
- lib/wdd-ruby-ext/string.rb
|
62
80
|
- lib/wdd-ruby-ext/system.rb
|
63
81
|
- lib/wdd-ruby-ext/time.rb
|
@@ -65,9 +83,11 @@ files:
|
|
65
83
|
- lib/wdd-ruby-ext/utils/fixed_point.rb
|
66
84
|
- lib/wdd-ruby-ext/utils/hash_object.rb
|
67
85
|
- lib/wdd-ruby-ext/utils/helpers.rb
|
86
|
+
- lib/wdd-ruby-ext/utils/pretty_xml.rb
|
68
87
|
- lib/wdd-ruby-ext/utils/simpledebug.rb
|
69
88
|
- lib/wdd-ruby-ext/utils/time_gate.rb
|
70
89
|
- spec/lib/utils/fixed_point_spec.rb
|
90
|
+
- spec/lib/utils/pretty_xml_spec.rb
|
71
91
|
- spec/spec.opts
|
72
92
|
- spec/spec_helper.rb
|
73
93
|
- spec/wdd-ruby-ext_spec.rb
|
@@ -108,5 +128,6 @@ specification_version: 3
|
|
108
128
|
summary: Handy extensions to the Ruby base classes and other utilities.
|
109
129
|
test_files:
|
110
130
|
- spec/lib/utils/fixed_point_spec.rb
|
131
|
+
- spec/lib/utils/pretty_xml_spec.rb
|
111
132
|
- spec/spec_helper.rb
|
112
133
|
- spec/wdd-ruby-ext_spec.rb
|