insert_into 0.1.0 → 0.2.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/README.rdoc +5 -3
- data/VERSION +1 -1
- data/insert_into.gemspec +2 -2
- data/lib/insert_into.rb +24 -7
- data/spec/insert_into_spec.rb +20 -10
- metadata +3 -3
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/insert_into.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{insert_into}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Richard Hart"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-06}
|
13
13
|
s.description = %q{Insert text into XML/HTML.}
|
14
14
|
s.email = %q{richard@ur-ban.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/insert_into.rb
CHANGED
@@ -23,7 +23,7 @@ class InsertInto
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def into_text
|
26
|
-
@into_text.to_s
|
26
|
+
@into_text.to_s
|
27
27
|
end
|
28
28
|
|
29
29
|
def between_tag target_tag
|
@@ -32,6 +32,18 @@ class InsertInto
|
|
32
32
|
self
|
33
33
|
end
|
34
34
|
|
35
|
+
def prepend_to_tag target_tag
|
36
|
+
@target_tag = target_tag
|
37
|
+
@type = :prepend_to_tag
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def append_to_tag target_tag
|
42
|
+
@target_tag = target_tag
|
43
|
+
@type = :append_to_tag
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
35
47
|
def before_tag target_tag
|
36
48
|
@target_tag = target_tag
|
37
49
|
@type = :before
|
@@ -47,12 +59,17 @@ class InsertInto
|
|
47
59
|
def process
|
48
60
|
return @insert_text << into_text if @target_tag.empty?
|
49
61
|
@into_text.search(@target_tag) do |node|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
62
|
+
case @type
|
63
|
+
when :after
|
64
|
+
node.after insert_text
|
65
|
+
when :before
|
66
|
+
node.before insert_text
|
67
|
+
when :prepend_to_tag
|
68
|
+
node.inner_html (insert_text + node.inner_html)
|
69
|
+
when :append_to_tag
|
70
|
+
node.inner_html (node.inner_html + insert_text)
|
71
|
+
when :between
|
72
|
+
node.inner_html insert_text
|
56
73
|
end
|
57
74
|
end
|
58
75
|
into_text
|
data/spec/insert_into_spec.rb
CHANGED
@@ -18,8 +18,8 @@ describe InsertInto do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should initialize the text to be inserted into" do
|
21
|
-
ii = InsertInto.new.into("<into/>")
|
22
|
-
ii.into_text.should == "<into/>"
|
21
|
+
ii = InsertInto.new.into("<into />")
|
22
|
+
ii.into_text.should == "<into />"
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should initialize the target tag as an empty string" do
|
@@ -33,9 +33,9 @@ describe InsertInto do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should initialize multiple values" do
|
36
|
-
ii = InsertInto.new.insert("insert").into("<into/>").between_tag("tag")
|
36
|
+
ii = InsertInto.new.insert("insert").into("<into />").between_tag("tag")
|
37
37
|
ii.insert_text.should == "insert"
|
38
|
-
ii.into_text.should == "<into/>"
|
38
|
+
ii.into_text.should == "<into />"
|
39
39
|
ii.target_tag.should == "tag"
|
40
40
|
end
|
41
41
|
|
@@ -45,8 +45,8 @@ describe InsertInto do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should insert text before a string if no target tag is supplied" do
|
48
|
-
result = InsertInto.new.insert("insert").into("<into/>").process
|
49
|
-
result.should == "insert<into/>"
|
48
|
+
result = InsertInto.new.insert("insert").into("<into />").process
|
49
|
+
result.should == "insert<into />"
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should insert text into a string if target tag is supplied" do
|
@@ -59,14 +59,24 @@ describe InsertInto do
|
|
59
59
|
result.should == "<bar><into><foo>insert</foo></into><into><foo>insert</foo></into></bar>"
|
60
60
|
end
|
61
61
|
|
62
|
+
it "should insert text into a string before the existing content if target tag is supplied" do
|
63
|
+
result = InsertInto.new.insert("<foo>insert</foo>").into("<into>into content</into>").prepend_to_tag("into").process
|
64
|
+
result.should == "<into><foo>insert</foo>into content</into>"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should insert text into a string after the existing content if target tag is supplied" do
|
68
|
+
result = InsertInto.new.insert("<foo>insert</foo>").into("<into>into content</into>").append_to_tag("into").process
|
69
|
+
result.should == "<into>into content<foo>insert</foo></into>"
|
70
|
+
end
|
71
|
+
|
62
72
|
it "should insert text before a tag" do
|
63
|
-
result = InsertInto.new.insert("<foo>insert</foo>").into("<bar><into/></bar>").before_tag("into").process
|
64
|
-
result.should == "<bar><foo>insert</foo><into/></bar>"
|
73
|
+
result = InsertInto.new.insert("<foo>insert</foo>").into("<bar><into /></bar>").before_tag("into").process
|
74
|
+
result.should == "<bar><foo>insert</foo><into /></bar>"
|
65
75
|
end
|
66
76
|
|
67
77
|
it "should insert text after a tag" do
|
68
|
-
result = InsertInto.new.insert("<foo>insert</foo>").into("<bar><into/></bar>").after_tag("into").process
|
69
|
-
result.should == "<bar><into/><foo>insert</foo></bar>"
|
78
|
+
result = InsertInto.new.insert("<foo>insert</foo>").into("<bar><into /></bar>").after_tag("into").process
|
79
|
+
result.should == "<bar><into /><foo>insert</foo></bar>"
|
70
80
|
end
|
71
81
|
|
72
82
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Richard Hart
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-06 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|