commaparty 0.0.1 → 0.0.2pre

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: fb1260fe51a78f3ddb15ecaf6dde6b7bf4454153
4
- data.tar.gz: 20b13794581d73bc1c5320e13823db4f9110785e
3
+ metadata.gz: 3ff205c728b610398ebae49f09f8b3f7bd76b7aa
4
+ data.tar.gz: 2fa31a4f7a4267c4a4ddadc1d8288f6b7872f7c2
5
5
  SHA512:
6
- metadata.gz: d740c51a965cb0432cf7115707abedcb8865f855460aa527eab4688e9678b553be9143898919799e17f889fd30d22f8db462c939a4ae43675ec6768d64b84e06
7
- data.tar.gz: 79977c9adcd41ff2140d07156ad2f9874d54e1b4c8edffc062027765292c2388335ba63f8c5aad710582b9a7e7290d16f4efb2dc29fe3659f897fa422bdd8ef1
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
@@ -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,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
- 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)
@@ -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) || child.nil?
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)
@@ -1,3 +1,3 @@
1
1
  module CommaParty
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2pre"
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,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>\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
29
  html = described_class.new([:theparent, [:tag1], [:tag2]]).call
30
- expect(html).to eq("<theparent><tag1></tag1><tag2></tag2></theparent>\n")
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>\n")
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>\n")
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>\n")
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
@@ -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.1
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-10 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
@@ -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: '0'
130
+ version: 1.3.1
132
131
  requirements: []
133
132
  rubyforge_project:
134
133
  rubygems_version: 2.0.3
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.0
4
- - 2.0.0
5
- - 1.9.3