commaparty 0.0.2 → 0.0.3pre

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
  SHA1:
3
- metadata.gz: c6e73d560a55fc00b3b576893d73e44430a59ed6
4
- data.tar.gz: 9e48ba511096e3ea56f0fd04ed90e2663c70db9b
3
+ metadata.gz: 0ccf4025df7a717391079619f63559d9018095a7
4
+ data.tar.gz: 1245299fe3cca38daa9748b5e4db70ba8fdd15c2
5
5
  SHA512:
6
- metadata.gz: 058f7d1a5fb6df420d9287fca8db5643b4a3dfcee1f4be03a882441643ed95e812f0e5763967cb08de2bb434c3ce385eb70ab4af75d5db51659fc63015c004bd
7
- data.tar.gz: e05832615dfff1cebff80dd2ec1a207032ccfe627d4315de6cf11a86b96afb32c3314db71d2208eee9f396fd945d0cc349f217ff706d56061272338458fc98c5
6
+ metadata.gz: 374c05013a8e124e6a993192866604231007c6f9c8cdaccbb0ae711afebe49a832aa4c773444763f208f04db9a1699fc0eff8c509c022e817e451bcb14dda2f2
7
+ data.tar.gz: b646a876669d879644a3aef76d10aa7cd7ecb788cc4ee548f78f7786efda463d2421ed903ee74f10b913ee0156d943c28301ecee6808a5193376c1340dc45905
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
@@ -1,6 +1 @@
1
1
  require "bundler/gem_tasks"
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -9,36 +9,29 @@ 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
- elements.each do |element|
28
- create_child(doc, element)
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)
34
- return if element == []
35
28
  tag, attributes, children = CommaParty::DestructureElement.new(element).call
36
29
  node.send(tag, attributes) {|n| make_nodes(n, children) }
37
30
  end
38
31
 
39
32
  def make_nodes(parent, children)
40
33
  children.each do |child|
41
- if terminal?(child)
34
+ if child.is_a?(String) || child.is_a?(Fixnum) || child.nil?
42
35
  parent << child.to_s
43
36
  else
44
37
  create_child(parent, child)
@@ -46,11 +39,5 @@ module CommaParty
46
39
  end
47
40
  end
48
41
 
49
- def terminal?(child)
50
- child.is_a?(String) ||
51
- child.is_a?(Fixnum) ||
52
- child.nil?
53
- end
54
-
55
42
  end
56
43
  end
@@ -1,3 +1,3 @@
1
1
  module CommaParty
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3pre"
3
3
  end
@@ -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.builder.to_xml
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
@@ -17,9 +17,5 @@ module CommaParty
17
17
  CommaParty::Markup.new(hiccup).call
18
18
  end
19
19
 
20
- def self.builder(hiccup)
21
- CommaParty::Markup.new(hiccup).builder
22
- end
23
-
24
20
  end
25
21
 
@@ -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 'destructures an element with a tag in the body' do
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,180 +7,47 @@ 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>\n")
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>\n")
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>\n")
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>\n")
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
- nested = [:parent, [:tag1, [:tag2, [:tag3, [:tag4, 'deep', [:tag5, 'nesting']]]]]]
30
- html = described_class.new(nested).call
31
- expect(html).to eq("<parent><tag1><tag2><tag3><tag4>deep<tag5>nesting</tag5></tag4></tag3></tag2></tag1></parent>\n")
29
+ html = described_class.new([:theparent, [:tag1], [:tag2]]).call
30
+ expect(html).to eq("<theparent><tag1></tag1><tag2></tag2></theparent>")
32
31
  end
33
32
 
34
33
  it 'handles tags with the same names as ruby methods' do
35
34
  html = described_class.new([:parent]).call
36
- expect(html).to eq("<parent></parent>\n")
35
+ expect(html).to eq("<parent></parent>")
37
36
  end
38
37
 
39
38
  it 'handles tags with shortcut syntax' do
40
39
  html = described_class.new([:'tag.one.two.three#id']).call
41
- expect(html).to eq("<tag class=\"one two three\" id=\"id\"></tag>\n")
40
+ expect(html).to eq("<tag class=\"one two three\" id=\"id\"></tag>")
42
41
  end
43
42
 
44
43
  it 'handles seqs in the tag body' do
45
44
  html = described_class.new([:ul, ["one", "two", "three"].map {|n| [:li, n]}]).call
46
- expect(html).to eq("<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>\n")
45
+ expect(html).to eq("<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>")
47
46
  end
48
47
 
49
48
  it 'handles nils in the tag body' do
50
49
  html = described_class.new([:div, nil]).call
