clifton_lib 0.0.5 → 0.0.7
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/Gemfile.lock +1 -1
- data/README.md +4 -2
- data/lib/clifton_lib/version.rb +1 -1
- data/lib/clifton_lib/xml/xml_document.rb +15 -0
- data/lib/clifton_lib/xml/xml_fragment.rb +17 -0
- data/test/xml_document_tests.rb +13 -0
- metadata +6 -5
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -34,11 +34,13 @@ This implementation:
|
|
34
34
|
|
35
35
|
## Revisions
|
36
36
|
|
37
|
-
0.0.
|
37
|
+
Published 0.0.7 - Added XmlFragment
|
38
|
+
0.0.6 -
|
39
|
+
Published 0.0.5 - Added support to disallow a closing tag for HTML5 compatibility. For example, <img> is valid, <img></img> is seen as a stray ending tag.
|
38
40
|
0.0.4 - Added support to disallow self-closing tags for HTML5 compatibility. For example, <div>...</div> is valid, </div> is not.
|
39
41
|
0.0.3 - Added support for valueless attributes. Example: <nav class="top-bar" data-topbar/>
|
40
42
|
0.0.2 - Additional internal properties for associating the XmlDocument to elements and XmlElement to attributes.
|
41
|
-
0.0.1 - Initial version.
|
43
|
+
Published 0.0.1 - Initial version.
|
42
44
|
|
43
45
|
## A note about the code
|
44
46
|
|
data/lib/clifton_lib/version.rb
CHANGED
@@ -3,6 +3,7 @@ require "clifton_lib/xml/xml_attribute"
|
|
3
3
|
require "clifton_lib/xml/xml_element"
|
4
4
|
require "clifton_lib/xml/xml_node"
|
5
5
|
require "clifton_lib/xml/xml_declaration_node"
|
6
|
+
require "clifton_lib/xml/xml_fragment"
|
6
7
|
|
7
8
|
module CliftonXml
|
8
9
|
class XmlDocument < XmlNode
|
@@ -39,6 +40,17 @@ module CliftonXml
|
|
39
40
|
elem
|
40
41
|
end
|
41
42
|
|
43
|
+
# XmlFragment create_xml_fragment(string fragment_text)
|
44
|
+
def create_xml_fragment(text)
|
45
|
+
elem = XmlFragment.new() {
|
46
|
+
@text = text
|
47
|
+
}
|
48
|
+
|
49
|
+
elem.xml_document = self
|
50
|
+
|
51
|
+
elem
|
52
|
+
end
|
53
|
+
|
42
54
|
# XmlAttribute create_attribute(string name, string val = '')
|
43
55
|
# Returns an XmlAttribute. Append to the desired element with XmlElement#append_attribute.
|
44
56
|
def create_attribute(name, value = '')
|
@@ -80,6 +92,9 @@ module CliftonXml
|
|
80
92
|
write_attributes(writer, node)
|
81
93
|
writer.write('?>')
|
82
94
|
writer.new_line()
|
95
|
+
elsif node.is_a?(XmlFragment)
|
96
|
+
# if it's a fragment, just write the fragment, which is expected to be a string.
|
97
|
+
writer.write(node.text)
|
83
98
|
else
|
84
99
|
# begin element tag and attributes
|
85
100
|
writer.write('<' + node.name)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "clifton_lib/version"
|
2
|
+
require "clifton_lib/xml/xml_node"
|
3
|
+
|
4
|
+
module CliftonXml
|
5
|
+
class XmlFragment < XmlNode
|
6
|
+
attr_accessor :text
|
7
|
+
|
8
|
+
# HtmlFragment.new() {@text = 'stuff'}
|
9
|
+
def initialize(&block)
|
10
|
+
super()
|
11
|
+
@text = ''
|
12
|
+
instance_eval(&block) unless block.nil?
|
13
|
+
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/test/xml_document_tests.rb
CHANGED
@@ -171,4 +171,17 @@ class XmlDocumentTests < Test::Unit::TestCase
|
|
171
171
|
assert_equal %Q|<img>|, output
|
172
172
|
|
173
173
|
end
|
174
|
+
|
175
|
+
def test_xml_fragment
|
176
|
+
xdoc = XmlDocument.new()
|
177
|
+
products = xdoc.create_element('Products')
|
178
|
+
xdoc.append_child(products)
|
179
|
+
frag = xdoc.create_xml_fragment('<Injected/>')
|
180
|
+
xdoc.append_child(frag)
|
181
|
+
tw = XmlTextWriter.new()
|
182
|
+
tw.formatting = :indented
|
183
|
+
xdoc.save(tw)
|
184
|
+
output = tw.output
|
185
|
+
assert_equal %Q|<Products/>\r\n<Injected/>|, output
|
186
|
+
end
|
174
187
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clifton_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2014-04-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &25736568 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.3'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *25736568
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &25736244 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *25736244
|
36
36
|
description: A collection of useful helper classes, initially a set of classes to
|
37
37
|
support creation and serialization of XML.
|
38
38
|
email:
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/clifton_lib/xml/xml_declaration_node.rb
|
56
56
|
- lib/clifton_lib/xml/xml_document.rb
|
57
57
|
- lib/clifton_lib/xml/xml_element.rb
|
58
|
+
- lib/clifton_lib/xml/xml_fragment.rb
|
58
59
|
- lib/clifton_lib/xml/xml_node.rb
|
59
60
|
- lib/clifton_lib/xml/xml_text_writer.rb
|
60
61
|
- test/xml_document_tests.rb
|