yaks-html 0.9.0 → 0.10.0

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: ed93c7c669916c02044d83a3551c54ae5bfe3453
4
- data.tar.gz: b65cb8b1b64bfb732fd7d7a64e7839035ed07a7f
3
+ metadata.gz: 00098aaad249008d6a0748ed5d94483be2eb6694
4
+ data.tar.gz: e870922d4a96e4bd90ca12c31c4b5be8e71e0428
5
5
  SHA512:
6
- metadata.gz: 1f434db45836fa126ffb99da5416d98d43ffeb4448d32bf252a1c533336ab5872d0f48787f391df2c055597ab26e240c1b11c9584e50095c16bbb7651607d294
7
- data.tar.gz: d29d68208ab4b5688cf34b6709ef9c7f228b4a8fde9885e76c6d393962ae78335e02cc7827326818a72514ae2ee3270f268e4426ecca0b2482fb2bc5d15d5e32
6
+ metadata.gz: 73a42d1ca3639992a8ac660d15e5359d8e9647e67e0a5cc75aaa78eedad9cac63b01b0cf611bfc8e0fc9deb1a02d9636c6611e8bfb5ac787740580fb8e129766
7
+ data.tar.gz: 625d9f5d71a110d4c07383e6cca9a69fb27a89dbe1595591931c305e76804f5e1aad00134da11ad4bc720e1ae24b99646aade45aec92485268bee34ea623a550
@@ -3,6 +3,6 @@ require 'yaks'
3
3
  require 'yaks/format/html'
4
4
 
5
5
  -> do
6
- unparser = Hexp::Unparser.new({})
7
- Yaks::Serializer.register(:html, ->(data, env) { unparser.call(data) })
6
+ unparser = Hexp::Unparser.new(no_escape: [:script, :style])
7
+ Yaks::Serializer.register(:html, ->(data, _env) { unparser.call(data) })
8
8
  end.call
@@ -12,12 +12,12 @@ module Yaks
12
12
  end
13
13
 
14
14
  def section(name)
15
- template.select(".#{name}").first
15
+ template.select(".#{name}").first # rubocop:disable Performance/Detect
16
16
  end
17
17
 
18
18
  def serialize_resource(resource)
19
19
  template.replace('.resource') do |_|
20
- render_resource(resource)
20
+ render(resource)
21
21
  end.replace('.yaks-version') do |ver|
22
22
  ver.content(Yaks::VERSION)
23
23
  end.replace('.request-info') do |req|
@@ -25,6 +25,12 @@ module Yaks
25
25
  end
26
26
  end
27
27
 
28
+ def render(*args)
29
+ object = args.first
30
+ type = object.class.name.split('::').last
31
+ send("render_#{underscore(type)}", *args)
32
+ end
33
+
28
34
  def render_resource(resource, templ = section('resource'))
29
35
  templ
30
36
  .replace('.type') { |header| header.content(resource.type.to_s + (resource.collection? ? ' collection' : '')) }
@@ -33,6 +39,8 @@ module Yaks
33
39
  .replace('.forms') {|div| render_forms(resource.forms).call(div) }
34
40
  .replace('.subresource') {|sub_templ| render_subresources(resource, templ, sub_templ) }
35
41
  end
42
+ alias_method :render_collection_resource, :render_resource
43
+ alias_method :render_null_resource, :render_resource
36
44
 
37
45
  def render_attributes(attributes)
38
46
  ->(templ) do
@@ -56,8 +64,13 @@ module Yaks
56
64
  ->(templ) do
57
65
  links.map do |link|
58
66
  templ
59
- .replace('.rel a') {|a| a.attr('href', rel_href(link.rel)).content(link.rel.to_s) }
60
- .replace('.uri a') {|a| a.attr('href', link.uri).content(link.uri) }
67
+ .replace('.rel a') {|a|
68
+ a.attr('href', rel_href(link.rel)).content(link.rel.to_s)
69
+ }
70
+ .replace('.uri a') {|a|
71
+ a.attr('href', link.uri).content(link.uri)
72
+ .attr('rel', link.rel.to_s)
73
+ }
61
74
  .replace('.title') {|x| x.content(link.title.to_s) }
62
75
  .replace('.templated') {|x| x.content(link.templated?.inspect) }
63
76
  end
@@ -65,26 +78,28 @@ module Yaks
65
78
  end
66
79
 
67
80
  def render_subresources(resource, templ, sub_templ)
68
- templ = templ.replace('h1,h2,h3,h4') {|h| h.set_tag("h#{h.tag[/\d/].to_i.next}") }
81
+ templ = templ
82
+ .replace('h1,h2,h3,h4') {|h| h.set_tag("h#{h.tag[/\d/].to_i.next}") }
83
+ .add_class('collapsed')
69
84
  if resource.collection?
70
85
  resource.seq.map do |r|
71
- render_resource(r, templ)
86
+ render(r, templ)
72
87
  end
73
88
  else
74
89
  resource.subresources.map do |resources|
75
90
  rel = resources.rels.first
76
91
  sub_templ
77
92
  .replace('.rel a') {|a| a.attr('href', rel_href(rel)).content(rel.to_s) }
78
- .replace('.value') {|x| x.content(resources.seq.map { |resource| render_resource(resource, templ) })}
93
+ .replace('.value') {|x| x.content(resources.seq.map { |res| render(res, templ) })}
94
+ .attr('rel', rel.to_s)
79
95
  end
80
96
  end
81
97
  end
82
98
 
83
-
84
99
  def render_forms(forms)
85
100
  ->(div) do
86
101
  div.content(
87
- forms.map(&method(:render_form))
102
+ forms.map(&method(:render))
88
103
  )
89
104
  end
90
105
  end
@@ -96,7 +111,7 @@ module Yaks
96
111
  form = form.attr('action', form_control.action) if form_control.action
97
112
  form = form.attr('enctype', form_control.media_type) if form_control.media_type
98
113
 
99
- rows = form_control.fields.map(&method(:render_field))
114
+ rows = form_control.fields.map(&method(:render))
100
115
  rows << H[:tr, H[:td], H[:td, H[:input, {type: 'submit'}]]]
101
116
 
102
117
  H[:div,
@@ -105,7 +120,6 @@ module Yaks
105
120
  end
106
121
 
107
122
  def render_field(field)
108
- return render_fieldset(field) if field.type == :fieldset
109
123
  extra_info = reject_keys(field.to_h_compact, :type, :name, :value, :label, :options)
110
124
  H[:tr,
111
125
  H[:td,
@@ -116,8 +130,6 @@ module Yaks
116
130
  H[:select, reject_keys(field.to_h_compact, :options), render_select_options(field.options)]
117
131
  when /textarea/
118
132
  H[:textarea, reject_keys(field.to_h_compact, :value), field.value || '']
119
- when /legend/
120
- H[:legend, field.to_h_compact]
121
133
  when /hidden/
122
134
  [ field.value.inspect,
123
135
  H[:input, field.to_h_compact]
@@ -130,12 +142,13 @@ module Yaks
130
142
  end
131
143
 
132
144
  def render_fieldset(fieldset)
133
- legend = fieldset.fields.select {|field|field.type == :legend}.first
134
- legend = legend ? legend.name : ''
145
+ legend = fieldset.fields.find {|field| field.type == :legend}
146
+ fields = fieldset.fields.reject {|field| field.type == :legend}
147
+ legend = legend ? legend.label : ''
135
148
 
136
149
  H[:tr,
137
150
  H[:th, legend],
138
- H[:td, H[:fieldset, H[:table, fieldset.fields.map(&method(:render_field))]]]]
151
+ H[:td, H[:fieldset, H[:table, fields.map(&method(:render))]]]]
139
152
  end
140
153
 
141
154
  def render_select_options(options)
@@ -70,6 +70,26 @@
70
70
  .footer {
71
71
  margin-top: 1em;
72
72
  }
73
+
74
+ .collapsed .heading::before, .expanded .heading::before {
75
+ font-size: 0.6em;
76
+ display: block;
77
+ float: left;
78
+ margin-top: 0.4em;
79
+ margin-right: 0.5em;
80
+ }
81
+
82
+ .collapsed .heading::before {
83
+ content: "▶";
84
+ }
85
+
86
+ .expanded .heading::before {
87
+ content: "▼";
88
+ }
89
+
90
+ .collapsed .body {
91
+ display: none;
92
+ }
73
93
  </style>
74
94
  </head>
75
95
  <body>
@@ -77,40 +97,65 @@
77
97
  </div>
78
98
 
79
99
  <div class="resource">
80
- <h1 class="type">Resource Type</h1>
81
-
82
- <table class="attributes">
83
- <tr class="attribute"><td class="name">name</td><td class="value">value</td></tr>
84
- </table>
85
-
86
- <table class="links">
87
- <tr>
88
- <th>Rel</th>
89
- <th>URI</th>
90
- <th>Title</th>
91
- <th>Templated</th>
92
- </tr>
93
-
94
- <tr class="link">
95
- <td class="rel"><a href="">rel</a></td>
96
- <td class="uri"><a href="">uri</a></td>
97
- <td class="title">title</td>
98
- <td class="templated">false</td>
99
- </tr>
100
- </table>
101
-
102
- <div class="forms"></div>
103
-
104
- <div class="subresource">
105
- <div class="subresource-rel rel"><a></a></div>
106
- <div class="value"></div>
107
- </div>
100
+ <h1 class="heading type">Resource Type</h1>
101
+
102
+ <div class="resource-data body">
103
+ <table class="attributes">
104
+ <tr class="attribute"><td class="name">name</td><td class="value">value</td></tr>
105
+ </table>
106
+
107
+ <table class="links">
108
+ <tr>
109
+ <th>Rel</th>
110
+ <th>URI</th>
111
+ <th>Title</th>
112
+ <th>Templated</th>
113
+ </tr>
114
+
115
+ <tr class="link">
116
+ <td class="rel"><a href="">rel</a></td>
117
+ <td class="uri"><a href="">uri</a></td>
118
+ <td class="title">title</td>
119
+ <td class="templated">false</td>
120
+ </tr>
121
+ </table>
122
+
123
+ <div class="forms"></div>
124
+
125
+ <div class="subresource collapsed">
126
+ <div class="subresource-rel rel heading"><a></a></div>
127
+ <div class="value body" class="collapsed"></div>
128
+ </div>
108
129
 
130
+ </div>
109
131
  </div>
110
132
 
111
133
  <div class="footer">
112
134
  generated with <a href="https://github.com/plexus/yaks">Yaks <span class="yaks-version"></span></a>
113
135
  </div>
114
136
 
137
+ <script>
138
+ function setupCollapseExpand() {
139
+ var nodes = document.getElementsByClassName("heading");
140
+
141
+ for (var i=0; i < nodes.length; i++) {
142
+ var node = nodes[i];
143
+ node.onclick = function() {
144
+ var parent = this.parentNode;
145
+ if (parent.className.indexOf("collapsed") >= 0) {
146
+ parent.className = parent.className.replace("collapsed", "expanded");
147
+ } else {
148
+ parent.className = parent.className.replace("expanded", "collapsed");
149
+ }
150
+ };
151
+ }
152
+ };
153
+
154
+ if (window.addEventListener) {
155
+ window.addEventListener("load", setupCollapseExpand, false);
156
+ } else if (window.attachEvent) {
157
+ window.attachEvent("onload", setupCollapseExpand);
158
+ }
159
+ </script>
115
160
  </body>
116
161
  </html>
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'English'
3
4
  require File.expand_path('../../yaks/lib/yaks/version', __FILE__)
4
5
 
5
6
  Gem::Specification.new do |gem|
@@ -13,10 +14,12 @@ Gem::Specification.new do |gem|
13
14
  gem.license = 'MIT'
14
15
 
15
16
  gem.require_paths = %w[lib]
16
- gem.files = `git ls-files`.split($/)
17
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
18
  gem.test_files = gem.files.grep(/^spec/)
18
19
  gem.extra_rdoc_files = %w[README.md]
19
20
 
21
+ gem.required_ruby_version = '>= 1.9.3'
22
+
20
23
  gem.add_runtime_dependency 'yaks', Yaks::VERSION
21
24
  gem.add_runtime_dependency 'hexp', '>= 0.4'
22
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaks-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arne Brasseur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-17 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaks
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.0
19
+ version: 0.10.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.0
26
+ version: 0.10.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hexp
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -65,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.9.3
69
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
- rubygems_version: 2.2.2
76
+ rubygems_version: 2.4.5
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: HTML output format for Yaks