requestjs-rails 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9916bd029b2135b5211b19d728b8f046ac451c69796b25aaf97e5cf003a90ca
4
- data.tar.gz: 6ff947cb98c9692d7da177fcb99a3c2b5cc9804c7cb34b78265a1bd532077345
3
+ metadata.gz: 7197ad0ee10519041959da9d8bb15c46ca0cf8d9beaecfab20c622860f958986
4
+ data.tar.gz: cc9609ff3a0a1a734ca9e5fc730f8817827340cbefbe7fb3173377fd651e540e
5
5
  SHA512:
6
- metadata.gz: 986c4734b1ce9a324dace368d029a4bb5dea55dfe9a00265cdb0ffd29aa0a53b235cf4d0b37a3110bee1795b4116aa3667cb5ffe47354bc46ee25f44496e1983
7
- data.tar.gz: 96238d856e7b6ae9c1c27495a1ab842ca51115642dedef49895e9d87fa46376c0892daa05f79b412f202332774b7ead4bdae2a729505d618eef75e18ac7b38da
6
+ metadata.gz: 24cd14d2019382171aa3b90432ce64b1eae3b480c185971ba5ed296c3e13ad83e2e2204ee0295dacfe3ff0662cf46c8e041ae8611ef1db388f36611a41a077a4
7
+ data.tar.gz: db70051cd27a70fc4267e120c3856ec867c0a0d7be59036cec43384d89238a899dbd21ab9a86c1f04bfd43b2311c7578d8f399c943e089e6bb086ca121629b3f
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  If using the asset pipeline to manage JavaScript, the last command will:
12
12
 
13
- - Append import "@rails/request.js" to your app/assets/javascripts/application.js entrypoint.
13
+ - Append `import "@rails/request.js"` to your `app/assets/javascripts/application.js` entrypoint.
14
14
 
15
15
  Make sure you've already installed `importmap-rails` and that it's referenced before `requestjs-rails` in your Gemfile.
16
16
 
@@ -24,4 +24,4 @@ With the installation done check the documentation in the [Rails Request.JS](htt
24
24
 
25
25
  ## License
26
26
 
27
- Request.JS for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
27
+ Request.JS for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
@@ -14,6 +14,9 @@ class FetchResponse {
14
14
  get unauthenticated() {
15
15
  return this.statusCode === 401;
16
16
  }
17
+ get unprocessableEntity() {
18
+ return this.statusCode === 422;
19
+ }
17
20
  get authenticationURL() {
18
21
  return this.response.headers.get("WWW-Authenticate");
19
22
  }
@@ -31,7 +34,7 @@ class FetchResponse {
31
34
  return Promise.reject(new Error(`Expected an HTML response but got "${this.contentType}" instead`));
32
35
  }
33
36
  get json() {
34
- if (this.contentType.match(/^application\/json/)) {
37
+ if (this.contentType.match(/^application\/.*json$/)) {
35
38
  return this.responseJson || (this.responseJson = this.response.json());
36
39
  }
37
40
  return Promise.reject(new Error(`Expected a JSON response but got "${this.contentType}" instead`));
@@ -45,7 +48,7 @@ class FetchResponse {
45
48
  async renderTurboStream() {
46
49
  if (this.isTurboStream) {
47
50
  if (window.Turbo) {
48
- window.Turbo.renderStreamMessage(await this.text);
51
+ await window.Turbo.renderStreamMessage(await this.text);
49
52
  } else {
50
53
  console.warn("You must set `window.Turbo = Turbo` to automatically process Turbo Stream events with request.js");
51
54
  }
@@ -115,7 +118,7 @@ class FetchRequest {
115
118
  constructor(method, url, options = {}) {
116
119
  this.method = method;
117
120
  this.options = options;
118
- this.originalUrl = url;
121
+ this.originalUrl = url.toString();
119
122
  }
120
123
  async perform() {
121
124
  try {
@@ -131,7 +134,7 @@ class FetchRequest {
131
134
  return Promise.reject(window.location.href = response.authenticationURL);
132
135
  }
133
136
  if (response.ok && response.isTurboStream) {
134
- response.renderTurboStream();
137
+ await response.renderTurboStream();
135
138
  }
136
139
  return response;
137
140
  }
@@ -180,7 +183,7 @@ class FetchRequest {
180
183
  return "text/vnd.turbo-stream.html, text/html, application/xhtml+xml";
181
184
 
182
185
  case "json":
183
- return "application/json";
186
+ return "application/json, application/vnd.api+json";
184
187
 
185
188
  default:
186
189
  return "*/*";
@@ -205,7 +208,7 @@ class FetchRequest {
205
208
  return query.length > 0 ? `?${query}` : "";
206
209
  }
207
210
  get url() {
208
- return this.originalUrl.split("?")[0] + this.query;
211
+ return this.originalUrl.split("?")[0].split("#")[0] + this.query;
209
212
  }
210
213
  get responseKind() {
211
214
  return this.options.responseKind || "html";
@@ -1,4 +1,7 @@
1
1
  APP_JS_ROOT = Rails.root.join("app/assets/javascripts")
2
+ APP_JS_PATH = APP_JS_ROOT.exist? ? APP_JS_ROOT : Rails.root.join("app/javascript")
2
3
 
3
- say "Import Request.JS in existing app/assets/javascripts/application.js"
4
- append_to_file APP_JS_ROOT.join("application.js"), %(import "@rails/request.js"\n)
4
+ create_file Rails.root.join("app/javascript/application.js") unless APP_JS_PATH.exist?
5
+
6
+ say "Import Request.JS in existing #{APP_JS_PATH}"
7
+ append_to_file APP_JS_PATH.join("application.js"), %(import "@rails/request.js"\n)
@@ -7,9 +7,9 @@ module Requestjs
7
7
  end
8
8
 
9
9
  initializer "requestjs.importmap" do
10
- if Rails.application.config.respond_to?(:importmap)
11
- Rails.application.config.importmap.paths.tap do |paths|
12
- paths.asset "@rails/request.js", path: "rails-requestjs"
10
+ if Rails.application.respond_to?(:importmap)
11
+ Rails.application.importmap.draw do
12
+ pin "@rails/request.js", to: "rails-requestjs"
13
13
  end
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module Requestjs
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requestjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Lauxen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-11 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails