Skip to content

Commit 8e37084

Browse files
committed
get trix editor working and assets loading reliably (in dev)
1 parent 6f97431 commit 8e37084

File tree

7 files changed

+33
-23
lines changed

7 files changed

+33
-23
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// app/assets/config/better_together_manifest.js
22

3-
//= link_tree ../../javascript/better_together/controllers .js
43
//= link_tree ../../javascript/better_together .js
4+
//= link_tree ../../javascript/better_together/controllers .js
55
//= link_tree ../stylesheets/better_together .css
6+
//= link_tree ../stylesheets/better_together .scss
67
//= link_tree ../images/better_together
78

9+
//= link actioncable.js
10+
//= link activestorage.js
11+
//= link actiontext.js
812
//= link bootstrap.min.js
913
//= link popper.js
1014

11-
//= link stimulus.min.js
15+
//= link stimulus.js
1216
//= link stimulus-loading.js
13-
//= link turbo.min.js
17+
//= link turbo.js

app/javascript/better_together/application.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@
1010
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
1111
// about supported directives.
1212
//
13-
// require activestorage
1413
//= require popper
1514
//= require bootstrap-sprockets
16-
// require better_together/controllers
17-
//= require better_together/tooltips
1815

1916
import { Turbo } from '@hotwired/turbo-rails'
2017

21-
import './better_together/controllers'
18+
import 'trix'
19+
import '@rails/actiontext'
2220

23-
// import 'better_together/trix-extensions/richtext'
24-
// import 'trix'
25-
// import { start as startActionText } from '@rails/actiontext'
21+
import './better_together/controllers.js'
22+
import './better_together/tooltips.js'
23+
24+
import './better_together/trix-extensions/richtext.js'
2625

2726
// Turbo.session.drive = false
2827

app/javascript/better_together/controllers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// require better_together/controllers/application
22

3-
import { application } from './controllers/application'
3+
import { application } from './controllers/application.js'
44

55
// load all controllers defined in the import map under controllers/**/*_controller
66
import { lazyLoadControllersFrom } from 'stimulus-loading'

app/javascript/better_together/trix-extensions/richtext.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import Trix from 'trix'
1+
2+
import 'trix'
23

34
document.addEventListener("turbo:load", () => {
45
addHeadingAttributes()
56
addForegroundColorAttributes()
67
addBackgroundColorAttributes()
78

89
addEventListener("trix-initialize", function (event) {
9-
new RichText(event.target)
10+
new RichText(event.target)
1011
})
1112

1213
addEventListener("trix-action-invoke", function (event) {

app/views/layouts/better_together/application.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
<meta name="color-scheme" content="light dark">
66
<%= csrf_meta_tags %>
77
<%= csp_meta_tag %>
8-
9-
<script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js" data-turbo-track="reload"></script>
10-
<%= javascript_importmap_tags %>
118

129
<!-- Stylesheets -->
10+
<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/dist/trix.css">
1311
<%= stylesheet_link_tag 'better_together/application', media: 'all', 'data-turbo-track': 'reload' %>
1412

13+
<%= javascript_importmap_tags %>
1514
</head>
1615
<body class="bg-light">
1716
<!-- Navbar -->

config/importmap.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
# config/importmap.rb
44

5-
pin "application", preload: true
6-
pin 'bootstrap', to: 'bootstrap.min.js', preload: true
7-
pin 'stimulus-loading', to: 'stimulus-loading.js', preload: true
8-
pin 'trix', preload: true
9-
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
10-
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
5+
pin '@hotwired/turbo-rails', to: 'turbo.js', preload: true
6+
pin '@hotwired/stimulus', to: 'stimulus.js', preload: true
117
pin '@popperjs/core', to: 'popper.js', preload: true
8+
pin '@rails/actioncable', to: 'actioncable.js', preload: true
9+
pin '@rails/activestorage', to: 'activestorage.js', preload: true
1210
pin '@rails/actiontext', to: 'actiontext.js', preload: true
13-
pin_all_from "app/javascript/controllers", under: "controllers"
11+
12+
pin 'application', preload: true
13+
pin 'bootstrap', to: 'bootstrap.min.js', preload: true
14+
pin 'es-module-shims', to: 'https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js', preload: true
15+
pin 'stimulus-loading', to: 'stimulus-loading.js', preload: true
16+
pin 'trix', to: 'https://unpkg.com/[email protected]/dist/trix.umd.min.js', preload: true
17+
18+
pin_all_from 'app/javascript/better_together/controllers', under: 'better_together/controllers'
19+
pin_all_from 'app/javascript/better_together/trix-extensions', under: 'better_together/trix-extensions'

lib/better_together/engine.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'action_cable/engine'
34
require 'action_text/engine'
45
require 'active_storage/engine'
56
require 'activerecord-import'

0 commit comments

Comments
 (0)