super_tools 0.0.17 → 2.1.0

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
  SHA1:
3
- metadata.gz: e8f4cea2632f6d8712a085a3448aa82fef714b9b
4
- data.tar.gz: 6aab879d3139d822467fab9d16307f3b639d07ab
3
+ metadata.gz: 248f805a4956e73dcc11f4623ebfeb7f124c0d49
4
+ data.tar.gz: f24028ac4d9d1a4f80f8bd0e5552174fc735f4da
5
5
  SHA512:
6
- metadata.gz: ae7a3bb6e1bfb1ee93898a27586610f7c8fdad296660370fd83788e214ba9154e3139c6bbd77238536125646dc83ff96c97e38ebb1ed304871f77026fccea64d
7
- data.tar.gz: a06f5b4c11240c3fdc6a684cc500c8e78ac39de06deac9e5a622a8a8dd6b8eb73e4d8b2b08708cff3ef1b9514f6d0abdf0ab24cec6b38acb85271414e8b1483e
6
+ metadata.gz: 9ec67d9425ff7fa208a0cadd4682eb4a0e1b63dde2eb3e22b9715f679d9a3bd22534b56e65a7f8e792061a8e97686ceccd7f2b78b21afabcfb5e1cacfd93a59d
7
+ data.tar.gz: 6447defbdd74912a56d187406c3d80e0890b037062c96d06a3d02ac7f6c4074949772321d24ad85b8147908e5def0ff5cdd5340a387c085bd3cabcadaac16847
data/README.md CHANGED
@@ -84,7 +84,8 @@ SuperTable::Tableable.send(:include, ::Rails.application.routes.url_helpers)
84
84
 
85
85
  ```ruby
86
86
  class ApplicationController < ActionController::Base
87
- include SuperInteraction::ControllerHelper
87
+ include SuperInteraction::BootstrapHelper
88
+ include SuperInteraction::BeyondrHelper
88
89
  end
89
90
  ```
90
91
 
@@ -0,0 +1,77 @@
1
+ module SuperInteraction
2
+ class Beyond < Struct.new(:context)
3
+
4
+ attr_accessor :commands
5
+
6
+ delegate :helpers, to: :context
7
+
8
+ def run
9
+ context.render js: (commands || []).join(";"), layout: false
10
+ end
11
+
12
+ def b_notice(message)
13
+ b_alert('info', message)
14
+ self
15
+ end
16
+
17
+ def b_danger(message)
18
+ b_alert('danger', message)
19
+ self
20
+ end
21
+
22
+ def b_success(message)
23
+ b_alert('success', message)
24
+ end
25
+
26
+ def alert(message)
27
+ cmd("alert('#{helpers.j(message)}');")
28
+ end
29
+
30
+ # modal 裡如果有 javascript 需寫在 .modal 層
31
+ # size: sm / md / lg / xl / xxl
32
+ # 注意:不要包 respond_to :js 會有問題
33
+ def modal(partial: nil, size: 'md', title: '', desc: '', classname: '')
34
+ partial ||= context.action_name
35
+ locals = { size: size, title: title, desc: desc, classname: classname }
36
+ modal_html = context.render_to_string(partial, layout: "beyond.haml", locals: locals)
37
+ cmd("$(function() { $.uniqModal().modal('show', '#{helpers.j(modal_html)}'); });")
38
+ end
39
+
40
+ # 關閉 Modal
41
+ def close
42
+ cmd("$.uniqModal().modal('hide');")
43
+ end
44
+
45
+ # 重新讀取頁面
46
+ def reload
47
+ cmd("Turbolinks.visit(location.toString());");
48
+ end
49
+
50
+ # 導入頁面
51
+ def redirect_to(url)
52
+ cmd("Turbolinks.visit('#{url}');");
53
+ end
54
+
55
+ def modal_saved_rediret_to(message, redirect_url)
56
+ close.alert(message).redirect_to(redirect_url)
57
+ end
58
+
59
+ def modal_saved_reload(message)
60
+ close.alert(message).reload
61
+ end
62
+
63
+ def ajax_get(url)
64
+ cmd("$.get('#{url}');")
65
+ end
66
+
67
+ def b_alert(class_type, text)
68
+ cmd("if (typeof($.alert) == undefined) { alert('#{helpers.j(text)}'); } else { $.alert.#{class_type}('#{helpers.j(text)}'); }")
69
+ end
70
+
71
+ def cmd(js_code)
72
+ self.commands ||= []
73
+ self.commands.push(js_code)
74
+ self
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,13 @@
1
+ module SuperInteraction
2
+ module BeyondHelper
3
+ def srj(&block)
4
+ i = Beyond.new(self)
5
+ if block_given?
6
+ yield(i)
7
+ i.run
8
+ else
9
+ i
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module SuperInteraction
2
- class Command < Struct.new(:context)
2
+ class Bootstrap < Struct.new(:context)
3
3
 
