ruby_html 0.0.3 → 0.0.4

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
  SHA256:
3
- metadata.gz: e4875574430eb91491d8bc9df2596a672b27f7af4c64d69cf346846e2da34bff
4
- data.tar.gz: 53e7cd3caafb6d3c7494f2ffc41460a620548d3c40768ab167d0dcd513bb0819
3
+ metadata.gz: b034710a87722e625acd301794325c89c5ddabe186f6293b20a1529e2a0ef0f1
4
+ data.tar.gz: 6585a22ff7f15f3568062645259550247e9a1e8d0add3dd1b74a0c949ce142eb
5
5
  SHA512:
6
- metadata.gz: dc3efe40d2695bda6044721fc28e6d20fb2818f841c3fab757fae165d0d22fc3fe3166140e765a1622547bd803fe5e5a6e3cbffe51fc32f5aca6e755f4e45e86
7
- data.tar.gz: d84b875bf71c100fd786bb150e0427ada92bb85455178cfcf9212db38308914039f599d00e132457120b5983249a12cbfca8e9a99157e2becc587e4681945036
6
+ metadata.gz: a08bebc39b11f328a313924e7596d37cab8f919248a200f4bccad852b4cd8975aed9a5f64a8f7d3b360030da1119ec0f25142087e168218a23dd8549d26a1806
7
+ data.tar.gz: 001d5efa900a8382c8348848e33733e2efdbdbed33852fbbd52b16c18b646bcc42522d5ac6f2be6395f66e64b46d08fe1e999e29dc1d5fce207f0102478ee462
data/README.md CHANGED
@@ -23,14 +23,14 @@ Or install it yourself as:
23
23
  HTML elements have the names you think they would. For example, to create a div:
24
24
 
25
25
  ```
26
- div = Div.new
26
+ div = HTML::Div.new
27
27
  ```
28
28
 
29
29
  Elements can receive arguments. These can be strings, or can be other elements themselves.
30
30
  These elements will be nested under their parent.
31
31
 
32
32
  ```
33
- div = Div.new("Hello", P.new("World"))
33
+ div = HTML::Div.new("Hello", 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.
@@ -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 = Div.new(H6.new("Hello"), "World")
49
+ div = HTML::Div.new(H6.new("Hello"), "World")
50
50
  div.render
51
51
  => "<div><h6>Hello</h6>World</div>"
52
52
  ```
@@ -54,7 +54,7 @@ div.render
54
54
  To add attributes to an element, pass a hash to the object like so:
55
55
 
56
56
  ```
57
- p_with_class = P.new("Hello World", attributes: { "class": "red" })
57
+ p_with_class = HTML::P.new("Hello World", attributes: { "class": "red" })
58
58
  p_with_class.render
59
59
  => <p class='red'>Hello World</p>
60
60
  ```
@@ -63,21 +63,22 @@ Most importantly, if you want to actually create an HTML page, you'll want to cr
63
63
  A document recieves elements, as well as header elements (such as `<title>` or `<style>`).
64
64
 
65
65
  ```
66
- title = Title.new("Page Title")
67
- Document.new(Div.new, header_elements: [title])
66
+ title = HTML::Title.new("Page Title")
67
+ Document.new(HTML::Div.new, header_elements: [title])
68
68
  ```
69
69
 
70
70
  `Document` has a special method, `#render_to_file` that receives a file path, and creates your html document there.
71
71
 
72
72
  ```
73
- Document.new.render_to_file("hello_world.html")
73
+ HTML::Document.new.render_to_file("hello_world.html")
74
74
  => creates html document
75
75
  ```
76
76
 
77
77
 
78
78
  ### TODO
79
79
 
