effective_bootstrap 0.9.24 → 0.9.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/app/assets/images/icons/grip-lines.svg +1 -0
  4. data/app/assets/images/icons/reorder.svg +10 -0
  5. data/app/assets/javascripts/effective_article_editor/initialize.js.coffee +18 -0
  6. data/app/assets/javascripts/effective_article_editor/input.js +1 -0
  7. data/app/assets/javascripts/effective_bootstrap.js +1 -0
  8. data/app/assets/javascripts/effective_bootstrap/tabs.js +7 -0
  9. data/app/assets/javascripts/effective_has_many/initialize.js.coffee +10 -9
  10. data/app/assets/javascripts/effective_has_many/input.js +2 -1
  11. data/app/assets/javascripts/effective_has_many/sortable-jquery.js +76 -0
  12. data/app/assets/javascripts/effective_has_many/sortable.js +3722 -0
  13. data/app/assets/stylesheets/effective_article_editor/input.scss +1 -0
  14. data/app/assets/stylesheets/effective_article_editor/overrides.scss +1 -0
  15. data/app/assets/stylesheets/effective_bootstrap_article_editor.scss +1 -0
  16. data/app/assets/stylesheets/effective_has_many/input.scss +5 -30
  17. data/app/assets/stylesheets/effective_rich_text_area/extensions.scss +1 -13
  18. data/app/assets/stylesheets/effective_rich_text_area/rich_text_area.scss +0 -5
  19. data/app/models/effective/form_builder.rb +4 -0
  20. data/app/models/effective/form_inputs/article_editor.rb +77 -0
  21. data/app/models/effective/form_inputs/has_many.rb +30 -8
  22. data/config/effective_bootstrap.rb +0 -22
  23. data/lib/effective_bootstrap.rb +4 -23
  24. data/lib/effective_bootstrap/engine.rb +5 -1
  25. data/lib/effective_bootstrap/version.rb +1 -1
  26. metadata +29 -6
  27. data/app/assets/javascripts/effective_has_many/jquery.sortable.js +0 -696
