bootstrap_builder 0.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.
@@ -0,0 +1,14 @@
1
+ .control-group{:class => ('error' if error_messages.present?)}
2
+
3
+ = builder.label(method, label_text, :class => 'control-label')
4
+ .controls
5
+ - if defined?(values)
6
+ - values.each do |value|
7
+ %label.checkbox #{value[:field]} #{value[:label_text]}
8
+ - else
9
+ %label.checkbox
10
+ = field
11
+ = help_block if help_block.present?
12
+
13
+ - if error_messages.present?
14
+ %span.help-inline= error_messages
@@ -0,0 +1,33 @@
1
+ - if builder.options[:html] && builder.options[:html][:class] =~ /form-horizontal/
2
+ .control-group{:class => ('error' if error_messages.present?)}
3
+ = builder.label(method, label_text, :class => 'control-label')
4
+ .controls
5
+ - if prepend.present?
6
+ .input-prepend
7
+ %span.add-on= prepend
8
+ = field
9
+ - elsif append.present?
10
+ .input-append
11
+ = field
12
+ %span.add-on= append
13
+ - else
14
+ = field
15
+
16
+
17
+ - if error_messages.present?
18
+ %span.help-inline= error_messages
19
+
20
+ - if help_block.present?
21
+ %p.help-block= help_block
22
+
23
+ - else
24
+ - if label_text.present?
25
+ = builder.label(method, label_text, :class => 'control-label')
26
+ = field
27
+
28
+ - if error_messages.present?
29
+ %span.help-inline= error_messages
30
+
31
+ - if help_block.present?
32
+ %p.help-block= help_block
33
+
@@ -0,0 +1,24 @@
1
+ .clearfix{:class => ('error' if error_messages.present?)}
2
+
3
+ %label
4
+ = label_text
5
+ - if required
6
+ %span.required *
7
+
8
+ .input
9
+ %ul.inputs-list
10
+ - choices.each do |choice|
11
+ %li
12
+ %label{:for => choice[:label_for]}
13
+ = choice[:field]
14
+ %span= choice[:label]
15
+
16
+
17
+
18
+ - if description.present?
19
+ %span.help-block= description
20
+
21
+ - if error_messages.present?
22
+ %span.help-inline= error_messages
23
+
24
+
@@ -0,0 +1,9 @@
1
+ - case builder.options[:html][:class]
2
+ - when /form-search/
3
+ = field
4
+ = after_text
5
+ - else
6
+ .form-actions
7
+ = field
8
+ = after_text
9
+
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "bootstrap_builder"
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jack Neto", "The Working Group Inc."]
12
+ s.date = "2012-02-05"
13
+ s.description = ""
14
+ s.email = "jack@twg.ca"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".DS_Store",
21
+ "LICENSE.txt",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "app/.DS_Store",
26
+ "app/assets/images/glyphicons-halflings-white.png",
27
+ "app/assets/images/glyphicons-halflings.png",
28
+ "app/assets/javascripts/bootstrap.js",
29
+ "app/assets/javascripts/formatted_form.js",
30
+ "app/assets/stylesheets/bootstrap-responsive.css",
31
+ "app/assets/stylesheets/bootstrap.css",
32
+ "app/views/bootstrap_builder/_check_box.html.haml",
33
+ "app/views/bootstrap_builder/_default_field.html.haml",
34
+ "app/views/bootstrap_builder/_radio_button.html.haml",
35
+ "app/views/bootstrap_builder/_submit.html.haml",
36
+ "bootstrap_builder.gemspec",
37
+ "lib/bootstrap_builder.rb",
38
+ "lib/bootstrap_builder/.DS_Store",
39
+ "lib/bootstrap_builder/builder.rb",
40
+ "lib/bootstrap_builder/configuration.rb",
41
+ "lib/bootstrap_builder/engine.rb",
42
+ "lib/bootstrap_builder/helper.rb",
43
+ "lib/bootstrap_builder/railtie.rb",
44
+ "rails-bootstrap-builder.gemspec",
45
+ "vendor/.DS_Store"
46
+ ]
47
+ s.homepage = "http://github.com/twg/bootstrap_builder"
48
+ s.licenses = ["MIT"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = "1.8.15"
51
+ s.summary = "A Rails form builder that generates Twitter Bootstrap markup"
52
+
53
+ if s.respond_to? :specification_version then
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ else
58
+ end
59
+ else
60
+ end
61
+ end
62
+
Binary file
@@ -0,0 +1,168 @@
1
+ module BootstrapBuilder
2
+ class Builder < ActionView::Helpers::FormBuilder
3
+
4
+ %w(text_field password_field text_area file_field datetime_select date_select time_zone_select).each do |field_name|
5
+ define_method field_name do |method, *args|
6
+ options = args.detect { |a| a.is_a?(Hash) } || {}
7
+ render_field(field_name, method, options) { super(method, options) }
8
+ end
9
+ end
10
+
11
+ def select(method, choices, options = {}, html_options = {})
12
+ render_field('select', method, options) { super(method, choices, options, html_options) }
13
+ end
14
+
15
+ def hidden_field(method, options = {}, html_options = {})
16
+ super(method, options)
17
+ end
18
+
19
+ def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
20
+ if options[:values].present?
21
+ values = options[:values].collect do |key, val|
22
+
23
+ {
24
+ :field => super(method, options.merge({:name => "#{object_name}[#{method}][]"}), val, nil),
25
+ :label_text => key,
26
+ :label_for => "#{object_name}_#{method}_#{val.to_s.gsub(' ', '_').underscore}"
27
+ }
28
+ end
29
+ @template.render(:partial => "#{BootstrapBuilder.config.template_folder}/check_box", :locals => {
30
+ :builder => self,
31
+ :method => method,
32
+ :values => values,
33
+ :label_text => label_text(method, options.delete(:label)),
34
+ :error_messages => error_messages_for(method)
35
+ })
36
+ else
37
+ render_field('check_box', method, options) do
38
+ super(method, options, checked_value, unchecked_value)
39
+ end
40
+ end
41
+ end
42
+
43
+ def radio_button(method, tag_value, options = {})
44
+ case tag_value
45
+ when Array
46
+ choices = tag_value.collect do |choice|
47
+ if !choice.is_a?(Array)
48
+ choice = [choice, choice]
49
+ elsif choice.length == 1
50
+ choice << choice[0]
51
+ end
52
+ {
53
+ :field => super(method, choice[1], options),
54
+ :label => choice[0],
55
+ :label_for => "#{object_name}_#{method}_#{choice[1].to_s.gsub(' ', '_').underscore}"
56
+ }
57
+ end
58
+ else
59
+ choices = [{
60
+ :field => super(method, tag_value),
61
+ :label => tag_value,
62
+ :label_for => "#{object_name}_#{method}_#{tag_value.to_s.gsub(' ', '_').underscore}"
63
+ }]
64
+ end
65
+
66
+ @template.render(:partial => "#{BootstrapBuilder.config.template_folder}/radio_button", :locals => {
67
+ :builder => self,
68
+ :method => method,
69
+ :label_text => label_text(method, options.delete(:label)),
70
+ :choices => choices,
71
+ :required => options.delete(:required),
72
+ :before_text => @template.raw(options.delete(:before_text)),
73
+ :after_text => @template.raw(options.delete(:after_text)),
74
+ :help_block => @template.raw(options.delete(:help_block)),
75
+ :error_messages => error_messages_for(method)
76
+ })
77
+ end
78
+
79
+ # f.submit 'Log In', :change_to_text => 'Logging you in ...'
80
+ def submit(value, options={}, &block)
81
+ after_text = @template.capture(&block) if block_given?
82
+
83
+ # Add specific bootstrap class
84
+ options[:class] ||= ''
85
+ options[:class] += ' btn'
86
+ unless options[:class] =~ /btn-/
87
+ options[:class] += ' btn-primary'
88
+ end
89
+
90
+ # Set the script to change the text
91
+ if change_to_text = options.delete(:change_to_text)
92
+ options[:onclick] ||= ''
93
+ options[:onclick] = "$(this).closest('.actions').hide();$(this).closest('.actions').after($('<div class=actions>#{change_to_text}</div>'))"
94
+ end
95
+
96
+ @template.render(:partial => "#{BootstrapBuilder.config.template_folder}/submit", :locals => {
97
+ :builder => self,
98
+ :field => super(value, options),
99
+ :after_text => after_text,
100
+ :change_to_text => change_to_text
101
+ })
102
+ end
103
+
104
+ # generic container for all things form
105
+ def element(label = '&nbsp;', value = '', type = 'text_field', &block)
106
+ value += @template.capture(&block) if block_given?
107
+ %{
108
+ <div class='form_element #{type}'>
109
+ <div class='label'>
110
+ #{label}
111
+ </div>
112
+ <div class='value'>
113
+ #{value}
114
+ </div>
115
+ </div>
116
+ }.html_safe
117
+ end
118
+
119
+ def error_messages
120
+ if object && !object.errors.empty?
121
+ message = object.errors[:base].present? ? object.errors[:base]: 'There were some problems submitting this form. Please correct all the highlighted fields and try again'
122
+ @template.content_tag(:div, message, :class => 'form_error')
123
+ end
124
+ end
125
+
126
+ def error_messages_for(method)
127
+ if (object and object.respond_to?(:errors) and errors = object.errors[method] and !errors.empty?)
128
+ errors.is_a?(Array) ? errors.first : errors
129
+ end
130
+ end
131
+
132
+ def fields_for(record_or_name_or_array, *args, &block)
133
+ options = args.extract_options!
134
+ options.merge!(:builder => BootstrapBuilder::Builder)
135
+ super(record_or_name_or_array, *(args << options), &block)
136
+ end
137
+
138
+
139
+ protected
140
+
141
+ # Main rendering method
142
+ def render_field(field_name, method, options={}, &block)
143
+ case field_name
144
+ when 'check_box'
145
+ template = field_name
146
+ else
147
+ template = 'default_field'
148
+ end
149
+ @template.render(:partial => "#{BootstrapBuilder.config.template_folder}/#{template}", :locals => {
150
+ :builder => self,
151
+ :method => method,
152
+ :field_name => field_name,
153
+ :field => @template.capture(&block),
154
+ :label_text => label_text(method, options.delete(:label)),
155
+ :required => options.delete(:required),
156
+ :prepend => @template.raw(options.delete(:prepend)),
157
+ :append => @template.raw(options.delete(:append)),
158
+ :help_block => @template.raw(options.delete(:help_block)),
159
+ :error_messages => error_messages_for(method)
160
+ })
161
+ end
162
+
163
+ def label_text(method, text = nil)
164
+ text.nil? ? method.to_s.titleize.capitalize : @template.raw(text)
165
+ end
166
+
167
+ end
168
+ end
@@ -0,0 +1,17 @@
1
+ module BootstrapBuilder
2
+ class Configuration
3
+
4
+ # The templates folder
5
+ attr_accessor :template_folder
6
+
7
+ # The templates folder
8
+ attr_accessor :default_form_class
9
+
10
+ # Configuration defaults
11
+ def initialize
12
+ @template_folder = :bootstrap_builder
13
+ @default_form_class = 'form-horizontal'
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ require "bootstrap_builder"
2
+ require "rails"
3
+
4
+ module BootstrapBuilder
5
+ class Engine < Rails::Engine
6
+
7
+ initializer 'helper' do |app|
8
+ ActionView::Base.send(:include, BootstrapBuilder::Helper)
9
+
10
+ # Remove field_with_errors div around elements with errors
11
+ ActionView::Base.field_error_proc = proc { |input, instance| input }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module BootstrapBuilder::Helper
2
+
3
+ def bootstrap_form_for(record_or_name_or_array, *args, &proc)
4
+ options = args.extract_options!
5
+ options.merge!(:builder => BootstrapBuilder::Builder)
6
+ options[:html] ||= {:class => ''}
7
+ if !(options[:html][:class] =~ /form-/)
8
+ options[:html][:class] += ' ' + BootstrapBuilder.config.default_form_class
9
+ end
10
+ form_for(record_or_name_or_array, *(args << options), &proc)
11
+ end
12
+
13
+ end
@@ -0,0 +1,12 @@
1
+ # Configure Rails 3.0 to use public/javascripts/jquery et al
2
+ module Jquery
3
+ module Rails
4
+
5
+ class Railtie < ::Rails::Railtie
6
+ config.before_configuration do
7
+ config.action_view.javascript_expansions[:defaults] |= ['bootstrap']
8
+ end
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ require 'bootstrap_builder/engine'
2
+ require 'bootstrap_builder/builder'
3
+ require 'bootstrap_builder/helper'
4
+ require 'bootstrap_builder/configuration'
5
+
6
+ module BootstrapBuilder
7
+ class << self
8
+
9
+ def configure
10
+ yield configuration
11
+ end
12
+
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+ alias :config :configuration
17
+
18
+ end
19
+ end
20
+
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rails-bootstrap-builder"
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jack Neto", "The Working Group Inc."]
12
+ s.date = "2012-02-04"
13
+ s.description = ""
14
+ s.email = "jack@twg.ca"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ "LICENSE.txt",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "app/.DS_Store",
25
+ "app/views/bootstrap_builder/_check_box.html.haml",
26
+ "app/views/bootstrap_builder/_default_field.html.haml",
27
+ "app/views/bootstrap_builder/_radio_button.html.haml",
28
+ "app/views/bootstrap_builder/_submit.html.haml",
29
+ "lib/bootstrap_builder.rb",
30
+ "lib/bootstrap_builder/.DS_Store",
31
+ "lib/bootstrap_builder/builder.rb",
32
+ "lib/bootstrap_builder/configuration.rb",
33
+ "lib/bootstrap_builder/engine.rb",
34
+ "lib/bootstrap_builder/helper.rb",
35
+ "vendor/.DS_Store"
36
+ ]
37
+ s.homepage = "http://github.com/twg/rails-bootstrap-builder"
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = "1.8.15"
41
+ s.summary = "A Rails form builder to the generates Twitter Bootstrap markup"
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ else
48
+ end
49
+ else
50
+ end
51
+ end
52
+
data/vendor/.DS_Store ADDED
Binary file
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jack Neto
9
+ - The Working Group Inc.
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-02-05 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: ''
16
+ email: jack@twg.ca
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ files:
23
+ - .DS_Store
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - VERSION
28
+ - app/.DS_Store
29
+ - app/assets/images/glyphicons-halflings-white.png
30
+ - app/assets/images/glyphicons-halflings.png
31
+ - app/assets/javascripts/bootstrap.js
32
+ - app/assets/javascripts/formatted_form.js
33
+ - app/assets/stylesheets/bootstrap-responsive.css
34
+ - app/assets/stylesheets/bootstrap.css
35
+ - app/views/bootstrap_builder/_check_box.html.haml
36
+ - app/views/bootstrap_builder/_default_field.html.haml
37
+ - app/views/bootstrap_builder/_radio_button.html.haml
38
+ - app/views/bootstrap_builder/_submit.html.haml
39
+ - bootstrap_builder.gemspec
40
+ - lib/bootstrap_builder.rb
41
+ - lib/bootstrap_builder/.DS_Store
42
+ - lib/bootstrap_builder/builder.rb
43
+ - lib/bootstrap_builder/configuration.rb
44
+ - lib/bootstrap_builder/engine.rb
45
+ - lib/bootstrap_builder/helper.rb
46
+ - lib/bootstrap_builder/railtie.rb
47
+ - rails-bootstrap-builder.gemspec
48
+ - vendor/.DS_Store
49
+ homepage: http://github.com/twg/bootstrap_builder
50
+ licenses:
51
+ - MIT
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.15
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: A Rails form builder that generates Twitter Bootstrap markup
74
+ test_files: []