80
- - Build out remaining elements. There are a few that conflict with ruby (such as `Object`).
80
+ - Build out remaining elements. There are a few that conflict with ruby (such as `Object`). This should not be an issue anymore
81
+ now that the `HTML` namespace has been added.
81
82
  - Code clean up (alphabetical order, some methods probably don't need to be public, etc).
82
83
  - The single quotes for attributes are a bit weird, and you might not always want those.
83
84
  - It desperately needs some tests!
@@ -1,26 +1,28 @@
1
- class Document < Element
2
- attr_reader :header_elements
1
+ module HTML
2
+ class Document < Element
3
+ attr_reader :header_elements
3
4
 
4
- def initialize(*elements, header_elements: [])
5
- @elements = elements
6
- @header_elements = header_elements.flatten
7
- end
5
+ def initialize(*elements, header_elements: [])
6
+ @elements = elements
7
+ @header_elements = header_elements.flatten
8
+ end
8
9
 
9
- def opening_tag
10
- "<!DOCTYPE><html><head>#{rendered_header_elements}</head><body>"
11
- end
10
+ def opening_tag
11
+ "<!DOCTYPE><html><head>#{rendered_header_elements}</head><body>"
12
+ end
12
13
 
13
- def rendered_header_elements
14
- header_elements.map do |element|
15
- element.render
16
- end.join("")
17
- end
14
+ def rendered_header_elements
15
+ header_elements.map do |element|
16
+ element.render
17
+ end.join("")
18
+ end
18
19
 
19
- def closing_tag
20
- "</body></html>"
21
- end
20
+ def closing_tag
21
+ "</body></html>"
22
+ end
22
23
 
23
- def render_to_file(path)
24
- File.open(path, "w") { |file| file.write(render) }
24
+ def render_to_file(path)
25
+ File.open(path, "w") { |file| file.write(render) }
26
+ end
25
27
  end
26
28
  end
@@ -1,55 +1,57 @@
1
- class Element
2
- attr_reader :elements, :attributes
1
+ module HTML
2
+ class Element
3
+ attr_reader :elements, :attributes
3
4
 
4
- def initialize(*elements, attributes: {})
5
- @elements = elements
6
- @attributes = attributes
7
- end
5
+ def initialize(*elements, attributes: {})
6
+ @elements = elements
7
+ @attributes = attributes
8
+ end
8
9
 
9
- def add_elements(*new_elements)
10
- new_elements.each do |element|
11
- @elements.push(element)
10
+ def add_elements(*new_elements)
11
+ new_elements.each do |element|
12
+ @elements.push(element)
13
+ end
12
14
  end
13
- end
14
15
 
15
- def add_attribute(attribute_hash)
16
- @attributes.merge!(attribute_hash)
17
- ## TODO: Account for adding elements that already exist.
18
- end
16
+ def add_attribute(attribute_hash)
17
+ @attributes.merge!(attribute_hash)
18
+ ## TODO: Account for adding elements that already exist.
19
+ end
19
20
 
20
- def render
21
- opening_tag + rendered_elements + closing_tag
22
- end
23
-
24
- def rendered_elements
25
- elements.map do |element|
26
- if element.is_a? String
27
- element
21
+ def render
22
+ opening_tag + rendered_elements + closing_tag
23
+ end
24
+
25
+ def rendered_elements
26
+ elements.map do |element|
27
+ if element.is_a? String
28
+ element
29
+ else
30
+ element.render
31
+ end
32
+ end.join("")
33
+ end
34
+
35
+ def tag
36
+ self.class.name.downcase
37
+ end
38
+
39
+ def opening_tag
40
+ if rendered_attributes != ""
41
+ "<#{tag} #{rendered_attributes}>"
28
42
  else
29
- element.render
43
+ "<#{tag}>"
30
44
  end
31
- end.join("")
32
- end
33
-
34
- def tag
35
- self.class.name.downcase
36
- end
37
-
38
- def opening_tag
39
- if rendered_attributes != ""
40
- "<#{tag} #{rendered_attributes}>"
41
- else
42
- "<#{tag}>"
43
45
  end
44
- end
45
46
 
46
- def closing_tag
47
- "</#{tag}>"
48
- end
47
+ def closing_tag
48
+ "</#{tag}>"
49
+ end
49
50
 
50
- def rendered_attributes
51
- attributes.map do |k, v|
52
- "#{k}='#{v}'"
53
- end.join(" ")
51
+ def rendered_attributes
52
+ attributes.map do |k, v|
53
+ "#{k}='#{v}'"
54
+ end.join(" ")
55
+ end
54
56
  end
55
57
  end
@@ -114,6 +114,6 @@ elements = %w(
114
114
  )
115
115
 
116
116
  elements.each do |klass_name|
117
- klass = Class.new(Element)
118
- Object.const_set(klass_name, klass)
117
+ klass = Class.new(HTML::Element)
118
+ HTML.const_set(klass_name, klass)
119
119
  end
@@ -1,3 +1,3 @@
1
1
  module RubyHtml
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  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.3
4
+ version: 0.0.4
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-05 00:00:00.000000000 Z
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: engtagger