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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +20 -9
  3. data/CHANGELOG.md +2 -3
  4. data/Gemfile +2 -1
  5. data/Rakefile +29 -50
  6. data/yaks/README.md +526 -0
  7. data/{lib → yaks/lib}/yaks/breaking_changes.rb +0 -0
  8. data/{lib → yaks/lib}/yaks/collection_mapper.rb +0 -0
  9. data/{lib → yaks/lib}/yaks/collection_resource.rb +0 -0
  10. data/{lib → yaks/lib}/yaks/config/dsl.rb +0 -0
  11. data/{lib → yaks/lib}/yaks/config.rb +0 -0
  12. data/{lib → yaks/lib}/yaks/default_policy.rb +2 -1
  13. data/{lib → yaks/lib}/yaks/format/collection_json.rb +0 -0
  14. data/{lib → yaks/lib}/yaks/format/hal.rb +0 -0
  15. data/{lib → yaks/lib}/yaks/format/json_api.rb +0 -0
  16. data/{lib → yaks/lib}/yaks/format.rb +0 -0
  17. data/{lib → yaks/lib}/yaks/fp/callable.rb +0 -0
  18. data/{lib → yaks/lib}/yaks/fp/hash_updatable.rb +0 -0
  19. data/{lib → yaks/lib}/yaks/fp/updatable.rb +0 -0
  20. data/{lib → yaks/lib}/yaks/fp.rb +0 -0
  21. data/{lib → yaks/lib}/yaks/mapper/association.rb +0 -0
  22. data/{lib → yaks/lib}/yaks/mapper/association_mapper.rb +0 -0
  23. data/{lib → yaks/lib}/yaks/mapper/attribute.rb +0 -0
  24. data/{lib → yaks/lib}/yaks/mapper/class_methods.rb +0 -0
  25. data/{lib → yaks/lib}/yaks/mapper/config.rb +0 -0
  26. data/{lib → yaks/lib}/yaks/mapper/has_many.rb +0 -0
  27. data/{lib → yaks/lib}/yaks/mapper/has_one.rb +0 -0
  28. data/{lib → yaks/lib}/yaks/mapper/link.rb +0 -0
  29. data/{lib → yaks/lib}/yaks/mapper.rb +0 -0
  30. data/{lib → yaks/lib}/yaks/null_resource.rb +0 -0
  31. data/{lib → yaks/lib}/yaks/primitivize.rb +0 -0
  32. data/{lib → yaks/lib}/yaks/resource/link.rb +0 -0
  33. data/{lib → yaks/lib}/yaks/resource.rb +0 -0
  34. data/{lib → yaks/lib}/yaks/runner.rb +12 -1
  35. data/{lib → yaks/lib}/yaks/util.rb +0 -0
  36. data/yaks/lib/yaks/version.rb +3 -0
  37. data/{lib → yaks/lib}/yaks.rb +0 -0
  38. data/{spec → yaks/spec}/acceptance/acceptance_spec.rb +0 -0
  39. data/{spec → yaks/spec}/acceptance/json_shared_examples.rb +0 -0
  40. data/{spec → yaks/spec}/acceptance/models.rb +0 -0
  41. data/{spec → yaks/spec}/fixture_helpers.rb +0 -0
  42. data/{spec → yaks/spec}/integration/map_to_resource_spec.rb +0 -0
  43. data/{spec → yaks/spec}/json/confucius.collection.json +0 -0
  44. data/{spec → yaks/spec}/json/confucius.hal.json +0 -0
  45. data/{spec → yaks/spec}/json/confucius.json_api.json +0 -0
  46. data/{spec → yaks/spec}/json/john.hal.json +0 -0
  47. data/{spec → yaks/spec}/json/plant_collection.collection.json +0 -0
  48. data/{spec → yaks/spec}/json/plant_collection.hal.json +0 -0
  49. data/{spec → yaks/spec}/json/youtypeitwepostit.collection.json +0 -0
  50. data/{spec → yaks/spec}/spec_helper.rb +0 -0
  51. data/{spec → yaks/spec}/support/classes_for_policy_testing.rb +0 -0
  52. data/{spec → yaks/spec}/support/deep_eql.rb +0 -0
  53. data/{spec → yaks/spec}/support/fixtures.rb +0 -0
  54. data/{spec → yaks/spec}/support/friends_mapper.rb +0 -0
  55. data/{spec → yaks/spec}/support/models.rb +0 -0
  56. data/{spec → yaks/spec}/support/pet_mapper.rb +0 -0
  57. data/{spec → yaks/spec}/support/pet_peeve_mapper.rb +0 -0
  58. data/{spec → yaks/spec}/support/shared_contexts.rb +0 -0
  59. data/{spec → yaks/spec}/support/youtypeit_models_mappers.rb +0 -0
  60. data/{spec → yaks/spec}/unit/yaks/collection_mapper_spec.rb +0 -0
  61. data/{spec → yaks/spec}/unit/yaks/collection_resource_spec.rb +0 -0
  62. data/{spec → yaks/spec}/unit/yaks/config/dsl_spec.rb +0 -0
  63. data/{spec → yaks/spec}/unit/yaks/config_spec.rb +0 -0
  64. data/{spec → yaks/spec}/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +0 -0
  65. data/{spec → yaks/spec}/unit/yaks/default_policy_spec.rb +0 -0
  66. data/{spec → yaks/spec}/unit/yaks/format/collection_json_spec.rb +0 -0
  67. data/{spec → yaks/spec}/unit/yaks/format/hal_spec.rb +0 -0
  68. data/{spec → yaks/spec}/unit/yaks/format/json_api_spec.rb +0 -0
  69. data/{spec → yaks/spec}/unit/yaks/format_spec.rb +0 -0
  70. data/{spec → yaks/spec}/unit/yaks/fp/callable_spec.rb +0 -0
  71. data/{spec → yaks/spec}/unit/yaks/fp/hash_updatable_spec.rb +0 -0
  72. data/{spec → yaks/spec}/unit/yaks/fp/updatable_spec.rb +0 -0
  73. data/{spec → yaks/spec}/unit/yaks/fp_spec.rb +0 -0
  74. data/{spec → yaks/spec}/unit/yaks/mapper/association_mapper_spec.rb +0 -0
  75. data/{spec → yaks/spec}/unit/yaks/mapper/association_spec.rb +0 -0
  76. data/{spec → yaks/spec}/unit/yaks/mapper/attribute_spec.rb +0 -0
  77. data/{spec → yaks/spec}/unit/yaks/mapper/class_methods_spec.rb +0 -0
  78. data/{spec → yaks/spec}/unit/yaks/mapper/config_spec.rb +0 -0
  79. data/{spec → yaks/spec}/unit/yaks/mapper/has_many_spec.rb +0 -0
  80. data/{spec → yaks/spec}/unit/yaks/mapper/has_one_spec.rb +0 -0
  81. data/{spec → yaks/spec}/unit/yaks/mapper/link_spec.rb +0 -0
  82. data/{spec → yaks/spec}/unit/yaks/mapper_spec.rb +0 -0
  83. data/{spec → yaks/spec}/unit/yaks/null_resource_spec.rb +0 -0
  84. data/{spec → yaks/spec}/unit/yaks/primitivize_spec.rb +0 -0
  85. data/{spec → yaks/spec}/unit/yaks/resource/link_spec.rb +0 -0
  86. data/{spec → yaks/spec}/unit/yaks/resource_spec.rb +0 -0
  87. data/{spec → yaks/spec}/unit/yaks/runner_spec.rb +1 -1
  88. data/{spec → yaks/spec}/unit/yaks/util_spec.rb +0 -0
  89. data/{spec → yaks/spec}/yaml/confucius.yaml +0 -0
  90. data/{spec → yaks/spec}/yaml/youtypeitwepostit.yaml +0 -0
  91. data/{yaks.gemspec → yaks/yaks.gemspec} +0 -0
  92. data/yaks-html/README.md +3 -0
  93. data/yaks-html/lib/yaks/format/html.rb +70 -0
  94. data/yaks-html/lib/yaks/format/template.html +56 -0
  95. data/yaks-html/lib/yaks-html.rb +3 -0
  96. data/yaks-html/spec/spec_helper.rb +6 -0
  97. data/yaks-html/yaks-html.gemspec +22 -0
  98. metadata +99 -164
  99. data/lib/yaks/version.rb +0 -3
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -92,7 +92,8 @@ module Yaks
92
92
  # @return [#call] format_class
93
93
  def serializer_for_format(format_class)
94
94
  {
95
- json: JSON.method(:pretty_generate)
95
+ json: JSON.method(:pretty_generate),
96
+ html: :to_html.to_proc
96
97
  }.fetch(format_class.serializer)
97
98
  end
98
99
  end
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
@@ -37,7 +37,7 @@ module Yaks
37
37
  insert_hooks(
38
38
  [[ :map, mapper ],
39
39
  [ :format, formatter ],
40
- [ :primitivize, primitivize], # really a JSON-preprocessor, should be pulled out
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
@@ -0,0 +1,3 @@
1
+ module Yaks
2
+ VERSION = '0.6.0.alpha'
3
+ end
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.primitivize],
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
@@ -0,0 +1,3 @@
1
+ A HTML output format for Yaks.
2
+
3
+ Browse your hypermedia API like a good old fashioned web site.
@@ -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,3 @@
1
+ require 'hexp'
2
+
3
+ require 'yaks/format/html'
@@ -0,0 +1,6 @@
1
+ RSpec.configure do |rspec|
2
+ rspec.include FixtureHelpers
3
+ rspec.backtrace_exclusion_patterns = [] if ENV['FULLSTACK']
4
+ rspec.disable_monkey_patching!
5
+ rspec.raise_errors_for_deprecations!
6
+ end
@@ -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