commaparty 0.0.1pre → 0.0.1

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: 03a8339495655f770639b4379f0efd00ed002bc4
4
- data.tar.gz: 3e7f1c68a4075921dfc9499db7be3d74d4689456
3
+ metadata.gz: fb1260fe51a78f3ddb15ecaf6dde6b7bf4454153
4
+ data.tar.gz: 20b13794581d73bc1c5320e13823db4f9110785e
5
5
  SHA512:
6
- metadata.gz: 63980a3c5b5cf2b9849443cdb99a9f1937f8bbc6e8d24cdd9b060c7ca11e4f3b7cb6ba9bc14befe22eec5988489f40ac0cf18a3e3819e8521c211684f3745ce4
7
- data.tar.gz: fa24ef4475c3e4e55cb46b6405a1ccd826bb5d568abdd12858c7156a2e8b6f4766a68ab7e30dba1bf1a8a2860f6d86d2c85c54aad4c4e8eb54b37c0fb3f90575
6
+ metadata.gz: d740c51a965cb0432cf7115707abedcb8865f855460aa527eab4688e9678b553be9143898919799e17f889fd30d22f8db462c939a4ae43675ec6768d64b84e06
7
+ data.tar.gz: 79977c9adcd41ff2140d07156ad2f9874d54e1b4c8edffc062027765292c2388335ba63f8c5aad710582b9a7e7290d16f4efb2dc29fe3659f897fa422bdd8ef1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
data/README.md CHANGED
@@ -1,9 +1,12 @@
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
6
- attributes. Unlike in Clojure, you have to use a lot of commas everywhere.
8
+ attributes. Unlike in Clojure, you have to use a lot of commas everywhere all
9
+ the time.
7
10
 
8
11
  Install
9
12
  -------
@@ -25,42 +28,31 @@ Syntax
25
28
  Here is a basic example of commaparty syntax:
26
29
 
27
30
  ```ruby
28
- user=> (use 'hiccup.core)
29
- nil
30
- user=> (html [:span {:class "foo"} "bar"])
31
- "<span class=\"foo\">bar</span>"
31
+ [1] pry(main)> require 'commaparty'
32
+ => true
33
+ [2] pry(main)> CommaParty.markup([:span, {class: "foo"}, "bar"])
34
+ => "<span class=\"foo\">bar</span>"
32
35
  ```
33
36
 
34
- The first element of the vector is used as the element name. The second
35
- attribute can optionally be a map, in which case it is used to supply
37
+ The first element of the array is used as the element name. The second
38
+ attribute can optionally be a hash, in which case it is used to supply
36
39
  the element's attributes. Every other element is considered part of the
37
40
  tag's body.
38
41
 
39
- Hiccup is intelligent enough to render different HTML elements in
40
- different ways, in order to accommodate browser quirks:
41
-
42
- ```clojure
43
- user=> (html [:script])
44
- "<script></script>"
45
- user=> (html [:p])
46
- "<p />"
47
- ```
42
+ It provides a CSS-like shortcut for denoting `id` and `class`
43
+ attributes:
48
44
 
49
- And provides a CSS-like shortcut for denoting `id` and `class`
50
- attributes:
45
+ ```ruby
46
+ [1] pry(main)> CommaParty.markup([:'div#foo.bar.baz', "bang"])
47
+ => "<div class=\"bar baz\" id=\"foo\">bang</div>"
48
+ ```
51
49
 
52
- ```clojure
53
- user=> (html [:div#foo.bar.baz "bang"])
54
- "<div id=\"foo\" class=\"bar baz\">bang</div>"
55
- ```
50
+ If the body of the element is an array, its contents will be expanded out
51
+ into the element body. This makes working with methods like `map` more
52
+ convenient:
56
53
 
57
- If the body of the element is a seq, its contents will be expanded out
58
- into the element body. This makes working with forms like `map` and
59
- `for` more convenient:
60
54
 
61
- ```clojure
62
- user=> (html [:ul
63
- (for [x (range 1 4)]
64
- [:li x])])
65
- "<ul><li>1</li><li>2</li><li>3</li></ul>"
66
- ```
55
+ ```ruby
56
+ [2] pry(main)> CommaParty.markup([:ul, (1..4).map {|n| [:li, n]}])
57
+ => "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n<li>4</li>\n</ul>"
58
+ ```
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
data/commaparty.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "pry-nav"
26
27
  end
