axeml 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -0
- data/.gitignore +1 -0
- data/LICENSE +12 -0
- data/README.md +42 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/axeml.gemspec +54 -0
- data/lib/axeml.rb +33 -0
- data/spec/basic_spec.rb +44 -0
- data/spec/spec_helper.rb +1 -0
- metadata +93 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/LICENSE
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Copyright (c) 2010 Moritz Heidkamp
|
2
|
+
|
3
|
+
The Regents of the University of California. All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
+
3. All advertising materials mentioning features or use of this software must display the following acknowledgement: “This product includes software developed by the University of California, Berkeley and its contributors.”
|
10
|
+
4. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# AxML
|
2
|
+
|
3
|
+
AxML is a notation for Nokogiri XML documents inspired by [SXML](http://okmij.org/ftp/Scheme/SXML.html).
|
4
|
+
|
5
|
+
## Syntax
|
6
|
+
|
7
|
+
A document is represented by an array, possibly nested. The first
|
8
|
+
element of each array must be a symbol indicating the node
|
9
|
+
name. Further elements may either be strings or numbers which are
|
10
|
+
treated as the node's content, hashes representing this node's
|
11
|
+
attributes or further arrays which are then made into child nodes by
|
12
|
+
the same rules.
|
13
|
+
|
14
|
+
The syntax can be described by the following rammar:
|
15
|
+
|
16
|
+
node ::= [node-name, (node | attributes | content) ...]
|
17
|
+
node-name ::= Symbol
|
18
|
+
attributes ::= Hash
|
19
|
+
content ::= String | Fixnum | Float
|
20
|
+
|
21
|
+
|
22
|
+
## Example
|
23
|
+
|
24
|
+
AxML.transform([:ul, { :class => 'menu' },
|
25
|
+
[:li, [:a, { :href => '/foo' }, 'foo']],
|
26
|
+
[:li, [:a, { :href => '/bar' }, 'bar']]]).to_s
|
27
|
+
|
28
|
+
=>
|
29
|
+
|
30
|
+
<?xml version="1.0"?>
|
31
|
+
<ul class="menu">
|
32
|
+
<li>
|
33
|
+
<a href="/foo">foo</a>
|
34
|
+
</li>
|
35
|
+
<li>
|
36
|
+
<a href="/bar">bar</a>
|
37
|
+
</li>
|
38
|
+
</ul>
|
39
|
+
|
40
|
+
## Copyright
|
41
|
+
|
42
|
+
Copyright (c) 2010 Moritz Heidkamp. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "axeml"
|
8
|
+
gem.summary = %Q{An SXML-like library for contructing Nokogiri documents}
|
9
|
+
gem.description = %Q{AxeML is a notation for Nokogiri XML documents inspired by SXML}
|
10
|
+
gem.email = "moritz.heidkamp@bevuta.com"
|
11
|
+
gem.homepage = "http://github.com/DerGuteMoritz/axml"
|
12
|
+
gem.authors = ["Moritz Heidkamp"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "axeml #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/axeml.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{axeml}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Moritz Heidkamp"]
|
12
|
+
s.date = %q{2010-08-08}
|
13
|
+
s.description = %q{AxeML is a notation for Nokogiri XML documents inspired by SXML}
|
14
|
+
s.email = %q{moritz.heidkamp@bevuta.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"axeml.gemspec",
|
27
|
+
"lib/axeml.rb",
|
28
|
+
"spec/basic_spec.rb",
|
29
|
+
"spec/spec_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/DerGuteMoritz/axml}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.7}
|
35
|
+
s.summary = %q{An SXML-like library for contructing Nokogiri documents}
|
36
|
+
s.test_files = [
|
37
|
+
"spec/spec_helper.rb",
|
38
|
+
"spec/basic_spec.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/lib/axeml.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module AxeML
|
5
|
+
|
6
|
+
def self.transform(axeml)
|
7
|
+
doc = Nokogiri::XML::Document.new
|
8
|
+
transform_element(axeml, doc)
|
9
|
+
doc
|
10
|
+
end
|
11
|
+
|
12
|
+
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
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
el
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/spec/basic_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require Pathname.new(__FILE__).dirname.join('spec_helper')
|
2
|
+
|
3
|
+
describe AxeML do
|
4
|
+
|
5
|
+
describe 'only root' do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@doc = AxeML.transform([:p, 'hey'])
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should convert to a nokogiri tree' do
|
12
|
+
@doc.should be_a(Nokogiri::XML::Document)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should contain one p element containing hey' do
|
16
|
+
@doc.children.size.should == 1
|
17
|
+
@doc.root.node_name.should == 'p'
|
18
|
+
@doc.root.content.should == 'hey'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should allow nesting' do
|
24
|
+
doc = AxeML.transform([:foo, 'zing', [:bar, [:baz, "hello"], [:another, "here"]]])
|
25
|
+
doc.root.node_name.should == 'foo'
|
26
|
+
doc.root.content == 'zing'
|
27
|
+
doc.root.children.size.should == 2
|
28
|
+
doc.root.children[0].should be_a(Nokogiri::XML::Text)
|
29
|
+
bar = doc.root.children[1]
|
30
|
+
bar.node_name.should == 'bar'
|
31
|
+
bar.children.size.should == 2
|
32
|
+
bar.children[0].node_name.should == 'baz'
|
33
|
+
bar.children[0].content.should == 'hello'
|
34
|
+
bar.children[1].node_name.should == 'another'
|
35
|
+
bar.children[1].content.should == 'here'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should allow attributes' do
|
39
|
+
doc = AxeML.transform([:foo, { :bar => 'baz', :qux => '123' }, { :bar => 'heh!'}])
|
40
|
+
doc.root.attributes['bar'].content.should == 'heh!'
|
41
|
+
doc.root.attributes['qux'].content.should == '123'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require Pathname.new(__FILE__).dirname.join('..', 'lib', 'axeml')
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: axeml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Moritz Heidkamp
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-08 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: AxeML is a notation for Nokogiri XML documents inspired by SXML
|
38
|
+
email: moritz.heidkamp@bevuta.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.md
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- axeml.gemspec
|
54
|
+
- lib/axeml.rb
|
55
|
+
- spec/basic_spec.rb
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/DerGuteMoritz/axml
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: An SXML-like library for contructing Nokogiri documents
|
91
|
+
test_files:
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/basic_spec.rb
|