@@ -0,0 +1 @@
1
+ @import 'overrides';
@@ -0,0 +1 @@
1
+ body { padding-top: 0px !important; }
@@ -0,0 +1 @@
1
+ @import 'effective_article_editor/input';
@@ -1,42 +1,17 @@
1
- body.dragging,
2
- body.dragging * {
3
- cursor: move !important;
4
- }
5
-
6
1
  .form-has-many {
7
- .has-many-placeholder {
8
- position: relative;
9
- height: 2rem;
10
-
11
- &:before {
12
- position: absolute;
13
- content: '';
14
- background-image: asset-data-url('icons/arrow-right-circle.svg');
15
- background-repeat: no-repeat;
16
- height: 2rem;
17
- width: 2rem;
18
- }
19
- }
20
-
21
- .has-many-fields.dragged {
22
- position: absolute;
23
- opacity: 0;
24
- z-index: 2000;
25
- .has-many-move { display: none; }
26
- }
27
-
28
- .has-many-move svg { margin-top: 6px; }
2
+ .has-many-fields.sortable-ghost { border-top: solid 3px #212529; }
29
3
  .has-many-move { display: none; }
4
+ .has-many-remove-disabled { opacity: 0; cursor: default !important; }
30
5
 
31
- .has-many-remove { margin-top: 1.5rem; }
6
+ .has-many-remove { margin-top: 1rem; }
32
7
  .has-many-move { margin-top: 1.5rem; }
33
8
  }
34
9
 
35
10
  .form-has-many.reordering {
36
- .has-many-move { display: inline-block; }
11
+ .has-many-move { display: inline-block; cursor: grab; }
37
12
  }
38
13
 
39
14
  .form-has-many.tight {
40
15
  .has-many-remove { margin-top: 0; }
41
- .has-many-move { margin-top: 0; }
16
+ .has-many-move { margin-top: 0.5rem; }
42
17
  }
@@ -61,19 +61,7 @@ trix-editor {
61
61
  }
62
62
 
63
63
  .trix-content {
64
- h1, h2, h3, h4, h5, h6 {
65
- line-height: 1.2;
66
- margin: 0;
67
- }
68
-
69
- h1 { font-size: 36px; }
70
- h2 { font-size: 26px; }
71
- h3 { font-size: 18px; }
72
- h4 { font-size: 18px; }
73
- h5 { font-size: 14px; }
74
- h6 { font-size: 12px; }
75
-
76
- .attachment { width: 100%; }
64
+ .attachment { max-width: 100%; }
77
65
 
78
66
  .attachment--content.attachment--horizontal-rule,
79
67
  .attachment--content[data-trix-content-type~='vnd.rubyonrails.horizontal-rule.html'] {
@@ -12,11 +12,6 @@
12
12
  }
13
13
  }
14
14
 
15
- // Trix image caption
16
- .trix-content {
17
- figcaption.attachment__caption { display: none; }
18
- }
19
-
20
15
  // Bootstrap 4 Feedback client side
21
16
  .was-validated .form-control:invalid ~ .trix-content, { border-color: #dc3545 !important; }
22
17
  .was-validated .form-control:valid ~ .trix-content { border-color: #28a745 !important; }
@@ -22,6 +22,10 @@ module Effective
22
22
  alias_method :super_text_area, :text_area
23
23
  alias_method :super_hidden_field, :hidden_field
24
24
 
25
+ def article_editor(name, options = {}, &block)
26
+ Effective::FormInputs::ArticleEditor.new(name, options, builder: self).to_html(&block)
27
+ end
28
+
25
29
  def clear(name = 'Clear', options = {})
26
30
  (options = name; name = 'Clear') if name.kind_of?(Hash)
27
31
  Effective::FormInputs::Clear.new(name, options, builder: self).to_html
@@ -0,0 +1,77 @@
1
+ module Effective
2
+ module FormInputs
3
+ class ArticleEditor < Effective::FormInput
4
+
5
+ def build_input(&block)
6
+ @builder.super_text_area(name, options[:input])
7
+ end
8
+
9
+ def input_html_options
10
+ { class: 'effective_article_editor form-control', id: unique_id, autocomplete: 'off' }
11
+ end
12
+
13
+ def input_js_options
14
+ {
15
+ active_storage: active_storage,
16
+ css: '/assets/effective_article_editor/',
17
+ custom: {
18
+ css: ['/assets/application.css', '/assets/effective_bootstrap_article_editor.css']
19
+ },
20
+ classes: {
21
+ body: 'article-editor-body',
22
+ table: 'table'
23
+ },
24
+ grid: {
25
+ classname: 'row',
26
+ columns: 12,
27
+ gutter: '1px',
28
+ offset: {
29
+ left: '15px',
30
+ right: '15px',
31
+ },
32
+ patterns: {
33
+ '6|6': 'col-sm-6|col-sm-6',
34
+ '4|4|4': 'col-sm-4|col-sm-4|col-sm-4',
35
+ '3|3|3|3': 'col-sm-3|col-sm-3|col-sm-3|col-sm-3',
36
+ '2|2|2|2|2|2': 'col-sm-2|col-sm-2|col-sm-2|col-sm-2|col-sm-2|col-sm-2',
37
+ '3|6|3': 'col-sm-3|col-sm-6|col-sm-3',
38
+ '2|8|2': 'col-sm-2|col-sm-8|col-sm-2',
39
+ '5|7': 'col-sm-5|col-sm-7',
40
+ '7|5': 'col-sm-7|col-sm-5',
41
+ '4|8': 'col-sm-4|col-sm-8',
42
+ '8|4': 'col-sm-8|col-sm-4',
43
+ '3|9': 'col-sm-3|col-sm-9',
44
+ '9|3': 'col-sm-9|col-sm-3',
45
+ '2|10': 'col-sm-2|col-sm-10',
46
+ '10|2': 'col-sm-10|col-sm-2',
47
+ '12': 'col-sm-12'
48
+ }
49
+ },
50
+ plugins: ['blockcode', 'imageposition', 'imageresize', 'inlineformat', 'removeformat', 'reorder', 'style'],
51
+ quote: {
52
+ template: '<blockquote><p></p></blockquote>'
53
+ },
54
+ styles: {
55
+ table: {
56
+ 'bordered': { title: 'Bordered', classname: 'table-bordered' },
57
+ 'responsive': { title: 'Responsive', classname: 'table-responsive' },
58
+ 'small': { title: 'Small', classname: 'table-sm' },
59
+ 'striped': { title: 'Striped', classname: 'table-striped' },
60
+ }
61
+ }
62
+ }
63
+ end
64
+
65
+ def active_storage
66
+ return @active_storage unless @active_storage.nil?
67
+
68
+ @active_storage = if options.key?(:active_storage)
69
+ options.delete(:active_storage)
70
+ else
71
+ defined?(ActiveStorage).present?
72
+ end
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -7,8 +7,9 @@ module Effective
7
7
  object.send(name).build() if build? && collection.blank?
8
8
 
9
9
  errors = (@builder.error(name) if errors?) || BLANK
10
+ can_remove_method
10
11
 
11
- errors + content_tag(:div, options[:input]) do
12
+ errors + content_tag(:div, options[:input].except(:collection)) do
12
13
  has_many_fields_for(block) + has_many_links_for(block)
13
14
  end
14
15
  end
@@ -76,6 +77,11 @@ module Effective
76
77
  end
77
78
  end
78
79
 
80
+ def can_remove_method
81
+ return @can_remove_method unless @can_remove_method.nil?
82
+ @can_remove_method = (options[:input].delete(:can_remove_method) || false)
83
+ end
84
+
79
85
  # reorder: true
80
86
  def reorder?
81
87
  return @reorder unless @reorder.nil?
@@ -107,19 +113,23 @@ module Effective
107
113
 
108
114
  def render_resource(resource, block)
109
115
  remove = BLANK
116
+ reorder = BLANK
117
+ can_remove = (can_remove_method.blank? || !!resource.send(can_remove_method))
110
118
 
111
119
  content = @builder.fields_for(name, resource) do |form|
112
120
  fields = block.call(form)
113
121
 
114
- remove += form.super_hidden_field(:_destroy) if remove? && resource.persisted?
115
- remove += form.super_hidden_field(:position) if reorder? && !fields.include?('][position]')
122
+ remove += form.super_hidden_field(:_destroy) if remove? && can_remove && resource.persisted?
123
+ reorder += form.super_hidden_field(:position) if reorder? && !fields.include?('][position]')
116
124
 
117
125
  fields
118
126
  end
119
127
 
120
- remove += link_to_remove(resource) if (remove? || resource.new_record?)
128
+ if remove?
129
+ remove += (can_remove || resource.new_record?) ? link_to_remove(resource) : disabled_link_to_remove(resource)
130
+ end
121
131
 
122
- content_tag(:div, render_fields(content, remove), class: 'has-many-fields')
132
+ content_tag(:div, render_fields(content, (remove + reorder)), class: 'has-many-fields')
123
133
  end
124
134
 
125
135
  def render_fields(content, remove)
@@ -169,7 +179,7 @@ module Effective
169
179
  def link_to_reorder(block)
170
180
  content_tag(
171
181
  :button,
172
- icon('list') + 'Reorder',
182
+ icon('reorder') + 'Reorder',
173
183
  class: 'has-many-reorder btn btn-secondary',
174
184
  title: 'Reorder',
175
185
  data: {
@@ -181,7 +191,7 @@ module Effective
181
191
  def link_to_remove(resource)
182
192
  content_tag(
183
193
  :button,
184
- icon('trash-2') + 'Remove',
194
+ icon('trash-2'),
185
195
  class: 'has-many-remove btn btn-danger',
186
196
  title: 'Remove',
187
197
  data: {
@@ -191,8 +201,20 @@ module Effective
191
201
  )
192
202
  end
193
203
 
204
+ def disabled_link_to_remove(resource)
205
+ content_tag(
206
+ :button,
207
+ icon('trash-2'),
208
+ class: 'has-many-remove-disabled btn btn-danger',
209
+ title: 'Remove',
210
+ data: {
211
+ 'effective-form-has-many-remove-disabled': true,
212
+ }
213
+ )
214
+ end
215
+
194
216
  def has_many_move
195
- @has_many_move ||= content_tag(:span, icon('move'), class: 'has-many-move')
217
+ @has_many_move ||= content_tag(:span, icon('grip-lines'), class: 'has-many-move')
196
218
  end
197
219
 
198
220
  def build_resource
@@ -1,26 +1,4 @@
1
1
  EffectiveBootstrap.setup do |config|
2
- # Authorization Method
3
- #
4
- # This method is called by all controller actions with the appropriate action and resource
5
- # If it raises an exception or returns false, an Effective::AccessDenied Error will be raised
6
- #
7
- # Use via Proc:
8
- # Proc.new { |controller, action, resource| authorize!(action, resource) } # CanCan
9
- # Proc.new { |controller, action, resource| can?(action, resource) } # CanCan with skip_authorization_check
10
- # Proc.new { |controller, action, resource| authorize "#{action}?", resource } # Pundit
11
- # Proc.new { |controller, action, resource| current_user.is?(:admin) } # Custom logic
12
- #
13
- # Use via Boolean:
14
- # config.authorization_method = true # Always authorized
15
- # config.authorization_method = false # Always unauthorized
16
- #
17
- # Use via Method (probably in your application_controller.rb):
18
- # config.authorization_method = :my_authorization_method
19
- # def my_authorization_method(resource, action)
20
- # true
21
- # end
22
- config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) }
23
-
24
2
  # Replaces rails_ujs data-confirm with a custom inline implementation.
25
3
  # You will need to recompile assets (or "rm -rf tmp/") if you change this.
26
4
  config.use_custom_data_confirm = true
@@ -1,33 +1,14 @@
1
1
  require 'inline_svg'
2
+ require 'effective_resources'
2
3
  require 'effective_bootstrap/engine'
3
4
  require 'effective_bootstrap/version'
4
5
 
5
6
  module EffectiveBootstrap
6
7
 
7
- # The following are all valid config keys
8
- mattr_accessor :authorization_method
9
-
10
- mattr_accessor :use_custom_data_confirm
11
-
12
- def self.setup
13
- yield self
8
+ def self.config_keys
9
+ [:use_custom_data_confirm]
14
10
  end
15
11
 
16
- def self.authorized?(controller, action, resource)
17
- @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
18
-
19
- return !!authorization_method unless authorization_method.respond_to?(:call)
20
- controller = controller.controller if controller.respond_to?(:controller)
21
-
22
- begin
23
- !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
24
- rescue *@_exceptions
25
- false
26
- end
27
- end
28
-
29
- def self.authorize!(controller, action, resource)
30
- raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
31
- end
12
+ include EffectiveGem
32
13
 
33
14
  end
@@ -8,7 +8,11 @@ module EffectiveBootstrap
8
8
  end
9
9
 
10
10
  initializer 'effective_bootstrap.assets' do |app|
11
- app.config.assets.precompile += ['effective_bootstrap_manifest.js', 'icons/*']
11
+ app.config.assets.precompile += [
12
+ 'effective_bootstrap_manifest.js',
13
+ 'effective_bootstrap_article_editor.css',
14
+ 'icons/*'
15
+ ]
12
16
  end
13
17
 
14
18
  initializer 'effective_bootstrap.action_text' do |app|
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.9.24'.freeze
2
+ VERSION = '0.9.29'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.24
4
+ version: 0.9.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-09 00:00:00.000000000 Z
11
+ date: 2021-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -26,18 +26,32 @@ dependencies:
26
26
  version: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bootstrap
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "<"
39
+ - !ruby/object:Gem::Version
40
+ version: '5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: effective_resources
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 4.0.0
47
+ version: '0'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: 4.0.0
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: inline_svg
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +95,7 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: sass
98
+ name: sassc
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -242,6 +256,7 @@ files:
242
256
  - app/assets/images/icons/globe.svg
243
257
  - app/assets/images/icons/google.svg
244
258
  - app/assets/images/icons/grid.svg
259
+ - app/assets/images/icons/grip-lines.svg
245
260
  - app/assets/images/icons/hard-drive.svg
246
261
  - app/assets/images/icons/hash.svg
247
262
  - app/assets/images/icons/headphones.svg
@@ -318,6 +333,7 @@ files:
318
333
  - app/assets/images/icons/radio.svg
319
334
  - app/assets/images/icons/refresh-ccw.svg
320
335
  - app/assets/images/icons/refresh-cw.svg
336
+ - app/assets/images/icons/reorder.svg
321
337
  - app/assets/images/icons/repeat.svg
322
338
  - app/assets/images/icons/rewind.svg
323
339
  - app/assets/images/icons/rotate-ccw.svg
@@ -404,6 +420,8 @@ files:
404
420
  - app/assets/images/icons/zap.svg
405
421
  - app/assets/images/icons/zoom-in.svg
406
422
  - app/assets/images/icons/zoom-out.svg
423
+ - app/assets/javascripts/effective_article_editor/initialize.js.coffee
424
+ - app/assets/javascripts/effective_article_editor/input.js
407
425
  - app/assets/javascripts/effective_bootstrap.js
408
426
  - app/assets/javascripts/effective_bootstrap/base.js.coffee
409
427
  - app/assets/javascripts/effective_bootstrap/confirm.js.coffee.erb
@@ -435,7 +453,8 @@ files:
435
453
  - app/assets/javascripts/effective_file/input.js
436
454
  - app/assets/javascripts/effective_has_many/initialize.js.coffee
437
455
  - app/assets/javascripts/effective_has_many/input.js
438
- - app/assets/javascripts/effective_has_many/jquery.sortable.js
456
+ - app/assets/javascripts/effective_has_many/sortable-jquery.js
457
+ - app/assets/javascripts/effective_has_many/sortable.js
439
458
  - app/assets/javascripts/effective_integer/initialize.js.coffee
440
459
  - app/assets/javascripts/effective_integer/input.js
441
460
  - app/assets/javascripts/effective_number_text/initialize.js.coffee
@@ -592,11 +611,14 @@ files:
592
611
  - app/assets/javascripts/moment/locale/zh-hk.js
593
612
  - app/assets/javascripts/moment/locale/zh-tw.js
594
613
  - app/assets/javascripts/moment/moment.js
614
+ - app/assets/stylesheets/effective_article_editor/input.scss
615
+ - app/assets/stylesheets/effective_article_editor/overrides.scss
595
616
  - app/assets/stylesheets/effective_bootstrap.scss
596
617
  - app/assets/stylesheets/effective_bootstrap/base.scss
597
618
  - app/assets/stylesheets/effective_bootstrap/forms.scss
598
619
  - app/assets/stylesheets/effective_bootstrap/icons.scss
599
620
  - app/assets/stylesheets/effective_bootstrap/overrides.scss
621
+ - app/assets/stylesheets/effective_bootstrap_article_editor.scss
600
622
  - app/assets/stylesheets/effective_bootstrap_editor.scss
601
623
  - app/assets/stylesheets/effective_checks/input.scss
602
624
  - app/assets/stylesheets/effective_datetime/bootstrap-datetimepicker.scss
@@ -622,6 +644,7 @@ files:
622
644
  - app/helpers/effective_icons_helper.rb
623
645
  - app/models/effective/form_builder.rb
624
646
  - app/models/effective/form_input.rb
647
+ - app/models/effective/form_inputs/article_editor.rb
625
648
  - app/models/effective/form_inputs/check_box.rb
626
649
  - app/models/effective/form_inputs/checks.rb
627
650
  - app/models/effective/form_inputs/ck_editor.rb