unirer-bootstrap 0.5 → 0.6

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: 85a7458765d13a7a18f26fca404886e0bbb9a162
4
- data.tar.gz: 4113b9046bbb58de8a6e48ae56f9b0d6e8a154e5
3
+ metadata.gz: 36f6418daa098ae465f381f81bf9061ebe41d660
4
+ data.tar.gz: cf2ed59e2d63d933d63c0ec817cf9d0618f0dacc
5
5
  SHA512:
6
- metadata.gz: 73868f62cc918b995b59d5421198134c900642b9e083de58288ed7473de04926ad7a8862a911740b79c3473185a12e0eae2f4e360610ddd41a6b6a8d642e0317
7
- data.tar.gz: 8564970a1ead7da3579d5f7a7618035842ee70a090a96106f2228c82cd0326376a4a2b872ccd04fcec7b83da97fe3b7798ba0ac865a3c23f0d16dac9cb300269
6
+ metadata.gz: eb46ff94979670eab77a38d3e4e5cf252a4732d4a55e8206e3936cba83ae8ed6d9594df9c703206cb3018b3759e64d5e1d5f85cedb29f05d144d84b1a234f6af
7
+ data.tar.gz: 94b133fc0091f8d61fa212493d5651beb4fd5454ffd9375cae4e1aa2f925d7222cceb28217b215c775dd64318216cde8ff39bef4f7d93e2bb01c7166753f2509
data/README.md CHANGED
@@ -11,6 +11,15 @@ Unirer (统一资源表现)是一系列的资源表现引擎。Bootstrap 资源
11
11
  gem 'unirer-bootstrap'
12
12
  ```
13
13
 
14
+
15
+
16
+ ## Include the Helper in your Application Controller before Render the Style or Script
17
+ ```ruby
18
+ helper ::Unirer::Bootstrap::ApplicationHelper
19
+ ```
20
+
21
+
22
+
14
23
  ## Render the Pre-defined Partials
15
24
  ```erb
16
25
  <%= render partial: 'unirer/bootstrap/meta' %>
@@ -19,6 +28,8 @@ gem 'unirer-bootstrap'
19
28
  <%= render partial: 'unirer/bootstrap/form_field', locals: { options: { model: model, form: f, name: :phone_number, type: :telephone_field } } %>
20
29
  ```
21
30
 
31
+
32
+
22
33
  ### Render the Meta
23
34
  The Meta partial includes the HTML meta tags for Bootstrap.
24
35
  ```erb
@@ -35,6 +46,8 @@ The source codes of the Meta partial:
35
46
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
36
47
  ```
37
48
 
49
+
50
+
38
51
  ### Render the Script
39
52
  The Script partial includes the HTML script tags for jQuery, Bootstrap, and React. All the CDN servers of the JavaScript libraries are optimized for China only. The following code snippet does not load React JS.
40
53
  ```erb
@@ -48,22 +61,30 @@ The following code snippet loads the latest React JS.
48
61
 
49
62
  The following code snippet loads the React JS with the given version.
50
63
  ```erb
51
- <%= render partial: 'unirer/bootstrap/script', locals: { options: { react: { version: '0.14.6' } } } %>
64
+ <%= render partial: 'unirer/bootstrap/script', locals: { options: { :jquery => { version: '2.2.0' }, :'moment-with-locales' => true, :'bootstrap-datetimepicker' => true, :react => { version: '0.14.6' } } } %>
52
65
  ```
66
+ The following JavaScript libraries are always enabled, only the version can be configurable:
67
+ - :jquery
68
+ - :bootstrap
69
+ The following JavaScript libraries are switchable, and the version can be configurable:
70
+ - :'moment-with-locales'
71
+ - :'bootstrap-datetimepicker'
72
+ - :react
73
+
74
+
53
75
 
54
76
  ### Render the Style
55
77
  The Style partial includes the HTML style tags for Bootstrap and Font Awesome. All the CDN servers of the CSS libraries are optimized for China only.
56
78
  ```erb
57
- <%= render partial: 'unirer/bootstrap/style' %>
79
+ <%= render partial: 'unirer/bootstrap/style', locals: { options: { :'font-awesome' => { version: '4.4.0' }, :'bootstrap-datetimepicker' => true } } %>
58
80
  ```
81
+ The following CSS libraries are always enabled, only the version can be configurable:
82
+ - :bootstrap
83
+ The following JavaScript libraries are switchable, and the version can be configurable:
84
+ - :'font-awesome'
85
+ - :'bootstrap-datetimepicker'
59
86
 
60
- The source codes of the Style partial:
61
- ```html
62
- <%= stylesheet_link_tag '//cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css', media: 'all' %>
63
- <%= stylesheet_link_tag '//cdn.bootcss.com/font-awesome/4.5.0/css/font-awesome.min.css', media: 'all' %>
64
87
 
65
- <%= stylesheet_link_tag '//cdn.bootcss.com/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css', media: 'all' %>
66
- ```
67
88
 
68
89
  ### Render the Form Field
69
90
  The Form Field partial includes the HTML form field tags for Rails Form Builder and Bootstrap.
@@ -74,8 +95,10 @@ The Form Field partial includes the HTML form field tags for Rails Form Builder
74
95
  The 4 options are required: model, form, name, and type.
75
96
  Here are more options:
76
97
  - label: the customized label text.
