binco 0.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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +100 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/binco.js +4 -0
  6. data/app/assets/javascripts/select2-rails.coffee +5 -0
  7. data/app/assets/stylesheets/binco.scss +9 -0
  8. data/app/helpers/binco/bootstrap_form_builder.rb +121 -0
  9. data/app/helpers/binco/bootstrap_form_helper.rb +14 -0
  10. data/app/helpers/binco/breadcrumbs_helper.rb +28 -0
  11. data/app/helpers/binco/button_helper.rb +41 -0
  12. data/app/helpers/binco/button_link_helper.rb +41 -0
  13. data/app/helpers/binco/modal_helper.rb +42 -0
  14. data/app/views/binco/_breadcrumb.html.erb +11 -0
  15. data/lib/binco.rb +2 -0
  16. data/lib/binco/engine.rb +18 -0
  17. data/lib/binco/version.rb +3 -0
  18. data/test/binco_test.rb +7 -0
  19. data/test/dummy/Rakefile +6 -0
  20. data/test/dummy/app/assets/javascripts/application.js +13 -0
  21. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  22. data/test/dummy/app/controllers/application_controller.rb +5 -0
  23. data/test/dummy/app/helpers/application_helper.rb +2 -0
  24. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  25. data/test/dummy/bin/bundle +3 -0
  26. data/test/dummy/bin/rails +4 -0
  27. data/test/dummy/bin/rake +4 -0
  28. data/test/dummy/bin/setup +29 -0
  29. data/test/dummy/config.ru +4 -0
  30. data/test/dummy/config/application.rb +29 -0
  31. data/test/dummy/config/boot.rb +5 -0
  32. data/test/dummy/config/environment.rb +5 -0
  33. data/test/dummy/config/environments/development.rb +38 -0
  34. data/test/dummy/config/environments/production.rb +76 -0
  35. data/test/dummy/config/environments/test.rb +42 -0
  36. data/test/dummy/config/initializers/assets.rb +11 -0
  37. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  38. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  39. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/test/dummy/config/initializers/inflections.rb +16 -0
  41. data/test/dummy/config/initializers/mime_types.rb +4 -0
  42. data/test/dummy/config/initializers/session_store.rb +3 -0
  43. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  44. data/test/dummy/config/locales/en.yml +23 -0
  45. data/test/dummy/config/routes.rb +56 -0
  46. data/test/dummy/config/secrets.yml +22 -0
  47. data/test/dummy/public/404.html +67 -0
  48. data/test/dummy/public/422.html +67 -0
  49. data/test/dummy/public/500.html +66 -0
  50. data/test/dummy/public/favicon.ico +0 -0
  51. data/test/test_helper.rb +17 -0
  52. metadata +206 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 174e159bcca99e63b3c550f15252312a83f224dc