@@ -1,3 +1,5 @@
1
+ require 'commaparty/parse_attributes'
2
+ require 'commaparty/parse_body'
1
3
  require 'commaparty/parse_tag'
2
4
 
3
5
  module CommaParty
@@ -14,22 +16,12 @@ module CommaParty
14
16
  private
15
17
 
16
18
  def normalize_element(element)
17
- tag, tag_attributes = CommaParty::ParseTag.new(element.shift).call
18
- tag = safe_tagname(tag)
19
- attributes = attribute(element) || {}
19
+ tag, tag_attributes = CommaParty::ParseTag.new(element).call
20
+ attributes = CommaParty::ParseAttributes.new(element).call
21
+ body = CommaParty::ParseBody.new(element).call
20
22
  [tag,
21
23
  attributes.merge(tag_attributes),
22
- element]
23
- end
24
-
25
- def safe_tagname(tag)
26
- "#{tag.to_s}_".to_sym
27
- end
28
-
29
- def attribute(element)
30
- if element.first && element.first.is_a?(Hash)
31
- element.shift
32
- end
24
+ body]
33
25
  end
34
26
 
35
27
  end
@@ -4,32 +4,44 @@ require 'commaparty/destructure_element'
4
4
  module CommaParty
5
5
  class Markup
6
6
 
7
- def initialize(*hiccup)
8
- @hiccup = hiccup
7
+ def initialize(hiccup)
8
+ @hiccup = [hiccup]
9
9
  end
10
10
 
11
11
  def call
12
- build(*@hiccup)
12
+ build(@hiccup).doc.to_html
13
+ end
14
+
15
+ def builder
16
+ build(@hiccup)
17
+ end
18
+
19
+ def hiccup
20
+ @hiccup.flatten(1)
13
21
  end
14
22
 
15
23
  private
16
24
 
17
- 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
25
+ def build(elements)
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)
28
34
  tag, attributes, children = CommaParty::DestructureElement.new(element).call
29
- if children.empty? || children.first.is_a?(String)
30
- node.send(tag, attributes) {|n| n << children.first }
31
- else
32
- node.send(tag, attributes) {|n| n << build(*children) }
35
+ node.send(tag, attributes) {|n| make_nodes(n, children) }
36
+ end
37
+
38
+ def make_nodes(parent, children)
39
+ children.each do |child|
40
+ if child.is_a?(String) || child.is_a?(Fixnum) || child.nil?
41
+ parent << child.to_s
42
+ else
43
+ create_child(parent, child)
44
+ end
33
45
  end
34
46
  end
35
47
 
@@ -0,0 +1,17 @@
1
+ module CommaParty
2
+ class ParseAttributes
3
+
4
+ def initialize(element)
5
+ @attributes = element[1]
6
+ end
7
+
8
+ def call
9
+ if @attributes.is_a?(Hash)
10
+ @attributes
11
+ else
12
+ {}
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module CommaParty
2
+ class ParseBody
3
+
4
+ def initialize(element)
5
+ @element = element
6
+ end
7
+
8
+ def call
9
+ if nested?
10
+ body.flatten(1)
11
+ else
12
+ body
13
+ end
14
+ end
15
+
16
+ def body
17
+ @body ||=
18
+ if @element[1].is_a?(Hash)
19
+ @element[2..-1]
20
+ else
21
+ @element[1..-1]
22
+ end
23
+ end
24
+
25
+ def nested?
26
+ body[0].is_a?(Array) && !body[0][0].is_a?(Symbol)
27
+ end
28
+
29
+ end
30
+ end
@@ -2,11 +2,11 @@ module CommaParty
2
2
  class ParseTag
3
3
 
4
4
  def initialize(tag)
5
- @tag = tag
5
+ @tag = tag[0]
6
6
  end
7
7
 
8
8
  def call
9
- [tag_name, attributes]
9
+ [safe_tag_name, attributes]
10
10
  end
11
11
 
12
12
  private