4
4
  attr_accessor :commands
5
5
 
@@ -32,7 +32,7 @@ module SuperInteraction
32
32
  # 注意:不要包 respond_to :js 會有問題
33
33
  def modal(partial: nil, size: 'md', title: '', desc: '')
34
34
  partial ||= context.action_name
35
- modal_html = context.render_to_string(partial, layout: "interaction_modal.html.haml", locals: { bs_modal_size: size, title: title, desc: desc })
35
+ modal_html = context.render_to_string(partial, layout: ::SuperInteraction::Layout.modal_layout, locals: { size: size, title: title, desc: desc })
36
36
  cmd("$(function() { $.modal.show('#{helpers.j(modal_html)}'); });")
37
37
  end
38
38
 
@@ -1,7 +1,7 @@
1
1
  module SuperInteraction
2
- module ControllerHelper
2
+ module BootstrapHelper
3
3
  def js(&block)
4
- i = Command.new(self)
4
+ i = Bootstrap.new(self)
5
5
  yield(i) if block_given?
6
6
  i
7
7
  end
@@ -2,6 +2,10 @@ module SuperInteraction
2
2
  if defined?(Rails::Engine)
3
3
  class Engine < Rails::Engine
4
4
  paths["app/views"] = "lib/super_interaction/views"
5
+
6
+ initializer 'beyond.assets.precompile' do |app|
7
+ app.config.assets.paths << root.join('lib', 'super_interaction', 'javascripts').to_s
8
+ end
5
9
  end
6
10
  end
7
11
  end
@@ -0,0 +1,29 @@
1
+ module SuperInteraction
2
+ module Layout
3
+
4
+ FRAMEWORKS = [ :bootstrap3, :bootstrap4, :beyond ]
5
+
6
+ def self.framework=(f)
7
+ raise "Not support framework: #{f}" if FRAMEWORKS.include?(f) == false
8
+ @@framework = f
9
+ end
10
+
11
+ def self.framework
12
+ @@framework
13
+ end
14
+
15
+ def self.modal_layout
16
+ case @@framework
17
+ when :bootstrap3
18
+ "modal_bs3.haml"
19
+ when :bootstrap4
20
+ "modal_bs4.haml"
21
+ when :beyond
22
+ "modal_beyond.haml"
23
+ else
24
+ # Default
25
+ "modal_bs3.haml"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ - if Rails.version[0].to_i >= 5
2
+ - size = local_assigns[:size]
3
+ - title = local_assigns[:title]
4
+ - desc = local_assigns[:desc]
5
+ - classname = local_assigns[:classname]
6
+
7
+ .modal{"aria-labelledby" => "modalLabel", "data-modal" => "box-modal", :role => "dialog", :tabindex => "-1"}
8
+ .modal-dialog{ role: 'document', class: "modal-#{size} #{classname}" }
9
+ .modal-content
10
+ .modal-header
11
+ = yield :header
12
+ - if title.present?
13
+ %h4.modal-title
14
+ = title
15
+ %small= desc if desc
16
+ %button.btn-close{'aria-label': 'Close', 'data-close': true, 'type': 'button'}
17
+ = b_icon('cross')
18
+ = yield
19
+ = yield :before_body
20
+ - body_html = capture { yield :body }
21
+ - if body_html.present?
22
+ .modal-body.bg-content= body_html
23
+ = yield :after_body
24
+ - footer_html = capture { yield :footer }
25
+ - if footer_html.present?
26
+ .modal-footer
27
+ = footer_html
@@ -1,10 +1,10 @@
1
1
  - if Rails.version[0].to_i >= 5
2
- - bs_modal_size = local_assigns[:bs_modal_size]
2
+ - size = local_assigns[:size]
3
3
  - title = local_assigns[:title]
4
4
  - desc = local_assigns[:desc]
5
5
  .modal
6
6
  = yield :wrapper
7
- .modal-dialog{ class: "modal-#{bs_modal_size}" }
7
+ .modal-dialog{ class: "modal-#{size}" }
8
8
  .modal-content
9
9
  .modal-header
10
10
  %button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
