simple_form_extensions 1.0.0

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 (57) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +202 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/images/simple_form_extensions/append_1.png +0 -0
  5. data/app/assets/images/simple_form_extensions/append_2.png +0 -0
  6. data/app/assets/images/simple_form_extensions/prepend_1.png +0 -0
  7. data/app/assets/images/simple_form_extensions/prepend_2.png +0 -0
  8. data/app/assets/images/simple_form_extensions/prepend_append_1.png +0 -0
  9. data/app/assets/images/simple_form_extensions/prepend_append_2.png +0 -0
  10. data/app/assets/images/simple_form_extensions/prepend_append_3.png +0 -0
  11. data/app/assets/javascripts/simple_form_extensions/application.js +15 -0
  12. data/app/assets/stylesheets/simple_form_extensions/application.css +13 -0
  13. data/app/controllers/simple_form_extensions/application_controller.rb +4 -0
  14. data/app/helpers/simple_form_extensions/application_helper.rb +4 -0
  15. data/app/views/layouts/simple_form_extensions/application.html.erb +14 -0
  16. data/config/initializers/defaults.rb +6 -0
  17. data/config/initializers/simple_form/appends_component.rb +21 -0
  18. data/config/initializers/simple_form/prepends_component.rb +21 -0
  19. data/config/initializers/simple_form_bootstrap.rb +45 -0
  20. data/config/locales/en.yml +4 -0
  21. data/config/routes.rb +2 -0
  22. data/lib/simple_form_extensions/engine.rb +5 -0
  23. data/lib/simple_form_extensions/version.rb +3 -0
  24. data/lib/simple_form_extensions.rb +5 -0
  25. data/lib/tasks/simple_form_extensions_tasks.rake +4 -0
  26. data/test/dummy/README.rdoc +261 -0
  27. data/test/dummy/Rakefile +7 -0
  28. data/test/dummy/app/assets/javascripts/application.js +15 -0
  29. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  30. data/test/dummy/app/controllers/application_controller.rb +3 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  33. data/test/dummy/config/application.rb +59 -0
  34. data/test/dummy/config/boot.rb +10 -0
  35. data/test/dummy/config/database.yml +25 -0
  36. data/test/dummy/config/environment.rb +5 -0
  37. data/test/dummy/config/environments/development.rb +37 -0
  38. data/test/dummy/config/environments/production.rb +67 -0
  39. data/test/dummy/config/environments/test.rb +37 -0
  40. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/test/dummy/config/initializers/inflections.rb +15 -0
  42. data/test/dummy/config/initializers/mime_types.rb +5 -0
  43. data/test/dummy/config/initializers/secret_token.rb +7 -0
  44. data/test/dummy/config/initializers/session_store.rb +8 -0
  45. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/test/dummy/config/locales/en.yml +5 -0
  47. data/test/dummy/config/routes.rb +4 -0
  48. data/test/dummy/config.ru +4 -0
  49. data/test/dummy/public/404.html +26 -0
  50. data/test/dummy/public/422.html +26 -0
  51. data/test/dummy/public/500.html +25 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/dummy/script/rails +6 -0
  54. data/test/integration/navigation_test.rb +10 -0
  55. data/test/simple_form_extensions_test.rb +7 -0
  56. data/test/test_helper.rb +15 -0
  57. metadata +148 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
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,202 @@
1
+ # SimpleFormExtensions
2
+
3
+ SimpleFormExtensions are SimpleForm and Twitter Bootstrap integration.
4
+ This allow you to use input with append o prepend span.
5
+
6
+ ## Installation
7
+
8
+ Add the gem to your project's `Gemfile` as follows:
9
+
10
+ ```ruby
11
+ gem 'simple_form_extensions'
12
+ ```
13
+
14
+ Then install it by running:
15
+
16
+ ```bash
17
+ bundle install
18
+ ```
19
+
20
+ ## Getting Started
21
+
22
+ ### Appending
23
+
24
+ For `append` value into input:
25
+
26
+ ```
27
+ <%= simple_form_for @user, :html => { :class => 'form-horizontal' } do |f| %>
28
+ <%= f.input :percentage, wrapper: :e_append %>
29
+ <% end %>
30
+ ```
31
+
32
+ This generate the following markup:
33
+
34
+ ```
35
+ <form class="simple_form form-horizontal">
36
+ <div class="control-group">
37
+ <label class="control-label" for="user_percentage">Percentage</label>
38
+ <div class="controls">
39
+ <div class="input-append">
40
+ <input name="user[percentage]" type="text">
41
+ <span class="add-on">%</span>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ </form>
47
+ ```
48
+
49
+ And the result:
50
+
51
+ ![Append 1](https://bitbucket.org/mespina/simple_form_extensions/raw/master/app/assets/images/simple_form_extensions/append_1.png)
52
+
53
+
54
+ ### Prepending
55
+
56
+ For `prepend` value into input:
57
+
58
+ ```
59
+ <%= simple_form_for @user, :html => { :class => 'form-horizontal' } do |f| %>
60
+ <%= f.input :price, wrapper: :e_prepend %>
61
+ <% end %>
62
+ ```
63
+
64
+ This generate the following markup:
65
+
66
+ ```
67
+ <form class="simple_form form-horizontal">
68
+ <div class="control-group">
69
+ <label class="control-label" for="user_price">Price</label>
70
+ <div class="controls">
71
+ <div class="input-prepend">
72
+ <span class="add-on">$</span>
73
+ <input name="user[price]" type="text">
74
+ </div>
75
+ </div>
76
+ </div>
77
+ </div>
78
+ </form>
79
+ ```
80
+
81
+ And the result:
82
+
83
+ ![Prepend 1](https://bitbucket.org/mespina/simple_form_extensions/raw/master/app/assets/images/simple_form_extensions/prepend_1.png)
84
+
85
+
86
+ ### Prepending and Appending
87
+
88
+ For `append` and `prepend` values into input:
89
+
90
+ ```
91
+ <%= simple_form_for @user, :html => { :class => 'form-horizontal' } do |f| %>
92
+ <%= f.input :sample, wrapper: :e_prepend_append %>
93
+ <% end %>
94
+ ```
95
+
96
+ This generate the following markup:
97
+
98
+ ```
99
+ <form class="simple_form form-horizontal">
100
+ <div class="control-group">
101
+ <label class="control-label" for="user_sample">Sample</label>
102
+ <div class="controls">
103
+ <div class="input-prepend input-append">
104
+ <span class="add-on">$</span>
105
+ <input name="user[sample]" type="text">
106
+ <span class="add-on">%</span>
107
+ </div>
108
+ </div>
109
+ </div>
110
+ </div>
111
+ </form>
112
+ ```
113
+
114
+ And the result:
115
+
116
+ ![Prepending and Appending 1](https://bitbucket.org/mespina/simple_form_extensions/raw/master/app/assets/images/simple_form_extensions/prepend_append_1.png)
117
+
118
+
119
+ ### Customize
120
+
121
+ By default `append` and `prepend` have default values:
122
+
123
+
124
+ Value | Default
125
+ :--------|:-------:
126
+ append | %
127
+ prepend | $
128
+
129
+
130
+ You can change de default values, creating your locale:
131
+
132
+ ```YML
133
+ en:
134
+ simple_form_extensions:
135
+ default_prepend: YOUR_CUSTOM_DEFAULT_FOR_PREPEND_HERE
136
+ default_append: YOUR_CUSTOM_DEFAULT_FOR_APPEND_HERE
137
+ ```
138
+
139
+ Or you can change only one:
140
+
141
+ ```
142
+ <%= simple_form_for @user, :html => { :class => 'form-horizontal' } do |f| %>
143
+ <%= f.input :sample, wrapper: :e_prepend_append, prepend: '€', append: '.00' %>
144
+ <% end %>
145
+ ```
146
+
147
+ This generate the following markup:
148
+
149
+ ```
150
+ <form class="simple_form form-horizontal">
151
+ <div class="control-group">
152
+ <label class="control-label" for="user_sample">Sample</label>
153
+ <div class="controls">
154
+ <div class="input-prepend input-append">
155
+ <span class="add-on">€</span>
156
+ <input name="user[sample]" type="text">
157
+ <span class="add-on">.00</span>
158
+ </div>
159
+ </div>
160
+ </div>
161
+ </div>
162
+ </form>
163
+ ```
164
+
165
+ And the result:
166
+
167
+ ![Prepending and Appending 2](https://bitbucket.org/mespina/simple_form_extensions/raw/master/app/assets/images/simple_form_extensions/prepend_append_2.png)
168
+
169
+
170
+ Or you can try using icons:
171
+
172
+ ```
173
+ <%= simple_form_for @user, :html => { :class => 'form-horizontal' } do |f| %>
174
+ <%= f.input :sample, prepend: "<i class='icon-plus'></i>", append: "<i class='icon-minus'></i>" %>
175
+ <% end %>
176
+ ```
177
+
178
+ This generate the following markup:
179
+
180
+ ```
181
+ <form class="simple_form form-horizontal">
182
+ <div class="control-group">
183
+ <label class="control-label" for="user_sample">Sample</label>
184
+ <div class="controls">
185
+ <div class="input-prepend input-append">
186
+ <span class="add-on">
187
+ <i class="icon-plus"></i>
188
+ </span>
189
+ <input name="user[sample]" type="text">
190
+ <span class="add-on">
191
+ <i class="icon-minus"></i>
192
+ </span>
193
+ </div>
194
+ </div>
195
+ </div>
196
+ </div>
197
+ </form>
198
+ ```
199
+
200
+ And the result:
201
+
202
+ ![Prepending and Appending 3](https://bitbucket.org/mespina/simple_form_extensions/raw/master/app/assets/images/simple_form_extensions/prepend_append_3.png)
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'SimpleFormExtensions'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module SimpleFormExtensions
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleFormExtensions
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>SimpleFormExtensions</title>
5
+ <%= stylesheet_link_tag "simple_form_extensions/application", :media => "all" %>
6
+ <%= javascript_include_tag "simple_form_extensions/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,6 @@
1
+ # SimpleFormExtensions.setup do |config|
2
+
3
+ # config.default_prepend = "$"
4
+ # config.default_append = "%"
5
+
6
+ # end
@@ -0,0 +1,21 @@
1
+ module SimpleForm
2
+ module Components
3
+ # Needs to be enabled in order to do automatic lookups
4
+ module Appends
5
+ # Name of the component method
6
+ def append
7
+ @append ||= begin
8
+ default = I18n.t('simple_form_extensions.default_append').include?('translation missing:') ? '%' : I18n.t('simple_form_extensions.default_append')
9
+ options[:append].present? ? options[:append].to_s.html_safe : default
10
+ end
11
+ end
12
+
13
+ # Used when the append is optional
14
+ def has_append?
15
+ append.present?
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ SimpleForm::Inputs::Base.send(:include, SimpleForm::Components::Appends)
@@ -0,0 +1,21 @@
1
+ module SimpleForm
2
+ module Components
3
+ # Needs to be enabled in order to do automatic lookups
4
+ module Prepends
5
+ # Name of the component method
6
+ def prepend
7
+ @prepend ||= begin
8
+ default = I18n.t('simple_form_extensions.default_prepend').include?('translation missing:') ? '$' : I18n.t('simple_form_extensions.default_prepend')
9
+ options[:prepend].present? ? options[:prepend].to_s.html_safe : default
10
+ end
11
+ end
12
+
13
+ # Used when the prepend is optional
14
+ def has_prepend?
15
+ prepend.present?
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ SimpleForm::Inputs::Base.send(:include, SimpleForm::Components::Prepends)
@@ -0,0 +1,45 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ config.wrappers :e_prepend, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
4
+ b.use :html5
5
+ b.use :placeholder
6
+ b.use :label
7
+ b.wrapper :tag => 'div', :class => 'controls' do |input|
8
+ input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
9
+ prepend.use :prepend, :wrap_with => { :tag => 'span', :class => 'add-on'}
10
+ prepend.use :input
11
+ end
12
+ input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
13
+ input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
14
+ end
15
+ end
16
+
17
+ config.wrappers :e_append, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
18
+ b.use :html5
19
+ b.use :placeholder
20
+ b.use :label
21
+ b.wrapper :tag => 'div', :class => 'controls' do |input|
22
+ input.wrapper :tag => 'div', :class => 'input-append' do |prepend|
23
+ prepend.use :input
24
+ prepend.use :append, :wrap_with => { :tag => 'span', :class => 'add-on'}
25
+ end
26
+ input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
27
+ input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
28
+ end
29
+ end
30
+
31
+ config.wrappers :e_prepend_append, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
32
+ b.use :html5
33
+ b.use :placeholder
34
+ b.use :label
35
+ b.wrapper :tag => 'div', :class => 'controls' do |input|
36
+ input.wrapper :tag => 'div', :class => 'input-prepend input-append' do |prepend|
37
+ prepend.use :prepend, :wrap_with => { :tag => 'span', :class => 'add-on'}
38
+ prepend.use :input
39
+ prepend.use :append, :wrap_with => { :tag => 'span', :class => 'add-on'}
40
+ end
41
+ input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
42
+ input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ en:
2
+ simple_form_extensions:
3
+ default_prepend: '$'
4
+ default_append: '%'
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ SimpleFormExtensions::Engine.routes.draw do
2
+ end
@@ -0,0 +1,5 @@
1
+ module SimpleFormExtensions
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SimpleFormExtensions
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleFormExtensions
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "simple_form_extensions/engine"
2
+
3
+ module SimpleFormExtensions
4
+
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :simple_form_extensions do
3
+ # # Task goes here
4
+ # end