mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Minimize boilerplate setup code for JavaScript libraries
This commit is contained in:
parent
90536ebfb3
commit
385d31d209
8 changed files with 14 additions and 23 deletions
|
@ -40,8 +40,7 @@ In a conventional Rails application that uses the asset pipeline, require `rails
|
|||
If you're using the Webpacker gem or some other JavaScript bundler, add the following to your main JS file:
|
||||
|
||||
```javascript
|
||||
import Rails from "@rails/ujs"
|
||||
Rails.start()
|
||||
require("@rails/ujs").start()
|
||||
```
|
||||
|
||||
## How to run tests
|
||||
|
|
|
@ -118,8 +118,7 @@ Active Storage, with its included JavaScript library, supports uploading directl
|
|||
```
|
||||
Using the npm package:
|
||||
```js
|
||||
import * as ActiveStorage from "@rails/activestorage"
|
||||
ActiveStorage.start()
|
||||
require("@rails/activestorage").start()
|
||||
```
|
||||
2. Annotate file inputs with the direct upload URL.
|
||||
|
||||
|
|
|
@ -181,9 +181,9 @@ established using the following JavaScript, which is generated by default by Rai
|
|||
// Action Cable provides the framework to deal with WebSockets in Rails.
|
||||
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
|
||||
|
||||
import ActionCable from "@rails/actioncable"
|
||||
import { createConsumer } from "@rails/actioncable"
|
||||
|
||||
export default ActionCable.createConsumer()
|
||||
export default createConsumer()
|
||||
```
|
||||
|
||||
This will ready a consumer that'll connect against `/cable` on your server by default.
|
||||
|
|
|
@ -489,8 +489,7 @@ directly from the client to the cloud.
|
|||
Using the npm package:
|
||||
|
||||
```js
|
||||
import * as ActiveStorage from "@rails/activestorage"
|
||||
ActiveStorage.start()
|
||||
require("@rails/activestorage").start()
|
||||
```
|
||||
|
||||
2. Annotate file inputs with the direct upload URL.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Action Cable provides the framework to deal with WebSockets in Rails.
|
||||
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
|
||||
|
||||
import ActionCable from "@rails/actioncable"
|
||||
import { createConsumer } from "@rails/actioncable"
|
||||
|
||||
export default ActionCable.createConsumer()
|
||||
export default createConsumer()
|
||||
|
|
|
@ -3,19 +3,13 @@
|
|||
// a relevant structure within app/javascript and only use these pack files to reference
|
||||
// that code so it'll be compiled.
|
||||
|
||||
import Rails from "@rails/ujs"
|
||||
Rails.start()
|
||||
require("@rails/ujs").start()
|
||||
<%- unless options[:skip_turbolinks] -%>
|
||||
|
||||
import Turbolinks from "turbolinks"
|
||||
Turbolinks.start()
|
||||
require("turbolinks").start()
|
||||
<%- end -%>
|
||||
<%- unless skip_active_storage? -%>
|
||||
|
||||
import * as ActiveStorage from "@rails/activestorage"
|
||||
ActiveStorage.start()
|
||||
require("@rails/activestorage").start()
|
||||
<%- end -%>
|
||||
<%- unless options[:skip_action_cable] -%>
|
||||
|
||||
import "channels"
|
||||
require("channels")
|
||||
<%- end -%>
|
||||
|
|
|
@ -118,7 +118,7 @@ module ApplicationTests
|
|||
end
|
||||
|
||||
def test_code_statistics_sanity
|
||||
assert_match "Code LOC: 32 Test LOC: 0 Code to Test Ratio: 1:0.0",
|
||||
assert_match "Code LOC: 29 Test LOC: 0 Code to Test Ratio: 1:0.0",
|
||||
rails("stats")
|
||||
end
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ module SharedGeneratorTests
|
|||
|
||||
unless generator_class.name == "Rails::Generators::PluginGenerator"
|
||||
assert_file "#{application_path}/app/javascript/packs/application.js" do |content|
|
||||
assert_match(/^import \* as ActiveStorage from "@rails\/activestorage"\nActiveStorage.start\(\)/, content)
|
||||
assert_match(/^require\("@rails\/activestorage"\)\.start\(\)/, content)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -267,7 +267,7 @@ module SharedGeneratorTests
|
|||
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_storage\/engine["']/
|
||||
|
||||
assert_file "#{application_path}/app/javascript/packs/application.js" do |content|
|
||||
assert_no_match(/^import * as ActiveStorage from "@rails\/activestorage"\nActiveStorage.start\(\)/, content)
|
||||
assert_no_match(/^require\("@rails\/activestorage"\)\.start\(\)/, content)
|
||||
end
|
||||
|
||||
assert_file "#{application_path}/config/environments/development.rb" do |content|
|
||||
|
|
Loading…
Reference in a new issue