51
- expect(html).to eq("<div></div>\n")
52
- end
53
-
54
- it 'handles empty arrays in the tag body' do
55
- html = described_class.new([:div, [], 'he', [[]], 'llo']).call
56
- expect(html).to eq("<div>hello</div>\n")
57
- end
58
- end
59
-
60
- describe 'Generating builders' do
61
-
62
- it 'returns a Nokogiri builder' do
63
- builder = described_class.new([:div]).builder
64
- expect(builder.class).to eq(Nokogiri::XML::Builder)
65
- end
66
-
67
- it 'produces the same XML' do
68
- markup = described_class.new([:div, [:span, 'lol']])
69
- expect(markup.builder.doc.to_html).to eq(markup.call)
70
- end
71
-
72
- end
73
-
74
- describe 'Retrieving hiccup' do
75
-
76
- it 'returns its hiccup' do
77
- hiccup = described_class.new([:div, [:ul, (1..3).map {|n| [:li, n]}]]).hiccup
78
- expect(hiccup).to eq([:div, [:ul, [[:li, 1], [:li, 2], [:li, 3]]]])
79
- end
80
-
81
- end
82
-
83
- describe 'Hiccup specs' do
84
-
85
- describe 'basic tags' do
86
- specify { expect(described_class.new([:div]).call).to eq("<div></div>\n") }
87
- specify { expect(described_class.new(["div"]).call).to eq("<div></div>\n") }
88
- end
89
-
90
- describe 'tag syntax sugar' do
91
- specify { expect(described_class.new([:'div#foo']).call).to eq("<div id=\"foo\"></div>\n") }
92
- specify { expect(described_class.new([:'div.foo']).call).to eq("<div class=\"foo\"></div>\n") }
93
- specify { expect(described_class.new([:'div.foo', ["bar", "baz"].join]).call).
94
- to eq("<div class=\"foo\">barbaz</div>\n") }
95
- specify { expect(described_class.new([:'div.a.b']).call).to eq("<div class=\"a b\"></div>\n") }
96
- specify { expect(described_class.new([:'div.a.b.c']).call).to eq("<div class=\"a b c\"></div>\n") }
97
- specify { expect(described_class.new([:'div#foo.bar.baz']).call).
98
- to eq("<div class=\"bar baz\" id=\"foo\"></div>\n") }
99
- end
100
-
101
- describe 'tag contents' do
102
- specify { expect(described_class.new([:div]).call).to eq("<div></div>\n") }
103
- specify { expect(described_class.new([:h1]).call).to eq("<h1></h1>\n") }
104
- specify { expect(described_class.new([:script]).call).to eq("<script></script>\n") }
105
- specify { expect(described_class.new([:text]).call).to eq("<text></text>\n") }
106
- specify { expect(described_class.new([:a]).call).to eq("<a></a>\n") }
107
- specify { expect(described_class.new([:iframe]).call).to eq("<iframe></iframe>\n") }
108
- specify { expect(described_class.new([:title]).call).to eq("<title></title>\n") }
109
- specify { expect(described_class.new([:section]).call).to eq("<section></section>\n") }
110
- specify { expect(described_class.new([:select]).call).to eq("<select></select>\n") }
111
- specify { expect(described_class.new([:object]).call).to eq("<object></object>\n") }
112
- specify { expect(described_class.new([:video]).call).to eq("<video></video>\n") }
113
- end
114
-
115
- describe 'tags containing text' do
116
- specify { expect(described_class.new([:text, "Lorem Ipsum"]).call).
117
- to eq("<text>Lorem Ipsum</text>\n") }
118
- end
119
-
120
- describe 'contents are concatenated' do
121
- specify { expect(described_class.new([:body, "foo", "bar"]).call).
122
- to eq("<body>foobar</body>\n") }
123
- specify { expect(described_class.new([:body, [:p], [:br]]).call).
124
- to eq("<body>\n<p></p>\n<br>\n</body>\n") }
125
- end
126
-
127
- describe 'seqs are expanded' do
128
- specify { expect(described_class.new([:body, ["foo", "bar"]]).call).
129
- to eq("<body>foobar</body>\n") }
130
- end
131
-
132
- describe 'tags can contain tags' do
133
- specify { expect(described_class.new([:div, [:p]]).call).
134
- to eq("<div><p></p></div>\n") }
135
- specify { expect(described_class.new([:div, [:b]]).call).
136
- to eq("<div><b></b></div>\n") }
137
- specify { expect(described_class.new([:p, [:span, [:a, "foo"]]]).call).
138
- to eq("<p><span><a>foo</a></span></p>\n") }
139
- end
140
-
141
- describe 'tag with blank attribute map' do
142
- specify { expect(described_class.new([:xml, {}]).call).
143
- to eq("<xml></xml>\n") }
144
- end
145
-
146
- describe 'tag with populated attribute map' do
147
- specify { expect(described_class.new([:xml, {a: "1", b: "2"}]).call).
148
- to eq("<xml a=\"1\" b=\"2\"></xml>\n") }
149
- specify { expect(described_class.new([:img, {id: "foo"}]).call).
150
- to eq("<img id=\"foo\">\n") }
151
- end
152
-
153
- describe 'tag content can be vars' do
154
- var = "foo"
155
- specify { expect(described_class.new([:span, var]).call).
156
- to eq("<span>foo</span>\n") }
157
- end
158
-
159
- describe 'tag content can be function calls' do
160
- specify { expect(described_class.new([:span, [1, 1].inject(:+)]).call).
161
- to eq("<span>2</span>\n") }
162
- specify { expect(described_class.new([:span, {foo: "bar"}.fetch(:foo)]).call).
163
- to eq("<span>bar</span>\n") }
164
- end
165
-
166
- describe 'attributes can contain vars' do
167
- var = "foo"
168
- specify { expect(described_class.new([:xml, {x: var}]).call).
169
- to eq("<xml x=\"foo\"></xml>\n") }
170
- specify { expect(described_class.new([:xml, {x: var}, "bar"]).call).
171
- to eq("<xml x=\"foo\">bar</xml>\n") }
172
- end
173
-
174
- describe 'attributes can contain function calls' do
175
-
176
- def foo
177
- "foo"
178
- end
179
-
180
- specify { expect(described_class.new([:img, {src: ["/foo", "/bar"].join}]).call).
181
- to eq("<img src=\"/foo/bar\">\n") }
182
- specify { expect(described_class.new([:div, {id: ["a", "b"].join}, foo]).call).
183
- to eq("<div id=\"ab\">foo</div>\n") }
50
+ expect(html).to eq("<div></div>")
184
51
  end
