binco 2.0.1 → 3.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.
@@ -1,13 +1,41 @@
1
- @import "bootstrap-sprockets";
1
+ @import "bootstrap_variables";
2
2
  @import "bootstrap";
3
3
  @import "select2";
4
4
  @import "select2-bootstrap";
5
- @import "bootstrap-datepicker3";
5
+ @import "datepicker";
6
6
 
7
7
  .field_with_errors {
8
- @extend .has-error;
9
-
10
- .form-control {
11
- border-width: 1px;
8
+ input, select {
9
+ @extend .is-invalid;
10
+ @extend .was-validated;
12
11
  }
13
12
  }
13
+
14
+ .form-group > .field_with_errors {
15
+ display: inline;
16
+ }
17
+
18
+ .form-group > .field_with_errors:last-child {
19
+ display: block;
20
+ }
21
+
22
+ select.custom-select {
23
+ width: 100%;
24
+ }
25
+
26
+ .select2-container {
27
+ width: 100% !important;
28
+ }
29
+
30
+ .field_with_errors .select2-container .select2-selection--single {
31
+ border-color: $form-feedback-invalid-color;
32
+ }
33
+
34
+ .field_with_errors .custom-select {
35
+ border-color: $form-feedback-invalid-color;
36
+ }
37
+
38
+ .pagination {
39
+ margin-top: 1rem;
40
+ margin-bottom: 1rem;
41
+ }
@@ -1,31 +1,58 @@
1
1
  module Binco
2
2
  class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
3
3
  alias_method :collection_select_original, :collection_select
4
+ alias_method :check_box_original, :check_box
4
5
  alias_method :select_original, :select
6
+ alias_method :submit_original, :submit
7
+
8
+ CHECK_BOX_GROUP_CLASS = 'form-check'
9
+ CHECK_BOX_LABEL_CLASS = 'form-check-label'
10
+ FORM_ELEMENT_CLASS = 'form-control'
11
+ CHECK_BOX_INPUT_CLASS = 'form-check-input'
12
+
13
+ def initialize(object_name, object, template, options)
14
+ ActionView::Base::field_error_proc = Proc.new do |html_tag, instance|
15
+ if instance.respond_to?(:error_message) && instance.class.to_s != 'ActionView::Helpers::Tags::Label'
16
+ error_messages = instance.error_message.collect{ |error| "<div class=\"invalid-feedback\">#{error}</div>" }.join
17
+
18
+ "<div class=\"field_with_errors\">#{html_tag} #{error_messages}</div>".html_safe
19
+ else
20
+ "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe
21
+ end
22
+ end
23
+
24
+ super(object_name, object, template, options)
25
+ end
5
26
 
6
27
  def text_field(name, options = {})
7
- options = add_class_to_options('form-control', options)
28
+ options = add_class_to_options(FORM_ELEMENT_CLASS, options)
8
29
  super name, options
9
30
  end
10
31
 
11
32
  def telephone_field(name, options = {})
12
- options = add_class_to_options('form-control', options)
33
+ options = add_class_to_options(FORM_ELEMENT_CLASS, options)
13
34
  super name, options
14
35
  end
36
+ alias_method :phone_field, :telephone_field
15
37
 
16
38
  def select(method, choices = nil, options = {}, html_options = {}, &block)
17
- html_options = add_class_to_options('form-control', html_options)
39
+ html_options = add_class_to_options('custom-select', html_options)
18
40
  super method, choices, options, html_options, &block
19
41
  end
20
42
 
43
+ def select2(method, choices = nil, options = {}, html_options = {}, &block)
44
+ html_options = add_class_to_options('select2-rails', html_options)
45
+ select_original method, choices, options, html_options, &block
46
+ end
47
+
21
48
  def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
22
49
  if block_given?
23
50
  super(method, collection, value_method, text_method, options, html_options, &block)
24
51
  else
25
52
  super method, collection, value_method, text_method, options, html_options do |b|
26
- group_tag class: 'checkbox' do
27
- b.label do
28
- b.check_box + b.text
53
+ group_tag class: CHECK_BOX_GROUP_CLASS do
54
+ b.label class: CHECK_BOX_LABEL_CLASS do
55
+ b.check_box(class: CHECK_BOX_INPUT_CLASS) + " " + b.text
29
56
  end
30
57
  end
31
58
  end
@@ -40,27 +67,27 @@ module Binco
40
67
  end
41
68
 
42
69
  def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
43
- html_options = add_class_to_options('form-control', html_options)
70
+ html_options = add_class_to_options('custom-select', html_options)
44
71
  super method, collection, value_method, text_method, options, html_options
45
72
  end
46
73
 
47
74
  def collection_select2(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
48
75
  html_options = add_class_to_options('select2-rails', html_options)
49
- collection_select(method, collection, value_method, text_method, options, html_options)
76
+ collection_select_original(method, collection, value_method, text_method, options, html_options)
50
77
  end
51
78
 
52
79
  def email_field(name, options = {})
53
- options = add_class_to_options('form-control', options)
80
+ options = add_class_to_options(FORM_ELEMENT_CLASS, options)
54
81
  super name, options
55
82
  end
56
83
 
57
84
  def number_field(name, options = {})
58
- options = add_class_to_options('form-control', options)
85
+ options = add_class_to_options(FORM_ELEMENT_CLASS, options)
59
86
  super name, options
60
87
  end
61
88
 
62
89
  def password_field(name, options = {})
63
- options = add_class_to_options('form-control', options)
90
+ options = add_class_to_options(FORM_ELEMENT_CLASS, options)
64
91
  super name, options
65
92
  end
66
93
 
@@ -70,20 +97,34 @@ module Binco
70
97
  end
71
98
 
72
99
  def text_area(method, options = {})
73
- options = add_class_to_options('form-control', options)
100
+ options = add_class_to_options(FORM_ELEMENT_CLASS, options)
74
101
  super(method, options)
75
102
  end
76
103
 
77
104
  def radio_button(method, tag_value, options = {})
78
- options = add_class_to_options('radio', options)
79
105
  super method, tag_value, options
80
106
  end
81
107
 
82
108
  def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
83
- options = add_class_to_options('checkbox', options)
109
+ options = add_class_to_options(CHECK_BOX_INPUT_CLASS, options)
84
110
  super method, options, checked_value, unchecked_value
85
111
  end
86
112
 
113
+ def custom_check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
114
+ options = add_class_to_options('custom-control-input', options)
115
+ base_proc = ActionView::Base::field_error_proc
116
+ ActionView::Base::field_error_proc = Proc.new { |html_tag, instance| html_tag }
117
+ html = check_box_original(method, options, checked_value, unchecked_value)
118
+ ActionView::Base::field_error_proc = base_proc
119
+
120
+ return html
121
+ end
122
+
123
+ def file_field(method, options = {})
124
+ options = add_class_to_options('form-control-file', options)
125
+ super method, options
126
+ end
127
+
87
128
  def submit(value = nil, options = {})
88
129
  options = add_class_to_options('btn btn-success', options)
89
130
  add_data_to_options({ disable_with: 'Enviando' }, options)
@@ -100,16 +141,28 @@ module Binco
100
141
  group_tag options, &block
101
142
  end
102
143
 
103
- def checkbox_group(options = {}, &block)
104
- options = add_class_to_options('checkbox', options)
144
+ def form_check(options = {}, &block)
145
+ options = add_class_to_options(CHECK_BOX_GROUP_CLASS, options)
105
146
  group_tag options, &block
106
147
  end
148
+ alias_method :check_box_group, :form_check
149
+
150
+ def check_label(method, options = {}, &block)
151
+ options = add_class_to_options(CHECK_BOX_LABEL_CLASS, options)
152
+ @template.label(@object_name, method, nil, objectify_options(options), &block)
153
+ end
154
+ alias_method :check_box_label, :check_label
107
155
 
108
156
  def input_group(options = {}, &block)
109
157
  options = add_class_to_options('input-group', options)
110
158
  group_tag options, &block
111
159
  end
112
160
 
161
+ def addon(icon, options = {})
162
+ options = add_class_to_options('input-group-addon', options)
163
+ @template.content_tag(:span, icon, options)
164
+ end
165
+
113
166
  private
114
167
 
115
168
  # Add the specified class_name the the options hash
@@ -0,0 +1,9 @@
1
+ module Binco
2
+ module ImageHelper
3
+ def image_fluid(source, options={})
4
+ tag_class = "img-fluid #{options[:class]}"
5
+ options[:class] = tag_class
6
+ image_tag(source, options)
7
+ end
8
+ end
9
+ end
@@ -1,159 +1,64 @@
1
+ require 'will_paginate/view_helpers/action_view'
2
+
1
3
  module Binco
2
- class PaginationRenderer < ::WillPaginate::ViewHelpers::LinkRendererBase
3
- # * +collection+ is a WillPaginate::Collection instance or any other object
4
- # that conforms to that API
5
- # * +options+ are forwarded from +will_paginate+ view helper
6
- # * +template+ is the reference to the template being rendered
7
- def prepare(collection, options, template)
8
- super(collection, options)
9
- @template = template
10
- @container_attributes = @base_url_params = nil
11
- end
4
+ class PaginationRenderer < WillPaginate::ActionView::LinkRenderer
5
+ ELLIPSIS = '&hellip;'
12
6
 
13
- # Process it! This method returns the complete HTML string which contains
14
- # pagination links. Feel free to subclass LinkRenderer and change this
15
- # method as you see fit.
16
7
  def to_html
17
- html = pagination.map do |item|
18
- item.is_a?(Fixnum) ?
19
- page_number(item) :
20
- send(item)
8
+ list_items = pagination.map do |item|
9
+ case item
10
+ when Fixnum
11
+ page_number(item)
12
+ else
13
+ send(item)
14
+ end
21
15
  end.join(@options[:link_separator])
22
16
 
23
- @options[:container] ? html_container(html) : html
17
+ list_wrapper = tag :ul, list_items, class: 'pagination', role: 'group'
18
+ tag :nav, list_wrapper, class: @options[:class]
24
19
  end
25
20
 
26
- # Returns the subset of +options+ this instance was initialized with that
27
- # represent HTML attributes for the container element of pagination links.
28
21
  def container_attributes
29
- @container_attributes ||= @options.except(*(ViewHelpers.pagination_options.keys + [:renderer] - [:class]))
22
+ super.except(*[:link_options])
30
23
  end
31
24
 
32
- protected
25
+ protected
33
26
 
34
27
  def page_number(page)
35
- unless page == current_page
36
- tag(:li, link(page, page, rel: rel_value(page)))
37
- else
38
- tag(:li, link(page, '#'), class: 'active')
39
- end
40
- end
41
-
42
- def gap
43
- text = @template.will_paginate_translate(:page_gap) { '&hellip;' }
44
- %(<li><a>#{text}</a></li>)
45
- end
46
-
47
- def previous_page
48
- num = @collection.current_page > 1 && @collection.current_page - 1
49
- previous_or_next_page(num, @options[:previous_label], 'previous_page')
50
- end
28
+ link_options = @options[:link_options] || {}
51
29
 
52
- def next_page
53
- num = @collection.current_page < total_pages && @collection.current_page + 1
54
- previous_or_next_page(num, @options[:next_label], 'next_page')
55
- end
56
-
57
- def previous_or_next_page(page, text, classname)
58
- if page
59
- tag(:li, link(text, page, class: classname))
30
+ if page == current_page
31
+ tag :li, tag(:span, page, class: 'page-link'), class: 'page-item active'
60
32
  else
61
- tag(:li, link(text, '#'), class: classname + ' disabled')
33
+ link_options.merge! class: 'page-link', rel: rel_value(page)
34
+ tag :li, link(page, page, link_options), class: 'page-item'
62
35
  end
63
36
  end
64
37
 
65
- def html_container(html)
66
- tag(:ul, html, class: 'pagination pagination-xs')
67
- end
68
-
69
- # Returns URL params for +page_link_or_span+, taking the current GET params
70
- # and <tt>:params</tt> option into account.
71
- def default_url_params
72
- {}
73
- end
74
-
75
- def url(page)
76
- @base_url_params ||= begin
77
- url_params = merge_get_params(default_url_params)
78
- url_params[:only_path] = true
79
- merge_optional_params(url_params)
80
- end
81
-
82
- url_params = @base_url_params.dup
83
- add_current_page_param(url_params, page)
84
-
85
- @template.url_for(url_params)
86
- end
87
-
88
- def merge_optional_params(url_params)
89
- symbolized_update(url_params, @options[:params]) if @options[:params]
90
- url_params
91
- end
92
-
93
- def merge_get_params(url_params)
94
- if @template.respond_to? :request and @template.request and @template.request.get?
95
- symbolized_update(url_params, @template.params)
96
- end
97
- url_params
98
- end
38
+ def previous_or_next_page(page, text, classname)
39
+ link_options = @options[:link_options] || {}
99
40
 
100
- def add_current_page_param(url_params, page)
101
- unless param_name.index(/[^\w-]/)
102
- url_params[param_name.to_sym] = page
41
+ if page
42
+ link_wrapper = link(text, page, link_options.merge(class: 'page-link'))
43
+ tag :li, link_wrapper, class: '%s page-item' % classname
103
44
  else
104
- page_param = parse_query_parameters("#{param_name}=#{page}")
105
- symbolized_update(url_params, page_param)
45
+ span_wrapper = tag(:span, text, class: 'page-link')
46
+ tag :li, span_wrapper, class: '%s page-item disabled' % classname
106
47
  end
107
48
  end
108
49
 
109
- private
110
-
111
- def parse_query_parameters(params)
112
- Rack::Utils.parse_nested_query(params)
113
- end
114
-
115
- def param_name
116
- @options[:param_name].to_s
117
- end
118
-
119
- def link(text, target, attributes = {})
120
- if target.is_a? Fixnum
121
- attributes[:rel] = rel_value(target)
122
- target = url(target)
123
- end
124
- attributes[:href] = target
125
- tag(:a, text, attributes)
126
- end
127
-
128
- def tag(name, value, attributes = {})
129
- string_attributes = attributes.inject('') do |attrs, pair|
130
- unless pair.last.nil?
131
- attrs << %( #{pair.first}="#{CGI::escapeHTML(pair.last.to_s)}")
132
- end
133
- attrs
134
- end
135
- "<#{name}#{string_attributes}>#{value}</#{name}>"
50
+ def gap
51
+ tag :li, tag(:i, ELLIPSIS, class: 'page-link'), class: 'page-item disabled'
136
52
  end
137
53
 
138
- def rel_value(page)
139
- case page
140
- when @collection.current_page - 1; 'prev' + (page == 1 ? ' start' : '')
141
- when @collection.current_page + 1; 'next'
142
- when 1; 'start'
143
- end
54
+ def previous_page
55
+ num = @collection.current_page > 1 && @collection.current_page - 1
56
+ previous_or_next_page num, @options[:previous_label], 'previous'
144
57
  end
145
58
 
146
- def symbolized_update(target, other)
147
- other.each do |key, value|
148
- key = key.to_sym
149
- existing = target[key]
150
-
151
- if value.is_a?(Hash) and (existing.is_a?(Hash) or existing.nil?)
152
- symbolized_update(existing || (target[key] = {}), value)
153
- else
154
- target[key] = value
155
- end
156
- end
59
+ def next_page
60
+ num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
61
+ previous_or_next_page num, @options[:next_label], 'next'
157
62
  end
158
63
  end
159
64
  end
@@ -1,6 +1,6 @@
1
1
  <ol class="breadcrumb">
2
2
  <% breadcrumb.each do |route| %>
3
- <li class="<%= 'active' if breadcrumb.last == route %>">
3
+ <li class="<%= 'active' if breadcrumb.last == route %> breadcrumb-item">
4
4
  <% if route[:url] %>
5
5
  <%= link_to route[:title], route[:url] %>
6
6
  <% else %>
@@ -1,6 +1,8 @@
1
- require 'bootstrap-datepicker-rails'
1
+ require 'jquery-rails'
2
+ require 'bootstrap'
2
3
  require 'select2-rails'
3
4
  require 'will_paginate'
5
+ require 'bootstrap-datepicker-rails'
4
6
 
5
7
  module Binco
6
8
  class Engine < ::Rails::Engine
@@ -1,3 +1,3 @@
1
1
  module Binco
2
- VERSION = '2.0.1'
2
+ VERSION = '3.0.1'
3
3
  end
@@ -13,7 +13,7 @@ module Binco
13
13
  end
14
14
 
15
15
  def create_overrides
16
- copy_file '_bootstrap-overrides.scss', 'app/assets/stylesheets/_bootstrap-overrides.scss'
16
+ copy_file '_bootstrap_variables.scss', 'app/assets/stylesheets/_bootstrap_variables.scss'
17
17
  end
18
18
 
19
19
  def add_javascripts