ruby_html 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,14 +30,14 @@ Elements can receive arguments. These can be strings, or can be other elements t
30
30
  These elements will be nested under their parent.
31
31
 
32
32
  ```
33
- div = HTML::Div.new("Hello", P.new("World"))
33
+ div = HTML::Div.new("Hello", HTML::P.new("World"))
34
34
  ```
35
35
 
36
36
  You can also add new elements to a previously created element with `#add_elements`, which accepts any number of arguments.
37
37
 
38
38
  ```
39
39
  div.add_elements("Hello")
40
- div.add_elements("Hello", "From", H3.new("Earth"))
40
+ div.add_elements("Hello", "From", HTML::H3.new("Earth"))
41
41
  ```
42
42
 
43
43
  You can pass the same element as an argument as many times as you want - just like a partial or component.
@@ -46,7 +46,7 @@ All elements have a method `#render`, which prints all the element's contents (c
46
46
  contained within.
47
47
 
48
48
  ```
49
- div = HTML::Div.new(H6.new("Hello"), "World")
49
+ div = HTML::Div.new(HTML::H6.new("Hello"), "World")
50
50
  div.render
51
51
  => "<div><h6>Hello</h6>World</div>"
52
52
  ```
@@ -81,7 +81,7 @@ HTML::Document.new.render_to_file("hello_world.html")
81
81
  now that the `HTML` namespace has been added.
82
82
  - Code clean up (alphabetical order, some methods probably don't need to be public, etc).
83
83
  - The single quotes for attributes are a bit weird, and you might not always want those.
84
- - It desperately needs some tests!
84
+ - Example in the docs of how to use with Rails, and maybe a full document built with ruby_html.
85
85
 
86
86
  ### Contributing
87
87
 
@@ -24,5 +24,9 @@ module HTML
24
24
  def render_to_file(path)
25
25
  File.open(path, "w") { |file| file.write(render) }
26
26
  end
27
+
28
+ def add_attribute(arg)
29
+ raise NotImplementedError
30
+ end
27
31
  end
28
32
  end
@@ -1,3 +1,3 @@
1
1
  module RubyHtml
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe HTML::Document do
4
+ it "can be created" do
5
+ expect(HTML::Document.new).to_not eq nil
6
+ end
7
+
8
+ context "when passed an element" do
9
+ let(:document) { HTML::Document.new(HTML::Div.new) }
10
+
11
+ it "can be created" do
12
+ expect(document).to_not eq nil
13
+ end
14
+
15
+ describe "#render" do
16
+ it "renders the correct string" do
17
+ rendered = "<!DOCTYPE><html><head></head><body><div></div></body></html>"
18
+ expect(document.render).to eq rendered
19
+ end
20
+ end
21
+ end
22
+
23
+ context "when passed header_elements" do
24
+ let(:document) { HTML::Document.new(header_elements: [HTML::Title.new("Title")]) }
25
+
26
+ it "can be created" do
27
+ expect(document).to_not eq nil
28
+ end
29
+
30
+ describe "#render" do
31
+ it "renders the correct string" do
32
+ rendered = "<!DOCTYPE><html><head><title>Title</title></head><body></body></html>"
33
+ expect(document.render).to eq rendered
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -1,40 +1,81 @@
1
1
  require "spec_helper"
2
+
2
3
  RSpec.shared_examples "HTML element" do |element|
3
4
  let(:klass) do
4
5
  Object.const_get("HTML::#{element}")
5
6
  end
6
7
 
8
+ let(:tag) { element.downcase }
9
+
7
10
  it "can be created" do
8
11
  expect do
9
12
  klass.new
10
13
  end.to_not raise_error
11
14
  end
12
-
13
- it "can be created with string content" do
14
- end
15
-
16
- it "can be created with another element as content" do
15
+
16
+ context "when passed a string" do
17
+ let(:el) { klass.new("Hello World") }
18
+
19
+ it "can be created" do
20
+ expect(el).to_not eq nil
21
+ end
22
+
23
+ describe "#render" do
24
+ it "returns the correct string" do
25
+ rendered = "<#{tag}>Hello World</#{tag}>"
26
+ expect(el.render).to eq rendered
27
+ end
28
+ end
17
29
  end
30
+
31
+ context "when passed another element as content" do
32
+ let(:el) { klass.new(klass.new) }
33
+
18
34
 
19
- it "can be created with multiple elements as content" do
35
+ it "can be created" do
36
+ expect(el).to_not eq nil
37
+ end
38
+
39
+ describe "#render" do
40
+ it "returns the correct string" do
41
+ rendered = "<#{tag}><#{tag}></#{tag}></#{tag}>"
42
+ expect(el.render).to eq rendered
43
+ end
44
+ end
20
45
  end
21
46
 
22
- it "can be created with attributes" do
47
+ context "when passed multiple elements as content" do
48
+ let(:el) { klass.new(klass.new, klass.new) }
49
+
50
+ it "can be created" do
51
+ expect(el).to_not eq nil
52
+ end
53
+
54
+ it "returns the correct string" do
55
+ rendered = "<#{tag}><#{tag}></#{tag}><#{tag}></#{tag}></#{tag}>"
56
+ expect(el.render).to eq rendered
57
+ end
23
58
  end
59
+
60
+ context "when passed attributes" do
61
+ let(:el) { klass.new(klass.new, attributes: { "class": "red" }) }
24
62
 
25
- describe "#render" do
26
- it "returns a string" do
63
+ it "can be created" do
64
+ expect(el).to_not eq nil
27
65
  end
28
66
 
29
67
  it "returns the correct string" do
30
- end
31
-
32
- it "returns the correct string when it has attributes" do
68
+ rendered = "<#{tag} class='red'><#{tag}></#{tag}></#{tag}>"
69
+ expect(el.render).to eq rendered
33
70
  end
34
71
  end
35
72
 
36
73
  describe "#add_attribute" do
37
74
  it "will append an attribute" do
75
+ el = klass.new
76
+ el.add_attribute({"id": "some-id"})
77
+ rendered = "<#{tag} id='some-id'></#{tag}>"
78
+ expect(el.render).to eq rendered
38
79
  end
39
80
  end
40
81
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Thom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-09 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: engtagger
@@ -87,7 +87,6 @@ files:
87
87
  - lib/ruby_html/version.rb
88
88
  - ruby_html.gemspec
89
89
  - spec/document_spec.rb
90
- - spec/element_spec.rb
91
90
  - spec/elements_spec.rb
92
91
  - spec/spec_helper.rb
93
92
  homepage: ''
@@ -116,6 +115,5 @@ specification_version: 4
116
115
  summary: ''
117
116
  test_files:
118
117
  - spec/document_spec.rb
119
- - spec/element_spec.rb
120
118
  - spec/elements_spec.rb
121
119
  - spec/spec_helper.rb
data/spec/element_spec.rb DELETED
File without changes