提交 385d31d2 编写于 作者: J Javan Makhmali

Minimize boilerplate setup code for JavaScript libraries

上级 90536ebf
......@@ -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.
......
// 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 @@ def test_should_not_eager_load_model_for_rake
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 @@ def test_generator_for_active_storage
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 @@ def test_generator_does_not_generate_active_storage_contents_if_skip_active_reco
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|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册