yaks 0.5.0 → 0.6.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +20 -9
- data/CHANGELOG.md +2 -3
- data/Gemfile +2 -1
- data/Rakefile +29 -50
- data/yaks/README.md +526 -0
- data/{lib → yaks/lib}/yaks/breaking_changes.rb +0 -0
- data/{lib → yaks/lib}/yaks/collection_mapper.rb +0 -0
- data/{lib → yaks/lib}/yaks/collection_resource.rb +0 -0
- data/{lib → yaks/lib}/yaks/config/dsl.rb +0 -0
- data/{lib → yaks/lib}/yaks/config.rb +0 -0
- data/{lib → yaks/lib}/yaks/default_policy.rb +2 -1
- data/{lib → yaks/lib}/yaks/format/collection_json.rb +0 -0
- data/{lib → yaks/lib}/yaks/format/hal.rb +0 -0
- data/{lib → yaks/lib}/yaks/format/json_api.rb +0 -0
- data/{lib → yaks/lib}/yaks/format.rb +0 -0
- data/{lib → yaks/lib}/yaks/fp/callable.rb +0 -0
- data/{lib → yaks/lib}/yaks/fp/hash_updatable.rb +0 -0
- data/{lib → yaks/lib}/yaks/fp/updatable.rb +0 -0
- data/{lib → yaks/lib}/yaks/fp.rb +0 -0
- data/{lib → yaks/lib}/yaks/mapper/association.rb +0 -0
- data/{lib → yaks/lib}/yaks/mapper/association_mapper.rb +0 -0
- data/{lib → yaks/lib}/yaks/mapper/attribute.rb +0 -0
- data/{lib → yaks/lib}/yaks/mapper/class_methods.rb +0 -0
- data/{lib → yaks/lib}/yaks/mapper/config.rb +0 -0
- data/{lib → yaks/lib}/yaks/mapper/has_many.rb +0 -0
- data/{lib → yaks/lib}/yaks/mapper/has_one.rb +0 -0
- data/{lib → yaks/lib}/yaks/mapper/link.rb +0 -0
- data/{lib → yaks/lib}/yaks/mapper.rb +0 -0
- data/{lib → yaks/lib}/yaks/null_resource.rb +0 -0
- data/{lib → yaks/lib}/yaks/primitivize.rb +0 -0
- data/{lib → yaks/lib}/yaks/resource/link.rb +0 -0
- data/{lib → yaks/lib}/yaks/resource.rb +0 -0
- data/{lib → yaks/lib}/yaks/runner.rb +12 -1
- data/{lib → yaks/lib}/yaks/util.rb +0 -0
- data/yaks/lib/yaks/version.rb +3 -0
- data/{lib → yaks/lib}/yaks.rb +0 -0
- data/{spec → yaks/spec}/acceptance/acceptance_spec.rb +0 -0
- data/{spec → yaks/spec}/acceptance/json_shared_examples.rb +0 -0
- data/{spec → yaks/spec}/acceptance/models.rb +0 -0
- data/{spec → yaks/spec}/fixture_helpers.rb +0 -0
- data/{spec → yaks/spec}/integration/map_to_resource_spec.rb +0 -0
- data/{spec → yaks/spec}/json/confucius.collection.json +0 -0
- data/{spec → yaks/spec}/json/confucius.hal.json +0 -0
- data/{spec → yaks/spec}/json/confucius.json_api.json +0 -0
- data/{spec → yaks/spec}/json/john.hal.json +0 -0
- data/{spec → yaks/spec}/json/plant_collection.collection.json +0 -0
- data/{spec → yaks/spec}/json/plant_collection.hal.json +0 -0
- data/{spec → yaks/spec}/json/youtypeitwepostit.collection.json +0 -0
- data/{spec → yaks/spec}/spec_helper.rb +0 -0
- data/{spec → yaks/spec}/support/classes_for_policy_testing.rb +0 -0
- data/{spec → yaks/spec}/support/deep_eql.rb +0 -0
- data/{spec → yaks/spec}/support/fixtures.rb +0 -0
- data/{spec → yaks/spec}/support/friends_mapper.rb +0 -0
- data/{spec → yaks/spec}/support/models.rb +0 -0
- data/{spec → yaks/spec}/support/pet_mapper.rb +0 -0
- data/{spec → yaks/spec}/support/pet_peeve_mapper.rb +0 -0
- data/{spec → yaks/spec}/support/shared_contexts.rb +0 -0
- data/{spec → yaks/spec}/support/youtypeit_models_mappers.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/collection_mapper_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/collection_resource_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/config/dsl_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/config_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/default_policy_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/format/collection_json_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/format/hal_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/format/json_api_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/format_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/fp/callable_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/fp/hash_updatable_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/fp/updatable_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/fp_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/mapper/association_mapper_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/mapper/association_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/mapper/attribute_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/mapper/class_methods_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/mapper/config_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/mapper/has_many_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/mapper/has_one_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/mapper/link_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/mapper_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/null_resource_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/primitivize_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/resource/link_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/resource_spec.rb +0 -0
- data/{spec → yaks/spec}/unit/yaks/runner_spec.rb +1 -1
- data/{spec → yaks/spec}/unit/yaks/util_spec.rb +0 -0
- data/{spec → yaks/spec}/yaml/confucius.yaml +0 -0
- data/{spec → yaks/spec}/yaml/youtypeitwepostit.yaml +0 -0
- data/{yaks.gemspec → yaks/yaks.gemspec} +0 -0
- data/yaks-html/README.md +3 -0
- data/yaks-html/lib/yaks/format/html.rb +70 -0
- data/yaks-html/lib/yaks/format/template.html +56 -0
- data/yaks-html/lib/yaks-html.rb +3 -0
- data/yaks-html/spec/spec_helper.rb +6 -0
- data/yaks-html/yaks-html.gemspec +22 -0
- metadata +99 -164
- data/lib/yaks/version.rb +0 -3
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/{lib → yaks/lib}/yaks/fp.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -37,7 +37,7 @@ module Yaks
|
|
37
37
|
insert_hooks(
|
38
38
|
[[ :map, mapper ],
|
39
39
|
[ :format, formatter ],
|
40
|
-
[ :primitivize,
|
40
|
+
[ :primitivize, primitivizer],
|
41
41
|
[ :serialize, serializer ]])
|
42
42
|
end
|
43
43
|
memoize :steps
|
@@ -54,6 +54,17 @@ module Yaks
|
|
54
54
|
end
|
55
55
|
memoize :formatter
|
56
56
|
|
57
|
+
def primitivizer
|
58
|
+
->(input) do
|
59
|
+
if format_class.serializer == :json
|
60
|
+
primitivize.call(input)
|
61
|
+
else
|
62
|
+
input
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
memoize :primitivizer
|
67
|
+
|
57
68
|
# @param [Hash] opts
|
58
69
|
# @return [String]
|
59
70
|
def format_name
|
File without changes
|
data/{lib → yaks/lib}/yaks.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -235,7 +235,7 @@ RSpec.describe Yaks::Runner do
|
|
235
235
|
expect(runner.steps).to eql [
|
236
236
|
[ :map, runner.mapper ],
|
237
237
|
[ :format, runner.formatter ],
|
238
|
-
[ :primitivize, runner.
|
238
|
+
[ :primitivize, runner.primitivizer],
|
239
239
|
[ :serialize, runner.serializer ]
|
240
240
|
]
|
241
241
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/yaks-html/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Yaks
|
4
|
+
class Format
|
5
|
+
class HTML < self
|
6
|
+
include Adamantium
|
7
|
+
|
8
|
+
register :html, :html, 'text/html'
|
9
|
+
|
10
|
+
def template
|
11
|
+
Hexp.parse(File.read(File.expand_path('../template.html', __FILE__)))
|
12
|
+
end
|
13
|
+
memoize :template
|
14
|
+
|
15
|
+
def section(name)
|
16
|
+
template.select(".#{name}").first
|
17
|
+
end
|
18
|
+
|
19
|
+
def serialize_resource(resource)
|
20
|
+
template.replace('body') do |body|
|
21
|
+
body.content(render_resource(resource))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def render_resource(resource, templ = section('resource'))
|
26
|
+
templ
|
27
|
+
.replace('.type') { |header| header.content(resource.type.to_s + (resource.collection? ? ' collection' : '')) }
|
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) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_attributes(attributes)
|
34
|
+
->(templ) do
|
35
|
+
attributes.map do |key, value|
|
36
|
+
templ
|
37
|
+
.replace('.name') {|x| x.content(key.to_s) }
|
38
|
+
.replace('.value') {|x| x.content(value.inspect) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_links(links)
|
44
|
+
->(templ) do
|
45
|
+
links.map do |link|
|
46
|
+
templ
|
47
|
+
.replace('.rel a') {|a| a.attr('href', link.rel.to_s).content(link.rel.to_s) }
|
48
|
+
.replace('.uri a') {|a| a.attr('href', link.uri).content(link.uri) }
|
49
|
+
.replace('.title') {|x| x.content(link.title) }
|
50
|
+
.replace('.templated') {|x| x.content(link.templated?.inspect) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def render_subresources(subresources, templ)
|
56
|
+
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
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6
|
+
<style type="text/css">
|
7
|
+
.resource {
|
8
|
+
border: 1px solid black;
|
9
|
+
padding: 0.3em;
|
10
|
+
}
|
11
|
+
|
12
|
+
h1,h2,h3,h4,h5 {
|
13
|
+
background-color: #090
|
14
|
+
}
|
15
|
+
|
16
|
+
table {
|
17
|
+
width:99%;
|
18
|
+
margin: 0.5em;
|
19
|
+
}
|
20
|
+
|
21
|
+
th{ background-color: #fee; }
|
22
|
+
|
23
|
+
</style>
|
24
|
+
</head>
|
25
|
+
<body>
|
26
|
+
<div class="resource">
|
27
|
+
<h1 class="type">Resource Type</h1>
|
28
|
+
|
29
|
+
<table border="1" class="attributes">
|
30
|
+
<tr><th>Attribute</th><th>Value</th></tr>
|
31
|
+
<tr class="attribute"><td class="name">name</td><td class="value">value</td></tr>
|
32
|
+
</table>
|
33
|
+
|
34
|
+
<table border="1" class="links">
|
35
|
+
<tr>
|
36
|
+
<th>Rel</th>
|
37
|
+
<th>URI</th>
|
38
|
+
<th>Title</th>
|
39
|
+
<th>Templated</th>
|
40
|
+
</tr>
|
41
|
+
|
42
|
+
<tr class="link">
|
43
|
+
<td class="rel"><a href="">rel</a></td>
|
44
|
+
<td class="uri"><a href="">uri</a></td>
|
45
|
+
<td class="title">title</td>
|
46
|
+
<td class="templated">false</td>
|
47
|
+
</tr>
|
48
|
+
</table>
|
49
|
+
|
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>
|
54
|
+
</div>
|
55
|
+
</body>
|
56
|
+
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../yaks/lib/yaks/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'yaks-html'
|
7
|
+
gem.version = Yaks::VERSION
|
8
|
+
gem.authors = [ 'Arne Brasseur' ]
|
9
|
+
gem.email = [ 'arne@arnebrasseur.net' ]
|
10
|
+
gem.description = 'HTML output format for Yaks'
|
11
|
+
gem.summary = gem.description
|
12
|
+
gem.homepage = 'https://github.com/plexus/yaks'
|
13
|
+
gem.license = 'MIT'
|
14
|
+
|
15
|
+
gem.require_paths = %w[lib]
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.test_files = `git ls-files -- spec`.split($/)
|
18
|
+
gem.extra_rdoc_files = %w[README.md]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'yaks', Yaks::VERSION
|
21
|
+
gem.add_runtime_dependency 'hexp', '>= 0.3'
|
22
|
+
end
|