bs_form_builder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a6271a8504387db5be8a92def627b903f139a42
4
+ data.tar.gz: a09ebbad9c570964607874f4625c2a8755d0e4ea
5
+ SHA512:
6
+ metadata.gz: 7dc7b8c5a73a898a2aa793e7272000cc531be5023b2ddb14eda5246546adf1db971fc2a4b15552c8d7c17cecd1b097609e394d3470d0138b4f65a049e79241ea
7
+ data.tar.gz: afa560258a3b6e116e568b123d0b52576b2aeae805f975c4b3c32c3004310d73d4120864337980052188388b9e14f8b8dd5758885007c56a6fe79171b380caa4
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bootstrap_form_builder.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sean Geoghegan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # BootstrapFormBuilder
2
+
3
+ Rails Form Builders for bootstrap style forms.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bootstrap_form_builder'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bootstrap_form_builder
18
+
19
+ ## Usage
20
+
21
+ Currently only supports [horizontal forms](http://getbootstrap.com/css/#forms-horizontal).
22
+
23
+ To use, pass the builder class into the ``form_for`` method in a Rails form and set the
24
+ ``form-horizontal`` class on the form element:
25
+
26
+ ```
27
+ <%= form_for(resource,
28
+ :builder => BootstrapFormBuilder::HorizontalFormBuilder,
29
+ :html => { :class => 'form-horizontal' }) do |f| %>
30
+ ```
31
+
32
+ Then calling the usual form field methods will generate labels
33
+ and form elements confirming to the Bootstrap markup. If there
34
+ are errors on the object these will also be output using Bootstrap
35
+ [Validation States](http://getbootstrap.com/css/#forms-control-validation).
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/[my-github-username]/bootstrap_form_builder/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bootstrap_form_builder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bs_form_builder"
8
+ spec.version = BootstrapFormBuilder::VERSION
9
+ spec.authors = ["Sean Geoghegan"]
10
+ spec.email = ["sean@tushare.com"]
11
+ spec.summary = %q{A Rails form builder for bootstrap style forms.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'actionview'
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "bootstrap_form_builder/version"
2
+
3
+ module BootstrapFormBuilder
4
+ require 'bootstrap_form_builder/horizontal_form_builder'
5
+ end
@@ -0,0 +1,139 @@
1
+ # A form build that adheres to Bootstrap horizontal form conventions.
2
+ #
3
+ class BootstrapFormBuilder::HorizontalFormBuilder < ActionView::Helpers::FormBuilder
4
+ def email_field(name, opts = {})
5
+ form_group(name) do
6
+ super(name, opts.reverse_merge(:class => 'form-control',
7
+ :placeholder => help(name)))
8
+ end
9
+ end
10
+
11
+ def text_field(name, opts = {})
12
+ form_group(name) do
13
+ super(name, opts.reverse_merge(:class => 'form-control',
14
+ :placeholder => help(name)))
15
+ end
16
+ end
17
+
18
+ def password_field(name, opts = {})
19
+ form_group(name) do
20
+ super(name, opts.reverse_merge(:class => 'form-control',
21
+ :placeholder => help(name)))
22
+ end
23
+ end
24
+
25
+ def date_field(name, opts = {})
26
+ form_group(name) do
27
+ super(name, opts.reverse_merge(:class => 'form-control',
28
+ :placeholder => help(name)))
29
+ end
30
+ end
31
+
32
+ def number_field(name, opts = {})
33
+ form_group(name) do
34
+ super(name, opts.reverse_merge(:class => 'form-control',
35
+ :placeholder => help(name)))
36
+ end
37
+ end
38
+
39
+ def check_box(name, opts = {})
40
+ form_group(name) do
41
+ super(name, opts.reverse_merge(:class => 'form-control',
42
+ :placeholder => help(name)))
43
+ end
44
+ end
45
+
46
+ def radio_button_group(name, button_options, opts = {})
47
+ form_group(name) do
48
+ buttons = button_options.map do |button|
49
+ label(name, :value => button, :class => 'btn btn-default') do
50
+ radio_button(name, button) +
51
+ I18n.t("#{object_name}.#{name}_options.#{button}",
52
+ :scope => "helpers.label")
53
+ end
54
+ end.join("\n").html_safe
55
+
56
+ @template.content_tag(:div,
57
+ buttons,
58
+ :class => 'btn-group',
59
+ :data => { :toggle => 'buttons' })
60
+ end
61
+ end
62
+
63
+ def select(name, choices, options = {}, html_options = {})
64
+ form_group(name) do
65
+ super(name, choices, options, html_options.reverse_merge(:class => 'form-control'))
66
+ end
67
+ end
68
+
69
+ def text_area(name, opts = {})
70
+ form_group(name) do
71
+ super(name, opts.reverse_merge(:class => 'form-control',
72
+ :placeholder => help(name)))
73
+ end
74
+ end
75
+
76
+ def form_group(name, &block)
77
+ classes = ['form-group']
78
+
79
+ if @object.errors.has_key?(name)
80
+ classes << 'has-error'
81
+ end
82
+
83
+ @template.content_tag(:div,
84
+ label(name) +
85
+ col_wrap(block.call + errors(name)),
86
+ :class => classes.join(' '))
87
+ end
88
+
89
+ def col_wrap(html)
90
+ @template.content_tag(:div, html, :class => 'col-sm-7')
91
+ end
92
+
93
+ def label(name, opts = {})
94
+ super(name, opts.reverse_merge(:class => 'col-sm-3 control-label'))
95
+ end
96
+
97
+ def errors(name)
98
+ if @object.errors.has_key?(name)
99
+ errors = @object.errors.full_messages_for(name).join('. ')
100
+ @template.content_tag(:span, errors, :class => 'help-text text-danger')
101
+ else
102
+ ''
103
+ end
104
+ end
105
+
106
+ def help(name)
107
+ i18n_name = "helpers.hints.#{object_name}.#{name}"
108
+ if I18n.exists?(i18n_name)
109
+ I18n.t(i18n_name)
110
+ else
111
+ nil
112
+ end
113
+ end
114
+
115
+ def cancel_button(cancel_path)
116
+ @template.link_to(I18n.t('helpers.button.cancel'),
117
+ cancel_path,
118
+ :class => 'btn btn-default')
119
+ end
120
+
121
+ def submit_button(label = "")
122
+ @template.content_tag(:div,
123
+ @template.
124
+ content_tag(:div,
125
+ submit(label, :class => 'btn btn-primary'),
126
+ :class => 'col-sm-offset-3 col-sm-7'),
127
+ :class => 'form-group')
128
+ end
129
+
130
+ def submit_and_cancel(cancel_path)
131
+ @template.content_tag(:div,
132
+ @template.
133
+ content_tag(:div,
134
+ submit(:class => 'btn btn-primary') +
135
+ " " + cancel_button(cancel_path),
136
+ :class => 'col-sm-offset-3 col-sm-7'),
137
+ :class => 'form-group')
138
+ end
139
+ end
@@ -0,0 +1,3 @@
1
+ module BootstrapFormBuilder
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bs_form_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Geoghegan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - sean@tushare.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bootstrap_form_builder.gemspec
68
+ - lib/bootstrap_form_builder.rb
69
+ - lib/bootstrap_form_builder/horizontal_form_builder.rb
70
+ - lib/bootstrap_form_builder/version.rb
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A Rails form builder for bootstrap style forms.
95
+ test_files: []