media_types-serialization 1.3.8 → 1.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8954f231059a19dd11bf92dc2db6ce7528eb476507d4929fc0c06a32e9b94722
4
- data.tar.gz: c7864c12936076ab41f207472de9c59343ba71abb1a4e49b8febfbd10ec06dc2
3
+ metadata.gz: '096826bd7e4a4be4fcd147fec07f26d05aec0101b8651ae63ed376a7a2388077'
4
+ data.tar.gz: 2f783986be7ca3eff779e10a2ace5338d9ab7dbb755334ae79d01d7b422a77c9
5
5
  SHA512:
6
- metadata.gz: eb9d67937ca3d0fbb5fa6c12958c655fbedb7a8304f82ea9fa107aa12e5b1f8980f3293c664f2f0776e04064e43f30a05217dd270b7de64ba0d6a135a5f3239a
7
- data.tar.gz: 0d590e5fd4a2bf520d842b90a271aedb6db508043c8efeb4645869952bc36c15acdc10310405d72055e59dda092fa55d9dbdaed2bed92d8764a8b5c466b0bafc
6
+ metadata.gz: f0b58cdb8eb8e4f8c0c8ad73cc607673768cba38399cf9c804db16a54198b3fe0799a18c641e7c05d10e03c2936fc96a416b80ff51ff4bd5e6d570b10a47e712
7
+ data.tar.gz: e82051321d55df89abe34c6d43e62a0158245c4fb9ae60060fc3e939df854626b3014285f2ac277f7632f6c3cd099ef349265bdfffbf7b7b226f76287bb53147
@@ -17,12 +17,12 @@ jobs:
17
17
 
18
18
  strategy:
19
19
  matrix:
20
- ruby-version: [2.7.x, 2.6.x, 2.5.x]
20
+ ruby-version: ["3.1", "3.0", "2.7"]
21
21
 
22
22
  steps:
23
23
  - uses: actions/checkout@v1
24
24
  - name: Set up Ruby ${{ matrix.ruby-version }}
25
- uses: actions/setup-ruby@v1
25
+ uses: ruby/setup-ruby@v1
26
26
  with:
27
27
  ruby-version: ${{ matrix.ruby-version }}
28
28
  - name: Build and test with Rake
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
  .idea/workspace.xml
11
11
  .idea/usage.statistics.xml
12
12
  .idea/tasks.xml
13
+
14
+ /media_types-serialization*.gem
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0
4
+
5
+ - ✨ Add support for redirecting in serializers
6
+
7
+ ## 1.3.9
8
+
9
+ - ✨ Make serializer look slightly better on mobile by zooming in initially
10
+
11
+ ## 1.3.8
12
+
3
13
  ## 1.3.7
4
14
 
5
15
  - 🐛 Fix execution context for `output_error`
