yaks-html 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yaks/format/html.rb +25 -10
- data/lib/yaks/format/template.html +58 -21
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1555d183278030c85a244d6ea424eb409f656a26
|
4
|
+
data.tar.gz: d363127634e680fe518587797db332ca7a717090
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05253a6638552c33c602d6676a545a2c17515cd6f802dd8c59e85c199acd4a9d3dd12d4acb63936a3b511812a1d99ef4c047f0777d3071cf812222b87222dd6f
|
7
|
+
data.tar.gz: f420be1f76999f21547c2458538925dc781cb22d842728085ddebd7511e1fb0730f618df7a91f4e439151b0f7b0c7048377d6db13a3663e82ebb167499bbe6d7
|
data/lib/yaks/format/html.rb
CHANGED
@@ -3,22 +3,25 @@
|
|
3
3
|
module Yaks
|
4
4
|
class Format
|
5
5
|
class HTML < self
|
6
|
-
include
|
6
|
+
include Util
|
7
7
|
|
8
8
|
register :html, :html, 'text/html'
|
9
9
|
|
10
10
|
def template
|
11
|
-
Hexp.parse(File.read(File.expand_path('../template.html', __FILE__)))
|
11
|
+
@template ||= Hexp.parse(File.read(File.expand_path('../template.html', __FILE__)))
|
12
12
|
end
|
13
|
-
memoize :template
|
14
13
|
|
15
14
|
def section(name)
|
16
15
|
template.select(".#{name}").first
|
17
16
|
end
|
18
17
|
|
19
18
|
def serialize_resource(resource)
|
20
|
-
template.replace('
|
21
|
-
|
19
|
+
template.replace('.resource') do |_|
|
20
|
+
render_resource(resource)
|
21
|
+
end.replace('.yaks-version') do |ver|
|
22
|
+
ver.content(Yaks::VERSION)
|
23
|
+
end.replace('.request-info') do |req|
|
24
|
+
req.content(env['REQUEST_METHOD'], ' ', env['PATH_INFO'])
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
@@ -41,11 +44,19 @@ module Yaks
|
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
47
|
+
def rel_href(rel)
|
48
|
+
if rel.is_a?(Symbol)
|
49
|
+
"http://www.iana.org/assignments/link-relations/link-relations.xhtml"
|
50
|
+
else
|
51
|
+
rel.to_s
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
44
55
|
def render_links(links)
|
45
56
|
->(templ) do
|
46
57
|
links.map do |link|
|
47
58
|
templ
|
48
|
-
.replace('.rel a') {|a| a.attr('href', link.rel
|
59
|
+
.replace('.rel a') {|a| a.attr('href', rel_href(link.rel)).content(link.rel.to_s) }
|
49
60
|
.replace('.uri a') {|a| a.attr('href', link.uri).content(link.uri) }
|
50
61
|
.replace('.title') {|x| x.content(link.title.to_s) }
|
51
62
|
.replace('.templated') {|x| x.content(link.templated?.inspect) }
|
@@ -61,9 +72,9 @@ module Yaks
|
|
61
72
|
end
|
62
73
|
else
|
63
74
|
resource.subresources.map do |resources|
|
64
|
-
rel = resources.rels.first
|
75
|
+
rel = resources.rels.first
|
65
76
|
sub_templ
|
66
|
-
.replace('.rel a') {|a| a.attr('href', rel).content(rel) }
|
77
|
+
.replace('.rel a') {|a| a.attr('href', rel_href(rel)).content(rel.to_s) }
|
67
78
|
.replace('.value') {|x| x.content(resources.seq.map { |resource| render_resource(resource, templ) })}
|
68
79
|
end
|
69
80
|
end
|
@@ -87,7 +98,7 @@ module Yaks
|
|
87
98
|
|
88
99
|
rows = form_control.fields.map(&method(:render_field))
|
89
100
|
|
90
|
-
form.content(H[:table, form_control.title ||
|
101
|
+
form.content(H[:table, H[:h4, form_control.title || form_control.name.to_s], *rows, H[:tr, H[:td], H[:td, H[:input, {type: 'submit'}]]]])
|
91
102
|
end
|
92
103
|
|
93
104
|
def render_field(field)
|
@@ -95,7 +106,7 @@ module Yaks
|
|
95
106
|
extra_info = reject_keys(field.to_h_compact, :type, :name, :value, :label, :options)
|
96
107
|
H[:tr,
|
97
108
|
H[:td,
|
98
|
-
H[:label, {for: field.name}, [field.label, field.required ? '*' : ''].join]],
|
109
|
+
H[:label, {for: field.name}, [field.label || field.name.to_s, field.required ? '*' : ''].join]],
|
99
110
|
H[:td,
|
100
111
|
case field.type
|
101
112
|
when /select/
|
@@ -104,6 +115,10 @@ module Yaks
|
|
104
115
|
H[:textarea, reject_keys(field.to_h_compact, :value), field.value || '']
|
105
116
|
when /legend/
|
106
117
|
H[:legend, field.to_h_compact]
|
118
|
+
when /hidden/
|
119
|
+
[ field.value.inspect,
|
120
|
+
H[:input, field.to_h_compact]
|
121
|
+
]
|
107
122
|
else
|
108
123
|
H[:input, field.to_h_compact]
|
109
124
|
end],
|
@@ -4,44 +4,78 @@
|
|
4
4
|
<meta charset="utf-8">
|
5
5
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6
6
|
<style type="text/css">
|
7
|
+
* {
|
8
|
+
box-sizing: border-box;
|
9
|
+
}
|
10
|
+
|
7
11
|
body {
|
8
|
-
background-color: #
|
12
|
+
background-color: #F9E9DE;
|
13
|
+
margin: 0;
|
14
|
+
font-family: sans-serif;
|
9
15
|
}
|
10
16
|
|
11
17
|
.resource {
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
margin-left: 0.3em;
|
19
|
+
padding-left: 0.3em;
|
20
|
+
}
|
21
|
+
|
22
|
+
body .resource {
|
23
|
+
padding-right: 0.5em;
|
24
|
+
}
|
25
|
+
|
26
|
+
.resource .resource {
|
27
|
+
border-left: 4px solid #bababa;
|
15
28
|
}
|
16
29
|
|
17
30
|
h1,h2,h3,h4,h5 {
|
18
|
-
background-color: #
|
19
|
-
|
31
|
+
background-color: #FFB662;
|
32
|
+
padding: 0.2em;
|
20
33
|
margin-bottom: 0.2em;
|
21
|
-
border-radius: 8px;
|
22
34
|
}
|
23
35
|
|
24
|
-
|
25
|
-
|
36
|
+
.attributes {
|
37
|
+
margin-bottom: 0.2em;
|
38
|
+
}
|
39
|
+
|
40
|
+
th { background-color: #FFD19D; }
|
41
|
+
td { background-color: #E2ECBA; }
|
42
|
+
|
43
|
+
.rel a {
|
44
|
+
color: black;
|
45
|
+
text-decoration: none;
|
46
|
+
}
|
26
47
|
|
27
48
|
.subresource {
|
28
|
-
|
29
|
-
border-radius: 8px;
|
30
|
-
margin: 0.5em;
|
31
|
-
margin-left: 1em;
|
49
|
+
padding-top: 1em;
|
32
50
|
}
|
33
51
|
|
34
|
-
.subresource
|
35
|
-
background-color: #
|
36
|
-
|
37
|
-
|
38
|
-
|
52
|
+
.subresource-rel {
|
53
|
+
background-color: #FFB662;
|
54
|
+
padding: 0.5em;
|
55
|
+
margin-bottom: 0.5em;
|
56
|
+
}
|
57
|
+
|
58
|
+
.header, .footer {
|
59
|
+
width: 100%;
|
60
|
+
background-color: black;
|
61
|
+
color: white;
|
62
|
+
padding: 0.3em;
|
63
|
+
}
|
39
64
|
|
65
|
+
.footer a {
|
66
|
+
text-decoration: none;
|
67
|
+
color: white;
|
40
68
|
}
|
41
69
|
|
70
|
+
.footer {
|
71
|
+
margin-top: 1em;
|
72
|
+
}
|
42
73
|
</style>
|
43
74
|
</head>
|
44
75
|
<body>
|
76
|
+
<div class="header request-info">
|
77
|
+
</div>
|
78
|
+
|
45
79
|
<div class="resource">
|
46
80
|
<h1 class="type">Resource Type</h1>
|
47
81
|
|
@@ -50,7 +84,6 @@
|
|
50
84
|
</table>
|
51
85
|
|
52
86
|
<table class="links">
|
53
|
-
Links:
|
54
87
|
<tr>
|
55
88
|
<th>Rel</th>
|
56
89
|
<th>URI</th>
|
@@ -66,14 +99,18 @@
|
|
66
99
|
</tr>
|
67
100
|
</table>
|
68
101
|
|
102
|
+
<div class="forms"></div>
|
103
|
+
|
69
104
|
<div class="subresource">
|
70
|
-
<div class="rel"><a></a></div>
|
105
|
+
<div class="subresource-rel rel"><a></a></div>
|
71
106
|
<div class="value"></div>
|
72
107
|
</div>
|
73
108
|
|
74
|
-
<div class="forms"></div>
|
75
109
|
</div>
|
76
110
|
|
111
|
+
<div class="footer">
|
112
|
+
generated with <a href="https://github.com/plexus/yaks">Yaks <span class="yaks-version"></span></a>
|
113
|
+
</div>
|
77
114
|
|
78
115
|
</body>
|
79
116
|
</html>
|
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.8.
|
4
|
+
version: 0.8.2
|
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-02
|
11
|
+
date: 2015-03-02 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.8.
|
19
|
+
version: 0.8.2
|
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.8.
|
26
|
+
version: 0.8.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: hexp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|