object-view 0.4.8 → 0.4.9

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: 7fdbf95fc20bfc771a92a231f4e4d078da74e972
4
- data.tar.gz: 1cab6105620ccfdbf64eb8120499b38b2983a552
3
+ metadata.gz: e5ef04d593b48cf9662d57e22b02fb146231a0a0
4
+ data.tar.gz: 532a9bd9f58fa1ce23e77ea214a36b4ddf981677
5
5
  SHA512:
6
- metadata.gz: 4f2ad765044ab6ee361b22f0a9691e25b69dbc2e0a2f6ca22e10379144cdb5c733c67123811ba95fb69e83e92bdcf41316c903498914ee9e50cc2bd9a701c35a
7
- data.tar.gz: 7011650f82ac301ce98fd23914a4c2ede0354c668567c0f0aa853a862b5f9e4fd595f14fdc8f6c0fde96637f58a2a2fa55ee6e7debc8c77997bcbb82d7d5ba9c
6
+ metadata.gz: 4c0eb12bc3d84dcc42331a854451e41c8e477e3357b54fa1938eec7de83ab0ff664a227beb65317b57f1a1554e400efaa19301d0a103b3f80eb11437a11690f2
7
+ data.tar.gz: 3c692b9e8e3330ccb7281941e48f23c275f666c737f59c05ccaaafa2e78f7da6417a887534035c4d7c671019c489f525d3ac706e0f3a1183db6eb6d498762a94
data/lib/object-view.rb CHANGED
@@ -12,6 +12,8 @@ require_relative 'object_view/table'
12
12
  require_relative "object_view/link"
13
13
  require_relative "object_view/ul"
14
14
  require_relative "object_view/chart_data"
15
+ require_relative "object_view/paragraph"
16
+ require_relative "object_view/nav"
15
17
 
16
18
 
17
19
  module ObjectView
@@ -2,19 +2,26 @@ require_relative './errors/illegal_child_element_error'
2
2
 
3
3
  module ObjectView
4
4
 
5
- class Element
6
- attr_accessor :tag, :attributes, :single_line
5
+ class Element < Hash
6
+ attr_accessor :tag, :single_line
7
7
  attr_reader :children, :acceptable_children
8
8
 
9
9
  def initialize
10
10
  @tab = " "
11
11
  @single_line = false
12
12
  @tag = nil
13
- @attributes = Hash.new
14
13
  @children = []
15
14
  @acceptable_children = [String, Element]
16
15
  end
17
16
 
17
+ def attributes
18
+ return self
19
+ end
20
+
21
+ def style
22
+ self[:style] = {} if (!self[:style])
23
+ return self[:style]
24
+ end
18
25
 
19
26
  def find_element_with_tag(tag)
20
27
  found = []
@@ -33,7 +40,7 @@ module ObjectView
33
40
  end
34
41
 
35
42
  def attr(name, value)
36
- @attributes[name] = value
43
+ self[name] = value
37
44
  end
38
45
 
39
46
  def acceptable_children=(value)
@@ -66,14 +73,16 @@ module ObjectView
66
73
  end
67
74
 
68
75
  def add(element_or_string)
69
- if (self.is_acceptable_child?(element_or_string))
70
- @children << element_or_string
71
- elsif (element_or_string.is_a?(Array))
72
- element_or_string.each do |child|
73
- add child
76
+ if (element_or_string)
77
+ if (self.is_acceptable_child?(element_or_string))
78
+ @children << element_or_string
79
+ elsif (element_or_string.is_a?(Array))
80
+ element_or_string.each do |child|
81
+ add child
82
+ end
83
+ else
84
+ raise IllegalChildElementError.new "Parent: #{self.tag} - Attempt to add an element that is not a valid child, and not an ObjectView::Element. Class of element: #{element_or_string.class.name}: #{element_or_string}\nTag of parent: #{self.tag}.\nAcceptable children: #{@acceptable_children.join(',')}"
74
85
  end
75
- else
76
- raise IllegalChildElementError.new "Parent: #{self.tag} - Attempt to add an element that is not a valid child, and not an ObjectView::Element. Class of element: #{element_or_string.class.name}: #{element_or_string}\nTag of parent: #{self.tag}.\nAcceptable children: #{@acceptable_children.join(',')}"
77
86
  end
78
87
  return element_or_string
79
88
  end
@@ -114,8 +123,8 @@ module ObjectView
114
123
 
115
124
  def render_attributes
116
125
  html = StringIO.new
117
- if (@attributes.length > 0)
118
- @attributes.each do |name, value|
126
+ if (self.keys.length > 0)
127
+ self.each do |name, value|
119
128
  if (value.class == Hash)