data/Gemfile.lock CHANGED
@@ -1,128 +1,158 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- media_types-serialization (1.3.8)
5
- actionpack (>= 4.0.0)
6
- activesupport (>= 4.0.0)
7
- media_types (>= 2.1.1, < 3.0.0)
4
+ media_types-serialization (1.4.0)
5
+ actionpack (>= 6.0.0)
6
+ activesupport (>= 6.0.0)
7
+ media_types (>= 2.2.0, < 3.0.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (5.2.6)
13
- actionpack (= 5.2.6)
12
+ actioncable (6.1.7.3)
13
+ actionpack (= 6.1.7.3)
14
+ activesupport (= 6.1.7.3)
14
15
  nio4r (~> 2.0)
15
16
  websocket-driver (>= 0.6.1)
16
- actionmailer (5.2.6)
17
- actionpack (= 5.2.6)
18
- actionview (= 5.2.6)
19
- activejob (= 5.2.6)
17
+ actionmailbox (6.1.7.3)
18
+ actionpack (= 6.1.7.3)
19
+ activejob (= 6.1.7.3)
20
+ activerecord (= 6.1.7.3)
21
+ activestorage (= 6.1.7.3)
22
+ activesupport (= 6.1.7.3)
23
+ mail (>= 2.7.1)
24
+ actionmailer (6.1.7.3)
25
+ actionpack (= 6.1.7.3)
26
+ actionview (= 6.1.7.3)
27
+ activejob (= 6.1.7.3)
28
+ activesupport (= 6.1.7.3)
20
29
  mail (~> 2.5, >= 2.5.4)
21
30
  rails-dom-testing (~> 2.0)
22
- actionpack (5.2.6)
23
- actionview (= 5.2.6)
24
- activesupport (= 5.2.6)
25
- rack (~> 2.0, >= 2.0.8)
31
+ actionpack (6.1.7.3)
32
+ actionview (= 6.1.7.3)
33
+ activesupport (= 6.1.7.3)
34
+ rack (~> 2.0, >= 2.0.9)
26
35
  rack-test (>= 0.6.3)
27
36
  rails-dom-testing (~> 2.0)
28
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
- actionview (5.2.6)
30
- activesupport (= 5.2.6)
37
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
38
+ actiontext (6.1.7.3)
39
+ actionpack (= 6.1.7.3)
40
+ activerecord (= 6.1.7.3)
41
+ activestorage (= 6.1.7.3)
42
+ activesupport (= 6.1.7.3)
43
+ nokogiri (>= 1.8.5)
44
+ actionview (6.1.7.3)
45
+ activesupport (= 6.1.7.3)
31
46
  builder (~> 3.1)
32
47
  erubi (~> 1.4)
33
48
  rails-dom-testing (~> 2.0)
34
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
- activejob (5.2.6)
36
- activesupport (= 5.2.6)
49
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
50
+ activejob (6.1.7.3)
51
+ activesupport (= 6.1.7.3)
37
52
  globalid (>= 0.3.6)
38
- activemodel (5.2.6)
39
- activesupport (= 5.2.6)
40
- activerecord (5.2.6)
41
- activemodel (= 5.2.6)
42
- activesupport (= 5.2.6)
43
- arel (>= 9.0)
44
- activestorage (5.2.6)
45
- actionpack (= 5.2.6)
46
- activerecord (= 5.2.6)
47
- marcel (~> 1.0.0)
48
- activesupport (5.2.6)
53
+ activemodel (6.1.7.3)
54
+ activesupport (= 6.1.7.3)
55
+ activerecord (6.1.7.3)
56
+ activemodel (= 6.1.7.3)
57
+ activesupport (= 6.1.7.3)
58
+ activestorage (6.1.7.3)
59
+ actionpack (= 6.1.7.3)
60
+ activejob (= 6.1.7.3)
61
+ activerecord (= 6.1.7.3)
62
+ activesupport (= 6.1.7.3)
63
+ marcel (~> 1.0)
64
+ mini_mime (>= 1.1.0)
65
+ activesupport (6.1.7.3)
49
66
  concurrent-ruby (~> 1.0, >= 1.0.2)
50
- i18n (>= 0.7, < 2)
51
- minitest (~> 5.1)
52
- tzinfo (~> 1.1)
53
- arel (9.0.0)
67
+ i18n (>= 1.6, < 2)
68
+ minitest (>= 5.1)
69
+ tzinfo (~> 2.0)
70
+ zeitwerk (~> 2.3)
54
71
  awesome_print (1.9.2)
55
72
  builder (3.2.4)
56
- concurrent-ruby (1.1.9)
73
+ concurrent-ruby (1.2.2)
57
74
  crass (1.0.6)
58
- erubi (1.10.0)
59
- globalid (0.5.2)
75
+ date (3.3.3)
76
+ erubi (1.12.0)
77
+ globalid (1.1.0)
60
78
  activesupport (>= 5.0)
61
- i18n (1.8.10)
79
+ i18n (1.12.0)
62
80
  concurrent-ruby (~> 1.0)
63
- loofah (2.12.0)
81
+ loofah (2.19.1)
64
82
  crass (~> 1.0.2)
65
83
  nokogiri (>= 1.5.9)
66
- mail (2.7.1)
84
+ mail (2.8.1)
67
85
  mini_mime (>= 0.1.1)
68
- marcel (1.0.1)
69
- media_types (2.1.1)
86
+ net-imap
87
+ net-pop
88
+ net-smtp
89
+ marcel (1.0.2)
90
+ media_types (2.2.0)
70
91
  method_source (1.0.0)
71
- mini_mime (1.1.0)
72
- minitest (5.14.4)
92
+ mini_mime (1.1.2)
93
+ minitest (5.18.0)
94
+ net-imap (0.3.4)
95
+ date
96
+ net-protocol
97
+ net-pop (0.1.2)
98
+ net-protocol
99
+ net-protocol (0.2.1)
100
+ timeout
101
+ net-smtp (0.3.3)
102
+ net-protocol
73
103
  nio4r (2.5.8)
74
- nokogiri (1.12.3-x64-mingw32)
104
+ nokogiri (1.14.2-x64-mingw32)
75
105
  racc (~> 1.4)
76
- nokogiri (1.12.3-x86_64-linux)
77
- racc (~> 1.4)
78
- oj (3.13.4)
79
- racc (1.5.2)
80
- rack (2.2.3)
81
- rack-test (1.1.0)
82
- rack (>= 1.0, < 3)
83
- rails (5.2.6)
84
- actioncable (= 5.2.6)
85
- actionmailer (= 5.2.6)
86
- actionpack (= 5.2.6)
87
- actionview (= 5.2.6)
88
- activejob (= 5.2.6)
89
- activemodel (= 5.2.6)
90
- activerecord (= 5.2.6)
91
- activestorage (= 5.2.6)
92
- activesupport (= 5.2.6)
93
- bundler (>= 1.3.0)
94
- railties (= 5.2.6)
106
+ oj (3.14.2)
107
+ racc (1.6.2)
108
+ rack (2.2.6.4)
109
+ rack-test (2.1.0)
110
+ rack (>= 1.3)
111
+ rails (6.1.7.3)
112
+ actioncable (= 6.1.7.3)
113
+ actionmailbox (= 6.1.7.3)
114
+ actionmailer (= 6.1.7.3)
115
+ actionpack (= 6.1.7.3)
116
+ actiontext (= 6.1.7.3)
117
+ actionview (= 6.1.7.3)
118
+ activejob (= 6.1.7.3)
119
+ activemodel (= 6.1.7.3)
120
+ activerecord (= 6.1.7.3)
121
+ activestorage (= 6.1.7.3)
122
+ activesupport (= 6.1.7.3)
123
+ bundler (>= 1.15.0)
124
+ railties (= 6.1.7.3)
95
125
  sprockets-rails (>= 2.0.0)
96
126
  rails-dom-testing (2.0.3)
97
127
  activesupport (>= 4.2.0)
98
128
  nokogiri (>= 1.6)
99
- rails-html-sanitizer (1.4.1)
100
- loofah (~> 2.3)
101
- railties (5.2.6)
102
- actionpack (= 5.2.6)
103
- activesupport (= 5.2.6)
129
+ rails-html-sanitizer (1.5.0)
130
+ loofah (~> 2.19, >= 2.19.1)
131
+ railties (6.1.7.3)
132
+ actionpack (= 6.1.7.3)
133
+ activesupport (= 6.1.7.3)
104
134
  method_source
105
- rake (>= 0.8.7)
106
- thor (>= 0.19.0, < 2.0)
135
+ rake (>= 12.2)
136
+ thor (~> 1.0)
107
137
  rake (13.0.6)
108
- sprockets (4.0.2)
138
+ sprockets (4.2.0)
109
139
  concurrent-ruby (~> 1.0)
110
- rack (> 1, < 3)
111
- sprockets-rails (3.2.2)
112
- actionpack (>= 4.0)
113
- activesupport (>= 4.0)
140
+ rack (>= 2.2.4, < 4)
141
+ sprockets-rails (3.4.2)
142
+ actionpack (>= 5.2)
143
+ activesupport (>= 5.2)
114
144
  sprockets (>= 3.0.0)
115
- thor (1.1.0)
116
- thread_safe (0.3.6)
117
- tzinfo (1.2.9)
118
- thread_safe (~> 0.1)
145
+ thor (1.2.1)
146
+ timeout (0.3.2)
147
+ tzinfo (2.0.6)
148
+ concurrent-ruby (~> 1.0)
119
149
  websocket-driver (0.7.5)
120
150
  websocket-extensions (>= 0.1.0)
121
151
  websocket-extensions (0.1.5)
152
+ zeitwerk (2.6.7)
122
153
 
123
154
  PLATFORMS
124
155
  x64-mingw32
125
- x86_64-linux
126
156
 
127
157
  DEPENDENCIES
128
158
  awesome_print
@@ -130,8 +160,8 @@ DEPENDENCIES
130
160
  media_types-serialization!
131
161
  minitest (~> 5.0)
132
162
  oj
133
- rails (~> 5.2)
163
+ rails (~> 6.0)
134
164
  rake (~> 13.0)
135
165
 
136
166
  BUNDLED WITH
137
- 2.2.17
167
+ 2.1.4
data/README.md CHANGED
@@ -887,7 +887,15 @@ Can be used to render a view.
887
887
  You can set local variables in the view by assigning a hash to the `assigns:` parameter.
888
888
  Returns a `string`
889
889
 
890
- > When possible, prefer `output_raw` with `context.class.render(params)`
890
+ > When possible, prefer `output_raw` with context.render_to_string(params)`
891
+
892
+ #### `redirect_to(url, context, **options)`
893
+
894
+ This redirects the user to the specified url when this serializer is rendered. The output of the serializer is still shown in the API viewer.
895
+
896
+ #### `suppress_render do |result|`
897
+
898
+ Replaces the render at the end of `render_media` and substitutes it with the contents of the block.
891
899
 
892
900
  ### Controller definition
893
901
 
@@ -916,6 +924,11 @@ Outputs the specified description as help information.
916
924
 
917
925
  Accepts the same filters as `before_action`.
918
926
 
927
+ #### `output_error(klazz, serializers = []) do`
928
+
929
+ Wraps the controller method in a `rescue_from` and presents the users with a `text/html` or `application/problem+json` representation of the error.
930
+ The `text/html` response can be overridden by supplying an additional serializer in the `serializers` array. It will use the nil view for the given serializers.
931
+
919
932
  #### `allow_input_serializer( serializer, views: nil, **filters )`
920
933
 
921
934
  Configure the controller to allow the client to send bodies with a `Content-Type` that can be deserialized using the specified serializer.
@@ -4,7 +4,6 @@ require 'erb'
4
4
 
5
5
  module MediaTypes
6
6
  class Problem
7
-
8
7
  def initialize(error)
9
8
  self.error = error
10
9
  self.translations = {}
@@ -17,7 +16,7 @@ module MediaTypes
17
16
  def type
18
17
  return custom_type unless custom_type.nil?
19
18
 
20
- "https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util::url_encode(error.class.name)}"
19
+ "https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util.url_encode(error.class.name)}"
21
20
  end
22
21
 
23
22
  def url(href)
@@ -31,13 +30,17 @@ module MediaTypes
31
30
 
32
31
  def override_detail(detail, lang:)
33
32
  raise 'Unable to override detail message without having a title in the same language.' unless translations[lang]
33
+
34
34
  translations[lang][:detail] = detail
35
35
  end
36
36
 
37
37
  def attribute(name, value)
38
38
  str_name = name.to_s
39
39
 
40
- raise "Unable to add an attribute with name '#{str_name}'. Name should start with a letter, consist of the letters A-Z, a-z, 0-9 or _ and be at least 3 characters long." unless str_name =~ /^[a-zA-Z][a-zA-Z0-9_]{2,}$/
40
+ unless str_name =~ /^[a-zA-Z][a-zA-Z0-9_]{2,}$/
41
+ raise "Unable to add an attribute with name '#{str_name}'. Name should start with a letter, consist of the " \
42
+ 'letters A-Z, a-z, 0-9 or _ and be at least 3 characters long.'
43
+ end
41
44
 
42
45
  custom_attributes[str_name] = value
43
46
  end
@@ -54,7 +57,7 @@ module MediaTypes
54
57
  inner = error.cause
55
58
  return nil if inner.nil?
56
59
 
57
- "https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util::url_encode(inner.class.name)}"
60
+ "https://docs.delftsolutions.nl/wiki/Error/#{ERB::Util.url_encode(inner.class.name)}"
58
61
  end
59
62
 
60
63
  def languages
@@ -11,10 +11,11 @@ module MediaTypes
11
11
  @serialization_links = links
12
12
  @serialization_context = context
13
13
  @serialization_vary = vary
14
+ @serialization_custom_render = nil
14
15
  super(serializer)
15
16
  end
16
17
 
17
- attr_accessor :serialization_dsl_result
18
+ attr_accessor :serialization_dsl_result, :serialization_custom_render
18
19
 
19
20
  def attribute(key, value = {}, &block)
20
21
  unless block.nil?
@@ -112,6 +113,23 @@ module MediaTypes
112
113
 
113
114
  context.serialization_dsl_result
114
115
  end
116
+
117
+ def redirect_to(url, context, **options)
118
+ suppress_render do |result|
119
+ context.redirect_to(
120
+ url,
121
+ **options
122
+ )
123
+ end
124
+
125
+ "Redirecting to: #{url}"
126
+ end
127
+
128
+ def suppress_render(&block)
129
+ @serialization_custom_render = block || lambda { |result| }
130
+
131
+ serialization_dsl_result
132
+ end
115
133
  end
116
134
  end
117
135
  end
@@ -16,7 +16,7 @@ module MediaTypes
16
16
  return uri unless viewer.host == current_host
17
17
 
18
18
  query_parts = viewer.query&.split('&') || []
19
- query_parts = query_parts.select { |p| !p.starts_with? 'api_viewer=' }
19
+ query_parts = query_parts.reject { |p| p.starts_with?('api_viewer=') }
20
20
  query_parts.append("api_viewer=#{type}")
21
21
  viewer.query = query_parts.join('&')
22
22
  viewer.to_s
@@ -45,42 +45,45 @@ module MediaTypes
45
45
  result = {
46
46
  identifier: identifier,
47
47
  href: viewerify(context.request.original_url, context.request.host, type: identifier),
48
- selected: identifier == original_identifier,
48
+ selected: identifier == original_identifier
49
49
  }
50
50
  result[:href] = '#output' if identifier == original_identifier
51
51
 
52
52
  result
53
53
  end
54
54
 
55
-
56
- escaped_output = original_output&.split("\n").
57
- map { |l| CGI::escapeHTML(l).gsub(/ (?= )/, '&nbsp;') }.
58
- map { |l| (l.gsub(/\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;{}]*[-A-Z0-9+@#\/%=}~_|](?![a-z]*;)/i) do |m|
59
- converted = m
60
- invalid = false
61
- begin
62
- converted = viewerify(m, context.request.host)
63
- rescue URI::InvalidURIError
64
- invalid = true
55
+ escaped_output = original_output
56
+ &.split("\n")
57
+ &.map { |l| CGI.escapeHTML(l).gsub(/ (?= )/, '&nbsp;') }
58
+ &.map do |l|
59
+ l.gsub(/\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;{}]*[-A-Z0-9+@#\/%=}~_|](?![a-z]*;)/i) do |m|
60
+ converted = m
61
+ invalid = false
62
+ begin
63
+ converted = viewerify(m, context.request.host)
64
+ rescue URI::InvalidURIError
65
+ invalid = true
66
+ end
67
+ style = ''
68
+ style = ' style="color: red"' if invalid
69
+ "<a#{style} href=\"#{converted}\">#{m}</a>"
65
70
  end
66
- style = ''
67
- style = ' style="color: red"' if invalid
68
- "<a#{style} href=\"#{converted}\">#{m}</a>"
69
- end) }.
70
- join("<br>\n")
71
-
71
+ end
72
+ &.join("<br>\n")
72
73
 
73
74
  input = OpenStruct.new(
74
75
  original_identifier: original_identifier,
75
76
  escaped_output: escaped_output,
76
77
  api_fied_links: api_fied_links,
77
78
  media_types: media_types,
78
- css: CommonCSS.css,
79
+ css: CommonCSS.css
79
80
  )
80
81
 
81
82
  template = ERB.new <<-TEMPLATE
82
83
  <html lang="en">
83
84
  <head>
85
+ <meta content="width=device-width, initial-scale=1" name="viewport">
86
+
84
87
  <title>API Viewer [<%= CGI::escapeHTML(original_identifier) %>]</title>
85
88
  <style>
86
89
  <%= css.split("\n").join("\n ") %>
@@ -15,28 +15,28 @@ module MediaTypes
15
15
  self.logo_media_type = 'image/svg+xml'
16
16
  self.logo_width = 8
17
17
  self.logo_data = <<-HERE
18
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 114 93">
19
- <title>Delft Solutions</title>
20
-
21
- <filter id="dropshadow">
22
- <feGaussianBlur in="SourceAlpha" stdDeviation="1"></feGaussianBlur> <!-- stdDeviation is how much to blur -->
23
- <feOffset dx="2" dy="1" result="offsetblur"></feOffset> <!-- how much to offset -->
24
- <feComponentTransfer>
25
- <feFuncA type="linear" slope="0.5"></feFuncA> <!-- slope is the opacity of the shadow -->
26
- </feComponentTransfer>
27
- <feMerge>
28
- <feMergeNode></feMergeNode> <!-- this contains the offset blurred image -->
29
- <feMergeNode in="SourceGraphic"></feMergeNode> <!-- this contains the element that the filter is applied to -->
30
- </feMerge>
31
- </filter>
32
-
33
- <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
34
- <g fill="#FFFFFF" fill-rule="nonzero">
35
-
36
- <path d="M81.5784638,1.07718279e-13 C82.7664738,1.07718279e-13 83.8032488,0.734079641 84.4157016,1.75205281 L109.531129,43.5095713 C110.813908,45.6417099 110.657922,48.2974919 109.15835,50.2831454 L80.6973102,87.9923196 C80.0557678,88.7870619 79.0855103,89.3973447 78.0602378,89.3973447 L42.8594985,89.3973447 L14.6289023,43.5796094 L38.1043811,13.5281311 L47.8307983,13.5281311 L25.7347121,43.6175319 L48.0361926,79.9158441 L75.0253918,79.9158441 L101.326814,46.2820182 L73.5454136,1.07718279e-13 L81.5784638,1.07718279e-13 Z M68.8174965,0.000338312914 L96.4191607,45.9808751 L73.2382461,75.6684695 L61.4283598,75.6684695 L84.975762,45.385564 L63.4142078,9.46643441 L36.1380842,9.46643441 L9.60299852,43.3032035 L35.9112712,85.3931029 L38.1241857,89.3191214 L29.1498474,89.3973434 C27.9592604,89.4075947 26.8506993,88.7919375 26.2302294,87.7757572 L0.893096605,46.2796422 C-0.418595034,44.1314075 -0.274907213,41.3978442 1.25477457,39.3989643 L30.388821,1.32865425 L30.4563519,1.24328222 C31.0981823,0.458113729 32.0600455,0.000338312914 33.0779839,0.000338312914 L68.8174965,0.000338312914 Z" id="logo-mark-colour"></path>
37
- </g>
38
- </g>
39
- </svg>
18
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 114 93">
19
+ <title>Delft Solutions</title>
20
+
21
+ <filter id="dropshadow">
22
+ <feGaussianBlur in="SourceAlpha" stdDeviation="1"></feGaussianBlur> <!-- stdDeviation is how much to blur -->
23
+ <feOffset dx="2" dy="1" result="offsetblur"></feOffset> <!-- how much to offset -->
24
+ <feComponentTransfer>
25
+ <feFuncA type="linear" slope="0.5"></feFuncA> <!-- slope is the opacity of the shadow -->
26
+ </feComponentTransfer>
27
+ <feMerge>
28
+ <feMergeNode></feMergeNode> <!-- this contains the offset blurred image -->
29
+ <feMergeNode in="SourceGraphic"></feMergeNode> <!-- this contains the element that the filter is applied to -->
30
+ </feMerge>
31
+ </filter>
32
+
33
+ <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
34
+ <g fill="#FFFFFF" fill-rule="nonzero">
35
+
36
+ <path d="M81.5784638,1.07718279e-13 C82.7664738,1.07718279e-13 83.8032488,0.734079641 84.4157016,1.75205281 L109.531129,43.5095713 C110.813908,45.6417099 110.657922,48.2974919 109.15835,50.2831454 L80.6973102,87.9923196 C80.0557678,88.7870619 79.0855103,89.3973447 78.0602378,89.3973447 L42.8594985,89.3973447 L14.6289023,43.5796094 L38.1043811,13.5281311 L47.8307983,13.5281311 L25.7347121,43.6175319 L48.0361926,79.9158441 L75.0253918,79.9158441 L101.326814,46.2820182 L73.5454136,1.07718279e-13 L81.5784638,1.07718279e-13 Z M68.8174965,0.000338312914 L96.4191607,45.9808751 L73.2382461,75.6684695 L61.4283598,75.6684695 L84.975762,45.385564 L63.4142078,9.46643441 L36.1380842,9.46643441 L9.60299852,43.3032035 L35.9112712,85.3931029 L38.1241857,89.3191214 L29.1498474,89.3973434 C27.9592604,89.4075947 26.8506993,88.7919375 26.2302294,87.7757572 L0.893096605,46.2796422 C-0.418595034,44.1314075 -0.274907213,41.3978442 1.25477457,39.3989643 L30.388821,1.32865425 L30.4563519,1.24328222 C31.0981823,0.458113729 32.0600455,0.000338312914 33.0779839,0.000338312914 L68.8174965,0.000338312914 Z" id="logo-mark-colour"></path>
37
+ </g>
38
+ </g>
39
+ </svg>
40
40
  HERE
41
41
 
42
42
  def self.logo_url
@@ -78,7 +78,7 @@ module MediaTypes
78
78
  a:hover {
79
79
  color: #5E7EFF;
80
80
  }
81
-
81
+
82
82
  #logo {
83
83
  width: <%= logo_width %>em;
84
84
  height: 6em;
@@ -160,7 +160,7 @@ module MediaTypes
160
160
  TEMPLATE
161
161
  template = ERB.new custom_css unless custom_css.nil?
162
162
 
163
- template.result(binding())
163
+ template.result(binding)
164
164
  end
165
165
  end
166
166
  end
@@ -11,21 +11,24 @@ module MediaTypes
11
11
  unvalidated 'text/html'
12
12
 
13
13
  def self.escape_text(text)
14
- text.split("\n").
15
- map { |l| CGI::escapeHTML(l).gsub(/ (?= )/, '&nbsp;') }.
16
- map { |l| (l.gsub(/\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;{}]*[-A-Z0-9+@#\/%=}~_|](?![a-z]*;)/i) do |m|
17
- converted = m
18
- invalid = false
19
- begin
20
- converted = viewerify(m, context.request.host)
21
- rescue URI::InvalidURIError
22
- invalid = true
14
+ text
15
+ .split("\n")
16
+ .map { |l| CGI.escapeHTML(l).gsub(/ (?= )/, '&nbsp;') }
17
+ .map do |l|
18
+ l.gsub(/\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;{}]*[-A-Z0-9+@#\/%=}~_|](?![a-z]*;)/i) do |m|
19
+ converted = m
20
+ invalid = false
21
+ begin
22
+ converted = viewerify(m, context.request.host)
23
+ rescue URI::InvalidURIError
24
+ invalid = true
25
+ end
26
+ style = ''
27
+ style = ' style="color: red"' if invalid
28
+ "<a#{style} href=\"#{converted}\">#{m}</a>"
23
29
  end
24
- style = ''
25
- style = ' style="color: red"' if invalid
26
- "<a#{style} href=\"#{converted}\">#{m}</a>"
27
- end) }.
28
- join("<br>\n")
30
+ end
31
+ .join("<br>\n")
29
32
  end
30
33
 
31
34
  output_raw do |obj, version, context|
@@ -46,6 +49,7 @@ module MediaTypes
46
49
  template = ERB.new <<-TEMPLATE
47
50
  <html lang="en">
48
51
  <head>
52
+ <meta content="width=device-width, initial-scale=1" name="viewport">
49
53
  <title>Invalid input detected</title>
50
54
  <style>
51
55
  <%= css.split("\n").join("\n ") %>
@@ -15,7 +15,9 @@ module MediaTypes
15
15
  output do |problem, _, context|
16
16
  raise 'No translations defined, add at least one title' unless problem.translations.keys.any?
17
17
 
18
- accept_language_header = Utils::AcceptLanguageHeader.new(context.request.get_header(HEADER_ACCEPT_LANGUAGE) || '')
18
+ accept_language_header = Utils::AcceptLanguageHeader.new(
19
+ context.request.get_header(HEADER_ACCEPT_LANGUAGE) || ''
20
+ )
19
21
  translation_entry = accept_language_header.map do |locale|
20
22
  problem.translations.keys.find do |l|
21
23
  l.start_with? locale.locale
@@ -30,6 +32,9 @@ module MediaTypes
30
32
  attribute key, value
31
33
  end
32
34
 
35
+ hidden do
36
+ link :type, href: problem.type
37
+ end
33
38
  attribute :type, problem.type
34
39
  attribute :title, title unless title.nil?
35
40
  attribute :detail, detail unless detail.nil?
@@ -40,13 +45,19 @@ module MediaTypes
40
45
  output_alias 'application/problem+json'
41
46
 
42
47
  output_raw view: :html do |problem, _, context|
43
- accept_language_header = Utils::AcceptLanguageHeader.new(context.request.get_header(HEADER_ACCEPT_LANGUAGE) || '')
48
+ accept_language_header = Utils::AcceptLanguageHeader.new(
49
+ context.request.get_header(HEADER_ACCEPT_LANGUAGE) || ''
50
+ )
44
51
  translation_entry = accept_language_header.map do |locale|
45
52
  problem.translations.keys.find do |l|
46
53
  l.starts_with? locale.locale
47
54
  end
48
55
  end.compact.first || problem.translations.keys.first
49
56
  translation = problem.translations[translation_entry]
57
+
58
+ hidden do
59
+ link :type, href: problem.type
60
+ end
50
61
 
51
62
  title = translation[:title]
52
63
  detail = translation[:detail] || problem.error.message
@@ -57,12 +68,13 @@ module MediaTypes
57
68
  title: title,
58
69
  detail: detail,
59
70
  help_url: problem.type,
60
- css: CommonCSS.css,
71
+ css: CommonCSS.css
61
72
  )
62
73
 
63
74
  template = ERB.new <<-TEMPLATE
64
75
  <html lang="en">
65
76
  <head>
77
+ <meta content="width=device-width, initial-scale=1" name="viewport">
66
78
  <title>Error - <%= CGI::escapeHTML(title) %></title>
67
79
  <style>
68
80
  <%= css.split("\n").join("\n ") %>
@@ -93,7 +105,6 @@ module MediaTypes
93
105
  enable_wildcards
94
106
 
95
107
  output_alias_optional 'text/html', view: :html
96
-
97
108
  end
98
109
  end
99
110
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module MediaTypes
3
4
  module Serialization
4
- VERSION = '1.3.8'
5
+ VERSION = '1.4.0'
5
6
  end
6
7
  end
@@ -321,7 +321,7 @@ module MediaTypes
321
321
  end
322
322
  end
323
323
 
324
- def output_error(klazz)
324
+ def output_error(klazz, serializers: [])
325
325
  rescue_from klazz do |error|
326
326
  problem = Problem.new(error)
327
327
  instance_exec { yield problem, error, self } if block_given?
@@ -331,7 +331,7 @@ module MediaTypes
331
331
 
332
332
  render_media(
333
333
  problem,
334
- serializers: [registrations],
334
+ serializers: [registrations] + serializers.map { |s| s.outputs_for(views: [nil])},
335
335
  status: problem.response_status_code
336
336
  )
337
337
  end
@@ -663,9 +663,13 @@ module MediaTypes
663
663
  return
664
664
  end
665
665
 
666
- render body: result, **options
666
+ if context.serialization_custom_render.nil?
667
+ render body: result, **options
667
668
 
668
- response.content_type = registrations.identifier_for(identifier)
669
+ response.content_type = registrations.identifier_for(identifier)
670
+ else
671
+ context.serialization_custom_render.call(result)
672
+ end
669
673
  end
670
674
  end
671
675
  end
@@ -35,13 +35,13 @@ Gem::Specification.new do |spec|
35
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
36
  spec.require_paths = ['lib']
37
37
 
38
- spec.add_dependency 'actionpack', '>= 4.0.0'
39
- spec.add_dependency 'activesupport', '>= 4.0.0'
40
- spec.add_dependency 'media_types', '>= 2.1.1', '< 3.0.0'
38
+ spec.add_dependency 'actionpack', '>= 6.0.0'
39
+ spec.add_dependency 'activesupport', '>= 6.0.0'
40
+ spec.add_dependency 'media_types', '>= 2.2.0', '< 3.0.0'
41
41
 
42
42
  spec.add_development_dependency 'awesome_print'
43
43
  spec.add_development_dependency 'bundler'
44
- spec.add_development_dependency 'rails', '~> 5.2'
44
+ spec.add_development_dependency 'rails', '~> 6.0'
45
45
  spec.add_development_dependency 'rake', '~> 13.0'
46
46
  spec.add_development_dependency 'minitest', '~> 5.0'
47
47
  spec.add_development_dependency 'oj'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: media_types-serialization
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.8
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-11-04 00:00:00.000000000 Z
12
+ date: 2023-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -17,35 +17,35 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 4.0.0
20
+ version: 6.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 4.0.0
27
+ version: 6.0.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: activesupport
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 4.0.0
34
+ version: 6.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 4.0.0
41
+ version: 6.0.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: media_types
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 2.1.1
48
+ version: 2.2.0
49
49
  - - "<"
50
50
  - !ruby/object:Gem::Version
51
51
  version: 3.0.0
@@ -55,7 +55,7 @@ dependencies:
55
55
  requirements:
56
56
  - - ">="
57
57
  - !ruby/object:Gem::Version
58
- version: 2.1.1
58
+ version: 2.2.0
59
59
  - - "<"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.0.0
@@ -93,14 +93,14 @@ dependencies:
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '5.2'
96
+ version: '6.0'
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '5.2'
103
+ version: '6.0'
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rake
106
106
  requirement: !ruby/object:Gem::Requirement