binco 0.0.3 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dab42b5d3e30ad2398513cbdb305d6cc3cad40de
4
- data.tar.gz: b6675a73b28f4c5d5957fe57907573c98dc90194
3
+ metadata.gz: 4b8f444e8f93fd3f697b01871aa74ed5b41d0dd9
4
+ data.tar.gz: 0a74ac386487f7233e676ed06c4fd953346daafb
5
5
  SHA512:
6
- metadata.gz: 961b48a867d1ba9ca1f45108c8cefd75b4be48aba9d8d2ccafeb51884f681a241895d9309c9dc228067681238ae53f122990c543cf027052ddefeb53925dc14a
7
- data.tar.gz: 077b9b50f0b1702a012c672c44e30714b7ab53d2b53c38c588228215e18f57547571744b5677e020714a37316f71a4a3552c5a04ada4a6116f4a2efe05da65eb
6
+ metadata.gz: 51812ee665f90f68b56c1f3fdc859440b9ad3514b2f1e6bd911e0c62b4835b31c41077754f487b572193d997d4d60fcf8936b28a1c5fe433ad6b8364accdcab6
7
+ data.tar.gz: e3cbec3d4995e3dc1f0601483e17e57a48fe510e101b298eed3f7ec353a6d995c39b62d477fb1d526465b079b5408c53c2e27d130eec71dd93cfb113a18e2290
data/README.md CHANGED
@@ -6,9 +6,9 @@ This is a wrapper for adding bootstrap to a project. By includinig this gem you'
6
6
  * [Bootstrap Datepicker](https://github.com/Nerian/bootstrap-datepicker-rails)
7
7
  * [Select2](https://github.com/argerim/select2-rails)
8
8
  * [Will paginate](https://github.com/mislav/will_paginate)
9
+ * Links with `data: { confirm: 'Sure?' }` opens in Bootstrap Modal by default.
9
10
  * Bootstrap Helpers
10
11
 
11
-
12
12
  ## Installation
13
13
 
14
14
  To install simply include into Gemfile:
@@ -96,7 +96,7 @@ In your layout render the partial wherever your like
96
96
  ```
97
97
  In your views, add an element to breadcrumb with:
98
98
  ```erb
99
- <%= breadcrumb_add(title: 'new', url: pages_new_path) %>
99
+ <% breadcrumb_add(title: 'new', url: pages_new_path) %>
100
100
  ```
101
101
  Notice that first in first out. So be careful with the order.
102
102
 
@@ -1,4 +1,6 @@
1
+ //= require binco_namespace
1
2
  //= require bootstrap-sprockets
2
3
  //= require select2
3
4
  //= require bootstrap-datepicker/core
4
5
  //= require select2-rails
6
+ //= require bootstrap-data-confirm
@@ -0,0 +1 @@
1
+ window.Binco = {}
@@ -0,0 +1,129 @@
1
+ $.fn.twitter_bootstrap_confirmbox =
2
+ defaults:
3
+ title: null
4
+ proceed: "OK"
5
+ proceed_class: "btn"
6
+ cancel: "Cancelar"
7
+ cancel_class: "btn"
8
+
9
+ TwitterBootstrapConfirmBox = (message, element, callback) ->
10
+
11
+ $dialog = $("""
12
+ <div class="modal fade" id="confirmation_dialog" role="dialog" tabindex="-1">
13
+ <div class="modal-dialog">
14
+ <div class="modal-content">
15
+ <div class="modal-header">
16
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
17
+ <h4 class="modal-title"></h4>
18
+ </div>
19
+ <div class="modal-body"></div>
20
+ <div class="modal-footer"></div>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ """)
25
+
26
+ $dialog
27
+ .find(".modal-header")
28
+ .find(".modal-title")
29
+ .html(element.data("confirm-title") || $.fn.twitter_bootstrap_confirmbox.defaults.title || window.top.location.origin)
30
+ .end()
31
+ .end()
32
+
33
+ .find(".modal-body")
34
+ .html(message.toString().replace(/\n/g, "<br />"))
35
+ .end()
36
+
37
+ .find(".modal-footer")
38
+ .append(
39
+ $("<a />", { href: "#", "data-dismiss": "modal" })
40
+ .html(element.data("confirm-cancel") || $.fn.twitter_bootstrap_confirmbox.defaults.cancel)
41
+ .addClass($.fn.twitter_bootstrap_confirmbox.defaults.cancel_class)
42
+ .addClass(element.data("confirm-cancel-class") || "btn-default")
43
+ .click((event) ->
44
+ event.preventDefault()
45
+ $dialog.modal("hide")
46
+ )
47
+ ,
48
+ $("<a />", { href: "#" })
49
+ .html(element.data("confirm-proceed") || $.fn.twitter_bootstrap_confirmbox.defaults.proceed)
50
+ .addClass($.fn.twitter_bootstrap_confirmbox.defaults.proceed_class)
51
+ .addClass(element.data("confirm-proceed-class") || "btn-warning")
52
+ .click((event) ->
53
+ event.preventDefault()
54
+ $dialog.modal("hide")
55
+ callback()
56
+ )
57
+ )
58
+ .end()
59
+
60
+ .on('keypress', (e) ->
61
+ $('.modal-footer a:last').trigger('click') if e.keyCode == 13 # Enter Key Code
62
+ )
63
+
64
+ .on("hidden", -> $(@).remove())
65
+
66
+ .modal("show")
67
+
68
+ .appendTo(document.body)
69
+
70
+ $.rails.allowAction = (element) ->
71
+ $(element).blur();
72
+ message = element.data("confirm")
73
+ answer = false
74
+ return true unless message
75
+
76
+ if $.rails.fire(element, "confirm")
77
+ TwitterBootstrapConfirmBox message, element, ->
78
+ if $.rails.fire(element, "confirm:complete", [answer])
79
+ allowAction = $.rails.allowAction
80
+
81
+ $.rails.allowAction = ->
82
+ true
83
+
84
+ if element.get(0).click
85
+ element.get(0).click()
86
+
87
+ else if Event?
88
+ evt = new Event("click", {
89
+ bubbles: true,
90
+ cancelable: true,
91
+ view: window,
92
+ detail: 0,
93
+ screenX: 0,
94
+ screenY: 0,
95
+ clientX: 0,
96
+ clientY: 0,
97
+ ctrlKey: false,
98
+ altKey: false,
99
+ shiftKey: false,
100
+ metaKey: false,
101
+ button: 0,
102
+ relatedTarget: document.body.parentNode
103
+ })
104
+ element.get(0).dispatchEvent(evt)
105
+
106
+ else if $.isFunction(document.createEvent)
107
+ evt = document.createEvent "MouseEvents"
108
+ evt.initMouseEvent(
109
+ "click",
110
+ true, # e.bubbles,
111
+ true, # e.cancelable,
112
+ window, # e.view,
113
+ 0, # e.detail,
114
+ 0, # e.screenX,
115
+ 0, # e.screenY,
116
+ 0, # e.clientX,
117
+ 0, # e.clientY,
118
+ false, # e.ctrlKey,
119
+ false, # e.altKey,
120
+ false, # e.shiftKey,
121
+ false, # e.metaKey,
122
+ 0, # e.button,
123
+ document.body.parentNode # e.relatedTarget
124
+ )
125
+ element.get(0).dispatchEvent(evt)
126
+
127
+ $.rails.allowAction = allowAction
128
+
129
+ false
@@ -1,5 +1,12 @@
1
- load = ->
2
- $('.select2-rails').select2()
1
+ window.Binco.Select2 =
2
+ load: (selector) ->
3
+ selector = if typeof selector == 'string' then selector else '.select2-rails'
4
+ $(selector).select2()
5
+ destroy: (selector) ->
6
+ selector = if typeof selector == 'string' then selector else '.select2-rails'
7
+ $(selector).each((i,e) ->
8
+ $(e).select2('destroy')
9
+ )
3
10
 
4
- $(document).ready load
5
- $(document).on 'page:load', load
11
+ $(document).on 'turbolinks:load', window.Binco.Select2.load
12
+ $(document).on 'turbolinks:before-cache', window.Binco.Select2.destroy
@@ -1,10 +1,13 @@
1
1
  @import "bootstrap-sprockets";
2
- @import "bootstrap-overrides";
3
2
  @import "bootstrap";
4
3
  @import "select2";
5
4
  @import "select2-bootstrap";
6
- @import "bootstrap-datepicker3.css";
5
+ @import "bootstrap-datepicker3";
7
6
 
8
7
  .field_with_errors {
9
8
  @extend .has-error;
9
+
10
+ .form-control {
11
+ border-width: 1px;
12
+ }
10
13
  }
@@ -1,5 +1,8 @@
1
1
  module Binco
2
2
  class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
3
+ alias_method :collection_select_original, :collection_select
4
+ alias_method :select_original, :select
5
+
3
6
  def text_field(name, options = {})
4
7
  options = add_class_to_options('form-control', options)
5
8
  super name, options
@@ -31,18 +34,18 @@ module Binco
31
34
 
32
35
  # Since select2 support multiple choices (checkboxes)
33
36
  def collection_check_boxes2(method, collection, value_method, text_method, options = {}, html_options = {})
34
- options ||= {}
35
- options[:multiple] = 'multiple'
37
+ html_options ||= {}
38
+ html_options[:multiple] = 'multiple'
36
39
  collection_select2 method, collection, value_method, text_method, options, html_options
37
40
  end
38
41
 
39
42
  def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
40
- html_options = add_class_to_options('form-control', options)
43
+ html_options = add_class_to_options('form-control', html_options)
41
44
  super method, collection, value_method, text_method, options, html_options
42
45
  end
43
46
 
44
47
  def collection_select2(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
45
- options = add_class_to_options('select2-rails', options)
48
+ html_options = add_class_to_options('select2-rails', html_options)
46
49
  collection_select(method, collection, value_method, text_method, options, html_options)
47
50
  end
48
51
 
@@ -83,6 +86,7 @@ module Binco
83
86
 
84
87
  def submit(value = nil, options = {})
85
88
  options = add_class_to_options('btn btn-success', options)
89
+ add_data_to_options({ disable_with: 'Enviando' }, options)
86
90
  super value, options
87
91
  end
88
92
 
@@ -0,0 +1,26 @@
1
+ module Binco
2
+ module FormHelper
3
+ def bootstrap_form_for(record, options = {}, &block)
4
+ options[:builder] = BootstrapFormBuilder
5
+ form_for(record, options, &block)
6
+ end
7
+
8
+ def bootstrap_form_tag(url_for_options = {}, options = {}, &block)
9
+ options[:acts_like_form_tag] = true
10
+ options[:url] = url_for_options
11
+ bootstrap_form_for("", options, &block)
12
+ end
13
+
14
+ def materialize_form_for(record, options = {}, &block)
15
+ options[:builder] = MaterializeFormBuilder
16
+ form_for(record, options, &block)
17
+ end
18
+
19
+ def materialize_form_tag(url_for_options = {}, options = {}, &block)
20
+ options[:acts_like_form_tag] = true
21
+ options[:url] = url_for_options
22
+ materialize_form_for("", options, &block)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,127 @@
1
+ module Binco
2
+ class MaterializeFormBuilder < ActionView::Helpers::FormBuilder
3
+ alias_method :collection_select_original, :collection_select
4
+ alias_method :select_original, :select
5
+
6
+ def text_field(name, options = {})
7
+ super name, options
8
+ end
9
+
10
+ def telephone_field(name, options = {})
11
+ super name, options
12
+ end
13
+
14
+ def select(method, choices = nil, options = {}, html_options = {}, &block)
15
+ super method, choices, options, html_options, &block
16
+ end
17
+
18
+ def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
19
+ if block_given?
20
+ super(method, collection, value_method, text_method, options, html_options, &block)
21
+ else
22
+ super method, collection, value_method, text_method, options, html_options do |b|
23
+ group_tag class: 'checkbox' do
24
+ b.label do
25
+ b.check_box + b.text
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ # Since select2 support multiple choices (checkboxes)
33
+ def collection_check_boxes2(method, collection, value_method, text_method, options = {}, html_options = {})
34
+ html_options ||= {}
35
+ html_options[:multiple] = 'multiple'
36
+ collection_select2 method, collection, value_method, text_method, options, html_options
37
+ end
38
+
39
+ def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
40
+ super method, collection, value_method, text_method, options, html_options
41
+ end
42
+
43
+ def collection_select2(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
44
+ html_options = add_class_to_options('select2-rails', html_options)
45
+ collection_select(method, collection, value_method, text_method, options, html_options)
46
+ end
47
+
48
+ def email_field(name, options = {})
49
+ super name, options
50
+ end
51
+
52
+ def number_field(name, options = {})
53
+ super name, options
54
+ end
55
+
56
+ def password_field(name, options = {})
57
+ super name, options
58
+ end
59
+
60
+ def datepicker(method, options = {})
61
+ options = add_data_to_options({ provide: 'datepicker' }, options)
62
+ text_field(method, options)
63
+ end
64
+
65
+ def text_area(method, options = {})
66
+ options = add_class_to_options('materialize-textarea', options)
67
+ super(method, options)
68
+ end
69
+
70
+ def radio_button(method, tag_value, options = {})
71
+ options = add_class_to_options('radio', options)
72
+ super method, tag_value, options
73
+ end
74
+
75
+ def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
76
+ options = add_class_to_options('checkbox', options)
77
+ super method, options, checked_value, unchecked_value
78
+ end
79
+
80
+ def submit(value = nil, options = {})
81
+ options = add_class_to_options('btn', options)
82
+ super value, options
83
+ end
84
+
85
+ def form_group(options = {}, &block)
86
+ options = add_class_to_options('input-field', options)
87
+ group_tag options, &block
88
+ end
89
+
90
+ def radio_group(options = {}, &block)
91
+ options = add_class_to_options('radio', options)
92
+ group_tag options, &block
93
+ end
94
+
95
+ def checkbox_group(options = {}, &block)
96
+ options = add_class_to_options('checkbox', options)
97
+ group_tag options, &block
98
+ end
99
+
100
+ def input_group(options = {}, &block)
101
+ options = add_class_to_options('input-group', options)
102
+ group_tag options, &block
103
+ end
104
+
105
+ private
106
+
107
+ # Add the specified class_name the the options hash
108
+ def add_class_to_options(class_name, options = {})
109
+ options[:class] ||= ''
110
+ options[:class] << " #{class_name}"
111
+ options
112
+ end
113
+
114
+ # Add the specified data-attributes the the options hash
115
+ def add_data_to_options(data, options = {})
116
+ options[:data] ||= {}
117
+ options[:data].merge! data
118
+ options
119
+ end
120
+
121
+ def group_tag(attributes = {}, &block)
122
+ @template.content_tag :div, attributes do
123
+ yield
124
+ end
125
+ end
126
+ end
127
+ end
@@ -1,3 +1,3 @@
1
1
  module Binco
2
- VERSION = '0.0.3'
2
+ VERSION = '2.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Camacho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-18 00:00:00.000000000 Z
11
+ date: 2018-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: 4.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.0'
22
+ version: '6'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '3.2'
29
+ version: 4.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.0'
32
+ version: '6'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bootstrap-datepicker-rails
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -112,13 +112,16 @@ files:
112
112
  - README.md
113
113
  - Rakefile
114
114
  - app/assets/javascripts/binco.js
115
+ - app/assets/javascripts/binco_namespace.js
116
+ - app/assets/javascripts/bootstrap-data-confirm.coffee
115
117
  - app/assets/javascripts/select2-rails.coffee
116
118
  - app/assets/stylesheets/binco.scss
117
119
  - app/helpers/binco/bootstrap_form_builder.rb
118
- - app/helpers/binco/bootstrap_form_helper.rb
119
120
  - app/helpers/binco/breadcrumbs_helper.rb
120
121
  - app/helpers/binco/button_helper.rb
121
122
  - app/helpers/binco/button_link_helper.rb
123
+ - app/helpers/binco/form_helper.rb
124
+ - app/helpers/binco/materialize_form_builder.rb
122
125
  - app/helpers/binco/modal_helper.rb
123
126
  - app/helpers/binco/pagination_renderer.rb
124
127
  - app/views/binco/_breadcrumb.html.erb
@@ -183,43 +186,42 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
186
  version: '0'
184
187
  requirements: []
185
188
  rubyforge_project:
186
- rubygems_version: 2.2.2
189
+ rubygems_version: 2.6.11
187
190
  signing_key:
188
191
  specification_version: 4
189
192
  summary: Bootstrap Sass for use in Ruby on Rails applications
190
193
  test_files:
191
- - test/binco_test.rb
194
+ - test/dummy/app/controllers/application_controller.rb
195
+ - test/dummy/app/views/layouts/application.html.erb
192
196
  - test/dummy/app/assets/javascripts/application.js
193
197
  - test/dummy/app/assets/stylesheets/application.css
194
- - test/dummy/app/controllers/application_controller.rb
195
198
  - test/dummy/app/helpers/application_helper.rb
196
- - test/dummy/app/views/layouts/application.html.erb
197
- - test/dummy/bin/bundle
198
- - test/dummy/bin/rails
199
199
  - test/dummy/bin/rake
200
200
  - test/dummy/bin/setup
201
- - test/dummy/config/application.rb
202
- - test/dummy/config/boot.rb
203
- - test/dummy/config/environment.rb
204
- - test/dummy/config/environments/development.rb
201
+ - test/dummy/bin/bundle
202
+ - test/dummy/bin/rails
203
+ - test/dummy/config/secrets.yml
204
+ - test/dummy/config/routes.rb
205
+ - test/dummy/config/locales/en.yml
205
206
  - test/dummy/config/environments/production.rb
207
+ - test/dummy/config/environments/development.rb
206
208
  - test/dummy/config/environments/test.rb
207
- - test/dummy/config/initializers/assets.rb
209
+ - test/dummy/config/environment.rb
210
+ - test/dummy/config/application.rb
211
+ - test/dummy/config/boot.rb
208
212
  - test/dummy/config/initializers/backtrace_silencers.rb
209
- - test/dummy/config/initializers/cookies_serializer.rb
210
- - test/dummy/config/initializers/filter_parameter_logging.rb
211
- - test/dummy/config/initializers/inflections.rb
212
213
  - test/dummy/config/initializers/mime_types.rb
214
+ - test/dummy/config/initializers/filter_parameter_logging.rb
213
215
  - test/dummy/config/initializers/session_store.rb
214
216
  - test/dummy/config/initializers/wrap_parameters.rb
215
- - test/dummy/config/locales/en.yml
216
- - test/dummy/config/routes.rb
217
- - test/dummy/config/secrets.yml
217
+ - test/dummy/config/initializers/assets.rb
218
+ - test/dummy/config/initializers/cookies_serializer.rb
219
+ - test/dummy/config/initializers/inflections.rb
218
220
  - test/dummy/config.ru
219
- - test/dummy/public/404.html
221
+ - test/dummy/Rakefile
222
+ - test/dummy/public/favicon.ico
220
223
  - test/dummy/public/422.html
221
224
  - test/dummy/public/500.html
222
- - test/dummy/public/favicon.ico
223
- - test/dummy/Rakefile
225
+ - test/dummy/public/404.html
226
+ - test/binco_test.rb
224
227
  - test/test_helper.rb
225
- has_rdoc:
@@ -1,14 +0,0 @@
1
- module Binco
2
- module BootstrapFormHelper
3
- def bootstrap_form_for(record, options = {}, &block)
4
- options[:builder] = BootstrapFormBuilder
5
- form_for(record, options, &block)
6
- end
7
-
8
- def bootstrap_form_tag(url_for_options = {}, options = {}, &block)
9
- options[:acts_like_form_tag] = true
10
- options[:url] = url_for_options
11
- bootstrap_form_for("", options, &block)
12
- end
13
- end
14
- end