120
129
  attr_value = ''
121
130
  value.keys.each do |key|
@@ -139,26 +148,29 @@ module ObjectView
139
148
  if (indent != nil)
140
149
  html << (@tab * indent)
141
150
  end
142
- html << "<#{tag}#{render_attributes}>"
143
- if (self.single_line)
144
- html << "#{render_children(nil)}"
145
- else
146
- if (indent == nil)
147
- html << render_children(indent)
151
+ if (children.length > 0)
152
+ html << "<#{tag}#{render_attributes}>"
153
+ if (self.single_line)
154
+ html << "#{render_children(nil)}"
148
155
  else
149
- html << render_children(indent + 1)
156
+ if (indent == nil)
157
+ html << render_children(indent)
158
+ else
159
+ html << render_children(indent + 1)
160
+ end
150
161
  end
151
- end
152
-
153
-
154
- if (!self.single_line)
155
- html << "\n"
156
- if (indent != nil)
157
- html << @tab * indent
162
+
163
+ if (!self.single_line)
164
+ html << "\n"
165
+ if (indent != nil)
166
+ html << @tab * indent
167
+ end
158
168
  end
169
+ html << "</#{tag}>\n"
170
+ else
171
+ html << "<#{tag}#{render_attributes}/>"
159
172
  end
160
-
161
- html << "</#{tag}>\n"
173
+
162
174
  return html.string
163
175
  end
164
176
 
@@ -2,6 +2,7 @@ require_relative './element'
2
2
  require_relative './javascript'
3
3
  require_relative './javascript_file'
4
4
  require_relative './link'
5
+ require_relative './stylesheet'
5
6
 
6
7
  module ObjectView
7
8
 
@@ -10,7 +11,32 @@ module ObjectView
10
11
  def initialize
11
12
  super
12
13
  @tag = "head"
13
- self.acceptable_children = [Javascript, JavascriptFile, Link]
14
+ self.acceptable_children = [Javascript, JavascriptFile, Stylesheet, Title, String]
15
+ end
16
+
17
+ def add_stylesheet(path, id = Time.new.to_i.to_s)
18
+ link = self.add Stylesheet.new
19
+ link[:href] = path
20
+ link[:id] = id
21
+ link[:type] = 'text/css'
22
+ link[:media] = 'screen'
23
+ link[:rel] = 'stylesheet'
24
+ return link
25
+ end
26
+
27
+ def add_title(title)
28
+ self.add Title.new(title)
29
+ end
30
+
31
+ end
32
+
33
+ class Title < Element
34
+
35
+ def initialize(title)
36
+ super()
37
+ @tag = "title"
38
+ self.acceptable_children = [String]
39
+ self.add title if (title)
14
40
  end
15
41
  end
16
42
 
@@ -10,6 +10,7 @@ module ObjectView
10
10
  attr("type", "text/javascript")
11
11
  attr("src", file)
12
12
  @tag = "script"
13
+ self.add " "
13
14
  end
14
15
 
15
16
 
@@ -0,0 +1,12 @@
1
+ module ObjectView
2
+
3
+ class Nav < Element
4
+ def initialize(content = nil)
5
+ super()
6
+ @tag = "nav"
7
+ if (content != nil)
8
+ self.add content
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module ObjectView
2
+
3
+ class Paragraph < Element
4
+
5
+ def initialize(content = nil)
6
+ super()
7
+ @tag = "p"
8
+ if (content != nil)
9
+ self.add content
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require_relative './element'
2
+
3
+ module ObjectView
4
+
5
+ class Stylesheet < Element
6
+
7
+ def initialize
8
+ super
9
+ @tag = "link"
10
+ self.acceptable_children = []
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -112,7 +112,7 @@ module ObjectView
112
112
  super()
113
113
  self.single_line = true
114
114
  @tag = "td"
115
- self.acceptable_children = [Table, Div, Span, Javascript, Link, String]
115
+ self.acceptable_children = [Table, Div, Span, Javascript, Link, String, Header, Paragraph]
116
116
  end
117
117
  end
118
118
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-14 00:00:00.000000000 Z
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -86,8 +86,11 @@ files:
86
86
  - lib/object_view/javascript.rb
87
87
  - lib/object_view/javascript_file.rb
88
88
  - lib/object_view/link.rb
89
+ - lib/object_view/nav.rb
89
90
  - lib/object_view/page.rb
91
+ - lib/object_view/paragraph.rb
90
92
  - lib/object_view/span.rb
93
+ - lib/object_view/stylesheet.rb
91
94
  - lib/object_view/table.rb
92
95
  - lib/object_view/ul.rb
93
96
  homepage: https://github.com/mikejmoore/object-view