@@ -15,6 +15,7 @@
15
15
  = yield :header
16
16
  - if title.present?
17
17
  %h4.modal-title= title
18
+
18
19
  = yield
19
20
  = yield :before_body
20
21
  - body_html = capture { yield :body }
@@ -0,0 +1,28 @@
1
+ - if Rails.version[0].to_i >= 5
2
+ - size = local_assigns[:size]
3
+ - title = local_assigns[:title]
4
+ - desc = local_assigns[:desc]
5
+ .modal
6
+ = yield :wrapper
7
+ .modal-dialog{ class: "modal-#{size}" }
8
+ .modal-content
9
+ .modal-header
10
+ = yield :header
11
+ - if title.present?
12
+ %h5.modal-title
13
+ = title
14
+ - if desc.present?
15
+ %small.text-secondary= desc
16
+ %button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
17
+ = fas_icon('times')
18
+
19
+ = yield
20
+ = yield :before_body
21
+ - body_html = capture { yield :body }
22
+ - if body_html.present?
23
+ .modal-body= body_html
24
+ = yield :after_body
25
+
26
+ - footer_html = capture { yield :footer }
27
+ - if footer_html.present?
28
+ .modal-footer= footer_html
data/lib/super_tools.rb CHANGED
@@ -42,9 +42,12 @@ require 'super_search/scroll'
42
42
  # ZIP CODE
43
43
  require 'super_zipcode/taiwan'
44
44
  # INTERACTION
45
+ require 'super_interaction/layout'
45
46
  require 'super_interaction/engine'
46
- require 'super_interaction/command'
47
- require 'super_interaction/controller_helper'
47
+ require 'super_interaction/beyond'
48
+ require 'super_interaction/beyond_helper'
49
+ require 'super_interaction/bootstrap'
50
+ require 'super_interaction/bootstrap_helper'
48
51
  # FORMATTER
49
52
  require 'super_logger/formatter'
50
53
  # Values
@@ -1,3 +1,3 @@
1
1
  module SuperTools
2
- VERSION = '0.0.17'
2
+ VERSION = '2.1.0'
3
3
  end
data/super_tools.gemspec CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  # spec.add_dependency "activemodel", '>= 4', '<= 6'
37
37
  # spec.add_dependency "activesupport", '>= 4', '<= 6'
38
38
  # spec.add_dependency "activeview"
39
- spec.add_dependency "nokogiri", ">= 1.6", "<= 1.10.7"
39
+ spec.add_dependency "nokogiri", ">= 1.6"
40
40
  spec.add_dependency "fast_excel"
41
41
  spec.add_dependency "roo"
42
42
  spec.add_dependency "roo-xls"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - eddie
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,9 +87,6 @@ dependencies:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.6'
90
- - - "<="
91
- - !ruby/object:Gem::Version
92
- version: 1.10.7
93
90
  type: :runtime
94
91
  prerelease: false
95
92
  version_requirements: !ruby/object:Gem::Requirement
@@ -97,9 +94,6 @@ dependencies:
97
94
  - - ">="
98
95
  - !ruby/object:Gem::Version
99
96
  version: '1.6'
100
- - - "<="
101
- - !ruby/object:Gem::Version
102
- version: 1.10.7
103
97
  - !ruby/object:Gem::Dependency
104
98
  name: fast_excel
105
99
  requirement: !ruby/object:Gem::Requirement
@@ -316,10 +310,15 @@ files:
316
310
  - lib/super_formatter/tcat/head.rb
317
311
  - lib/super_formatter/tcat/import.rb
318
312
  - lib/super_formatter/tcat/row.rb
319
- - lib/super_interaction/command.rb
320
- - lib/super_interaction/controller_helper.rb
313
+ - lib/super_interaction/beyond.rb
314
+ - lib/super_interaction/beyond_helper.rb
315
+ - lib/super_interaction/bootstrap.rb
316
+ - lib/super_interaction/bootstrap_helper.rb
321
317
  - lib/super_interaction/engine.rb
322
- - lib/super_interaction/views/layouts/interaction_modal.html.haml
318
+ - lib/super_interaction/layout.rb
319
+ - lib/super_interaction/views/layouts/beyond.haml
320
+ - lib/super_interaction/views/layouts/modal_bs3.haml
321
+ - lib/super_interaction/views/layouts/modal_bs4.haml
323
322
  - lib/super_logger/formatter.rb
324
323
  - lib/super_process/core.rb
325
324
  - lib/super_search/scroll.rb