4
+ data.tar.gz: 5c273c604bf98572a504cf6e4391f28436de2f6d
5
+ SHA512:
6
+ metadata.gz: 434fd2e4feea935bb9370be771d4fde2e8dd99b418e17ed97dc91a068f4e27536bf1c4b6c33df01cbbf8b7c9649da4cfb8e04cbeca5502cb5d1220421a73c5db
7
+ data.tar.gz: 6450918e1692b55a8bce1acf20b17f24012e913861e3d9adc1cdaf42d321511546d505328b79fd83dbedeeaf3029ecb0107afad73c5c4bc0d8a5a20c61dc6571
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 vicocamacho
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # Binco
2
+
3
+ This is a wrapper for adding bootstrap to a project. By includinig this gem you'll add:
4
+
5
+ * [Bootstrap](https://github.com/twbs/bootstrap-sass)
6
+ * [Bootstrap Datepicker](https://github.com/Nerian/bootstrap-datepicker-rails)
7
+ * [Select2](https://github.com/argerim/select2-rails)
8
+ * Bootstrap Helpers
9
+
10
+
11
+ ## Installation
12
+
13
+ To install simply include into Gemfile:
14
+ ```
15
+ gem 'binco'
16
+ ```
17
+
18
+ and run:
19
+
20
+ ```
21
+ bundle install
22
+ ```
23
+
24
+ In your application.scss add:
25
+ ```
26
+ @include "binco"
27
+ ```
28
+
29
+ In your application.js add:
30
+ ```
31
+ //= require binco
32
+ ```
33
+
34
+ #### Optional
35
+ For customization of datepicker make sure to include your locale js and send it as data attribute when creating a datepicker.
36
+ ```
37
+ //= require bootstrap-datepicker/locales/bootstrap-datepicker.es.js
38
+ //= require select2_locale_es
39
+ ```
40
+
41
+
42
+ ## Usage
43
+
44
+
45
+ ```erb
46
+ <%= bootstrap_form_for(@object) do |f| %>
47
+ <%= f.form_group do %>
48
+ <%= f.label :product_id %>
49
+ <%= f.collection_select :product_id, @products, :id, :name, class: 'special-select-class-if-needed' %>
50
+ <% end %>
51
+
52
+ <%= f.form_group do %>
53
+ <%= f.label :name %>
54
+ <%= f.number_field :name %>
55
+ <% end %>
56
+
57
+ <!-- select2 support -->
58
+ <%= f.form_group do %>
59
+ <%= f.label :product %>
60
+ <%= f.collection_select2 :product_id, @products, :name, :id %>
61
+ <% end %>
62
+
63
+ <!-- select2 support for checkboxes -->
64
+ <%= f.form_group do %>
65
+ <%= f.label :products %>
66
+ <%= f.collection_check_boxes2 :product_id, @products, :name, :id %>
67
+ <% end %>
68
+
69
+ <%= f.submit 'Great!' %>
70
+ <% end %>
71
+ ```
72
+
73
+ ### Modals
74
+ ```erb
75
+ <%= modal 'filter-modal' do %>
76
+ <%= modal_header 'One fine title'%>
77
+ <%= modal_body do %>
78
+ One fine body
79
+ <% end %>
80
+ <%= modal_footer do %>
81
+ <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
82
+ <button type="button" class="btn btn-primary" data-dismiss="modal">Submit</button>
83
+ <% end %> <!-- end modal_footer -->
84
+ <% end %> <!-- end modal -->
85
+ ```
86
+
87
+ ### Breadcrumbs
88
+ In your layout render the partial wherever your like
89
+ ```erb
90
+ <%= render 'binco/breadcrumb' %>
91
+ ```
92
+ In your views, add an element to breadcrumb with:
93
+ ```erb
94
+ <%= breadcrumb_add(title: 'new', url: pages_new_path) %>
95
+ ```
96
+ Notice that first in first out. So be careful with the order.
97
+
98
+
99
+
100
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Binco'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,4 @@
1
+ //= require bootstrap-sprockets
2
+ //= require select2
3
+ //= require bootstrap-datepicker/core
4
+ //= require select2-rails
@@ -0,0 +1,5 @@
1
+ load = ->
2
+ $('.select2-rails').select2()
3
+
4
+ $(document).ready load
5
+ $(document).on 'page:load', load
@@ -0,0 +1,9 @@
1
+ @import "bootstrap-sprockets";
2
+ @import "bootstrap";
3
+ @import "select2";
4
+ @import "select2-bootstrap";
5
+ @import "bootstrap-datepicker3.css";
6
+
7
+ .field_with_errors {
8
+ @extend .has-error;
9
+ }
@@ -0,0 +1,121 @@
1
+ module Binco
2
+ class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
3
+ def text_field(name, options = {})
4
+ options = add_class_to_options('form-control', options)
5
+ super name, options
6
+ end
7
+
8
+ def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
9
+ if block_given?
10
+ super(method, collection, value_method, text_method, options, html_options, &block)
11
+ else
12
+ super method, collection, value_method, text_method, options, html_options do |b|
13
+ group_tag class: 'checkbox' do
14
+ b.label do
15
+ b.check_box + b.text
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ # Since select2 support multiple choices (checkboxes)
23
+ def collection_check_boxes2(method, collection, value_method, text_method, options = {}, html_options = {})
24
+ options ||= {}
25
+ options[:multiple] = 'multiple'
26
+ collection_select2 method, collection, value_method, text_method, options, html_options
27
+ end
28
+
29
+ def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
30
+ html_options = add_class_to_options('form-control', options)
31
+ super method, collection, value_method, text_method, options, html_options
32
+ end
33
+
34
+ def collection_select2(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
35
+ options = add_class_to_options('select2-rails', options)
36
+ collection_select(method, collection, value_method, text_method, options, html_options)
37
+ end
38
+
39
+ def email_field(name, options = {})
40
+ options = add_class_to_options('form-control', options)
41
+ super name, options
42
+ end
43
+
44
+ def number_field(name, options = {})
45
+ options = add_class_to_options('form-control', options)
46
+ super name, options
47
+ end
48
+
49
+ def password_field(name, options = {})
50
+ options = add_class_to_options('form-control', options)
51
+ super name, options
52
+ end
53
+
54
+ def datepicker(method, options = {})
55
+ options = add_data_to_options({ provide: 'datepicker' }, options)
56
+ text_field(method, options)
57
+ end
58
+
59
+ def text_area(method, options = {})
60
+ options = add_class_to_options('form-control', options)
61
+ super(method, options)
62
+ end
63
+
64
+ def radio_button(method, tag_value, options = {})
65
+ options = add_class_to_options('radio', options)
66
+ super method, tag_value, options
67
+ end
68
+
69
+ def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
70
+ options = add_class_to_options('checkbox', options)
71
+ super method, options, checked_value, unchecked_value
72
+ end
73
+
74
+ def submit(value = nil, options = {})
75
+ options = add_class_to_options('btn btn-success', options)
76
+ super value, options
77
+ end
78
+
79
+ def form_group(options = {}, &block)
80
+ options = add_class_to_options('form-group', options)
81
+ group_tag options, &block
82
+ end
83
+
84
+ def radio_group(options = {}, &block)
85
+ options = add_class_to_options('radio', options)
86
+ group_tag options, &block
87
+ end
88
+
89
+ def checkbox_group(options = {}, &block)
90
+ options = add_class_to_options('checkbox', options)
91
+ group_tag options, &block
92
+ end
93
+
94
+ def input_group(options = {}, &block)
95
+ options = add_class_to_options('input-group', options)
96
+ group_tag options, &block
97
+ end
98
+
99
+ private
100
+
101
+ # Add the specified class_name the the options hash
102
+ def add_class_to_options(class_name, options = {})
103
+ options[:class] ||= ''
104
+ options[:class] << " #{class_name}"
105
+ options
106
+ end
107
+
108
+ # Add the specified data-attributes the the options hash
109
+ def add_data_to_options(data, options = {})
110
+ options[:data] ||= {}
111
+ options[:data].merge! data
112
+ options
113
+ end
114
+
115
+ def group_tag(attributes = {}, &block)
116
+ @template.content_tag :div, attributes do
117
+ yield
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,28 @@
1
+ module Binco
2
+ module BreadcrumbsHelper
3
+
4
+ def breadcrumb_default
5
+ @breadcrumb = []
6
+ if Binco.breadcrumb_before
7
+ @breadcrumb << Binco.breadcrumb_before
8
+ end
9
+ if Binco.breadcrumb_default
10
+ Binco.breadcrumb_default.each do |member|
11
+ @breadcrumb << { title: member[:title], url: member[:url] }
12
+ end
13
+ end
14
+ @breadcrumb
15
+ end
16
+
17
+ def breadcrumb
18
+ @breadcrumb ||= breadcrumb_default
19
+ end
20
+
21
+ def breadcrumb_add(options = {})
22
+ breadcrumb << options
23
+ end
24
+
25
+ private
26
+
27
+ end
28
+ end
@@ -0,0 +1,41 @@
1
+ module Binco
2
+ module ButtonHelper
3
+ def button(title, options = {})
4
+ options[:type] ||= :default
5
+ options[:class] ||= ''
6
+ options[:class] << ' ' if options[:class].length > 1
7
+ options[:class] << "btn btn-#{options[:type]}"
8
+ content_tag :button, title, options.except(:type)
9
+ end
10
+
11
+ def button_primary(title, options = {})
12
+ options[:type] = :primary
13
+ button(title, options)
14
+ end
15
+
16
+ def button_default(title, options = {})
17
+ options[:type] = :default
18
+ button(title, options)
19
+ end
20
+
21
+ def button_success(title, options = {})
22
+ options[:type] = :default
23
+ button(title, options)
24
+ end
25
+
26
+ def button_info(title, options = {})
27
+ options[:type] = :info
28
+ button(title, options)
29
+ end
30
+
31
+ def button_warning(title, options = {})
32
+ options[:type] = :warning
33
+ button(title, options)
34
+ end
35
+
36
+ def button_danger(title, options = {})
37
+ options[:type] = :warning
38
+ button(title, options)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ module Binco
2
+ module ButtonLinkHelper
3
+ def button_link_to(name = nil, options = nil, html_options = {}, &block)
4
+ html_options[:type] ||= :default
5
+ html_options[:class] ||= ''
6
+ html_options[:class] << ' ' if html_options[:class].length > 1
7
+ html_options[:class] << "btn btn-#{html_options[:type]}"
8
+ link_to(name, options, html_options.except(:type), &block)
9
+ end
10
+
11
+ def button_primary_link_to(name = nil, options = nil, html_options = {}, &block)
12
+ html_options[:type] = :primary
13
+ button_link_to(name, options, html_options, &block)
14
+ end
15
+
16
+ def button_default_link_to(name = nil, options = nil, html_options = {}, &block)
17
+ html_options[:type] = :default
18
+ button_link_to(name, options, html_options, &block)
19
+ end
20
+
21
+ def button_danger_link_to(name = nil, options = nil, html_options = {}, &block)
22
+ html_options[:type] = :danger
23
+ button_link_to(name, options, html_options, &block)
24
+ end
25
+
26
+ def button_warning_link_to(name = nil, options = nil, html_options = {}, &block)
27
+ html_options[:type] = :warning
28
+ button_link_to(name, options, html_options, &block)
29
+ end
30
+
31
+ def button_success_link_to(name = nil, options = nil, html_options = {}, &block)
32
+ html_options[:type] = :success
33
+ button_link_to(name, options, html_options, &block)
34
+ end
35
+
36
+ def button_info_link_to(name = nil, options = nil, html_options = {}, &block)
37
+ html_options[:type] = :info
38
+ button_link_to(name, options, html_options, &block)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,42 @@
1
+ module Binco
2
+ module ModalHelper
3
+ def modal(id, &block)
4
+ content_tag :div, class: 'modal fade', tabindex: '-1', id: id do
5
+ content_tag :div, class: 'modal-dialog' do
6
+ content_tag :div, class: 'modal-content' do
7
+ yield
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ def modal_header(title = nil, &block)
14
+ content_tag :div, class: 'modal-header' do
15
+ close = content_tag :button, class: 'close' do
16
+ content_tag(:span, '&times;'.html_safe, data: { dismiss: 'modal' } )
17
+ end
18
+ if block_given?
19
+ title = yield
20
+ else
21
+ title = content_tag(:h4 , title, class: 'modal-title')
22
+ end
23
+
24
+ "#{close}#{title}".html_safe
25
+ end
26
+ end
27
+
28
+ def modal_body(options = {}, &block)
29
+ options[:class] ||= 'modal-body'
30
+ options[:class] << ' modal-body'
31
+ content_tag :div, options do
32
+ yield
33
+ end
34
+ end
35
+
36
+ def modal_footer(&block)
37
+ content_tag :div, class: 'modal-footer' do
38
+ yield
39
+ end
40
+ end
41
+ end
42
+ end