rs-activeadmin_trumbowyg 4.0.4
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 +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +292 -0
- data/Rakefile +27 -0
- data/lib/activeadmin/trumbowyg/engine.rb +29 -0
- data/lib/activeadmin/trumbowyg/version.rb +7 -0
- data/lib/activeadmin/trumbowyg.rb +3 -0
- data/lib/activeadmin_trumbowyg.rb +3 -0
- data/lib/formtastic/inputs/trumbowyg_input.rb +20 -0
- data/lib/generators/active_admin/trumbowyg/install/install_generator.rb +218 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a22e10401e857f619e1eb4cdb62c4c40236aea28553f6f787ed05f6e1d01b1c6
|
4
|
+
data.tar.gz: 7da8d51f4348d871bb730b1ecc9e5ebe96aefce64fa0572692a0ec3e7d089095
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd45b6ac6f8045f32901dd870c0c8d235b7afec239503b564591c797c69460bad8e32f804791c68762bf687468abf3d5c13f956706f755c79b6a053f6cd01b51
|
7
|
+
data.tar.gz: 359c294d51ac221c31d86b777c9683d5a0316d15f29e12131a0557c938d746f53c717e541149c2810bccc539e9626186665f4c478a6e988fe53d8180526b4788
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2017-2020 Mattia Roccoberton
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,292 @@
|
|
1
|
+
# Active Admin Trumbowyg (Rocket Sensei Fork)
|
2
|
+
|
3
|
+
[](https://github.com/glebtv/activeadmin_trumbowyg/actions/workflows/ci.yml)
|
4
|
+
[](https://www.npmjs.com/package/@rocket-sensei/activeadmin_trumbowyg)
|
5
|
+
|
6
|
+
**Note:** This is the Rocket Sensei fork of activeadmin_trumbowyg, providing full ActiveAdmin 4 and Rails 8 support.
|
7
|
+
|
8
|
+
An *Active Admin* plugin to use [Trumbowyg](https://alex-d.github.io/Trumbowyg/) as WYSIWYG editor in form inputs.
|
9
|
+
|
10
|
+
Features:
|
11
|
+
- Fast & lightweight rich editor for Active Admin
|
12
|
+
- Customizable options via data attributes
|
13
|
+
- Plugin support (image upload, emoji, etc.)
|
14
|
+
- Dark mode support for ActiveAdmin 4
|
15
|
+
- Automatic NPM package publishing on new releases
|
16
|
+
|
17
|
+
### Light Mode
|
18
|
+

|
19
|
+
|
20
|
+
### Dark Mode
|
21
|
+

|
22
|
+
|
23
|
+
Please :star: if you like it.
|
24
|
+
|
25
|
+
## Version 2.0 - ActiveAdmin 4 Support
|
26
|
+
|
27
|
+
This version is designed for **ActiveAdmin 4.x with modern JavaScript bundlers** (esbuild/webpack).
|
28
|
+
|
29
|
+
- **ActiveAdmin 4.x**: Use version 2.x of this gem
|
30
|
+
- **ActiveAdmin 1.x - 3.x**: Use version 1.x of this gem
|
31
|
+
|
32
|
+
### Requirements
|
33
|
+
|
34
|
+
- Ruby >= 3.2
|
35
|
+
- Rails >= 7.0
|
36
|
+
- ActiveAdmin ~> 4.0.0.beta
|
37
|
+
- Modern JavaScript bundler (esbuild or webpack)
|
38
|
+
- Propshaft for asset management (included in Rails 8, add manually for Rails 7)
|
39
|
+
|
40
|
+
**Note:** This gem is specifically designed for ActiveAdmin 4 with modern JavaScript bundlers. Sprockets is not supported.
|
41
|
+
|
42
|
+
## Install
|
43
|
+
|
44
|
+
### Step 1: Add the gem
|
45
|
+
|
46
|
+
Add to your Gemfile:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
gem 'rs-activeadmin_trumbowyg', '~> 4.0.3'
|
50
|
+
|
51
|
+
# For Rails 7, also add Propshaft (Rails 8 includes it by default):
|
52
|
+
gem 'propshaft' # Required for Rails 7
|
53
|
+
```
|
54
|
+
|
55
|
+
Then run `bundle install`.
|
56
|
+
|
57
|
+
### Step 2: Install JavaScript package and configure
|
58
|
+
|
59
|
+
ActiveAdmin 4 uses modern JavaScript bundlers. Choose your setup:
|
60
|
+
|
61
|
+
#### For esbuild or webpack (recommended)
|
62
|
+
|
63
|
+
1. Install the NPM packages:
|
64
|
+
```bash
|
65
|
+
npm install @rocket-sensei/activeadmin_trumbowyg jquery trumbowyg
|
66
|
+
```
|
67
|
+
|
68
|
+
2. Import and configure in your `app/javascript/active_admin.js`:
|
69
|
+
```javascript
|
70
|
+
// Import jQuery and make it globally available (required by Trumbowyg)
|
71
|
+
import $ from 'jquery';
|
72
|
+
window.$ = window.jQuery = $;
|
73
|
+
|
74
|
+
// Import Trumbowyg
|
75
|
+
import 'trumbowyg';
|
76
|
+
|
77
|
+
// Import and setup ActiveAdmin Trumbowyg
|
78
|
+
import { setupAutoInit } from '@rocket-sensei/activeadmin_trumbowyg';
|
79
|
+
|
80
|
+
// Optional: Configure the SVG icons path (default is '/icons.svg')
|
81
|
+
// window.TRUMBOWYG_SVG_PATH = '/assets/icons.svg';
|
82
|
+
|
83
|
+
setupAutoInit();
|
84
|
+
```
|
85
|
+
|
86
|
+
3. Copy Trumbowyg assets (icons and CSS) for Propshaft:
|
87
|
+
```bash
|
88
|
+
# Add these to your package.json scripts section:
|
89
|
+
"copy:trumbowyg-icons": "mkdir -p app/assets/builds && cp node_modules/trumbowyg/dist/ui/icons.svg app/assets/builds/icons.svg",
|
90
|
+
"copy:trumbowyg-css": "cp node_modules/trumbowyg/dist/ui/trumbowyg.min.css app/assets/builds/trumbowyg.css",
|
91
|
+
"build:assets": "npm run copy:trumbowyg-icons && npm run copy:trumbowyg-css"
|
92
|
+
|
93
|
+
# Then run:
|
94
|
+
npm run build:assets
|
95
|
+
```
|
96
|
+
|
97
|
+
**Note for Rails with Propshaft:** The icons.svg file needs to be accessible via HTTP. The default path is `/icons.svg` but you can configure it by setting `window.TRUMBOWYG_SVG_PATH` before calling `setupAutoInit()`. In production, Propshaft will serve files from `app/assets/builds/` with digest paths. You may need to configure the path based on your deployment setup.
|
98
|
+
|
99
|
+
4. Add Trumbowyg styles to `app/assets/stylesheets/active_admin.css`:
|
100
|
+
```css
|
101
|
+
/* Import Trumbowyg styles - the exact path depends on your asset pipeline setup */
|
102
|
+
/* For Propshaft/esbuild, the CSS will be in app/assets/builds/ */
|
103
|
+
@import 'trumbowyg.css';
|
104
|
+
|
105
|
+
/* Custom Trumbowyg input styles */
|
106
|
+
.trumbowyg-box {
|
107
|
+
margin: 0;
|
108
|
+
}
|
109
|
+
|
110
|
+
.trumbowyg-editor {
|
111
|
+
min-height: 200px;
|
112
|
+
}
|
113
|
+
```
|
114
|
+
|
115
|
+
**Note:** The icons.svg and trumbowyg.css files are copied from the npm package to your assets/builds directory. These files should be added to .gitignore as they're generated during the build process:
|
116
|
+
|
117
|
+
```gitignore
|
118
|
+
# Ignore generated Trumbowyg assets
|
119
|
+
app/assets/builds/icons.svg
|
120
|
+
app/assets/builds/trumbowyg.css
|
121
|
+
```
|
122
|
+
|
123
|
+
#### For importmap
|
124
|
+
|
125
|
+
Importmap users need manual configuration as it doesn't support NPM packages:
|
126
|
+
|
127
|
+
1. Run the installation generator:
|
128
|
+
```bash
|
129
|
+
rails generate active_admin:trumbowyg:install --bundler=importmap
|
130
|
+
```
|
131
|
+
|
132
|
+
This will:
|
133
|
+
- Add pins to your `config/importmap.rb`
|
134
|
+
- Copy vendor JavaScript files
|
135
|
+
- Add Trumbowyg styles to your ActiveAdmin stylesheet
|
136
|
+
|
137
|
+
### Step 3: Use in your forms
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
ActiveAdmin.register Article do
|
141
|
+
form do |f|
|
142
|
+
f.inputs 'Article' do
|
143
|
+
f.input :title
|
144
|
+
f.input :description, as: :trumbowyg
|
145
|
+
f.input :published
|
146
|
+
end
|
147
|
+
f.actions
|
148
|
+
end
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
### Step 4: Production setup
|
153
|
+
|
154
|
+
For production environments, simply deploy as usual. All assets are handled automatically through the NPM package or CDN.
|
155
|
+
|
156
|
+
## Usage
|
157
|
+
|
158
|
+
### Basic usage
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
form do |f|
|
162
|
+
f.inputs 'Article' do
|
163
|
+
f.input :title
|
164
|
+
f.input :description, as: :trumbowyg
|
165
|
+
f.input :published
|
166
|
+
end
|
167
|
+
f.actions
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
171
|
+
### With custom options
|
172
|
+
|
173
|
+
The **data-options** attribute allows you to pass Trumbowyg configuration directly. For reference see [options list](https://alex-d.github.io/Trumbowyg/documentation/).
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
f.input :description, as: :trumbowyg, input_html: {
|
177
|
+
data: {
|
178
|
+
options: {
|
179
|
+
btns: [
|
180
|
+
['bold', 'italic'],
|
181
|
+
['superscript', 'subscript'],
|
182
|
+
['link'],
|
183
|
+
['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
|
184
|
+
['unorderedList', 'orderedList'],
|
185
|
+
['horizontalRule'],
|
186
|
+
['removeformat']
|
187
|
+
]
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}
|
191
|
+
```
|
192
|
+
|
193
|
+
## Plugins
|
194
|
+
|
195
|
+
### Upload plugin
|
196
|
+
|
197
|
+
Plugin reference [here](https://alex-d.github.io/Trumbowyg/documentation/plugins/#plugin-upload).
|
198
|
+
|
199
|
+
Add to your JavaScript file (after importing trumbowyg):
|
200
|
+
|
201
|
+
```javascript
|
202
|
+
import 'trumbowyg/dist/plugins/upload/trumbowyg.upload.js';
|
203
|
+
```
|
204
|
+
|
205
|
+
Form field config:
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
unless resource.new_record?
|
209
|
+
f.input :description, as: :trumbowyg, input_html: {
|
210
|
+
data: {
|
211
|
+
options: {
|
212
|
+
btns: [['bold', 'italic'], ['link'], ['upload']],
|
213
|
+
plugins: {
|
214
|
+
upload: {
|
215
|
+
serverPath: upload_admin_post_path(resource.id),
|
216
|
+
fileFieldName: 'file_upload'
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
}
|
222
|
+
end
|
223
|
+
```
|
224
|
+
|
225
|
+
Upload action (using ActiveStorage):
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
member_action :upload, method: [:post] do
|
229
|
+
result = { success: resource.images.attach(params[:file_upload]) }
|
230
|
+
result[:file] = url_for(resource.images.last) if result[:success]
|
231
|
+
render json: result
|
232
|
+
end
|
233
|
+
```
|
234
|
+
|
235
|
+
For a complete upload example, see [examples/upload_plugin_using_activestorage/](examples/upload_plugin_using_activestorage/).
|
236
|
+
|
237
|
+
## Migration from version 1.x
|
238
|
+
|
239
|
+
If upgrading from version 1.x:
|
240
|
+
|
241
|
+
1. Update Ruby to >= 3.2 and Rails to >= 7.0
|
242
|
+
2. Update to ActiveAdmin 4.x
|
243
|
+
3. Remove old asset pipeline configurations:
|
244
|
+
- Remove `//= require activeadmin/trumbowyg/trumbowyg` from `active_admin.js`
|
245
|
+
- Remove `//= require activeadmin/trumbowyg_input` from `active_admin.js`
|
246
|
+
- Remove `@import 'activeadmin/trumbowyg/trumbowyg';` from `active_admin.scss`
|
247
|
+
- Remove `@import 'activeadmin/trumbowyg_input';` from `active_admin.scss`
|
248
|
+
4. Install the NPM package and import it (for esbuild/webpack) or run the generator (for importmap) - see Step 2 above
|
249
|
+
|
250
|
+
## Troubleshooting
|
251
|
+
|
252
|
+
### Trumbowyg not initializing
|
253
|
+
|
254
|
+
Make sure jQuery and Trumbowyg are loaded before the initialization script. Check your browser console for errors.
|
255
|
+
|
256
|
+
### Icons not showing
|
257
|
+
|
258
|
+
Ensure you're using the correct version of Trumbowyg from NPM. Icons are embedded in the CSS from the NPM package.
|
259
|
+
|
260
|
+
### Custom plugins not working
|
261
|
+
|
262
|
+
Ensure you're importing the plugin JavaScript files after the main Trumbowyg library.
|
263
|
+
|
264
|
+
## Changelog
|
265
|
+
|
266
|
+
The changelog is available [here](CHANGELOG.md).
|
267
|
+
|
268
|
+
## Contributing
|
269
|
+
|
270
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/glebtv/activeadmin_trumbowyg.
|
271
|
+
|
272
|
+
## Development
|
273
|
+
|
274
|
+
For development information please check [this document](extra/development.md).
|
275
|
+
|
276
|
+
### NPM Package Publishing
|
277
|
+
|
278
|
+
The JavaScript portion of this gem is automatically published to NPM as `@rocket-sensei/activeadmin_trumbowyg` when a new version tag is created. This happens through GitHub Actions CI/CD pipeline.
|
279
|
+
|
280
|
+
### Migration from Original Gem
|
281
|
+
|
282
|
+
If you're using the original `activeadmin_trumbowyg` gem, please see our [Migration Guide](docs/guide-update-your-app.md) for detailed upgrade instructions.
|
283
|
+
|
284
|
+
## Do you like it? Star it!
|
285
|
+
|
286
|
+
If you use this component just star it. A developer is more motivated to improve a project when there is some interest. My other [Active Admin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source).
|
287
|
+
|
288
|
+
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
|
289
|
+
|
290
|
+
## License
|
291
|
+
|
292
|
+
The gem is available as open-source under the terms of the [MIT](LICENSE.txt).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
APP_RAKEFILE = File.expand_path("spec/internal/Rakefile", __dir__)
|
10
|
+
load 'rails/tasks/engine.rake' if File.exist?(APP_RAKEFILE)
|
11
|
+
|
12
|
+
# load 'rails/tasks/statistics.rake' # Commented out - causes issues with Rails 8
|
13
|
+
|
14
|
+
require 'bundler/gem_tasks'
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'rspec/core/rake_task'
|
18
|
+
|
19
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
20
|
+
# t.ruby_opts = %w[-w]
|
21
|
+
t.rspec_opts = ['--color', '--format documentation']
|
22
|
+
end
|
23
|
+
|
24
|
+
task default: :spec
|
25
|
+
rescue LoadError
|
26
|
+
puts '! LoadError: no RSpec available'
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/engine'
|
4
|
+
|
5
|
+
module ActiveAdmin
|
6
|
+
module Trumbowyg
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
engine_name 'activeadmin_trumbowyg'
|
9
|
+
|
10
|
+
# Add our assets to the asset load paths
|
11
|
+
initializer 'activeadmin_trumbowyg.assets' do |app|
|
12
|
+
app.config.assets.paths << root.join('app', 'assets', 'stylesheets')
|
13
|
+
app.config.assets.paths << root.join('app', 'assets', 'javascripts')
|
14
|
+
app.config.assets.paths << root.join('app', 'assets', 'fonts')
|
15
|
+
end
|
16
|
+
|
17
|
+
initializer 'activeadmin_trumbowyg.setup', after: :load_config_initializers do
|
18
|
+
require 'active_admin' if defined?(Rails.application) && Rails.application
|
19
|
+
# Load the Formtastic input directly
|
20
|
+
require 'formtastic/inputs/trumbowyg_input'
|
21
|
+
|
22
|
+
# Also hook into ActiveAdmin's load process
|
23
|
+
ActiveSupport.on_load(:active_admin) do
|
24
|
+
require 'formtastic/inputs/trumbowyg_input'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Formtastic
|
4
|
+
module Inputs
|
5
|
+
class TrumbowygInput < Formtastic::Inputs::TextInput
|
6
|
+
def to_html
|
7
|
+
input_wrapping do
|
8
|
+
label_html << builder.text_area(method, input_html_options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def input_html_options
|
13
|
+
super.tap do |options|
|
14
|
+
options[:class] = [options[:class], 'trumbowyg-input'].compact.join(' ')
|
15
|
+
options['data-aa-trumbowyg'] = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module ActiveAdmin
|
6
|
+
module Trumbowyg
|
7
|
+
module Generators
|
8
|
+
class InstallGenerator < Rails::Generators::Base
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
10
|
+
|
11
|
+
desc 'Installs ActiveAdmin Trumbowyg for ActiveAdmin 4.x'
|
12
|
+
|
13
|
+
class_option :bundler,
|
14
|
+
type: :string,
|
15
|
+
default: 'esbuild',
|
16
|
+
desc: 'JavaScript bundler to use (esbuild, importmap, webpack)',
|
17
|
+
enum: %w[esbuild importmap webpack]
|
18
|
+
|
19
|
+
def install_npm_package
|
20
|
+
return if options[:bundler] == 'importmap'
|
21
|
+
|
22
|
+
say 'Installing @rocket-sensei/activeadmin_trumbowyg npm package...', :green
|
23
|
+
run 'npm install @rocket-sensei/activeadmin_trumbowyg jquery trumbowyg'
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup_javascript
|
27
|
+
case options[:bundler]
|
28
|
+
when 'esbuild'
|
29
|
+
setup_esbuild
|
30
|
+
when 'importmap'
|
31
|
+
setup_importmap
|
32
|
+
when 'webpack'
|
33
|
+
setup_webpack
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup_stylesheets
|
38
|
+
if File.exist?('app/assets/stylesheets/active_admin.css')
|
39
|
+
say 'Adding Trumbowyg styles to active_admin.css...', :green
|
40
|
+
append_to_file 'app/assets/stylesheets/active_admin.css' do
|
41
|
+
<<~CSS
|
42
|
+
|
43
|
+
/* Trumbowyg Editor */
|
44
|
+
@import url('https://cdn.jsdelivr.net/npm/trumbowyg@2/dist/ui/trumbowyg.min.css');
|
45
|
+
CSS
|
46
|
+
end
|
47
|
+
elsif File.exist?('app/assets/stylesheets/active_admin.scss')
|
48
|
+
say 'Adding Trumbowyg styles to active_admin.scss...', :green
|
49
|
+
append_to_file 'app/assets/stylesheets/active_admin.scss' do
|
50
|
+
<<~SCSS
|
51
|
+
|
52
|
+
// Trumbowyg Editor
|
53
|
+
@import url('https://cdn.jsdelivr.net/npm/trumbowyg@2/dist/ui/trumbowyg.min.css');
|
54
|
+
SCSS
|
55
|
+
end
|
56
|
+
else
|
57
|
+
say 'Please manually add Trumbowyg styles to your ActiveAdmin stylesheet', :yellow
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def copy_icons
|
62
|
+
say 'Icons are automatically included via the NPM package', :green
|
63
|
+
end
|
64
|
+
|
65
|
+
def show_post_install_message
|
66
|
+
say "\n✅ ActiveAdmin Trumbowyg has been installed!", :green
|
67
|
+
|
68
|
+
case options[:bundler]
|
69
|
+
when 'esbuild'
|
70
|
+
say "\nMake sure to rebuild your JavaScript:", :yellow
|
71
|
+
say ' npm run build', :cyan
|
72
|
+
say "\nFor development with watch mode:", :yellow
|
73
|
+
say ' npm run build -- --watch', :cyan
|
74
|
+
when 'importmap'
|
75
|
+
say "\nRestart your Rails server to load the new pins.", :yellow
|
76
|
+
when 'webpack'
|
77
|
+
say "\nRecompile your webpack bundles:", :yellow
|
78
|
+
say ' bin/webpack', :cyan
|
79
|
+
end
|
80
|
+
|
81
|
+
say "\n📚 Usage example:", :green
|
82
|
+
say <<~RUBY
|
83
|
+
|
84
|
+
# In your ActiveAdmin resource:
|
85
|
+
ActiveAdmin.register Article do
|
86
|
+
form do |f|
|
87
|
+
f.inputs 'Article' do
|
88
|
+
f.input :title
|
89
|
+
f.input :description, as: :trumbowyg
|
90
|
+
f.input :published
|
91
|
+
end
|
92
|
+
f.actions
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# With custom options:
|
97
|
+
f.input :description, as: :trumbowyg, input_html: {#{' '}
|
98
|
+
data: {#{' '}
|
99
|
+
options: {#{' '}
|
100
|
+
btns: [
|
101
|
+
['bold', 'italic'],#{' '}
|
102
|
+
['link'],
|
103
|
+
['upload']
|
104
|
+
],
|
105
|
+
plugins: {
|
106
|
+
upload: {
|
107
|
+
serverPath: upload_admin_article_path(resource.id),
|
108
|
+
fileFieldName: 'file_upload'
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
RUBY
|
115
|
+
|
116
|
+
say "\n📦 Note: Icons and styles are included automatically.", :green
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def setup_esbuild
|
122
|
+
say 'Setting up for esbuild...', :green
|
123
|
+
|
124
|
+
js_file = 'app/javascript/active_admin.js'
|
125
|
+
|
126
|
+
if File.exist?(js_file)
|
127
|
+
say "Adding Trumbowyg to #{js_file}...", :green
|
128
|
+
append_to_file js_file do
|
129
|
+
<<~JS
|
130
|
+
|
131
|
+
// ActiveAdmin Trumbowyg Editor
|
132
|
+
// All dependencies and initialization are handled by the package
|
133
|
+
import '@rocket-sensei/activeadmin_trumbowyg';
|
134
|
+
JS
|
135
|
+
end
|
136
|
+
else
|
137
|
+
say "Creating #{js_file}...", :green
|
138
|
+
create_file js_file do
|
139
|
+
<<~JS
|
140
|
+
import "@activeadmin/activeadmin";
|
141
|
+
|
142
|
+
// ActiveAdmin Trumbowyg Editor
|
143
|
+
// All dependencies and initialization are handled by the package
|
144
|
+
import '@rocket-sensei/activeadmin_trumbowyg';
|
145
|
+
JS
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
update_package_json_scripts
|
150
|
+
end
|
151
|
+
|
152
|
+
def setup_importmap
|
153
|
+
say 'Setting up for importmap...', :green
|
154
|
+
|
155
|
+
if File.exist?('config/importmap.rb')
|
156
|
+
say 'Adding pins to config/importmap.rb...', :green
|
157
|
+
append_to_file 'config/importmap.rb' do
|
158
|
+
<<~RUBY
|
159
|
+
|
160
|
+
# ActiveAdmin Trumbowyg Editor
|
161
|
+
pin "jquery", to: "https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"
|
162
|
+
pin "trumbowyg", to: "https://cdn.jsdelivr.net/npm/trumbowyg@2/dist/trumbowyg.min.js"
|
163
|
+
pin "activeadmin_trumbowyg", to: "activeadmin-trumbowyg.js"
|
164
|
+
RUBY
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
js_file = 'app/javascript/application.js'
|
169
|
+
return unless File.exist?(js_file)
|
170
|
+
|
171
|
+
say "Adding import to #{js_file}...", :green
|
172
|
+
append_to_file js_file do
|
173
|
+
<<~JS
|
174
|
+
|
175
|
+
// ActiveAdmin Trumbowyg Editor - single import loads everything
|
176
|
+
import "activeadmin_trumbowyg"
|
177
|
+
JS
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def setup_webpack
|
182
|
+
say 'Setting up for webpack...', :green
|
183
|
+
|
184
|
+
js_file = 'app/javascript/packs/active_admin.js'
|
185
|
+
|
186
|
+
if File.exist?(js_file)
|
187
|
+
say "Adding Trumbowyg to #{js_file}...", :green
|
188
|
+
append_to_file js_file do
|
189
|
+
<<~JS
|
190
|
+
|
191
|
+
// ActiveAdmin Trumbowyg Editor - single import loads everything
|
192
|
+
import '@rocket-sensei/activeadmin_trumbowyg';
|
193
|
+
JS
|
194
|
+
end
|
195
|
+
else
|
196
|
+
say 'Please manually add Trumbowyg import to your ActiveAdmin JavaScript pack', :yellow
|
197
|
+
say "Add this line: import '@rocket-sensei/activeadmin_trumbowyg';", :cyan
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def update_package_json_scripts
|
202
|
+
return unless File.exist?('package.json')
|
203
|
+
|
204
|
+
package_json = JSON.parse(File.read('package.json'))
|
205
|
+
return if package_json['scripts'] && package_json['scripts']['build']
|
206
|
+
|
207
|
+
say 'Adding build script to package.json...', :green
|
208
|
+
package_json['scripts'] ||= {}
|
209
|
+
package_json['scripts']['build'] =
|
210
|
+
'esbuild app/javascript/*.* --bundle --sourcemap --format=esm ' \
|
211
|
+
'--outdir=app/assets/builds --public-path=/assets'
|
212
|
+
|
213
|
+
File.write('package.json', JSON.pretty_generate(package_json))
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rs-activeadmin_trumbowyg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 4.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rocket Sensei
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activeadmin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0.beta
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0.beta
|
27
|
+
description: An Active Admin plugin to use Trumbowyg Editor
|
28
|
+
email: glebtv@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- LICENSE.txt
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/activeadmin/trumbowyg.rb
|
37
|
+
- lib/activeadmin/trumbowyg/engine.rb
|
38
|
+
- lib/activeadmin/trumbowyg/version.rb
|
39
|
+
- lib/activeadmin_trumbowyg.rb
|
40
|
+
- lib/formtastic/inputs/trumbowyg_input.rb
|
41
|
+
- lib/generators/active_admin/trumbowyg/install/install_generator.rb
|
42
|
+
homepage: https://github.com/glebtv/activeadmin_trumbowyg
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata:
|
46
|
+
homepage_uri: https://github.com/glebtv/activeadmin_trumbowyg
|
47
|
+
changelog_uri: https://github.com/glebtv/activeadmin_trumbowyg/blob/main/CHANGELOG.md
|
48
|
+
source_code_uri: https://github.com/glebtv/activeadmin_trumbowyg
|
49
|
+
rubygems_mfa_required: 'true'
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '3.2'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.4.10
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Trumbowyg Editor for ActiveAdmin
|
69
|
+
test_files: []
|