185
52
 
186
53
  end
@@ -3,7 +3,7 @@ require 'commaparty/parse_body'
3
3
 
4
4
  describe CommaParty::ParseBody do
5
5
 
6
- it 'returns [] for tags with no body' do
6
+ it 'returns nil for tags with no body' do
7
7
  body = described_class.new([:tag]).call
8
8
  expect(body).to eq([])
9
9
  end
@@ -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("<html><tag></tag></html>\n")
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("<tag/>\n")
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("<tag></tag>\n")
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>\n" }
25
- it { expect(CommaParty.markup [:p, "hello"]).to eq "<p>hello</p>\n" }
26
- it { expect(CommaParty.markup [:p, [:em, "hello"]]).to eq "<p><em>hello</em></p>\n" }
27
- it { expect(CommaParty.markup [:span, {:class => "foo"}, "bar"]).to eq "<span class=\"foo\">bar</span>\n" }
28
- it { expect(CommaParty.markup [:div, {id: "email", class: "selected starred"}, "..."]).to eq "<div id=\"email\" class=\"selected starred\">...</div>\n" }
29
- it { expect(CommaParty.markup [:a, {:href => "http://github.com"}, "GitHub"]).to eq "<a href=\"http://github.com\">GitHub</a>\n"}
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>\n"}
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>\n"}
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>\n" }
38
- it { expect(CommaParty.markup [:'p#hi', "hello"]).to eq "<p id=\"hi\">hello</p>\n" }
39
- it { expect(CommaParty.markup [:'p.hi.greet.left', "hello"]).to eq "<p class=\"hi greet left\">hello</p>\n" }
40
- it { expect(CommaParty.markup [:'p#hi.greet.left', "hello"]).to eq "<p class=\"greet left\" id=\"hi\">hello</p>\n" }
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>\n" }
45
- it { expect(CommaParty.markup [:div, [:p, "Hello"], [:em, "World!"]]).to eq "<div>\n<p>Hello</p>\n<em>World!</em>\n</div>\n" }
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.2
4
+ version: 0.0.3pre
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-12 00:00:00.000000000 Z
11
+ date: 2014-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -95,7 +95,6 @@ files:
95
95
  - Rakefile
96
96
  - commaparty.gemspec
97
97
  - lib/commaparty.rb
98
- - lib/commaparty/.markup.rb.swn
99
98
  - lib/commaparty/destructure_element.rb
100
99
  - lib/commaparty/html.rb
101
100
  - lib/commaparty/markup.rb
@@ -127,9 +126,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
126
  version: '0'
128
127
  required_rubygems_version: !ruby/object:Gem::Requirement
129
128
  requirements:
130
- - - '>='
129
+ - - '>'
131
130
  - !ruby/object:Gem::Version
132
- version: '0'
131
+ version: 1.3.1
133
132
  requirements: []
134
133
  rubyforge_project:
135
134
  rubygems_version: 2.0.3
Binary file