effective_bootstrap 0.10.9 → 0.10.10

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: f4c81334cb6ac486e6880fc75bc9e0517bbb1a19fa2a2a0b2ad435cbc7d35beb
4
- data.tar.gz: b792f8cb43154fe1f3e5eb96a8e68fb066ca0007224a58ba507c1e93d962a8d3
3
+ metadata.gz: 2397e2be81dbb9b78de24f2397762cfe44458a7f1d351d60d32a86769add1d9c
4
+ data.tar.gz: 6405deac6426fc49962d3da0dd30b006dcf5f113ceff08335c03f029d589a37a
5
5
  SHA512:
6
- metadata.gz: dd06f6e3db1c37e4b3e9136d0172c1388303f7faa62e24e91ad4e308bd2511e32ebd665b47c7dab5142bcd34278dc5723cef0e8fc9a76b8b5ba1d8efc122b777
7
- data.tar.gz: a06ba1c6e1cc2692bbf27d9cc9c78137d1ee18d57a6689974c5ca58b643cf99b340ac3c3b58abf51b2b58f97d2a2c368669ae76ae8be59e87985d03a89db7052
6
+ metadata.gz: 655c9ec56944dc576cf61a0ed8a6d2dfdb784cf4e4532f9a4b0e32b9c15ffcd6a2717682a5229f44df8d582b1aa734d9ee65d0762b71029fa210da21812238f7
7
+ data.tar.gz: 8ab4a5452665c92b72d0f018059df0e72a8e71ad8a1a6ad013849fb78f54909879ed823dac1c384159cc4c0c319c8c88675fabc6a266c6272bb2bc2d48f79de6
@@ -1,13 +1,36 @@
1
1
  # https://imperavi.com/article/
2
2
 
3
3
  uploadActiveStorage = (editor, data) ->
4
+ rails_url = '/rails/active_storage/blobs/redirect/'
5
+
4
6
  for file in data.files
5
7
  upload = new ActiveStorage.DirectUpload(file, '/rails/active_storage/direct_uploads')
6
8
 
7
9
  upload.create (error, blob) =>
8
- url = '/rails/active_storage/blobs/redirect/' + blob.signed_id + '/' + blob.filename
10
+ url = rails_url + blob.signed_id + '/' + blob.filename
9
11
  editor.complete({ file: { url: url, name: blob.filename, content_type: blob.content_type }}, data.e)
10
12
 
13
+ # We append this nested attachment html
14
+ attachment = $('<action-text-attachment>')
15
+ .attr('sgid', blob.attachable_sgid)
16
+ .attr('class', 'effective-article-editor-attachment')
17
+
18
+ attachment = $('<div>').append(attachment).html()
19
+
20
+ doc = editor.app.editor.getLayout()
21
+
22
+ doc
23
+ .find("img[src^='#{rails_url}']:not(.effective-article-editor-attachment)")
24
+ .after(attachment)
25
+ .addClass('effective-article-editor-attachment')
26
+
27
+ doc
28
+ .find("a[data-file][data-name='#{file.name}']:not(.action-text-attachment)")
29
+ .after(attachment)
30
+ .addClass('effective-article-editor-attachment')
31
+ .removeAttr('data-file')
32
+ .removeAttr('data-name')
33
+
11
34
  insertUploadByDrop = (response, e) ->
12
35
  if @app.block.is()
13
36
  instance = @app.block.get()
@@ -19,6 +19,8 @@ this.EffectiveForm ||= new class
19
19
  submitting: ($form) ->
20
20
  $form.addClass('form-is-valid').removeClass('form-is-invalid')
21
21
  @spin()
22
+ @saveTabs($form)
23
+
22
24
  setTimeout((-> EffectiveForm.disable($form)), 0)
23
25
 
24
26
  if ($form.attr('method') || '').toLowerCase() == 'get' || (@current_submit.length > 0 && @current_submit.hasClass('form-actions-reset'))
