xml-mixup 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16acef61e57573ecc6130c2f85b2026c469c6d767622ebe6e948b133022807bf
4
- data.tar.gz: 2e57c480714d5c8ec39dd8e8b5d9dcd017241854abf09b3f096e0a20ea71a6db
3
+ metadata.gz: 9a594513555bc316fae8b161bdb001a6f180dff72f9979277b4c2acdb8e0be60
4
+ data.tar.gz: 6cca44a5594a90854e0a78ea799e5e77d9356129a6bcb58a0c465b8f09b4b2e4
5
5
  SHA512:
6
- metadata.gz: e37f1fc13e2b437215c84b031c24586191dc4233a6016fbb63119cb01f9548e52b38a0a3cfe5c65e6e22535ad74665821bd4ce6fa1442c6aefa2a3ce9a76b845
7
- data.tar.gz: 7d49d0d3ef9fa95b97004904e0c449595e4f56568469b3d02c60cd81223c7c8e19d0f94bdd6ad902685a6da1f8421a76cfbad9c131f1d8f310f0c03e9ef736b4
6
+ metadata.gz: 5e776ca7dc85b8d3c4617dfa18d90e384a7659ac2cfd34aa663ca70b2da23a62add625c92567935e7a1f78b6bd1ad5ed8e46ff1aa93e07022652efb68908da68
7
+ data.tar.gz: a286229b7037866857840f7785e4a0ad9b2607765abbc655df237b89f22ac5b548078f66cffcd2ba0287a29e3e14b86b12c75344dc09d024bf9ac8ea5c5efbb4
data/README.md CHANGED
@@ -76,17 +76,19 @@ fun. Good luck with that.
76
76
  ### Enter `XML::Mixup`
77
77
 
78
78
  * __The input consists of ordinary Ruby data objects__ so you can
79
- build them up ahead of time, in bulk, transform them, etc.,
79
+ build them up ahead of time, in bulk, transform them using familiar
80
+ operations, etc.,
80
81
  * __Sprinkle pre-built XML subtrees anywhere into the spec__ so you
81
82
  can memoize repeating elements, or otherwise compile a document
82
83
  incrementally,
83
84
  * __Attach new generated content anywhere:__ underneath a parent node,
84
85
  or before, after, or _instead of_ a node at the sibling level.
85
86
 
86
- ## The spec format
87
+ ## The tree spec format
87
88
 
88
89
  At the heart of this module is a single method called `markup`, which,
89
- among other things, takes a `:spec`. The spec can be any composite
90
+ among other things, takes a `:spec`. The spec can be any composite of
91
+ these objects, and will behave as described:
90
92
 
91
93
  ### Hashes
92
94
 
@@ -98,12 +100,12 @@ generate pretty much any node with it:
98
100
  ```ruby
99
101
  { '#tag' => 'foo' } # => <foo/>
100
102
 
101
- # or
102
- { '#elem' => 'foo' } # => <foo/>
103
-
104
103
  # or, with the element name as a symbol
105
104
  { '#element' => :foo } # => <foo/>
106
105
 
106
+ # or
107
+ { '#elem' => 'foo' } # => <foo/>
108
+
107
109
  # or, with nil as a key
108
110
  { nil => :foo } # => <foo/>
109
111
 
@@ -122,8 +124,22 @@ generate pretty much any node with it:
122
124
 
123
125
  # or, shove your child nodes into an otherwise content-less key
124
126
  { [:hi] => :foo, bar: :hurr } # => <foo bar="hurr">hi</foo>
127
+
128
+ # or, if you have content and the element name is not a reserved word
129
+ { '#html' => { '#head' => { '#title' => :hi } } }
130
+ # => <html><head><title>hi</title></head></html>
131
+
132
+ # also works with namespaces
133
+ { '#atom:feed' => nil, 'xmlns:atom' => 'http://www.w3.org/2005/Atom' }
134
+ # => <atom:feed xmlns:atom="http://www.w3.org/2005/Atom"/>
125
135
  ```
126
136
 
137
+ Reserved hash keywords are: `#comment`, `#cdata`, `#doctype`, `#dtd`,
138
+ `#elem`, `#element`, `#pi`, `#processing-instruction`, `#tag`. Note
139
+ that the constructs `{ nil => :foo }`, `{ nil => 'foo' }`, and `{
140
+ '#foo' => nil }`, plus `[]` anywhere you see `nil`, are all
141
+ equivalent.
142
+
127
143
  Attributes are sorted lexically. Composite attribute values get
128
144
  flattened like this:
129
145
 
@@ -187,16 +203,23 @@ another `Proc`.)
187
203
 
188
204
  Turned into a text node.
189
205
 
206
+ ## Documentation
207
+
208
+ Generated and deposited
209
+ [in the usual place](http://www.rubydoc.info/gems/xml-mixup/).
210
+
190
211
  ## Installation
191
212
 
192
213
  Come on, you know how to do this:
193
214
 
194
215
  $ gem install xml-mixup
195
216
 
217
+ Or, [download it off rubygems.org](https://rubygems.org/gems/xml-mixup).
218
+
196
219
  ## Contributing
197
220
 
198
221
  Bug reports and pull requests are welcome at
199
- https://github.com/doriantaylor/rb-xml-mixup.
222
+ [the GitHub repository](https://github.com/doriantaylor/rb-xml-mixup).
200
223
 
201
224
  ## The Future
202
225
 
@@ -208,7 +231,7 @@ make more streamlined methods. This may or may not make the same kind
208
231
  of sense with Ruby.
209
232
 
210
233
  In particular, these methods do not touch the calling object's
211
- state. In fact they should be completely stateless nad side-effect
234
+ state. In fact they _should_ be completely stateless and side-effect
212
235
  free. Likewise, they are really meant to be private. As such, it may
213
236
  make sense to simply bundle them as class methods and use them as
214
237
  such. I don't know, I haven't decided yet.
@@ -1,5 +1,5 @@
1
1
  module XML
2
2
  module Mixup
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
data/lib/xml/mixup.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'xml/mixup/version'
2
2
  require 'nokogiri'
3
+ require 'set'
3
4
 
4
5
  module XML::Mixup
5
6
 
@@ -9,26 +10,26 @@ module XML::Mixup
9
10
  private
10
11
 
11
12
  ADJACENT = {
12
- parent: lambda do |node, parent|
13
- if parent.node_type == 9 and node.node_type == 1
14
- parent.root = node
15
- elsif node.node_type == 11
16
- node.children.each do |child|
17
- parent.add_child(child)
18
- end
19
- else
20
- parent.add_child(node)
21
- end
22
- end,
23
- before: lambda do |node, sibling|
24
- sibling.add_previous_sibling node
25
- end,
26
- after: lambda { |node, sibling| sibling.add_next_sibling node },
27
- replace: lambda { |node, target| target.replace node },
28
- }.freeze
29
-
30
- RESERVED = %w{comment cdata doctype dtd elem element
31
- pi processing-instruction tag}.map {|x| "##{x}"}.to_set.freeze
13
+ parent: lambda do |node, parent|
14
+ if parent.node_type == 9 and node.node_type == 1
15
+ parent.root = node
16
+ elsif node.node_type == 11
17
+ node.children.each do |child|
18
+ parent.add_child(child)
19
+ end
20
+ else
21
+ parent.add_child(node)
22
+ end
23
+ end,
24
+ before: lambda do |node, sibling|
25
+ sibling.add_previous_sibling node
26
+ end,
27
+ after: lambda { |node, sibling| sibling.add_next_sibling node },
28
+ replace: lambda { |node, target| target.replace node },
29
+ }.freeze
30
+
31
+ RESERVED = Set.new(%w{comment cdata doctype dtd elem element
32
+ pi processing-instruction tag}.map {|x| "##{x}"}).freeze
32
33
 
33
34
  public
34
35
 
@@ -478,7 +479,7 @@ module XML::Mixup
478
479
  prefix = local = nil
479
480
  if tag.respond_to? :to_a
480
481
  prefix, local = tag
481
- tag = tag.join ':'
482
+ tag = tag[0..1].join ':'
482
483
  end
483
484
  elem = doc.create_element tag.to_s
484
485
  ns.sort.each do |p, u|
data/xml-mixup.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{A mixin for (XML) markup}
13
13
  spec.description = %q{XML::Mixup uses declarative data structures to incrementally generate XML.}
14
14
  spec.homepage = "https://github.com/doriantaylor/rb-xml-mixup"
15
+ spec.required_ruby_version = "~> 2.0"
15
16
 
16
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml-mixup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,9 +94,9 @@ require_paths:
94
94
  - lib
95
95
  required_ruby_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ">="
97
+ - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: '0'
99
+ version: '2.0'
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="