activeadmin_trumbowyg 0.2.4 → 0.2.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: 2135ec8b6b680c3eaa9aa9ad24dcb095c8ecb8a3818f24eda7204ef9120805f2
4
- data.tar.gz: dd969ae0f3d7ef14ae838704edb09ee55b992b9187da9377c640dfde4007722d
3
+ metadata.gz: 6886f949b787fb24ce0e97c98bf9fbc4998fdda77239f06dab5aa879df105b06
4
+ data.tar.gz: e2240c1199cb395d9a93e176baf60c35ff042baa3486af5a6ee587abfb114324
5
5
  SHA512:
6
- metadata.gz: e9f58979d6e70d1deb175a4393eb12513c6f9c05248efeff7586c06bc43136d0d9d578fb8c5a50f2e62ede2175e6a75ac1adfb1e14b674c5f36bafa47e071fed
7
- data.tar.gz: fff726c5cf4423c19dabcc20ed9681ea505479df1fa4b8895c93694b666187f6104dd0e68ad93b5a235358294e755e09380e78ea641663ae6db8e494edd3d5b7
6
+ metadata.gz: b08dfbaa73acb9d1c407c2f99f9487eda21dfc23f9b0a94d62a37a336ad44a557b983dc64c2d94b69680348f113e71d1c6f44323e54b6b8feb38673ed0c0967b
7
+ data.tar.gz: db9aa890aa2a9d8cad07ddca102361da663de17915357cae796c113221e01a5fa07104929d9ad6481d89f7dff9929055266f18148065265ccddba9fd8959a837
data/README.md CHANGED
@@ -1,39 +1,32 @@
1
- # ActiveAdmin Trumbowyg [![Gem Version](https://badge.fury.io/rb/activeadmin_trumbowyg.svg)](https://badge.fury.io/rb/activeadmin_trumbowyg) [![CircleCI](https://circleci.com/gh/blocknotes/activeadmin_trumbowyg.svg?style=svg)](https://circleci.com/gh/blocknotes/activeadmin_trumbowyg)
1
+ # Active Admin Trumbowyg [![Gem Version](https://badge.fury.io/rb/activeadmin_trumbowyg.svg)](https://badge.fury.io/rb/activeadmin_trumbowyg) [![CircleCI](https://circleci.com/gh/blocknotes/activeadmin_trumbowyg.svg?style=svg)](https://circleci.com/gh/blocknotes/activeadmin_trumbowyg)
2
2
 
