media_types-serialization 0.8.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +10 -1
- data/.gitignore +12 -12
- data/.idea/.rakeTasks +5 -5
- data/.idea/inspectionProfiles/Project_Default.xml +5 -5
- data/.idea/runConfigurations/test.xml +19 -19
- data/CHANGELOG.md +18 -0
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +4 -4
- data/Gemfile.lock +58 -61
- data/LICENSE.txt +21 -21
- data/README.md +640 -173
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/media_types/problem.rb +64 -0
- data/lib/media_types/serialization.rb +431 -172
- data/lib/media_types/serialization/base.rb +111 -91
- data/lib/media_types/serialization/error.rb +178 -0
- data/lib/media_types/serialization/fake_validator.rb +52 -0
- data/lib/media_types/serialization/serialization_dsl.rb +117 -0
- data/lib/media_types/serialization/serialization_registration.rb +235 -0
- data/lib/media_types/serialization/serializers/api_viewer.rb +133 -0
- data/lib/media_types/serialization/serializers/common_css.rb +168 -0
- data/lib/media_types/serialization/serializers/endpoint_description_serializer.rb +80 -0
- data/lib/media_types/serialization/serializers/fallback_not_acceptable_serializer.rb +85 -0
- data/lib/media_types/serialization/serializers/fallback_unsupported_media_type_serializer.rb +58 -0
- data/lib/media_types/serialization/serializers/input_validation_error_serializer.rb +89 -0
- data/lib/media_types/serialization/serializers/problem_serializer.rb +87 -0
- data/lib/media_types/serialization/version.rb +1 -1
- data/media_types-serialization.gemspec +50 -50
- metadata +40 -43
- data/.travis.yml +0 -17
- data/lib/generators/media_types/serialization/api_viewer/api_viewer_generator.rb +0 -25
- data/lib/generators/media_types/serialization/api_viewer/templates/api_viewer.html.erb +0 -98
- data/lib/generators/media_types/serialization/api_viewer/templates/initializer.rb +0 -33
- data/lib/generators/media_types/serialization/api_viewer/templates/template_controller.rb +0 -23
- data/lib/media_types/serialization/media_type/register.rb +0 -4
- data/lib/media_types/serialization/migrations_command.rb +0 -38
- data/lib/media_types/serialization/migrations_support.rb +0 -50
- data/lib/media_types/serialization/mime_type_support.rb +0 -64
- data/lib/media_types/serialization/no_content_type_given.rb +0 -11
- data/lib/media_types/serialization/no_media_type_serializers.rb +0 -11
- data/lib/media_types/serialization/no_serializer_for_content_type.rb +0 -15
- data/lib/media_types/serialization/renderer.rb +0 -41
- data/lib/media_types/serialization/renderer/register.rb +0 -4
- data/lib/media_types/serialization/wrapper.rb +0 -13
- data/lib/media_types/serialization/wrapper/html_wrapper.rb +0 -45
- data/lib/media_types/serialization/wrapper/media_collection_wrapper.rb +0 -61
- data/lib/media_types/serialization/wrapper/media_index_wrapper.rb +0 -61
- data/lib/media_types/serialization/wrapper/media_object_wrapper.rb +0 -55
- data/lib/media_types/serialization/wrapper_support.rb +0 -38
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'media_types/serialization/base'
|
5
|
+
|
6
|
+
module MediaTypes
|
7
|
+
module Serialization
|
8
|
+
module Serializers
|
9
|
+
class ProblemSerializer < MediaTypes::Serialization::Base
|
10
|
+
|
11
|
+
unvalidated 'application/vnd.delftsolutions.problem'
|
12
|
+
|
13
|
+
output do |problem, _, context|
|
14
|
+
raise 'No translations defined, add at least one title' unless problem.translations.keys.any?
|
15
|
+
|
16
|
+
# TODO: content-language selection
|
17
|
+
|
18
|
+
translation = problem.translations[problem.translations.keys.first]
|
19
|
+
title = translation[:title]
|
20
|
+
detail = translation[:detail] || problem.error.message
|
21
|
+
|
22
|
+
problem.custom_attributes.each do |key, value|
|
23
|
+
attribute key, value
|
24
|
+
end
|
25
|
+
|
26
|
+
attribute :type, problem.type
|
27
|
+
attribute :title, title unless title.nil?
|
28
|
+
attribute :detail, detail unless detail.nil?
|
29
|
+
attribute :instance, problem.instance unless problem.instance.nil?
|
30
|
+
|
31
|
+
emit
|
32
|
+
end
|
33
|
+
output_alias 'application/problem+json'
|
34
|
+
|
35
|
+
output_raw view: :html do |problem, _, context|
|
36
|
+
# TODO: content-language selection
|
37
|
+
|
38
|
+
translation = problem.translations[problem.translations.keys.first]
|
39
|
+
title = translation[:title]
|
40
|
+
detail = translation[:detail] || problem.error.message
|
41
|
+
|
42
|
+
input = OpenStruct.new(
|
43
|
+
title: title,
|
44
|
+
detail: detail,
|
45
|
+
help_url: problem.type,
|
46
|
+
css: CommonCSS.css,
|
47
|
+
)
|
48
|
+
|
49
|
+
template = ERB.new <<-TEMPLATE
|
50
|
+
<html lang="en">
|
51
|
+
<head>
|
52
|
+
<title>Error - <%= CGI::escapeHTML(title) %></title>
|
53
|
+
<style>
|
54
|
+
<%= css.split("\n").join("\n ") %>
|
55
|
+
</style>
|
56
|
+
</head>
|
57
|
+
<body>
|
58
|
+
<header>
|
59
|
+
<div id="logo"></div>
|
60
|
+
<h1>Error</h1>
|
61
|
+
</header>
|
62
|
+
<section id="content">
|
63
|
+
<nav>
|
64
|
+
<section id="description">
|
65
|
+
<h2><a href="<%= help_url %>"><%= CGI::escapeHTML(title) %></a></h2>
|
66
|
+
</section>
|
67
|
+
</nav>
|
68
|
+
<main>
|
69
|
+
<p><%= detail %>
|
70
|
+
</main>
|
71
|
+
</section>
|
72
|
+
<!-- Made with ❤ by: https://delftsolutions.com -->
|
73
|
+
</body>
|
74
|
+
</html>
|
75
|
+
TEMPLATE
|
76
|
+
template.result(input.instance_eval { binding })
|
77
|
+
end
|
78
|
+
|
79
|
+
# Hack: results in the alias being registered as */* wildcard
|
80
|
+
self.serializer_output_registration.registrations.delete('*/*')
|
81
|
+
|
82
|
+
output_alias_optional 'text/html', view: :html
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'media_types/serialization/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'media_types-serialization'
|
8
|
-
spec.version = MediaTypes::Serialization::VERSION
|
9
|
-
spec.authors = ['Derk-Jan Karrenbeld']
|
10
|
-
spec.email = ['derk-jan@xpbytes.com']
|
11
|
-
|
12
|
-
spec.summary = 'Add media types supported serialization using your favourite serializer'
|
13
|
-
spec.homepage = 'https://github.com/XPBytes/media_types-serialization'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
|
16
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
-
if spec.respond_to?(:metadata)
|
19
|
-
# spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
|
20
|
-
|
21
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
-
spec.metadata['source_code_uri'] = spec.homepage
|
23
|
-
spec.metadata['changelog_uri'] = spec.homepage + '/CHANGELOG.md'
|
24
|
-
else
|
25
|
-
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
26
|
-
'public gem pushes.'
|
27
|
-
end
|
28
|
-
|
29
|
-
# Specify which files should be added to the gem when it is released.
|
30
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
-
end
|
34
|
-
spec.bindir = 'exe'
|
35
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
-
spec.require_paths = ['lib']
|
37
|
-
|
38
|
-
spec.add_dependency 'actionpack', '>= 4.0.0'
|
39
|
-
spec.add_dependency 'activesupport', '>= 4.0.0'
|
40
|
-
spec.add_dependency 'media_types', '>= 0.
|
41
|
-
spec.add_dependency '
|
42
|
-
spec.add_dependency 'http_headers-
|
43
|
-
|
44
|
-
|
45
|
-
spec.add_development_dependency '
|
46
|
-
spec.add_development_dependency '
|
47
|
-
spec.add_development_dependency '
|
48
|
-
spec.add_development_dependency '
|
49
|
-
spec.add_development_dependency '
|
50
|
-
end
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'media_types/serialization/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'media_types-serialization'
|
8
|
+
spec.version = MediaTypes::Serialization::VERSION
|
9
|
+
spec.authors = ['Derk-Jan Karrenbeld']
|
10
|
+
spec.email = ['derk-jan@xpbytes.com']
|
11
|
+
|
12
|
+
spec.summary = 'Add media types supported serialization using your favourite serializer'
|
13
|
+
spec.homepage = 'https://github.com/XPBytes/media_types-serialization'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
|
20
|
+
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
23
|
+
spec.metadata['changelog_uri'] = spec.homepage + '/CHANGELOG.md'
|
24
|
+
else
|
25
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
26
|
+
'public gem pushes.'
|
27
|
+
end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
|
38
|
+
spec.add_dependency 'actionpack', '>= 4.0.0'
|
39
|
+
spec.add_dependency 'activesupport', '>= 4.0.0'
|
40
|
+
spec.add_dependency 'media_types', '>= 2.0.0', '< 3.0.0'
|
41
|
+
spec.add_dependency 'http_headers-accept', '>= 0.2.2', '< 1.0.0'
|
42
|
+
spec.add_dependency 'http_headers-link', '< 1.0.0'
|
43
|
+
|
44
|
+
spec.add_development_dependency 'awesome_print'
|
45
|
+
spec.add_development_dependency 'bundler'
|
46
|
+
spec.add_development_dependency 'rails', '~> 5.2'
|
47
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
48
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
49
|
+
spec.add_development_dependency 'oj'
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: media_types-serialization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -44,28 +44,20 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
48
|
-
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.6.2
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: oj
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
47
|
+
version: 2.0.0
|
48
|
+
- - "<"
|
60
49
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
50
|
+
version: 3.0.0
|
62
51
|
type: :runtime
|
63
52
|
prerelease: false
|
64
53
|
version_requirements: !ruby/object:Gem::Requirement
|
65
54
|
requirements:
|
66
55
|
- - ">="
|
67
56
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
57
|
+
version: 2.0.0
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.0.0
|
69
61
|
- !ruby/object:Gem::Dependency
|
70
62
|
name: http_headers-accept
|
71
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,16 +110,16 @@ dependencies:
|
|
118
110
|
name: bundler
|
119
111
|
requirement: !ruby/object:Gem::Requirement
|
120
112
|
requirements:
|
121
|
-
- - "
|
113
|
+
- - ">="
|
122
114
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
115
|
+
version: '0'
|
124
116
|
type: :development
|
125
117
|
prerelease: false
|
126
118
|
version_requirements: !ruby/object:Gem::Requirement
|
127
119
|
requirements:
|
128
|
-
- - "
|
120
|
+
- - ">="
|
129
121
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
122
|
+
version: '0'
|
131
123
|
- !ruby/object:Gem::Dependency
|
132
124
|
name: rails
|
133
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,14 +140,14 @@ dependencies:
|
|
148
140
|
requirements:
|
149
141
|
- - "~>"
|
150
142
|
- !ruby/object:Gem::Version
|
151
|
-
version: '
|
143
|
+
version: '13.0'
|
152
144
|
type: :development
|
153
145
|
prerelease: false
|
154
146
|
version_requirements: !ruby/object:Gem::Requirement
|
155
147
|
requirements:
|
156
148
|
- - "~>"
|
157
149
|
- !ruby/object:Gem::Version
|
158
|
-
version: '
|
150
|
+
version: '13.0'
|
159
151
|
- !ruby/object:Gem::Dependency
|
160
152
|
name: minitest
|
161
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,6 +162,20 @@ dependencies:
|
|
170
162
|
- - "~>"
|
171
163
|
- !ruby/object:Gem::Version
|
172
164
|
version: '5.0'
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
name: oj
|
167
|
+
requirement: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
type: :development
|
173
|
+
prerelease: false
|
174
|
+
version_requirements: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
173
179
|
description:
|
174
180
|
email:
|
175
181
|
- derk-jan@xpbytes.com
|
@@ -188,7 +194,6 @@ files:
|
|
188
194
|
- ".idea/modules.xml"
|
189
195
|
- ".idea/runConfigurations/test.xml"
|
190
196
|
- ".idea/vcs.xml"
|
191
|
-
- ".travis.yml"
|
192
197
|
- CHANGELOG.md
|
193
198
|
- CODE_OF_CONDUCT.md
|
194
199
|
- Gemfile
|
@@ -198,29 +203,21 @@ files:
|
|
198
203
|
- Rakefile
|
199
204
|
- bin/console
|
200
205
|
- bin/setup
|
201
|
-
- lib/
|
202
|
-
- lib/generators/media_types/serialization/api_viewer/templates/api_viewer.html.erb
|
203
|
-
- lib/generators/media_types/serialization/api_viewer/templates/initializer.rb
|
204
|
-
- lib/generators/media_types/serialization/api_viewer/templates/template_controller.rb
|
206
|
+
- lib/media_types/problem.rb
|
205
207
|
- lib/media_types/serialization.rb
|
206
208
|
- lib/media_types/serialization/base.rb
|
207
209
|
- lib/media_types/serialization/error.rb
|
208
|
-
- lib/media_types/serialization/
|
209
|
-
- lib/media_types/serialization/
|
210
|
-
- lib/media_types/serialization/
|
211
|
-
- lib/media_types/serialization/
|
212
|
-
- lib/media_types/serialization/
|
213
|
-
- lib/media_types/serialization/
|
214
|
-
- lib/media_types/serialization/
|
215
|
-
- lib/media_types/serialization/
|
216
|
-
- lib/media_types/serialization/
|
210
|
+
- lib/media_types/serialization/fake_validator.rb
|
211
|
+
- lib/media_types/serialization/serialization_dsl.rb
|
212
|
+
- lib/media_types/serialization/serialization_registration.rb
|
213
|
+
- lib/media_types/serialization/serializers/api_viewer.rb
|
214
|
+
- lib/media_types/serialization/serializers/common_css.rb
|
215
|
+
- lib/media_types/serialization/serializers/endpoint_description_serializer.rb
|
216
|
+
- lib/media_types/serialization/serializers/fallback_not_acceptable_serializer.rb
|
217
|
+
- lib/media_types/serialization/serializers/fallback_unsupported_media_type_serializer.rb
|
218
|
+
- lib/media_types/serialization/serializers/input_validation_error_serializer.rb
|
219
|
+
- lib/media_types/serialization/serializers/problem_serializer.rb
|
217
220
|
- lib/media_types/serialization/version.rb
|
218
|
-
- lib/media_types/serialization/wrapper.rb
|
219
|
-
- lib/media_types/serialization/wrapper/html_wrapper.rb
|
220
|
-
- lib/media_types/serialization/wrapper/media_collection_wrapper.rb
|
221
|
-
- lib/media_types/serialization/wrapper/media_index_wrapper.rb
|
222
|
-
- lib/media_types/serialization/wrapper/media_object_wrapper.rb
|
223
|
-
- lib/media_types/serialization/wrapper_support.rb
|
224
221
|
- media_types-serialization.gemspec
|
225
222
|
homepage: https://github.com/XPBytes/media_types-serialization
|
226
223
|
licenses:
|
data/.travis.yml
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sudo: false
|
3
|
-
language: ruby
|
4
|
-
cache: bundler
|
5
|
-
rvm:
|
6
|
-
- 2.5
|
7
|
-
- 2.6
|
8
|
-
- ruby-head
|
9
|
-
before_install:
|
10
|
-
- gem install bundler -v 2.0.1
|
11
|
-
- gem update --system
|
12
|
-
- gem --version
|
13
|
-
matrix:
|
14
|
-
allow_failures:
|
15
|
-
- rvm: ruby-head
|
16
|
-
install:
|
17
|
-
- bundle install --with development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'rails/generators/base'
|
2
|
-
|
3
|
-
module MediaTypes
|
4
|
-
module Serialization
|
5
|
-
class ApiViewerGenerator < Rails::Generators::Base
|
6
|
-
source_root File.expand_path('templates', __dir__)
|
7
|
-
|
8
|
-
def copy_controllers
|
9
|
-
copy_file "template_controller.rb", "app/controllers/api/template_controller.rb"
|
10
|
-
end
|
11
|
-
|
12
|
-
def copy_views
|
13
|
-
copy_file "api_viewer.html.erb", "app/views/serializers/wrapper/html_wrapper.html.erb"
|
14
|
-
end
|
15
|
-
|
16
|
-
def copy_initializer
|
17
|
-
copy_file "initializer.rb", "config/initializers/media_types_serialization.rb"
|
18
|
-
end
|
19
|
-
|
20
|
-
def add_route
|
21
|
-
route "namespace :api do\n match '/template', controller: :template, action: :create, via: %i[get post], as: :template\nend\n\n"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<title>API Viewer</title>
|
5
|
-
<%= csrf_meta_tags %>
|
6
|
-
<%= csp_meta_tag %>
|
7
|
-
|
8
|
-
<% # The following expects webpacker to be active, but you can replace these if you use the sprockets pipeline %>
|
9
|
-
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
10
|
-
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
|
11
|
-
</head>
|
12
|
-
<%
|
13
|
-
def replace_link(full_match)
|
14
|
-
href = full_match[9...-1]
|
15
|
-
'"href": "%s"' % link_to(href.gsub('%7B', '{').gsub('%7D', '}'), href).html_safe
|
16
|
-
rescue
|
17
|
-
full_match
|
18
|
-
end
|
19
|
-
%>
|
20
|
-
<body class="container h-100" style="overflow: auto; justify-content: start">
|
21
|
-
|
22
|
-
<%# Remove the # below to show a logo %>
|
23
|
-
<%# link_to Rails.application.routes.url_helpers.root_path do %>
|
24
|
-
<%# render 'shared/logo', assigns: { width: 300, height: 63, style: "flex-shrink: 0; margin: 20px 0 40px" } %>
|
25
|
-
<%# end %>
|
26
|
-
|
27
|
-
<div class="h-auto w-100 mb-4">
|
28
|
-
<% links = @serializer.send(:header_links) %>
|
29
|
-
<% if links.present? %>
|
30
|
-
<nav class="card w-100 mb-4 card--inverse">
|
31
|
-
<div class="card-header">
|
32
|
-
<h5 class="card-title my-auto">HTTP Links</h5>
|
33
|
-
</div>
|
34
|
-
<ul class="list-group list-group-flush">
|
35
|
-
<% links.each do |key, link| %>
|
36
|
-
<% href = link && link[:href] || next %>
|
37
|
-
<li class="list-group-item">
|
38
|
-
<% if link[:templated] %>
|
39
|
-
<%# You need to add this route to your routes file; Use the provided generator %>
|
40
|
-
<%# rails g api_viewer %>
|
41
|
-
<%= form_tag Rails.application.routes.url_helpers.api_template_path, { method: :get, class: 'link-template-form' } do %>
|
42
|
-
<%= hidden_field_tag 'template[href]', href %>
|
43
|
-
<button type="submit"><strong><%= key %></strong></button>
|
44
|
-
<code><%= href.gsub(/:([a-z][^\/]*)|(?:{|%7B)([a-z][^\/{}]*)(%7D|})/) do |match|
|
45
|
-
tag = match.tr(':{}', '').delete('%7B').delete('%7D')
|
46
|
-
text_field_tag('template[%s]' % tag, nil, placeholder: tag)
|
47
|
-
end.html_safe %></code>
|
48
|
-
<% end %>
|
49
|
-
<% else %>
|
50
|
-
<%= link_to href do %>
|
51
|
-
<strong><%= key %></strong>
|
52
|
-
<code><%= href %></code>
|
53
|
-
<% end %>
|
54
|
-
<% end %>
|
55
|
-
</li>
|
56
|
-
<% end %>
|
57
|
-
</ul>
|
58
|
-
</nav>
|
59
|
-
<% end %>
|
60
|
-
|
61
|
-
<article class="card w-100 mb-4 card--inverse">
|
62
|
-
<div class="card-body">
|
63
|
-
<h5 class="card-title"><%= @mime_type %></h5>
|
64
|
-
<small class="card-subtitle mb-2 text-muted">Serialized by: <%= @serializer.class.name %></small>
|
65
|
-
<pre><code class="code" style="
|
66
|
-
white-space: pre-wrap;
|
67
|
-
white-space: -moz-pre-wrap;
|
68
|
-
white-space: -o-pre-wrap;
|
69
|
-
word-wrap: break-word;"><% code = JSON.pretty_generate(@serializer.to_hash).truncate(50_000)
|
70
|
-
.gsub('</h1>', "</h1>\n")
|
71
|
-
.gsub('</div>', "</div>\n")
|
72
|
-
.gsub('<', '<')
|
73
|
-
.gsub('>', '>')
|
74
|
-
.gsub('\n', "<br>")%>
|
75
|
-
<%= code.gsub(/"href": "(http(?:s?:\/\/.*?))"/, &method(:replace_link)).html_safe %></code></pre>
|
76
|
-
</div>
|
77
|
-
</article>
|
78
|
-
|
79
|
-
<nav class="card w-100 mb-4 card--inverse">
|
80
|
-
<div class="card-header">
|
81
|
-
<h5 class="card-title my-auto">Endpoint representations</h5>
|
82
|
-
</div>
|
83
|
-
<ul class="list-group list-group-flush">
|
84
|
-
<% @representations.each do |representation| %>
|
85
|
-
<% mime_type = Mime::Type.lookup(representation) || next %>
|
86
|
-
<li class="list-group-item">
|
87
|
-
<%= link_to (@url_context + ".#{mime_type.symbol}").sub('/.', '.') do %>
|
88
|
-
<strong><%= representation %></strong>
|
89
|
-
<code><%= mime_type.symbol %></code>
|
90
|
-
<% end %>
|
91
|
-
</li>
|
92
|
-
<% end %>
|
93
|
-
</ul>
|
94
|
-
</nav>
|
95
|
-
</div>
|
96
|
-
</body>
|
97
|
-
</html>
|
98
|
-
|