@@ -59,6 +61,16 @@ this.EffectiveForm ||= new class
59
61
 
60
62
  spin: -> @current_submit.addClass('form-current-submit') if @current_submit.length > 0
61
63
 
64
+ saveTabs: ($form) ->
65
+ $tabs = $form.parents('div.tab-pane[data-tab-label]')
66
+ $tabs = @current_submit.parents('div.tab-pane[data-tab-label]') if $tabs.length == 0
67
+
68
+ $form.find("input[name='_tabs[]']").remove()
69
+
70
+ $tabs.each (i, element) ->
71
+ label = $(element).data('tab-label')
72
+ $form.append("<input type='hidden' name='_tabs[]' value='#{label}'>")
73
+
62
74
  beforeAjax: ($form) ->
63
75
  return unless $form.data('remote')
64
76
 
@@ -0,0 +1,20 @@
1
+ module EffectiveBootstrap
2
+ module SaveTabs
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ # If there is a params[:_tabs], save it to the session
8
+ before_action(if: -> { params[:_tabs] }) do
9
+ session[:_tabs] = params[:_tabs]
10
+ end
11
+
12
+ # After we're done, delete it from session
13
+ after_action(if: -> { session[:_tabs] }) do
14
+ session.delete(:_tabs) unless response.redirect?
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EffectiveArticleEditorHelper
4
+
5
+ def render_article_editor_action_text_content(content)
6
+ raise('expected content to be an content') unless content.kind_of?(ActionText::Content)
7
+
8
+ rendered = render_action_text_content(content)
9
+
10
+ if rendered.include?('effective-article-editor')
11
+ doc = Nokogiri::HTML(rendered)
12
+ doc.search('action-text-attachment').each { |fragment| fragment.remove }
13
+
14
+ # Filter out <html><body>\n and \n</body></html>
15
+ rendered = doc.inner_html.to_s[13..-16].html_safe
16
+ end
17
+
18
+ rendered
19
+ end
20
+
21
+ end
@@ -488,24 +488,43 @@ module EffectiveBootstrapHelper
488
488
  # If you pass active 'label' it will make that tab active. Otherwise first.
489
489
  # Unique will make sure the tab html IDs are unique
490
490
  # $('#tab-demographics').tab('show')
491
- def tabs(active: nil, unique: false, list: {}, content: {}, &block)
491
+ def tabs(active: nil, unique: false, ignore_save_tab: false, list: {}, content: {}, &block)
492
492
  raise 'expected a block' unless block_given?
493
493
 
494
- @_tab_mode = :tablist
495
- @_tab_active = :first if active.nil?
494
+ # The Active Tab might be set from a previous form submission, or passed into helper
495
+ tab_active = session[:_tabs].try(:pop) unless ignore_save_tab
496
+ tab_active ||= active
497
+
498
+ # If an active tab is passed, we validate we have a tab with that label, or fallback to first
499
+ if tab_active.present?
500
+ @_tab_mode = :validate
501
+ @_tab_labels = []
502
+ yield
503
+
504
+ tab_active = nil unless @_tab_labels.include?(tab_active)
505
+ end
506
+
507
+ tab_active ||= :first
496
508
  @_tab_unique = effective_bootstrap_unique_id if unique
497
509
 
510
+ # Generate the html in two passes
498
511
  content_tag(:ul, {class: 'nav nav-tabs', role: 'tablist'}.merge(list)) do
512
+ @_tab_mode = :tablist
513
+ @_tab_active = tab_active
514
+
499
515
  yield # Yield to tab the first time
500
516
  end +
501
517
  content_tag(:div, {class: 'tab-content'}.merge(content)) do
502
518
  @_tab_mode = :content
503
- @_tab_active = (active || :first)
519
+ @_tab_active = tab_active
520
+
504
521
  yield # Yield to tab the second time
505
522
  end
506
523
  end
507
524
 
508
525
  def tab(label, options = {}, &block)