77
- - label_class: the CSS class for the label tag.
78
- - field_class: the CSS class for the wrapper of the form control.
79
- - error_class: the CSS class for the validation error block of this field.
98
+ - group_class: The CSS class for the form group wrapper. The .form-group class is mandatory, and can not be removed.
99
+ - label_class: the CSS class for the label tag. The .control-label class is mandatory, and can not be removed.
100
+ - field_class: the CSS class for the wrapper of the form control. The .input-group class is mandatory, and can not be removed.
101
+ - error_class: the CSS class for the validation error block of this field. The .text-danger class is mandatory, and can not be removed.
102
+ - error_hidden: Determines whether the error message block should be shown if the field has any error.
80
103
  - prefix: the HTML source codes of input group addon before the form control.
81
104
  - suffix: the HTML source codes of input group addon after the form control.
@@ -1,2 +1,11 @@
1
1
  module Unirer::Bootstrap::ApplicationHelper
2
+
3
+ def library_enabled?(name, options)
4
+ defined?(options) && options.try(:[], name).present?
5
+ end
6
+
7
+ def library_version(name, default_version, options)
8
+ defined?(options) ? options.try(:[], name).try(:[], :version)||default_version : default_version
9
+ end
10
+
2
11
  end
@@ -27,6 +27,8 @@
27
27
  maxlength: options[:maxlength],
28
28
  required: options[:required]
29
29
  }
30
+
31
+ error_hidden = options[:error_hidden]
30
32
  %>
31
33
 
32
34
  <div class='<%= group_class %>'>
@@ -49,7 +51,7 @@
49
51
  <% end %>
50
52
  </div>
51
53
 
52
- <% if model.errors[name].present? %>
54
+ <% if model.errors[name].present? && !error_hidden %>
53
55
  <p class='<%= error_class %>'><%= model.errors[name].first %></p>
54
56
  <% end %>
55
57
 
@@ -1,16 +1,11 @@
1
- <%= javascript_include_tag '//cdn.bootcss.com/jquery/2.2.1/jquery.min.js' %>
2
- <%= javascript_include_tag '//cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js' %>
1
+ <% options = defined?(options) ? options : nil %>
2
+ <%= javascript_include_tag "//cdn.bootcss.com/jquery/#{library_version(:jquery, '2.2.1', options)}/jquery.min.js" %>
3
+ <%= javascript_include_tag "//cdn.bootcss.com/bootstrap/#{library_version(:bootstrap, '3.3.6', options)}/js/bootstrap.min.js" %>
3
4
 
4
- <%= javascript_include_tag '//cdn.bootcss.com/moment.js/2.11.1/moment-with-locales.min.js' %>
5
- <%= javascript_include_tag '//cdn.bootcss.com/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js' %>
5
+ <%= javascript_include_tag "//cdn.bootcss.com/moment.js/#{library_version(:'moment-with-locales', '2.11.1', options)}/moment-with-locales.min.js" if library_enabled?(:'moment-with-locales', options) %>
6
+ <%= javascript_include_tag "//cdn.bootcss.com/bootstrap-datetimepicker/#{library_version(:'bootstrap-datetimepicker', '4.17.37', options)}/js/bootstrap-datetimepicker.min.js" if library_enabled?(:'bootstrap-datetimepicker', options) %>
6
7
 
7
- <% if defined?(options) && options.try(:[], :react).present? %>
8
- <% react_version = options[:react].try(:[], :version) %>
9
- <% if react_version.present? %>
10
- <%= javascript_include_tag "//cdn.bootcss.com/react/#{react_version}/react.min.js" %>
11
- <%= javascript_include_tag "//cdn.bootcss.com/react/#{react_version}/react-dom.min.js" %>
12
- <% else %>
13
- <%= javascript_include_tag '//cdn.bootcss.com/react/0.14.7/react.min.js' %>
14
- <%= javascript_include_tag '//cdn.bootcss.com/react/0.14.7/react-dom.min.js' %>
15
- <% end %>
8
+ <% if library_enabled?(:react, options) %>
9
+ <%= javascript_include_tag "//cdn.bootcss.com/react/#{library_version(:react, '0.14.7', options)}/react.min.js" %>
10
+ <%= javascript_include_tag "//cdn.bootcss.com/react/#{library_version(:react, '0.14.7', options)}/react-dom.min.js" %>
16
11
  <% end %>
@@ -1,4 +1,5 @@
1
- <%= stylesheet_link_tag '//cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css', media: 'all' %>
2
- <%= stylesheet_link_tag '//cdn.bootcss.com/font-awesome/4.5.0/css/font-awesome.min.css', media: 'all' %>
1
+ <% options = defined?(options) ? options : nil %>
2
+ <%= stylesheet_link_tag "//cdn.bootcss.com/bootstrap/#{library_version :bootstrap, '3.3.6', options}/css/bootstrap.min.css", media: 'all' %>
3
+ <%= stylesheet_link_tag "//cdn.bootcss.com/font-awesome/#{library_version(:'font-awesome', '4.5.0', options)}/css/font-awesome.min.css", media: 'all' if library_enabled?(:'font-awesome', options) %>
3
4
 
4
- <%= stylesheet_link_tag '//cdn.bootcss.com/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css', media: 'all' %>
5
+ <%= stylesheet_link_tag "//cdn.bootcss.com/bootstrap-datetimepicker/#{library_version(:'bootstrap-datetimepicker', '4.17.37', options)}/css/bootstrap-datetimepicker.min.css", media: 'all' if library_enabled?(:'bootstrap-datetimepicker', options) %>
@@ -1,5 +1,5 @@
1
1
  module Unirer
2
2
  module Bootstrap
3
- VERSION = '0.5'.freeze
3
+ VERSION = '0.6'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unirer-bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails