yaks-html 0.6.1 → 0.6.2

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
- ---
2
- SHA1:
3
- metadata.gz: 403c75e00fe2fd800a4f8e6ed5747fa66da4677e
4
- data.tar.gz: 9d251e41e9c6b4ac6ff9d4eaf070c45e877ded89
5
- SHA512:
6
- metadata.gz: 8d762bc75008d4329a3d9d4234db3ae1ddde7f544cd53fb90aa79745a0dcd55a4310d6510c468e1c5c99c0d7f2f9a934ca7ca3363eb30485c5054c8addc1239a
7
- data.tar.gz: 33ea66e8f92da89ae5e9f190a957fc419f98b590fc483d7de0a3843da33e85f2e35ceb1eb30b4e2f5743985ddb879ad23fe3f82b64bcd62caacccbc95f1f8715
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18b28bb7180d5d6f07d0c10c40fd14a6beda9f23
4
+ data.tar.gz: cb771dc27b2dc16b7db118bfac3c342c94bcc54b
5
+ SHA512:
6
+ metadata.gz: 66db9029a90c53ddf6d3da2001b7b9a3b02a68cb92b6911db526a8e6755b6e548e0a13e009bc1a84a0efda7c3076c221d018d7565288411d9f647463dc57c6c8
7
+ data.tar.gz: 3089ec5f28fd38a2f3f09a72d92e432d5dab7039ecf17fc403ed7f6a021da5a92a445ce433487836ccbdf6f50507de5af08e87ed168478b0e11194c8bf5cc677
@@ -26,8 +26,9 @@ module Yaks
26
26
  templ
27
27
  .replace('.type') { |header| header.content(resource.type.to_s + (resource.collection? ? ' collection' : '')) }
28
28
  .replace('.attribute', &render_attributes(resource.attributes))
29
- .replace('.link', &render_links(resource.links))
30
- .replace('.subresources') {|table| resource.subresources.empty? ? [] : render_subresources(resource.subresources, templ).call(table) }
29
+ .replace('.links') {|links| resource.links.empty? ? [] : links.replace('.link', &render_links(resource.links)) }
30
+ .replace('.controls') {|div| render_controls(resource.controls).call(div) }
31
+ .replace('.subresource') {|sub_templ| render_subresources(resource, templ, sub_templ) }
31
32
  end
32
33
 
33
34
  def render_attributes(attributes)
@@ -52,19 +53,50 @@ module Yaks
52
53
  end
53
54
  end
54
55
 
55
- def render_subresources(subresources, templ)
56
+ def render_subresources(resource, templ, sub_templ)
56
57
  templ = templ.replace('h1,h2,h3,h4') {|h| h.set_tag("h#{h.tag[/\d/].to_i.next}") }
57
- ->(wrap) do
58
- wrap.replace('.subresource') { |row|
59
- subresources.map do |rel, resources|
60
- row
61
- .replace('.rel a') {|a| a.attr('href', rel.to_s).content(rel.to_s) }
62
- .replace('.value') {|x| x.content(resources.map { |resource| render_resource(resource, templ) })}
63
- end
64
- }
58
+ if resource.collection?
59
+ resource.map do |r|
60
+ render_resource(r, templ)
61
+ end
62
+ else
63
+ resource.subresources.map do |rel, resources|
64
+ sub_templ
65
+ .replace('.rel a') {|a| a.attr('href', rel.to_s).content(rel.to_s) }
66
+ .replace('.value') {|x| x.content(resources.map { |resource| render_resource(resource, templ) })}
67
+ end
65
68
  end
66
69
  end
67
70
 
71
+
72
+ def render_controls(controls)
73
+ ->(div) do
74
+ div.content(
75
+ controls.map(&method(:render_control))
76
+ )
77
+ end
78
+ end
79
+
80
+ def render_control(control)
81
+ form = H[:form]
82
+ form = form.attr('name', control.name) if control.name
83
+ form = form.attr('method', control.method) if control.method
84
+ form = form.attr('action', control.href) if control.href
85
+ form = form.attr('enctype', control.media_type) if control.media_type
86
+
87
+ rows = control.fields.map do |field|
88
+ H[:tr,
89
+ H[:td, H[:label, {for: field.name}, field.label || '']],
90
+ H[:td, case field.type
91
+ when /\A(button|checkbox|file|hidden|image|password|radio|reset|submit|text)\z/
92
+ H[:input, type: field.type, value: field.value, name: field.name]
93
+ when /textarea/
94
+ H[:textarea, { name: field.name }, field.value || '']
95
+ end]
96
+ ]
97
+ end
98
+ form.content(H[:table, control.title || '', *rows, H[:tr, H[:td, H[:input, {type: 'submit'}]]]])
99
+ end
68
100
  end
69
101
  end
70
102
  end
@@ -4,21 +4,40 @@
4
4
  <meta charset="utf-8">
5
5
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
6
  <style type="text/css">
7
+ body {
8
+ background-color: #F9CDAD;
9
+ }
10
+
7
11
  .resource {
8
- border: 1px solid black;
9
- padding: 0.3em;
12
+ border: 1px solid #83AF9B;
13
+ border-radius: 8px;
14
+ margin: 0.3em;
10
15
  }
11
16
 
12
17
  h1,h2,h3,h4,h5 {
13
- background-color: #090
18
+ background-color: #FE4365;
19
+ margin-top: 0;
20
+ margin-bottom: 0.2em;
21
+ border-radius: 8px;
14
22
  }
15
23
 
16
- table {
17
- width:99%;
24
+ th { background-color: #FC9D9A; }
25
+ td { background-color: #C8C8A9; }
26
+
27
+ .subresource {
28
+ border: 1px solid #83AF9B;
29
+ border-radius: 8px;
18
30
  margin: 0.5em;
31
+ margin-left: 1em;
19
32
  }
20
33
 
21
- th{ background-color: #fee; }
34
+ .subresource .rel {
35
+ background-color: #83AF9B;
36
+ border-radius: 8px;
37
+ padding: 0.5em;
38
+ margin-bottom: 0.5em;
39
+
40
+ }
22
41
 
23
42
  </style>
24
43
  </head>
@@ -26,12 +45,12 @@
26
45
  <div class="resource">
27
46
  <h1 class="type">Resource Type</h1>
28
47
 
29
- <table border="1" class="attributes">
30
- <tr><th>Attribute</th><th>Value</th></tr>
48
+ <table class="attributes">
31
49
  <tr class="attribute"><td class="name">name</td><td class="value">value</td></tr>
32
50
  </table>
33
51
 
34
- <table border="1" class="links">
52
+ <table class="links">
53
+ Links:
35
54
  <tr>
36
55
  <th>Rel</th>
37
56
  <th>URI</th>
@@ -47,10 +66,14 @@
47
66
  </tr>
48
67
  </table>
49
68
 
50
- <table border="1" class="subresources">
51
- <tr><th>Rel</th><th>Subresource</th></tr>
52
- <tr class="subresource"><td class="rel"><a>rel</a></td><td class="value">value</td></tr>
53
- </table>
69
+ <div class="subresource">
70
+ <div class="rel"><a></a></div>
71
+ <div class="value"></div>
72
+ </div>
73
+
74
+ <div class="controls"></div>
54
75
  </div>
76
+
77
+
55
78
  </body>
56
79
  </html>
metadata CHANGED
@@ -1,46 +1,51 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: yaks-html
3
- version: !ruby/object:Gem::Version
4
- version: 0.6.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.2
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Arne Brasseur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2014-10-30 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- version_requirements: &id001 !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "="
18
- - !ruby/object:Gem::Version
19
- version: 0.6.1
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
20
14
  name: yaks
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.2
21
20
  type: :runtime
22
- requirement: *id001
23
21
  prerelease: false
24
- - !ruby/object:Gem::Dependency
25
- version_requirements: &id002 !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: "0.4"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.2
27
+ - !ruby/object:Gem::Dependency
30
28
  name: hexp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
31
34
  type: :runtime
32
- requirement: *id002
33
35
  prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
34
41
  description: HTML output format for Yaks
35
- email:
42
+ email:
36
43
  - arne@arnebrasseur.net
37
44
  executables: []
38
-
39
45
  extensions: []
40
-
41
- extra_rdoc_files:
46
+ extra_rdoc_files:
42
47
  - README.md
43
- files:
48
+ files:
44
49
  - README.md
45
50
  - Rakefile
46
51
  - lib/yaks-html.rb
@@ -49,30 +54,28 @@ files:
49
54
  - spec/spec_helper.rb
50
55
  - yaks-html.gemspec
51
56
  homepage: https://github.com/plexus/yaks
52
- licenses:
57
+ licenses:
53
58
  - MIT
54
59
  metadata: {}
55
-
56
60
  post_install_message:
57
61
  rdoc_options: []
58
-
59
- require_paths:
62
+ require_paths:
60
63
  - lib
61
- required_ruby_version: !ruby/object:Gem::Requirement
62
- requirements:
63
- - &id003
64
- - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
67
- required_rubygems_version: !ruby/object:Gem::Requirement
68
- requirements:
69
- - *id003
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
70
74
  requirements: []
71
-
72
75
  rubyforge_project:
73
76
  rubygems_version: 2.2.2
74
77
  signing_key:
75
78
  specification_version: 4
76
79
  summary: HTML output format for Yaks
77
- test_files:
80
+ test_files:
78
81
  - spec/spec_helper.rb