commaparty 0.0.3pre → 0.0.4pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ccf4025df7a717391079619f63559d9018095a7
4
- data.tar.gz: 1245299fe3cca38daa9748b5e4db70ba8fdd15c2
3
+ metadata.gz: d65c386526a36e92368ff878973c043eb17c3978
4
+ data.tar.gz: 6cf03a286ed901941f92fc07e524baa55f570ed2
5
5
  SHA512:
6
- metadata.gz: 374c05013a8e124e6a993192866604231007c6f9c8cdaccbb0ae711afebe49a832aa4c773444763f208f04db9a1699fc0eff8c509c022e817e451bcb14dda2f2
7
- data.tar.gz: b646a876669d879644a3aef76d10aa7cd7ecb788cc4ee548f78f7786efda463d2421ed903ee74f10b913ee0156d943c28301ecee6808a5193376c1340dc45905
6
+ metadata.gz: 0be2894400b3eb941b789afbdfe9a336c9512198efc9016dfd41320620d30a4cda20c22183f8d4abac90f62ac342875fec16dd27e80cb97de8e0e97add24d39a
7
+ data.tar.gz: cbc489039ff84a4131eb58ced7f781125d4300e8b6741e968cedf88f08bb975d53f3a3a265688d3a608865b8b6d682a0daa35f3f2163cb6a249fff70bf6135d7
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  CommaParty
2
2
  ======
3
+ [![Build Status](https://travis-ci.org/ecmendenhall/commaparty.png?branch=master)](https://travis-ci.org/ecmendenhall/commaparty)
4
+
3
5
  CommaParty is a Ruby implementation of Clojure's
4
6
  [Hiccup](https://github.com/weavejester/hiccup/) HTML generation library.
5
7
  It uses arrays to represent elements, and hashes to represent an element's
data/Rakefile CHANGED
@@ -1 +1,6 @@
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,19 +9,25 @@ module CommaParty
9
9
  end
10
10
 
11
11
  def call
12
+ build(@hiccup).doc.to_html
13
+ end
14
+
15
+ def builder
12
16
  build(@hiccup)
13
17
  end
14
18
 
19
+ def hiccup
20
+ @hiccup.flatten(1)
21
+ end
22
+
15
23
  private
16
24
 
17
25
  def build(elements)
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
26
+ Nokogiri::XML::Builder.new do |doc|
27
+ elements.each do |element|
28
+ create_child(doc, element)
23
29
  end
24
- end.doc.root.children.to_html
30
+ end
25
31
  end
26
32
 
27
33
  def create_child(node, element)
@@ -1,3 +1,3 @@
1
1
  module CommaParty
2
- VERSION = "0.0.3pre"
2
+ VERSION = "0.0.4pre"
3
3
  end
@@ -9,20 +9,13 @@ module CommaParty
9
9
  end
10
10
 
11
11
  def initialize(markup)
12
- @markup = CommaParty::Markup.new(markup).call
12
+ @markup = CommaParty::Markup.new(markup)
13
13
  end
14
14
 
15
15
  def call
16
- build(@markup)
16
+ @markup.builder.to_xml
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
26
19
  end
27
20
 
28
21
  end
data/lib/commaparty.rb CHANGED
@@ -17,5 +17,9 @@ 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
+
20
24
  end
21
25
 
@@ -7,47 +7,69 @@ 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>\n")
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>\n")
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>\n")
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>\n")
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>\n")
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>\n")
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>\n")
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>")
45
+ expect(html).to eq("<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>\n")
46
46
  end
47
47
 
48
48
  it 'handles nils in the tag body' do
49
49
  html = described_class.new([:div, nil]).call
50
- expect(html).to eq("<div></div>")
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]]]])
51
73
  end
52
74
 
53
75
  end
@@ -3,40 +3,46 @@ 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>')
6
+ expect(CommaParty.html([:tag])).to match("<html><tag></tag></html>\n")
7
7
  end
8
8
 
9
9
  it 'has a helpful xml method' do
10
- expect(CommaParty.xml([:tag])).to match('<tag/>')
10
+ expect(CommaParty.xml([:tag])).to match("<tag/>\n")
11
11
  end
12
12
 
13
13
  it 'has a helpful markup method' do
14
- expect(CommaParty.markup([:tag])).to match('<tag></tag>')
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]))
15
21
  end
16
22
 
17
23
  context 'converts ruby syntax to html string' do
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>"}
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"}
24
30
 
25
31
  context 'collections' do
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>"}
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"}
28
34
  end
29
35
 
30
36
  context 'css shorthand' do
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>" }
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" }
35
41
  end
36
42
 
37
43
  context 'different shaped trees' do
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>" }
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" }
40
46
  end
41
47
  end
42
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commaparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3pre
4
+ version: 0.0.4pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connor Mendenhall