commaparty 0.0.1 → 0.0.2pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/Rakefile +0 -5
- data/lib/commaparty/markup.rb +7 -13
- data/lib/commaparty/version.rb +1 -1
- data/lib/commaparty/xml.rb +9 -2
- data/lib/commaparty.rb +0 -4
- data/spec/commaparty/destructure_element_spec.rb +1 -1
- data/spec/commaparty/markup_spec.rb +8 -35
- data/spec/commaparty/parse_body_spec.rb +1 -1
- data/spec/commaparty_spec.rb +17 -23
- metadata +4 -5
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ff205c728b610398ebae49f09f8b3f7bd76b7aa
|
4
|
+
data.tar.gz: 2fa31a4f7a4267c4a4ddadc1d8288f6b7872f7c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b6b55a5955129843ad2c48b2f203c4e46126bc3a3c66fbf87df990d1aaf416a13418165cb60b1aa0e4b5e0f2f7a621ba33c7b2598238a860b62a8abc54921fe
|
7
|
+
data.tar.gz: 49d7511cb62731b6b664d4bb866252e85a492992930ef8c92f8d17db5e8416e80c9488459cfbc9057f811dc2f3939413c88f73896e1cad61c3f06b2994a77386
|
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
CommaParty
|
2
2
|
======
|
3
|
-
[![Build Status](https://travis-ci.org/ecmendenhall/commaparty.png?branch=master)](https://travis-ci.org/ecmendenhall/commaparty)
|
4
|
-
|
5
3
|
CommaParty is a Ruby implementation of Clojure's
|
6
4
|
[Hiccup](https://github.com/weavejester/hiccup/) HTML generation library.
|
7
5
|
It uses arrays to represent elements, and hashes to represent an element's
|
data/Rakefile
CHANGED
data/lib/commaparty/markup.rb
CHANGED
@@ -9,25 +9,19 @@ module CommaParty
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def call
|
12
|
-
build(@hiccup).doc.to_html
|
13
|
-
end
|
14
|
-
|
15
|
-
def builder
|
16
12
|
build(@hiccup)
|
17
13
|
end
|
18
14
|
|
19
|
-
def hiccup
|
20
|
-
@hiccup.flatten(1)
|
21
|
-
end
|
22
|
-
|
23
15
|
private
|
24
16
|
|
25
17
|
def build(elements)
|
26
|
-
Nokogiri::XML::Builder.new do |doc|
|
27
|
-
|
28
|
-
|
18
|
+
doc = Nokogiri::XML::Builder.new do |doc|
|
19
|
+
doc.root do |root|
|
20
|
+
elements.each do |element|
|
21
|
+
create_child(root, element)
|
22
|
+
end
|
29
23
|
end
|
30
|
-
end
|
24
|
+
end.doc.root.children.to_html
|
31
25
|
end
|
32
26
|
|
33
27
|
def create_child(node, element)
|
@@ -37,7 +31,7 @@ module CommaParty
|
|
37
31
|
|
38
32
|
def make_nodes(parent, children)
|
39
33
|
children.each do |child|
|
40
|
-
if child.is_a?(String) || child.is_a?(Fixnum)
|
34
|
+
if child.is_a?(String) || child.is_a?(Fixnum)
|
41
35
|
parent << child.to_s
|
42
36
|
else
|
43
37
|
create_child(parent, child)
|
data/lib/commaparty/version.rb
CHANGED
data/lib/commaparty/xml.rb
CHANGED
@@ -9,13 +9,20 @@ module CommaParty
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(markup)
|
12
|
-
@markup = CommaParty::Markup.new(markup)
|
12
|
+
@markup = CommaParty::Markup.new(markup).call
|
13
13
|
end
|
14
14
|
|
15
15
|
def call
|
16
|
-
@markup
|
16
|
+
build(@markup)
|
17
17
|
end
|
18
18
|
|
19
|
+
private
|
20
|
+
|
21
|
+
def build(markup)
|
22
|
+
Nokogiri::XML::Builder.new do |doc|
|
23
|
+
doc << markup
|
24
|
+
end.to_xml
|
25
|
+
end
|
19
26
|
end
|
20
27
|
|
21
28
|
end
|
data/lib/commaparty.rb
CHANGED
@@ -46,7 +46,7 @@ describe CommaParty::DestructureElement do
|
|
46
46
|
expect(body).to eq([[:li, "one"], [:li, "two"], [:li, "three"]])
|
47
47
|
end
|
48
48
|
|
49
|
-
it '
|
49
|
+
it 'wat' do
|
50
50
|
tag, attributes, body = described_class.new([:p, [:em, "hello"]]).call
|
51
51
|
expect(tag).to eq(:p_)
|
52
52
|
expect(attributes).to eq({})
|
@@ -7,69 +7,42 @@ describe CommaParty::Markup do
|
|
7
7
|
|
8
8
|
it 'generates a single tag' do
|
9
9
|
html = described_class.new([:tag]).call
|
10
|
-
expect(html).to eq("<tag></tag
|
10
|
+
expect(html).to eq("<tag></tag>")
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'generates a single tag with an attribute' do
|
14
14
|
html = described_class.new([:tag, {attribute: 'something'}]).call
|
15
|
-
expect(html).to eq("<tag attribute=\"something\"></tag
|
15
|
+
expect(html).to eq("<tag attribute=\"something\"></tag>")
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'generates a single tag with a value' do
|
19
19
|
html = described_class.new([:tag, 'value']).call
|
20
|
-
expect(html).to eq("<tag>value</tag
|
20
|
+
expect(html).to eq("<tag>value</tag>")
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'generates two sibling tags' do
|
24
24
|
html = described_class.new([:div, [:tag1], [:tag2]]).call
|
25
|
-
expect(html).to eq("<div>\n<tag1></tag1><tag2></tag2>\n</div
|
25
|
+
expect(html).to eq("<div>\n<tag1></tag1><tag2></tag2>\n</div>")
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'generates nested tags' do
|
29
29
|
html = described_class.new([:theparent, [:tag1], [:tag2]]).call
|
30
|
-
expect(html).to eq("<theparent><tag1></tag1><tag2></tag2></theparent
|
30
|
+
expect(html).to eq("<theparent><tag1></tag1><tag2></tag2></theparent>")
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'handles tags with the same names as ruby methods' do
|
34
34
|
html = described_class.new([:parent]).call
|
35
|
-
expect(html).to eq("<parent></parent
|
35
|
+
expect(html).to eq("<parent></parent>")
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'handles tags with shortcut syntax' do
|
39
39
|
html = described_class.new([:'tag.one.two.three#id']).call
|
40
|
-
expect(html).to eq("<tag class=\"one two three\" id=\"id\"></tag
|
40
|
+
expect(html).to eq("<tag class=\"one two three\" id=\"id\"></tag>")
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'handles seqs in the tag body' do
|
44
44
|
html = described_class.new([:ul, ["one", "two", "three"].map {|n| [:li, n]}]).call
|
45
|
-
expect(html).to eq("<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'handles nils in the tag body' do
|
49
|
-
html = described_class.new([:div, nil]).call
|
50
|
-
expect(html).to eq("<div></div>\n")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'Generating builders' do
|
55
|
-
|
56
|
-
it 'returns a Nokogiri builder' do
|
57
|
-
builder = described_class.new([:div]).builder
|
58
|
-
expect(builder.class).to eq(Nokogiri::XML::Builder)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'produces the same XML' do
|
62
|
-
markup = described_class.new([:div, [:span, 'lol']])
|
63
|
-
expect(markup.builder.doc.to_html).to eq(markup.call)
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'Retrieving hiccup' do
|
69
|
-
|
70
|
-
it 'returns its hiccup' do
|
71
|
-
hiccup = described_class.new([:div, [:ul, (1..3).map {|n| [:li, n]}]]).hiccup
|
72
|
-
expect(hiccup).to eq([:div, [:ul, [[:li, 1], [:li, 2], [:li, 3]]]])
|
45
|
+
expect(html).to eq("<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>")
|
73
46
|
end
|
74
47
|
|
75
48
|
end
|
data/spec/commaparty_spec.rb
CHANGED
@@ -3,46 +3,40 @@ require 'commaparty'
|
|
3
3
|
describe CommaParty do
|
4
4
|
|
5
5
|
it 'has a helpful html method' do
|
6
|
-
expect(CommaParty.html([:tag])).to match(
|
6
|
+
expect(CommaParty.html([:tag])).to match('<html><tag></tag></html>')
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'has a helpful xml method' do
|
10
|
-
expect(CommaParty.xml([:tag])).to match(
|
10
|
+
expect(CommaParty.xml([:tag])).to match('<tag/>')
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'has a helpful markup method' do
|
14
|
-
expect(CommaParty.markup([:tag])).to match(
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'has a helpful builder method' do
|
18
|
-
builder = CommaParty.builder([:tag])
|
19
|
-
expect(builder.class).to eq(Nokogiri::XML::Builder)
|
20
|
-
expect(builder.doc.to_html).to eq(CommaParty.markup([:tag]))
|
14
|
+
expect(CommaParty.markup([:tag])).to match('<tag></tag>')
|
21
15
|
end
|
22
16
|
|
23
17
|
context 'converts ruby syntax to html string' do
|
24
|
-
it { expect(CommaParty.markup [:script]).to eq "<script></script
|
25
|
-
it { expect(CommaParty.markup [:p, "hello"]).to eq "<p>hello</p
|
26
|
-
it { expect(CommaParty.markup [:p, [:em, "hello"]]).to eq "<p><em>hello</em></p
|
27
|
-
it { expect(CommaParty.markup [:span, {:class => "foo"}, "bar"]).to eq "<span class=\"foo\">bar</span
|
28
|
-
it { expect(CommaParty.markup [:div, {id: "email", class: "selected starred"}, "..."]).to eq "<div id=\"email\" class=\"selected starred\">...</div
|
29
|
-
it { expect(CommaParty.markup [:a, {:href => "http://github.com"}, "GitHub"]).to eq "<a href=\"http://github.com\">GitHub</a
|
18
|
+
it { expect(CommaParty.markup [:script]).to eq "<script></script>" }
|
19
|
+
it { expect(CommaParty.markup [:p, "hello"]).to eq "<p>hello</p>" }
|
20
|
+
it { expect(CommaParty.markup [:p, [:em, "hello"]]).to eq "<p><em>hello</em></p>" }
|
21
|
+
it { expect(CommaParty.markup [:span, {:class => "foo"}, "bar"]).to eq "<span class=\"foo\">bar</span>" }
|
22
|
+
it { expect(CommaParty.markup [:div, {id: "email", class: "selected starred"}, "..."]).to eq "<div id=\"email\" class=\"selected starred\">...</div>" }
|
23
|
+
it { expect(CommaParty.markup [:a, {:href => "http://github.com"}, "GitHub"]).to eq "<a href=\"http://github.com\">GitHub</a>"}
|
30
24
|
|
31
25
|
context 'collections' do
|
32
|
-
it { expect(CommaParty.markup [:ul, ['a','b'].map { |x| [:li, x]}]).to eq "<ul>\n<li>a</li>\n<li>b</li>\n</ul
|
33
|
-
it { expect(CommaParty.markup [:ul, (11...13).map { |n| [:li, n]}]).to eq "<ul>\n<li>11</li>\n<li>12</li>\n</ul
|
26
|
+
it { expect(CommaParty.markup [:ul, ['a','b'].map { |x| [:li, x]}]).to eq "<ul>\n<li>a</li>\n<li>b</li>\n</ul>"}
|
27
|
+
it { expect(CommaParty.markup [:ul, (11...13).map { |n| [:li, n]}]).to eq "<ul>\n<li>11</li>\n<li>12</li>\n</ul>"}
|
34
28
|
end
|
35
29
|
|
36
30
|
context 'css shorthand' do
|
37
|
-
it { expect(CommaParty.markup [:'p.hi', "hello"]).to eq "<p class=\"hi\">hello</p
|
38
|
-
it { expect(CommaParty.markup [:'p#hi', "hello"]).to eq "<p id=\"hi\">hello</p
|
39
|
-
it { expect(CommaParty.markup [:'p.hi.greet.left', "hello"]).to eq "<p class=\"hi greet left\">hello</p
|
40
|
-
it { expect(CommaParty.markup [:'p#hi.greet.left', "hello"]).to eq "<p class=\"greet left\" id=\"hi\">hello</p
|
31
|
+
it { expect(CommaParty.markup [:'p.hi', "hello"]).to eq "<p class=\"hi\">hello</p>" }
|
32
|
+
it { expect(CommaParty.markup [:'p#hi', "hello"]).to eq "<p id=\"hi\">hello</p>" }
|
33
|
+
it { expect(CommaParty.markup [:'p.hi.greet.left', "hello"]).to eq "<p class=\"hi greet left\">hello</p>" }
|
34
|
+
it { expect(CommaParty.markup [:'p#hi.greet.left', "hello"]).to eq "<p class=\"greet left\" id=\"hi\">hello</p>" }
|
41
35
|
end
|
42
36
|
|
43
37
|
context 'different shaped trees' do
|
44
|
-
it { expect(CommaParty.markup [:p, "Hello ", [:em, "World!"]]).to eq "<p>Hello <em>World!</em></p
|
45
|
-
it { expect(CommaParty.markup [:div, [:p, "Hello"], [:em, "World!"]]).to eq "<div>\n<p>Hello</p>\n<em>World!</em>\n</div
|
38
|
+
it { expect(CommaParty.markup [:p, "Hello ", [:em, "World!"]]).to eq "<p>Hello <em>World!</em></p>" }
|
39
|
+
it { expect(CommaParty.markup [:div, [:p, "Hello"], [:em, "World!"]]).to eq "<div>\n<p>Hello</p>\n<em>World!</em>\n</div>" }
|
46
40
|
end
|
47
41
|
end
|
48
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commaparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connor Mendenhall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -88,7 +88,6 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- .gitignore
|
91
|
-
- .travis.yml
|
92
91
|
- Gemfile
|
93
92
|
- LICENSE.txt
|
94
93
|
- README.md
|
@@ -126,9 +125,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
125
|
version: '0'
|
127
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
127
|
requirements:
|
129
|
-
- - '
|
128
|
+
- - '>'
|
130
129
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
130
|
+
version: 1.3.1
|
132
131
|
requirements: []
|
133
132
|
rubyforge_project:
|
134
133
|
rubygems_version: 2.0.3
|