@@ -32,5 +32,9 @@ module CommaParty
32
32
  @tag.to_s.match(/([^\.,#,\b]+)/).captures.first.to_sym
33
33
  end
34
34
 
35
+ def safe_tag_name
36
+ "#{tag_name.to_s}_".to_sym
37
+ end
38
+
35
39
  end
36
40
  end
@@ -1,3 +1,3 @@
1
1
  module CommaParty
2
- VERSION = "0.0.1pre"
2
+ VERSION = "0.0.1"
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
 
@@ -5,38 +5,52 @@ describe CommaParty::DestructureElement do
5
5
 
6
6
  describe 'Normalizing elements' do
7
7
  it 'destructures an element with tag only' do
8
- tag, attributes, values = described_class.new([:lol]).call
8
+ tag, attributes, body = described_class.new([:lol]).call
9
9
  expect(tag).to eq(:lol_)
10
10
  expect(attributes).to eq({})
11
- expect(values).to eq([])
11
+ expect(body).to eq([])
12
12
  end
13
13
 
14
- it 'destructures an element with tag, attributes, and values' do
15
- tag, attributes, values = described_class.new([:lol, {id: "the-id"}, "lol"]).call
14
+ it 'destructures an element with tag, attributes, and body' do
15
+ tag, attributes, body = described_class.new([:lol, {id: "the-id"}, "lol"]).call
16
16
  expect(tag).to eq(:lol_)
17
17
  expect(attributes).to eq({id: "the-id"})
18
- expect(values).to eq(["lol"])
18
+ expect(body).to eq(["lol"])
19
19
  end
20
20
 
21
21
  it 'destructures an element with tag and attributes only' do
22
- tag, attributes, values = described_class.new([:lol, {id: "the-id"}]).call
22
+ tag, attributes, body = described_class.new([:lol, {id: "the-id"}]).call
23
23
  expect(tag).to eq(:lol_)
24
24
  expect(attributes).to eq({id: "the-id"})
25
- expect(values).to eq([])
25
+ expect(body).to eq([])
26
26
  end
27
27
 
28
- it 'destructures an element with tag and values only' do
29
- tag, attributes, values = described_class.new([:lol, 'wut']).call
28
+ it 'destructures an element with tag and body only' do
29
+ tag, attributes, body = described_class.new([:lol, 'wut']).call
30
30
  expect(tag).to eq(:lol_)
31
31
  expect(attributes).to eq({})
32
- expect(values).to eq(['wut'])
32
+ expect(body).to eq(['wut'])
33
33
  end
34
34
 
35
35
  it 'destructures an element with sibling children' do
36
- tag, attributes, values = described_class.new([:lol, {}, [:div], [:ul], [:other]]).call
36
+ tag, attributes, body = described_class.new([:lol, {}, [:div, {lol: 'wut'}], [:ul], [:other]]).call
37
37
  expect(tag).to eq(:lol_)
38
38
  expect(attributes).to eq({})
39
- expect(values).to eq([[:div], [:ul], [:other]])
39
+ expect(body).to eq([[:div, {lol: 'wut'}], [:ul], [:other]])
40
+ end
41
+
42
+ it 'destructures an element with an array of children' do
43
+ tag, attributes, body = described_class.new([:ul, ["one", "two", "three"].map {|n| [:li, n]}]).call
44
+ expect(tag).to eq(:ul_)
45
+ expect(attributes).to eq({})
46
+ expect(body).to eq([[:li, "one"], [:li, "two"], [:li, "three"]])
47
+ end
48
+
49
+ it 'destructures an element with a tag in the body' do
50
+ tag, attributes, body = described_class.new([:p, [:em, "hello"]]).call
51
+ expect(tag).to eq(:p_)
52
+ expect(attributes).to eq({})
53
+ expect(body).to eq([[:em, "hello"]])
40
54
  end
41
55
  end
42
56
  end
@@ -7,37 +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
- html = described_class.new([:tag1], [:tag2]).call
25
- expect(html).to eq("<tag1></tag1><tag2></tag2>")
24
+ html = described_class.new([:div, [:tag1], [:tag2]]).call
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
+ end
42
+
43
+ it 'handles seqs in the tag body' do
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]]]])
41
73
  end