3
- An Active Admin plugin to use [Trumbowyg Editor](https://alex-d.github.io/Trumbowyg/)
3
+ An *Active Admin* plugin to use [Trumbowyg](https://alex-d.github.io/Trumbowyg/) as WYSIWYG editor in form inputs.
4
4
 
5
- ![screenshot](screenshot.jpg)
5
+ Features:
6
+ - automatically includes a fast & lightweight rich editor in Active Admin;
7
+ - customizable options via data attributes in the form input;
8
+ - plugins included, like images upload.
6
9
 
7
- ## Install
10
+ ![screenshot](screenshot.png)
8
11
 
9
- - Update your Gemfile: `gem 'activeadmin_trumbowyg'` (and execute *bundle*)
10
- - Add at the end of your ActiveAdmin styles (_app/assets/stylesheets/active_admin.scss_):
12
+ ## Install
13
+ - After installing Active Admin, add to your Gemfile: `gem 'activeadmin_trumbowyg'` (and execute *bundle*)
14
+ - Add at the end of your Active Admin styles (_app/assets/stylesheets/active_admin.scss_):
11
15
  ```css
12
16
  @import 'activeadmin/trumbowyg/trumbowyg';
13
17
  @import 'activeadmin/trumbowyg_input';
14
18
  ```
15
- - Add at the end of your ActiveAdmin javascripts (_app/assets/javascripts/active_admin.js_):
19
+ - Add at the end of your Active Admin javascripts (_app/assets/javascripts/active_admin.js_):
16
20
  ```js
17
21
  //= require activeadmin/trumbowyg/trumbowyg
18
22
  //= require activeadmin/trumbowyg_input
19
23
  ```
20
24
  - Use the input with `as: :trumbowyg` in Active Admin model conf
21
- - To fix icons in production execute the task: `rake trumbowyg:nondigest` (or `rails trumbowyg:nondigest` for Rails 5.x)
22
-
23
- Why 2 separated scripts? In this way you can include a different version of *trumbowyg editor* if you like.
25
+ - To fix icons in production environment execute the task: `rails trumbowyg:nondigest`
24
26
 
25
27
  > **UPDATE FROM VERSION < 2.0**: please change the Trumbowyg line in your _app/assets/stylesheets/active_admin.scss_ to: `@import 'activeadmin/trumbowyg/trumbowyg';`
26
28
 
27
- ## Options
28
-
29
- **data-options**: permits to set *trumbowyg editor* options directly - see [options list](https://alex-d.github.io/Trumbowyg/documentation/)
30
-
31
- ## Notes
32
-
33
- To use this plugins with ActiveAdmin 1.x please use the version 0.1.8
34
-
35
- ## Examples
36
-
29
+ ## Usage
37
30
  Form config (example model Article):
38
31
 
39
32
  ```ruby
@@ -47,45 +40,56 @@ form do |f|
47
40
  end
48
41
  ```
49
42
 
50
- Toolbar buttons configuration:
43
+ ## Notes
44
+ - **data-options** permits to set *Trumbowyg editor* options directly; some examples below. For reference see [options list](https://alex-d.github.io/Trumbowyg/documentation/).
45
+ - Why 2 separated scripts/style files? To allow to include different versions of *Trumbowyg editor* if needed.
46
+ - To use this plugins with *Active Admin 1.x* please use the version [0.1.8](https://github.com/blocknotes/activeadmin_trumbowyg/releases/tag/v0.1.8)
47
+
48
+ ## Examples
49
+
50
+ ### Toolbar buttons configuration
51
51
 
52
52
  ```ruby
53
- f.input :description, as: :trumbowyg, input_html: {data: {options: {btns: [['bold', 'italic'], ['superscript', 'subscript'], ['link'], ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'], ['unorderedList', 'orderedList'], ['horizontalRule'], ['removeformat']]}}}
53
+ f.input :description, as: :trumbowyg, input_html: { data: { options: { btns: [['bold', 'italic'], ['superscript', 'subscript'], ['link'], ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'], ['unorderedList', 'orderedList'], ['horizontalRule'], ['removeformat']] } } }
54
54
  ```
55
55
 
56
- ### Example with upload plugin
56
+ ### Trumbowyg upload plugin
57
+ Plugin reference [here](https://alex-d.github.io/Trumbowyg/documentation/plugins/#plugin-upload).
57
58
 
58
59
  Add to *active_admin.js* (after *trumbowyg* require):
59
60
 
60
- `//= require activeadmin/trumbowyg/plugins/upload/trumbowyg.upload`
61
+ ```js
62
+ //= require activeadmin/trumbowyg/plugins/upload/trumbowyg.upload
63
+ ```
61
64
 
62
65
  Form field config (example model Article):
63
66
 
64
67
  ```ruby
65
- f.input :description, as: :trumbowyg, input_html: {data: {options: {btns: [['bold', 'italic'], ['link'], ['upload']], plugins: {upload: {serverPath: upload_admin_article_path( resource.id ), fileFieldName: 'file_upload'}}}}}
68
+ unless resource.new_record?
69
+ f.input :description, as: :trumbowyg, input_html: { data: { options: { btns: [['bold', 'italic'], ['link'], ['upload']], plugins: { upload: { serverPath: upload_admin_post_path(resource.id), fileFieldName: 'file_upload' } } } } }
70
+ end
66
71
  ```
67
72
 
68
- Form method:
73
+ Upload method (using ActiveStorage):
69
74
 
70
75
  ```ruby
71
76
  member_action :upload, method: [:post] do
72
- response = nil
73
- resource.cover = params[:file_upload]
74
- response = resource.save ? {success: '1', file: resource.cover.url} : {success: '0'}
75
- render json: response
77
+ result = { success: resource.images.attach(params[:file_upload]) }
78
+ result[:file] = url_for(resource.images.last) if result[:success]
79
+ render json: result
76
80
  end
77
81
  ```
78
82
 
79
- ## Do you like it? Star it!
83
+ For the relevant files of this upload example see [here](examples/upload_plugin_using_activestorage/). Consider that this is just a basic example: images are uploaded as soon as they are attached to the editor (regardless of the form submit), it shows the editor only for an existing record (because of the *upload_admin_post_path*) and it doesn't provide a way to remove images (just deleting them from the editor will not destroy them, you'll need to implement a purge logic for that).
80
84
 
85
+ ## Do you like it? Star it!
81
86
  If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
82
87
 
83
- Take a look at [other ActiveAdmin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source) that I made if you are curious.
88
+ Take a look at [other Active Admin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source) that I made if you are curious.
84
89
 
85
90
  ## Contributors
86
-
87
91
  - [Mattia Roccoberton](http://blocknot.es): author
92
+ - The good guys that opened issues and pull requests from time to time
88
93
 
89
94
  ## License
90
-
91
- [MIT](LICENSE.txt)
95
+ The gem is available as open-source under the terms of the [MIT](LICENSE.txt).
@@ -1,20 +1,22 @@
1
- function initTrumbowygEditors() {
2
- $('.trumbowyg-textarea').each(function () {
3
- if (!$(this).hasClass('trumbowyg-textarea--active')) {
4
- var options = {
5
- svgPath: '/assets/trumbowyg/icons.svg'
6
- };
7
- options = $.extend({}, options, $(this).data('options'));
8
- $(this).trumbowyg(options);
9
- $(this).addClass('trumbowyg-textarea--active');
10
- }
11
- });
12
- }
1
+ (function () {
2
+ function initTrumbowygEditors() {
3
+ $('[data-aa-trumbowyg]').each(function () {
4
+ if (!$(this).hasClass('trumbowyg-textarea--active')) {
5
+ let options = {
6
+ svgPath: '/assets/trumbowyg/icons.svg'
7
+ }
8
+ options = $.extend({}, options, $(this).data('options'))
9
+ $(this).trumbowyg(options)
10
+ $(this).addClass('trumbowyg-textarea--active')
11
+ }
12
+ })
13
+ }
13
14
 
14
- $(document).on('has_many_add:after', function () {
15
- initTrumbowygEditors();
16
- });
15
+ $(document).ready(() => {
16
+ initTrumbowygEditors()
17
+ })
17
18
 
18
- $(document).ready(function () {
19
- initTrumbowygEditors();
20
- });
19
+ $(document).on('has_many_add:after', '.has_many_container', () => {
20
+ initTrumbowygEditors()
21
+ })
22
+ })()
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveAdmin
4
4
  module Trumbowyg
5
- VERSION = '0.2.4'
5
+ VERSION = '0.2.6'
6
6
  end
7
7
  end
@@ -5,7 +5,7 @@ module Formtastic
5
5
  class TrumbowygInput < Formtastic::Inputs::TextInput
6
6
  def to_html
7
7
  input_wrapping do
8
- label_html << builder.text_area(method, input_html_options.merge(class: 'trumbowyg-textarea'))
8
+ label_html << builder.text_area(method, input_html_options.merge('data-aa-trumbowyg': '1'))
9
9
  end
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_trumbowyg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2020-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin