bootstraps_bootstraps 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ..gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Robert L. Carpenter
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.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ ##Bootstraps_bootstraps
2
+
3
+ [Bootstrap 2.0](http://twitter.github.com/bootstrap/) is Twitter's CSS and Javascript framework. It is a great baseline for starting web applications. As a CSS/Javascript framework it does a great job of providing a baseline styleset and group of user interface components given that you play within its garden.
4
+
5
+ [Rails 3](http://rubyonrails.org/) is an open source web framework that does a lot to make web application development easy, secure, and quick.
6
+
7
+ To get the best experience out of both worlds Rails needs a bit of bootstrapping to get a form builder that plays nice with Bootstrap. This gem provides the bootstraps that Bootstrap needs to make Rails+Bootstrap a potent combination.
8
+
9
+ ##Current Features
10
+
11
+ An extended form_for called `bootstrap_form` with all the classic functionality yet extended to provide correct Bootstrap 2 syntax for horizontal forms (classed with .form_horizontal) for most elements.
12
+
13
+ ##Development Strategy
14
+
15
+ This isn't compatible with Bootstrap versions < 2.
16
+
17
+ More or less I'm writing this library as needed. Each time I find myself trying to do something with form_for or interact between Rails and Bootstrap I find a way to make them play nice together without losing baseline Rails functionality.
18
+
19
+ Things that I know aren't in the library yet:
20
+
21
+ - Collection methods (select box, check boxes, radio buttons)
22
+ - Check boxes in general
23
+ - Full implementation of an optional attribute to make bootstrapped_form silence and revert to the default for a specific form field
24
+ - `.form-vertical`, `.form-search`, and `.form-inline` specific html syntax
25
+
26
+ ##Use
27
+
28
+ Add this to your gemfile: `gem 'bootstraps_bootstraps', git: 'git@github.com:robacarp/bootstraps_bootstraps.git'`
29
+
30
+ To use the Bootstrap 2 form helper in your views:
31
+
32
+ ```ruby
33
+ = bootstrapped_form @user do |f|
34
+ = f.text_field :first_name
35
+ = f.text_field :last_name
36
+ = f.collection_select :occupations, Occupation.all, :id, :name, :label => 'Job'
37
+ = f.text_field :address, :label => "Address Line 1"
38
+ = f.text_field :address2, :label => "Line 2"
39
+ = f.submit ("Shipping Options &rarr;").html_safe, :class=>'fright'
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
49
+ 6. :-)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Robert L. Carpenter"]
6
+ gem.email = ["codemonkey@robacarp.com"]
7
+ gem.description = %q{A gem to make working with Bootstrap 2.0 in Rails 3 easier and better. Includes a new bootstrapped_form replacement for form_for which wgives error text handling and html formatting to match Bootstrap's syntax.}
8
+ gem.summary = %q{Bootstrap 2.0 html helpers for Rails 3}
9
+ gem.homepage = "https://github.com/robacarp/bootstraps_bootstraps"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "bootstraps_bootstraps"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = BootstrapsBootstraps::VERSION
17
+ end
@@ -0,0 +1,7 @@
1
+ require 'version.rb'
2
+
3
+ module BootstrapsBootstraps
4
+ require 'bootstraps_bootstraps/bootstrap_form_builder.rb'
5
+ require 'bootstraps_bootstraps/bootstrap_form_helper.rb'
6
+ require 'bootstraps_bootstraps/railtie'
7
+ end
@@ -0,0 +1,86 @@
1
+ module BootstrapsBootstraps
2
+ class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
3
+
4
+ delegate :capture, :content_tag, :tag, to: :@template
5
+
6
+ #
7
+ # This method started out as a gist somewhere but I can't seem to find the
8
+ # original. At any rate its been modified over time to make it not break
9
+ # and to update it to make it compatible with Bootstrap2.
10
+ #
11
+ # If I'm being brutally honest its a bit of a cluster of metaprogramming
12
+ # and it can be pretty difficult to understand. BUT it does seem to work
13
+ # so far.
14
+ #
15
+ %w[text_field text_area password_field collection_select].each do |method_name|
16
+ define_method(method_name) do |name, *args|
17
+ options = args.extract_options!
18
+
19
+ if options[:vanilla]
20
+ return super(name, *(args.push(options)))
21
+ end
22
+
23
+ errors = object.errors[name].any? ? 'error' : ''
24
+ error_msg = object.errors[name].any? ? content_tag(:span, object.errors[name].join(","), class: 'help-inline') : ''
25
+
26
+ help_text = options[:help_text].blank? ? '' : content_tag(:span,options[:help_text], class: 'help-block')
27
+ label = options[:label] == '' ? ''.html_safe : field_label(name, options)
28
+
29
+ if options[:large] || method_name == 'text_area'
30
+ options[:class] = [options[:class]] || []
31
+ options[:class].push 'xxlarge'
32
+ end
33
+
34
+ content_tag :div, class: "control-group #{errors}" do
35
+ label + content_tag(:div, class: "controls #{errors}") do
36
+ super(name, *(args.push(options))) + ' ' + error_msg
37
+ end + help_text
38
+ end
39
+ end
40
+ end
41
+
42
+ #TODO update for bootstrap 2
43
+ def check_box(name, *args)
44
+ content_tag :div, class:"clearfix" do
45
+ content_tag(:div, class:"input") do
46
+ content_tag(:ul, class:"inputs-list") do
47
+ content_tag(:li) do
48
+ content_tag(:label) do
49
+ super(name, *args) + content_tag(:span) do
50
+ field_label(name, *args)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def submit *args
60
+ options = args.extract_options!
61
+ args = args.push options
62
+
63
+ if options[:vanilla]
64
+ super *args
65
+ else
66
+ content_tag :div, class: 'form-actions' do
67
+ super *args
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ private
74
+
75
+ def field_label(name, *args)
76
+ options = args.extract_options!
77
+ required = object.class.validators_on(name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator}
78
+ label(name, options[:label], class: ("required" if required))
79
+ end
80
+
81
+ def objectify_options(options)
82
+ super.except(:label)
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,9 @@
1
+ module BootstrapsBootstraps
2
+ module BootstrapFormHelper
3
+ #merely setup the form_for to use our new form builder
4
+ def bootstrapped_form object, options={}, &block
5
+ options[:builder] = BootstrapFormBuilder
6
+ form_for object, options, &block
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module BootstrapsBootstraps
2
+ class Railtie < Rails::Railtie
3
+ initializer "bootstraps_bootstraps.configure_rails_initialization" do |application|
4
+ # Prevent Rails from wrapping form elements with errors in <div class="field_with_error">
5
+ # boxes. Bootstrap has a bit of a different paradigm.
6
+ # Credit where due: http://stackoverflow.com/questions/5267998/rails-3-field-with-errors-wrapper-changes-the-page-appearance-how-to-avoid-t
7
+ application.config.action_view.field_error_proc = Proc.new { |html_tag, instance| html_tag }
8
+ end
9
+
10
+ config.to_prepare do
11
+ ::ActionView::Helpers.send(:include, BootstrapsBootstraps::BootstrapFormHelper)
12
+ end
13
+ end
14
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module BootstrapsBootstraps
2
+ VERSION = "0.0.1"
3
+ end
data/railtie.rb ADDED
@@ -0,0 +1,10 @@
1
+ module BootstrapsBootstraps
2
+ class Railtie < Rails::Railtie
3
+ initializer "bootstraps_bootstraps.configure_rails_initialization" do |application|
4
+ #Disable the Rails default field_with_errors div wrapper.
5
+ application.config.action_view.field_error_proc = Proc.new { |html_tag, instance| html_tag }
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'bootstraps_bootstraps' if defined?(Rails)
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstraps_bootstraps
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Robert L. Carpenter
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-02-06 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A gem to make working with Bootstrap 2.0 in Rails 3 easier and better. Includes a new bootstrapped_form replacement for form_for which wgives error text handling and html formatting to match Bootstrap's syntax.
22
+ email:
23
+ - codemonkey@robacarp.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - LICENSE
34
+ - README.md
35
+ - Rakefile
36
+ - bootstraps_bootstraps.gemspec
37
+ - lib/bootstraps_bootstraps.rb
38
+ - lib/bootstraps_bootstraps/bootstrap_form_builder.rb
39
+ - lib/bootstraps_bootstraps/bootstrap_form_helper.rb
40
+ - lib/bootstraps_bootstraps/railtie.rb
41
+ - lib/version.rb
42
+ - railtie.rb
43
+ has_rdoc: true
44
+ homepage: https://github.com/robacarp/bootstraps_bootstraps
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.6
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Bootstrap 2.0 html helpers for Rails 3
73
+ test_files: []
74
+