42
74
 
43
75
  end
@@ -0,0 +1,21 @@
1
+ require 'rspec'
2
+ require 'commaparty/parse_attributes'
3
+
4
+ describe CommaParty::ParseAttributes do
5
+
6
+ it 'extracts attributes when explicitly included' do
7
+ attributes = described_class.new([:tag, {attribute: 'value'}]).call
8
+ expect(attributes).to eq({attribute: 'value'})
9
+ end
10
+
11
+ it 'extracts attributes when not explicitly included' do
12
+ attributes = described_class.new([:tag]).call
13
+ expect(attributes).to eq({})
14
+ end
15
+
16
+ it 'extracts default attributes when the tag has a body' do
17
+ attributes = described_class.new([:tag, 'body']).call
18
+ expect(attributes).to eq({})
19
+ end
20
+
21
+ end
@@ -0,0 +1,36 @@
1
+ require 'rspec'
2
+ require 'commaparty/parse_body'
3
+
4
+ describe CommaParty::ParseBody do
5
+
6
+ it 'returns [] for tags with no body' do
7
+ body = described_class.new([:tag]).call
8
+ expect(body).to eq([])
9
+ end
10
+
11
+ it 'returns the body for tags with a body' do
12
+ body = described_class.new([:tag, 'body']).call
13
+ expect(body).to eq(['body'])
14
+ end
15
+
16
+ it 'returns [] for tags with attributes and no body' do
17
+ body = described_class.new([:tag, {}]).call
18
+ expect(body).to eq([])
19
+ end
20
+
21
+ it 'returns the body for tags with attributes and a body' do
22
+ body = described_class.new([:tag, {}, 'body']).call
23
+ expect(body).to eq(['body'])
24
+ end
25
+
26
+ it 'returns the body for tags with attributes and a body' do
27
+ body = described_class.new([:p, [:em, "hello"]]).call
28
+ expect(body).to eq([[:em, 'hello']])
29
+ end
30
+
31
+ it 'returns the body for tags with attributes and a body' do
32
+ body = described_class.new([:p, "Hello ", [:em, "World!"]]).call
33
+ expect(body).to eq(["Hello ", [:em, "World!"]])
34
+ end
35
+
36
+ end
@@ -6,40 +6,52 @@ describe CommaParty::ParseTag do
6
6
  describe 'Tag shortcuts' do
7
7
 
8
8
  it 'parses tags without shortcut syntax' do
9
- tag, attributes = described_class.new(:boring).call
10
- expect(tag).to eq(:boring)
9
+ tag, attributes = described_class.new([:boring]).call
10
+ expect(tag).to eq(:boring_)
11
11
  expect(attributes).to eq({})
12
12
  end
13
13
 
14
14
  it 'parses tags with a class shortcut' do
15
- tag, attributes = described_class.new(:'exciting.class').call
16
- expect(tag).to eq(:exciting)
15
+ tag, attributes = described_class.new([:'exciting.class']).call
16
+ expect(tag).to eq(:exciting_)
17
17
  expect(attributes).to eq({class: 'class'})
18
18
  end
19
19
 
20
20
  it 'parses tags with an id shortcut' do
21
- tag, attributes = described_class.new(:'exciting#id').call
22
- expect(tag).to eq(:exciting)
21
+ tag, attributes = described_class.new([:'exciting#id']).call
22
+ expect(tag).to eq(:exciting_)
23
23
  expect(attributes).to eq({id: 'id'})
24
24
  end
25
25
 
26
26
  it 'parses tags with a class shortcut and id shortcut' do
27
- tag, attributes = described_class.new(:'exciting.class#id').call
28
- expect(tag).to eq(:exciting)
27
+ tag, attributes = described_class.new([:'exciting.class#id']).call
28
+ expect(tag).to eq(:exciting_)
29
29
  expect(attributes).to eq({class: 'class', id: 'id'})
30
30
  end
31
31
 
32
32
  it 'handles different orders' do
33
- tag, attributes = described_class.new(:'exciting#id.class').call
34
- expect(tag).to eq(:exciting)
33
+ tag, attributes = described_class.new([:'exciting#id.class']).call
34
+ expect(tag).to eq(:exciting_)
35
35
  expect(attributes).to eq({class: 'class', id: 'id'})
