bootstrap-forms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bootstrap-forms.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "bootstrap-forms"
6
+ s.version = "0.0.1"
7
+ s.author = "Seth Vargo"
8
+ s.email = "sethvargo@gmail.com"
9
+ s.homepage = "https://github.com/sethvargo/bootstrap_forms"
10
+ s.summary = %q{Bootstrap Forms makes Twitter's Bootstrap on Rails easy!}
11
+ s.description = %q{Bootstrap Forms makes Twitter's Bootstrap on Rails easy to use by creating helpful form builders that minimize markup in your views.}
12
+
13
+ s.rubyforge_project = "bootstrap-forms"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # specify any dependencies here; for example:
21
+ # s.add_development_dependency "rspec"
22
+ # s.add_runtime_dependency "rest-client"
23
+ end
@@ -0,0 +1,3 @@
1
+ module BootstrapForms
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,2 @@
1
+ Description:
2
+ The bootstrap_forms generator copies the form builder into `app/form_builders` and the initializer in `config/initializers`.
@@ -0,0 +1,10 @@
1
+ module BootstrapForms
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def generate_insall
6
+ copy_file 'bootstrap_form_builder.rb', 'app/form_builders/bootstrap_form_builder.rb'
7
+ copy_file 'bootstrap_forms.rb', 'config/initializers/bootstrap_forms.rb'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,143 @@
1
+ class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
2
+ delegate :content_tag, :hidden_field_tag, :check_box_tag, :radio_button_tag, :link_to, :to => :@template
3
+
4
+ %w(select check_box email_field file_field number_field password_field phone_field radio_button range_field search_field telephone_field text_area text_field url_field).each do |method_name|
5
+ define_method(method_name) do |name, *args|
6
+ @name = name
7
+ @options = args.extract_options!
8
+ @args = args
9
+
10
+ clearfix_div do
11
+ label_field + input_div do
12
+ extras {super}
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ def collection_check_boxes(attribute, records, record_id, record_name, *args)
19
+ @name = attribute
20
+ @options = args.extract_options!
21
+ @args = args
22
+
23
+ clearfix_div do
24
+ label_field + input_div do
25
+ extras do
26
+ content_tag(:ul, :class => 'inputs-list') do
27
+ records.collect do |record|
28
+ element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}"
29
+ checkbox = check_box_tag("#{object_name}[#{attribute}][]", record.send(record_id), object.send(attribute).include?(record.send(record_id)), :id => element_id)
30
+
31
+ content_tag(:li) do
32
+ content_tag(:label) do
33
+ checkbox + content_tag(:span, record.send(record_name))
34
+ end
35
+ end
36
+ end.join('').html_safe
37
+ end
38
+ end
39
+ end + hidden_field_tag("#{object_name}[#{attribute}][]")
40
+ end
41
+ end
42
+
43
+ def collection_radio_buttons(attribute, records, record_id, record_name, *args)
44
+ @name = attribute
45
+ @options = args.extract_options!
46
+ @args = args
47
+
48
+ clearfix_div do
49
+ label_field + input_div do
50
+ extras do
51
+ content_tag(:ul, :class => 'inputs-list') do
52
+ records.collect do |record|
53
+ element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}"
54
+ radiobutton = radio_button_tag("#{object_name}[#{attribute}][]", record.send(record_id), object.send(attribute) == record.send(record_id), :id => element_id)
55
+
56
+ content_tag(:li) do
57
+ content_tag(:label) do
58
+ radiobutton + content_tag(:span, record.send(record_name))
59
+ end
60
+ end
61
+ end.join('').html_safe
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ def uneditable_field(name, *args)
69
+ @name = name
70
+ @options = args.extract_options!
71
+ @args = args
72
+
73
+ clearfix_div do
74
+ label_field + input_div do
75
+ extras do
76
+ content_tag(:span, :class => 'uneditable-input') do
77
+ @options[:value] || object.send(@name.to_sym)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def submit(name = nil, *args)
85
+ @name = name
86
+ @options = args.extract_options!
87
+ @args = args
88
+
89
+ @options[:class] = 'btn primary'
90
+
91
+ content_tag(:div, :class => 'actions') do
92
+ super(name, *args << @options) +
93
+ link_to('Back', :back, :class => 'btn')
94
+ end
95
+ end
96
+
97
+ private
98
+ def clearfix_div(&block)
99
+ klasses = ['clearfix']
100
+ klasses << @options[:class] if @options[:class]
101
+ klasses << 'error' if @options[:error]
102
+ klasses << 'success' if @options[:success]
103
+ klasses << 'warning' if @options[:warning]
104
+ klass = klasses.join(' ')
105
+
106
+ content_tag(:div, :class => klass, &block)
107
+ end
108
+
109
+ def input_div(&block)
110
+ content_tag(:div, :class => 'input') do
111
+ if @options[:append] || @options[:prepend]
112
+ klass = 'input-prepend' if @options[:prepend]
113
+ klass = 'input-append' if @options[:append]
114
+ content_tag(:div, :class => klass, &block)
115
+ else
116
+ yield if block_given?
117
+ end
118
+ end
119
+ end
120
+
121
+ def label_field(&block)
122
+ required = object.class.validators_on(@name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
123
+ label(@name, block_given? ? block : @options[:label], :class => ('required' if required))
124
+ end
125
+
126
+ %w(help_inline error success warning help_block append prepend).each do |method_name|
127
+ define_method(method_name) do |*args|
128
+ return '' unless value = @options[method_name.to_sym]
129
+ klass = 'help-inline'
130
+ klass = 'help-block' if method_name == 'help_block'
131
+ klass = 'add-on' if method_name == 'append' || method_name == 'prepend'
132
+ content_tag(:span, value, :class => klass)
133
+ end
134
+ end
135
+
136
+ def extras(&block)
137
+ [prepend, (yield if block_given?), append, help_inline, error, success, warning, help_block].join('').html_safe
138
+ end
139
+
140
+ def objectify_options(options)
141
+ super.except(:label, :help_inline, :error, :success, :warning, :help_block, :prepend, :append)
142
+ end
143
+ end
@@ -0,0 +1,18 @@
1
+ module ActionView
2
+ module Helpers
3
+ module FormHelper
4
+ def form_for_with_bootstrap(record, options = {}, &proc)
5
+ options[:builder] = BootstrapFormBuilder
6
+ form_for_without_bootstrap(record, options, &proc)
7
+ end
8
+
9
+ def fields_for_with_bootstrap(record_name, record_object = nil, options = {}, &block)
10
+ options[:builder] = BootstrapFormBuilder
11
+ fields_for_without_bootstrap(record_name, record_object, options, &block)
12
+ end
13
+
14
+ alias_method_chain :form_for, :bootstrap
15
+ alias_method_chain :fields_for, :bootstrap
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap-forms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Seth Vargo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-31 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Bootstrap Forms makes Twitter's Bootstrap on Rails easy to use by creating
15
+ helpful form builders that minimize markup in your views.
16
+ email: sethvargo@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - bootstrap_forms.gemspec
25
+ - lib/bootstrap_forms.rb
26
+ - lib/generators/bootstrap_forms/install/USAGE
27
+ - lib/generators/bootstrap_forms/install/install_generator.rb
28
+ - lib/generators/bootstrap_forms/install/templates/bootstrap_form_builder.rb
29
+ - lib/generators/bootstrap_forms/install/templates/bootstrap_forms.rb
30
+ homepage: https://github.com/sethvargo/bootstrap_forms
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project: bootstrap-forms
50
+ rubygems_version: 1.8.10
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Bootstrap Forms makes Twitter's Bootstrap on Rails easy!
54
+ test_files: []
55
+ has_rdoc: