axeml 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # AxML
1
+ # AxeML
2
2
 
3
- AxML is a notation for Nokogiri XML documents inspired by [SXML](http://okmij.org/ftp/Scheme/SXML.html).
3
+ AxeML is a notation for Nokogiri XML documents inspired by [SXML](http://okmij.org/ftp/Scheme/SXML.html).
4
+
5
+ ## Installation
6
+
7
+ gem install axeml
4
8
 
5
9
  ## Syntax
6
10
 
@@ -11,31 +15,45 @@ treated as the node's content, hashes representing this node's
11
15
  attributes or further arrays which are then made into child nodes by
12
16
  the same rules.
13
17
 
14
- The syntax can be described by the following rammar:
18
+ The syntax can be described by the following grammar:
15
19
 
16
- node ::= [node-name, (node | attributes | content) ...]
17
- node-name ::= Symbol
18
- attributes ::= Hash
19
- content ::= String | Fixnum | Float
20
+ node ::= [<node-name>, (<node> | <attributes> | <content>) ...]
21
+ node-name ::= <Symbol>
22
+ attributes ::= <Hash>
23
+ content ::= <String> | <Fixnum> | <Float>
20
24
 
21
25
 
22
26
  ## Example
23
27
 
24
- AxML.transform([:ul, { :class => 'menu' },
25
- [:li, [:a, { :href => '/foo' }, 'foo']],
26
- [:li, [:a, { :href => '/bar' }, 'bar']]]).to_s
28
+ AxeML.transform([:ul, { :class => 'menu' },
29
+ [:li, [:a, { :href => '/foo' }, 'foo']],
30
+ [:li, [:a, { :href => '/bar' }, 'bar']]]).to_s
27
31
 
28
32
  =>
29
33
 
30
34
  <?xml version="1.0"?>
31
35
  <ul class="menu">
32
36
  <li>
33
- <a href="/foo">foo</a>
37
+ <a href="/foo">foo</a>
34
38
  </li>
35
39
  <li>
36
- <a href="/bar">bar</a>
40
+ <a href="/bar">bar</a>
37
41
  </li>
38
42
  </ul>
43
+
44
+
45
+ Note that since `AxeML.transform` returns an instance of
46
+ `Nokogiri::XML::Document` you can directly use its search facilities
47
+ for example:
48
+
49
+ AxeML.transform([:foo, [:bar, [:baz, "very well"]]]).search('foo baz').text
50
+ => "very well"
51
+
52
+
53
+ ## ToDo
54
+
55
+ * actually implement transformation rules :-)
56
+ * support XML namespaces
39
57
 
40
58
  ## Copyright
41
59
 
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/DerGuteMoritz/axeml"
12
12
  gem.authors = ["Moritz Heidkamp"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency 'nokogiri'
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.0.3
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{axeml}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Moritz Heidkamp"]
@@ -44,11 +44,14 @@ Gem::Specification.new do |s|
44
44
 
45
45
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
46
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
47
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
47
48
  else
48
49
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
50
+ s.add_dependency(%q<nokogiri>, [">= 0"])
49
51
  end
50
52
  else
51
53
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
54
+ s.add_dependency(%q<nokogiri>, [">= 0"])
52
55
  end
53
56
  end
54
57
 
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'nokogiri'
3
2
 
4
3
  module AxeML
@@ -10,24 +9,32 @@ module AxeML
10
9
  end
11
10
 
12
11
  def self.transform_element(axeml, doc, parent = doc)
13
- el = parent.add_child(Nokogiri::XML::Element.new(axeml[0].to_s, doc))
14
-
15
- axeml[1..-1].each do |e|
16
- case e
17
- when Array
18
- el.add_child(transform_element(e, doc, el))
19
- when String
20
- el.content += e
21
- when Fixnum, Float
22
- el.content += e.to_s
23
- when Hash
24
- e.each do |k,v|
25
- el[k.to_s] = v
12
+ case axeml[0]
13
+ when Symbol
14
+ el = parent.add_child(Nokogiri::XML::Element.new(axeml[0].to_s, doc))
15
+
16
+ axeml[1..-1].each do |e|
17
+ case e
18
+ when Array
19
+ transform_element(e, doc, el)
20
+ when String
21
+ el.content += e
22
+ when Fixnum, Float
23
+ el.content += e.to_s
24
+ when Hash
25
+ e.each do |k,v|
26
+ el[k.to_s] = v
27
+ end
26
28
  end
27
29
  end
28
- end
29
30
 
30
- el
31
+ el
32
+ when Array
33
+ axeml.each do |a|
34
+ transform_element(a, doc, parent)
35
+ end
36
+ end
37
+
31
38
  end
32
39
 
33
40
  end
@@ -40,5 +40,11 @@ describe AxeML do
40
40
  doc.root.attributes['bar'].content.should == 'heh!'
41
41
  doc.root.attributes['qux'].content.should == '123'
42
42
  end
43
+
44
+ it 'should allow arbitrary list wrapping' do
45
+ doc = AxeML.transform([:foo, [[[:foo, 'bar']], [:foo, 'baz']]])
46
+ doc.search('foo foo:first').text.should == 'bar'
47
+ doc.search('foo foo:last').text.should == 'baz'
48
+ end
43
49
 
44
50
  end
@@ -1 +1,2 @@
1
+ require 'rubygems'
1
2
  require Pathname.new(__FILE__).dirname.join('..', 'lib', 'axeml')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axeml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Moritz Heidkamp
@@ -34,6 +34,20 @@ 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: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
37
51
  description: AxeML is a notation for Nokogiri XML documents inspired by SXML
38
52
  email: moritz.heidkamp@bevuta.com
39
53
  executables: []