36
36
  end
37
37
 
38
38
  it 'handles multiple classes' do
39
- tag, attributes = described_class.new(:'exciting.one.two').call
40
- expect(tag).to eq(:exciting)
39
+ tag, attributes = described_class.new([:'exciting.one.two']).call
40
+ expect(tag).to eq(:exciting_)
41
41
  expect(attributes).to eq({class: 'one two'})
42
42
  end
43
+
44
+ it 'handles tags with attributes' do
45
+ tag, attributes = described_class.new([:tag, {}]).call
46
+ expect(tag).to eq(:tag_)
47
+ expect(attributes).to eq({})
48
+ end
49
+
50
+ it 'handles tags with attributes and values' do
51
+ tag, attributes = described_class.new([:tag, {}, 'value']).call
52
+ expect(tag).to eq(:tag_)
53
+ expect(attributes).to eq({})
54
+ end
43
55
  end
44
56
 
45
57
  end
@@ -0,0 +1,48 @@
1
+ require 'commaparty'
2
+
3
+ describe CommaParty do
4
+
5
+ it 'has a helpful html method' do
6
+ expect(CommaParty.html([:tag])).to match("<html><tag></tag></html>\n")
7
+ end
8
+
9
+ it 'has a helpful xml method' do
10
+ expect(CommaParty.xml([:tag])).to match("<tag/>\n")
11
+ end
12
+
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]))
21
+ end
22
+
23
+ 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"}
30
+
31
+ 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"}
34
+ end
35
+
36
+ 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" }
41
+ end
42
+
43
+ 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" }
46
+ end
47
+ end
48
+ 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.1pre
4
+ version: 0.0.1
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-02-22 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-nav
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: A ruby implementation of Clojure's Hiccup markup generation library.
70
84
  email:
71
85
  - ecmendenhall@gmail.com
@@ -74,6 +88,7 @@ extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
90
  - .gitignore
91
+ - .travis.yml
77
92
  - Gemfile
78
93
  - LICENSE.txt
79
94
  - README.md
@@ -83,14 +98,19 @@ files:
83
98
  - lib/commaparty/destructure_element.rb
84
99
  - lib/commaparty/html.rb
85
100
  - lib/commaparty/markup.rb
101
+ - lib/commaparty/parse_attributes.rb
102
+ - lib/commaparty/parse_body.rb
86
103
  - lib/commaparty/parse_tag.rb
87
104
  - lib/commaparty/version.rb
88
105
  - lib/commaparty/xml.rb
89
106
  - spec/commaparty/destructure_element_spec.rb
90
107
  - spec/commaparty/html_spec.rb
91
108
  - spec/commaparty/markup_spec.rb
109
+ - spec/commaparty/parse_attributes_spec.rb
110
+ - spec/commaparty/parse_body_spec.rb
92
111
  - spec/commaparty/parse_tag_spec.rb
93
112
  - spec/commaparty/xml_spec.rb
113
+ - spec/commaparty_spec.rb
94
114
  homepage: https://github.com/ecmendenhall/commaparty
95
115
  licenses:
96
116
  - MIT
@@ -106,9 +126,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
126
  version: '0'
107
127
  required_rubygems_version: !ruby/object:Gem::Requirement
108
128
  requirements:
109
- - - '>'
129
+ - - '>='
110
130
  - !ruby/object:Gem::Version
111
- version: 1.3.1
131
+ version: '0'
112
132
  requirements: []
113
133
  rubyforge_project:
114
134
  rubygems_version: 2.0.3
@@ -119,5 +139,8 @@ test_files:
119
139
  - spec/commaparty/destructure_element_spec.rb
120
140
  - spec/commaparty/html_spec.rb
121
141
  - spec/commaparty/markup_spec.rb
142
+ - spec/commaparty/parse_attributes_spec.rb
143
+ - spec/commaparty/parse_body_spec.rb
122
144
  - spec/commaparty/parse_tag_spec.rb
123
145
  - spec/commaparty/xml_spec.rb
146
+ - spec/commaparty_spec.rb