526
+ (@_tab_labels.push(label) and return) if @_tab_mode == :validate
527
+
509
528
  controls = options.delete(:controls) || label.to_s.parameterize.gsub('_', '-')
510
529
  controls = controls[1..-1] if controls[0] == '#'
511
530
  controls = "#{controls}-#{@_tab_unique}" if @_tab_unique
@@ -522,7 +541,7 @@ module EffectiveBootstrapHelper
522
541
  end
523
542
  else # Inserting the content into the tab itself
524
543
  classes = ['tab-pane', 'fade', ('show active' if active), options[:class].presence].compact.join(' ')
525
- content_tag(:div, id: controls, class: classes, role: 'tabpanel', 'aria-labelledby': ('tab-' + controls)) do
544
+ content_tag(:div, id: controls, class: classes, role: 'tabpanel', 'aria-labelledby': ('tab-' + controls), 'data-tab-label': label) do
526
545
  yield
527
546
  end
528
547
  end
@@ -69,8 +69,16 @@ module Effective
69
69
  }
70
70
  end
71
71
 
72
+ def content
73
+ if defined?(ActionText::RichText) && value.kind_of?(ActionText::RichText)
74
+ return value.body.to_html
75
+ end
76
+
77
+ value
78
+ end
79
+
72
80
  def build_input(&block)
73
- @builder.super_text_area(name, options[:input])
81
+ @builder.super_text_area(name, options[:input].merge(value: content))
74
82
  end
75
83
 
76
84
  def input_html_options
@@ -86,7 +94,7 @@ module Effective
86
94
  (@template.asset_pack_path('application.css') if @template.respond_to?(:asset_pack_path)),
87
95
  (@template.asset_path('application.css') if @template.respond_to?(:asset_path)),
88
96
  ('/assets/effective_bootstrap_article_editor.css')
89
- ]
97
+ ].compact
90
98
  end
91
99
 
92
100
  def active_storage
@@ -2,4 +2,8 @@ EffectiveBootstrap.setup do |config|
2
2
  # Replaces rails_ujs data-confirm with a custom inline implementation.
3
3
  # You will need to recompile assets (or "rm -rf tmp/") if you change this.
4
4
  config.use_custom_data_confirm = true
5
+
6
+ # Adds a before_action to ApplicationController
7
+ # To save and restore the active bootstrap tabs
8
+ config.save_tabs = true
5
9
  end
@@ -21,5 +21,14 @@ module EffectiveBootstrap
21
21
  end
22
22
  end
23
23
 
24
+ # Adds a before_action to application controller
25
+ initializer 'effective_bootstrap.action_controller' do |app|
26
+ if EffectiveBootstrap.save_tabs
27
+ app.config.to_prepare do
28
+ ApplicationController.send(:include, EffectiveBootstrap::SaveTabs)
29
+ end
30
+ end
31
+ end
32
+
24
33
  end
25
34
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.10.9'.freeze
2
+ VERSION = '0.10.10'.freeze
3
3
  end
@@ -6,7 +6,7 @@ require 'effective_bootstrap/version'
6
6
  module EffectiveBootstrap
7
7
 
8
8
  def self.config_keys
9
- [:use_custom_data_confirm]
9
+ [:use_custom_data_confirm, :save_tabs]
10
10
  end
11
11
 
12
12
  include EffectiveGem
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.10.9
4
+ version: 0.10.10
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: 2022-04-14 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -640,6 +640,8 @@ files:
640
640
  - app/assets/stylesheets/effective_select/overrides.scss
641
641
  - app/assets/stylesheets/effective_select/select2.css
642
642
  - app/assets/stylesheets/effective_select_or_text/input.scss
643
+ - app/controllers/concerns/effective_bootstrap/save_tabs.rb
644
+ - app/helpers/effective_article_editor_helper.rb
643
645
  - app/helpers/effective_bootstrap_helper.rb
644
646
  - app/helpers/effective_editor_helper.rb
645
647
  - app/helpers/effective_form_builder_helper.rb