flexa_lib 0.1.21 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Gemfile +2 -0
  2. data/flexa_lib.gemspec +6 -3
  3. data/lib/action_view/helpers/text_field_date_helper.rb +166 -0
  4. data/lib/flexa_formtastic_bootstrap/engine.rb +4 -0
  5. data/lib/flexa_formtastic_bootstrap/form_builder.rb +38 -0
  6. data/lib/flexa_formtastic_bootstrap/helpers/buttons_helper.rb +52 -0
  7. data/lib/flexa_formtastic_bootstrap/helpers/fieldset_wrapper.rb +37 -0
  8. data/lib/flexa_formtastic_bootstrap/helpers/input_helper.rb +12 -0
  9. data/lib/flexa_formtastic_bootstrap/helpers/inputs_helper.rb +36 -0
  10. data/lib/flexa_formtastic_bootstrap/helpers.rb +19 -0
  11. data/lib/flexa_formtastic_bootstrap/inputs/base/choices.rb +49 -0
  12. data/lib/flexa_formtastic_bootstrap/inputs/base/errors.rb +48 -0
  13. data/lib/flexa_formtastic_bootstrap/inputs/base/hints.rb +27 -0
  14. data/lib/flexa_formtastic_bootstrap/inputs/base/html.rb +21 -0
  15. data/lib/flexa_formtastic_bootstrap/inputs/base/labelling.rb +18 -0
  16. data/lib/flexa_formtastic_bootstrap/inputs/base/stringish.rb +18 -0
  17. data/lib/flexa_formtastic_bootstrap/inputs/base/timeish.rb +35 -0
  18. data/lib/flexa_formtastic_bootstrap/inputs/base/wrapping.rb +67 -0
  19. data/lib/flexa_formtastic_bootstrap/inputs/base.rb +22 -0
  20. data/lib/flexa_formtastic_bootstrap/inputs/boolean_input.rb +33 -0
  21. data/lib/flexa_formtastic_bootstrap/inputs/check_boxes_input.rb +35 -0
  22. data/lib/flexa_formtastic_bootstrap/inputs/date_input.rb +16 -0
  23. data/lib/flexa_formtastic_bootstrap/inputs/datetime_input.rb +19 -0
  24. data/lib/flexa_formtastic_bootstrap/inputs/email_input.rb +15 -0
  25. data/lib/flexa_formtastic_bootstrap/inputs/file_input.rb +14 -0
  26. data/lib/flexa_formtastic_bootstrap/inputs/hidden_input.rb +12 -0
  27. data/lib/flexa_formtastic_bootstrap/inputs/number_input.rb +15 -0
  28. data/lib/flexa_formtastic_bootstrap/inputs/password_input.rb +15 -0
  29. data/lib/flexa_formtastic_bootstrap/inputs/phone_input.rb +15 -0
  30. data/lib/flexa_formtastic_bootstrap/inputs/radio_input.rb +32 -0
  31. data/lib/flexa_formtastic_bootstrap/inputs/range_input.rb +15 -0
  32. data/lib/flexa_formtastic_bootstrap/inputs/search_input.rb +15 -0
  33. data/lib/flexa_formtastic_bootstrap/inputs/select_input.rb +14 -0
  34. data/lib/flexa_formtastic_bootstrap/inputs/string_input.rb +15 -0
  35. data/lib/flexa_formtastic_bootstrap/inputs/text_input.rb +14 -0
  36. data/lib/flexa_formtastic_bootstrap/inputs/time_input.rb +16 -0
  37. data/lib/flexa_formtastic_bootstrap/inputs/time_zone_input.rb +14 -0
  38. data/lib/flexa_formtastic_bootstrap/inputs/url_input.rb +14 -0
  39. data/lib/flexa_formtastic_bootstrap/inputs.rb +29 -0
  40. data/lib/flexa_formtastic_bootstrap.rb +6 -0
  41. data/lib/flexa_lib/inputs/boolean_input.rb +37 -0
  42. data/lib/flexa_lib/inputs/lookup_input.rb +8 -16
  43. data/lib/flexa_lib/inputs.rb +1 -0
  44. data/lib/flexa_lib.rb +3 -3
  45. data/vendor/assets/javascripts/flexa-themejs.js +8 -3
  46. data/vendor/assets/stylesheets/flexa-theme.css.scss +5 -1
  47. metadata +50 -27
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in menu_builder.gemspec
4
4
  gemspec
5
+
6
+ gem 'formtastic'
data/flexa_lib.gemspec CHANGED
@@ -7,7 +7,7 @@ require 'flexa_lib/version'
7
7
  Gem::Specification.new do |s|
8
8
  s.name = 'flexa_lib'
9
9
  # s.version = FlexaLib::VERSION
10
- s.version = '0.1.21'
10
+ s.version = '0.2.0'
11
11
  s.platform = Gem::Platform::RUBY
12
12
 
13
13
  s.authors = ['Allan Freitas','Marcio Sfalsin']
@@ -18,6 +18,10 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.rubyforge_project = "flexa_lib"
20
20
 
21
+ # s.extra_rdoc_files = [
22
+ # "LICENSE.txt",
23
+ # "README.md"
24
+ # ]
21
25
  s.files = Dir["vendor/**/*.{scss,js,png,css,jpg,gif}"] + Dir.glob('lib/**/*.{rb,erb}')+ %w(LICENSE README.txt init.rb flexa_lib.gemspec Gemfile Rakefile) + Dir["docs/**/*.*"]
22
26
  # s.files = 'git ls-files'.split("\n")
23
27
  # s.test_files = 'git ls-files -- {test,spec,features}/*'.split("\n")
@@ -30,9 +34,8 @@ Gem::Specification.new do |s|
30
34
  #s.add_development_dependency("devise", ">= 1.5.3")
31
35
  #s.add_dependency 'thor', '~> 0.14'
32
36
  s.add_dependency 'formtastic', '>=2.0.2'
33
- s.add_dependency 'formtastic-bootstrap', '>=1.2.0'
34
37
  s.add_dependency 'table_for_collection', '>=1.0.6'
35
38
  s.add_dependency 'will_paginate', '>=3.0.2'
36
39
  s.add_dependency 'will_paginate_twitter_bootstrap', '>=1.0.0'
37
40
 
38
- end
41
+ end
@@ -0,0 +1,166 @@
1
+ require 'action_view/helpers/form_tag_helper'
2
+
3
+ module ActionView
4
+ module Helpers
5
+
6
+ module TextFieldDateHelper
7
+
8
+ # These two handle an object with a method that returns a Date or Time object.
9
+ def date_text_field(object_name, method, options = {}, html_options = {})
10
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_date_text_field_tag(options, html_options)
11
+ end
12
+
13
+ def time_text_field(object_name, method, options = {}, html_options = {})
14
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_time_text_field_tag(options, html_options)
15
+ end
16
+
17
+ # These two handle Date and Time objects.
18
+ def text_field_date(date = Date.current, options = {}, html_options = {})
19
+ DateTimeSelector.new(date, options, html_options).text_field_date
20
+ end
21
+
22
+ def text_field_time(time = Time.current, options = {}, html_options = {})
23
+ DateTimeSelector.new(time, options, html_options).text_field_time
24
+ end
25
+ end
26
+
27
+ class DateTimeSelector
28
+
29
+ include ActionView::Helpers::FormTagHelper
30
+
31
+ def text_field_date
32
+ order = date_order.dup
33
+
34
+ @options[:discard_hour] = true
35
+ @options[:discard_minute] = true
36
+ @options[:discard_second] = true
37
+
38
+ @options[:discard_year] ||= true unless order.include?(:year)
39
+ @options[:discard_month] ||= true unless order.include?(:month)
40
+ @options[:discard_day] ||= true if @options[:discard_month] || !order.include?(:day)
41
+
42
+ # Save this so we can restore it.
43
+ original_datetime_separator_separator = @options[:datetime_separator]
44
+ original_date_separator = @options[:date_separator]
45
+
46
+ @options[:datetime_separator] = ""
47
+ @options[:date_separator] = " "
48
+
49
+ # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are
50
+ # valid (otherwise it could be 31 and February wouldn't be a valid date)
51
+ if @datetime && @options[:discard_day] && !@options[:discard_month]
52
+ @datetime = @datetime.change(:day => 1)
53
+ end
54
+
55
+ [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) }
56
+
57
+ build_text_field_from_types(order).tap do
58
+ # Restore.
59
+ @options[:datetime_separator] = original_datetime_separator_separator
60
+ @options[:date_separator] = original_date_separator
61
+ end
62
+ end
63
+
64
+ def text_field_time
65
+ order = []
66
+
67
+ @options[:discard_month] = true
68
+ @options[:discard_year] = true
69
+ @options[:discard_day] = true
70
+ @options[:discard_second] ||= true unless @options[:include_seconds]
71
+
72
+ # Save this so we can restore it.
73
+ original_datetime_separator = @options[:datetime_separator]
74
+ original_time_separator = @options[:time_separator]
75
+ original_date_separator = @options[:date_separator]
76
+
77
+ @options[:datetime_separator] = ''
78
+ @options[:time_separator] = ':'
79
+ @options[:date_separator] = " "
80
+
81
+ order += [:year, :month, :day] unless @options[:ignore_date]
82
+
83
+ order += [:hour, :minute]
84
+ order << :second if @options[:include_seconds]
85
+
86
+ build_text_field_from_types(order).tap do
87
+ # Restore.
88
+ @options[:datetime_separator] = original_datetime_separator
89
+ @options[:date_separator] = original_date_separator
90
+ @options[:time_separator] = original_time_separator
91
+ end
92
+ end
93
+
94
+ def text_field_second
95
+ unless @options[:use_hidden] || @options[:discard_second]
96
+ build_text(:second, sec)
97
+ end
98
+ end
99
+
100
+ def text_field_minute
101
+ unless @options[:use_hidden] || @options[:discard_minute]
102
+ build_text(:minute, min)
103
+ end
104
+ end
105
+
106
+ def text_field_hour
107
+ unless @options[:use_hidden] || @options[:discard_hour]
108
+ build_text(:hour, hour, :ampm => @options[:ampm])
109
+ end
110
+ end
111
+
112
+ def text_field_day
113
+ unless @options[:use_hidden] || @options[:discard_day]
114
+ build_text(:day, day, :leading_zeros => false)
115
+ end
116
+ end
117
+
118
+ def text_field_month
119
+ unless @options[:use_hidden] || @options[:discard_month]
120
+ build_text(:month, month.nil? ? "" : month_name(month), :leading_zeros => false)
121
+ end
122
+ end
123
+
124
+ def text_field_year
125
+ unless @options[:use_hidden] || @options[:discard_year]
126
+ build_text(:year, year, :leading_zeros => false)
127
+ end
128
+ end
129
+
130
+ def build_text_field_from_types(order)
131
+ input = ''
132
+ order.reverse.each do |type|
133
+ separator = separator(type) unless type == order.first # don't add on last field
134
+ input.insert(0, separator.to_s + send("text_field_#{type}").to_s)
135
+ end
136
+ text_field_tag("", input.html_safe, @html_options).html_safe
137
+ end
138
+
139
+ def build_text(selected, value, options = {})
140
+ unless value.nil?
141
+ options.reverse_merge!({:leading_zeros => true, :ampm => false})
142
+ leading_zeros = options.delete(:leading_zeros)
143
+ value = leading_zeros ? sprintf("%02d", value) : value
144
+ text = options[:ampm] ? AMPM_TRANSLATION[value] : value
145
+ else
146
+ ""
147
+ end
148
+ end
149
+
150
+ end
151
+
152
+ class InstanceTag #:nodoc:
153
+ def to_date_text_field_tag(options = {}, html_options = {})
154
+ datetime_selector(options, html_options).text_field_date.html_safe
155
+ end
156
+
157
+ def to_time_text_field_tag(options = {}, html_options = {})
158
+ datetime_selector(options, html_options).text_field_time.html_safe
159
+ end
160
+ end
161
+
162
+ autoload :TextFieldDateHelper
163
+ include TextFieldDateHelper
164
+
165
+ end
166
+ end
@@ -0,0 +1,4 @@
1
+ module FlexaFormtasticBootstrap
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,38 @@
1
+ module FlexaFormtasticBootstrap
2
+
3
+ class FormBuilder < Formtastic::FormBuilder
4
+
5
+ configure :default_inline_error_class, 'help-inline'
6
+ configure :default_block_error_class, 'help-block'
7
+ configure :default_inline_hint_class, 'help-inline'
8
+ configure :default_block_hint_class, 'help-block'
9
+
10
+ def self.default_error_class
11
+ # self.default_inline_error_class
12
+ raise
13
+ end
14
+
15
+ def self.default_error_class=(error_class)
16
+ # self.default_inline_error_class = error_class
17
+ # self.default_block_error_class = error_class
18
+ raise
19
+ end
20
+
21
+ def self.default_hint_class
22
+ # self.default_inline_hint_class
23
+ raise
24
+ end
25
+
26
+ def self.default_hint_class=(hint_class)
27
+ # self.default_inline_hint_class = hint_class
28
+ # self.default_block_hint_class = hint_class
29
+ raise
30
+ end
31
+
32
+ include FlexaFormtasticBootstrap::Helpers::InputHelper
33
+ include FlexaFormtasticBootstrap::Helpers::InputsHelper
34
+ include FlexaFormtasticBootstrap::Helpers::ButtonsHelper
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,52 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Helpers
3
+ module ButtonsHelper
4
+
5
+ include Formtastic::Helpers::ButtonsHelper
6
+
7
+ def buttons(*args, &block)
8
+
9
+ html_options = args.extract_options!
10
+ html_options[:class] ||= "actions"
11
+
12
+ if html_options.has_key?(:name)
13
+ ActiveSupport::Deprecation.warn('The :name option is not supported')
14
+ end
15
+
16
+ if block_given?
17
+ template.content_tag(:div, html_options) do
18
+ yield
19
+ end
20
+ else
21
+ args = [:commit] if args.empty?
22
+ contents = args.map { |button_name| send(:"#{button_name}_button") }
23
+ template.content_tag(:div, html_options.except(:builder, :parent, :name)) do
24
+ Formtastic::Util.html_safe(contents.join)
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ def commit_button(*args)
31
+ options = args.extract_options!
32
+ text = options.delete(:label) || args.shift
33
+
34
+ text = (localized_string(commit_button_i18n_key, text, :action, :model => commit_button_object_name) ||
35
+ Formtastic::I18n.t(commit_button_i18n_key, :model => commit_button_object_name)) unless text.is_a?(::String)
36
+
37
+ button_html = options.delete(:button_html) || {}
38
+ button_html.merge!(:class => [button_html[:class], "btn commit", commit_button_i18n_key].compact.join(' '))
39
+
40
+ # TODO We don't have a wrapper. Add deprecation message.
41
+ # wrapper_html = options.delete(:wrapper_html) || {}
42
+ # wrapper_html[:class] = (commit_button_wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')
43
+
44
+ accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
45
+ button_html = button_html.merge(:accesskey => accesskey) if accesskey
46
+
47
+ Formtastic::Util.html_safe(submit(text, button_html))
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,37 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Helpers
3
+ module FieldsetWrapper
4
+
5
+ include Formtastic::Helpers::FieldsetWrapper
6
+
7
+ protected
8
+
9
+ def field_set_and_list_wrapping(*args, &block) #:nodoc:
10
+ contents = args.last.is_a?(::Hash) ? '' : args.pop.flatten
11
+ html_options = args.extract_options!
12
+
13
+ legend = (html_options[:name] || '').to_s
14
+ legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
15
+ legend = template.content_tag(:legend, Formtastic::Util.html_safe(legend)) unless legend.blank?
16
+
17
+ if block_given?
18
+ contents = if template.respond_to?(:is_haml?) && template.is_haml?
19
+ template.capture_haml(&block)
20
+ else
21
+ template.capture(&block)
22
+ end
23
+ end
24
+
25
+ # Ruby 1.9: String#to_s behavior changed, need to make an explicit join.
26
+ contents = contents.join if contents.respond_to?(:join)
27
+ fieldset = template.content_tag(:fieldset,
28
+ Formtastic::Util.html_safe(legend) << Formtastic::Util.html_safe(contents),
29
+ html_options.except(:builder, :parent, :name)
30
+ )
31
+
32
+ fieldset
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Helpers
3
+ module InputHelper
4
+ include Formtastic::Helpers::InputHelper
5
+
6
+ def standard_input_class_name(as)
7
+ "FlexaFormtasticBootstrap::Inputs::#{as.to_s.camelize}Input"
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Helpers
3
+ module InputsHelper
4
+ include FlexaFormtasticBootstrap::Helpers::FieldsetWrapper
5
+
6
+ def inputs(*args, &block)
7
+ wrap_it = @already_in_an_inputs_block ? true : false
8
+ @already_in_an_inputs_block = true
9
+
10
+ title = field_set_title_from_args(*args)
11
+ html_options = args.extract_options!
12
+ html_options[:class] ||= "inputs"
13
+ html_options[:name] = title
14
+
15
+ out = begin
16
+ if html_options[:for] # Nested form
17
+ inputs_for_nested_attributes(*(args << html_options), &block)
18
+ elsif block_given?
19
+ field_set_and_list_wrapping(*(args << html_options), &block)
20
+ else
21
+ legend = args.shift if args.first.is_a?(::String)
22
+ args = default_columns_for_object if @object && args.empty?
23
+ contents = fieldset_contents_from_column_list(args)
24
+ args.unshift(legend) if legend.present?
25
+ field_set_and_list_wrapping(*((args << html_options) << contents))
26
+ end
27
+ end
28
+
29
+ # out = template.content_tag(:li, out, :class => "input") if wrap_it
30
+ @already_in_an_inputs_block = false
31
+ out
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ require "flexa_formtastic_bootstrap/helpers/buttons_helper"
2
+ require "flexa_formtastic_bootstrap/helpers/fieldset_wrapper"
3
+ require "flexa_formtastic_bootstrap/helpers/input_helper"
4
+ require "flexa_formtastic_bootstrap/helpers/inputs_helper"
5
+
6
+ module FlexaFormtasticBootstrap
7
+ module Helpers
8
+ # autoload :ErrorsHelper, 'formtastic/helpers/errors_helper'
9
+ # autoload :FieldsetWrapper, 'formtastic/helpers/fieldset_wrapper'
10
+ # autoload :FileColumnDetection, 'formtastic/helpers/file_column_detection'
11
+ # autoload :FormHelper, 'formtastic/helpers/form_helper'
12
+ # autoload :InputHelper, 'formtastic/helpers/input_helper'
13
+ # autoload :InputsHelper, 'formtastic/helpers/inputs_helper'
14
+ # autoload :LabelHelper, 'formtastic/helpers/label_helper'
15
+ # autoload :SemanticFormHelper, 'formtastic/helpers/semantic_form_helper'
16
+ # autoload :Reflection, 'formtastic/helpers/reflection'
17
+ end
18
+ end
19
+
@@ -0,0 +1,49 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Inputs
3
+ module Base
4
+ module Choices
5
+
6
+ def input_div_wrapping(&block)
7
+ template.content_tag(:div, choices_wrapping_html_options) do
8
+ [yield, error_html(:block), hint_html(:block)].join("\n").html_safe
9
+ end
10
+ end
11
+
12
+ def choices_wrapping_html_options
13
+ # TODO Call the Formtastic one explicity and append?
14
+ { :class => "choices input" }
15
+ end
16
+
17
+ def choices_group_wrapping(&block)
18
+ template.content_tag(:ul,
19
+ template.capture(&block),
20
+ choices_group_wrapping_html_options
21
+ )
22
+ end
23
+
24
+ def choices_group_wrapping_html_options
25
+ { :class => "choices-group inputs-list" }
26
+ end
27
+
28
+ def choice_label(choice)
29
+ "\n".html_safe + template.content_tag(:span) do
30
+ # (choice.is_a?(Array) ? choice.first : choice).to_s
31
+ (choice.is_a?(Array) ? choice.first : choice).to_s
32
+ end
33
+ end
34
+
35
+ # This is actually a label in Bootstrap.
36
+ def legend_html
37
+ template.content_tag(:label, label_html_options) do
38
+ render_label? ? label_text : "".html_safe
39
+ end
40
+ end
41
+
42
+ def label_html_options
43
+ super.merge(:for => nil)
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Inputs
3
+ module Base
4
+ module Errors
5
+
6
+ include Formtastic::Inputs::Base::Errors
7
+
8
+ def error_html(inline_or_block = :inline)
9
+ errors? ? send(:"error_#{builder.inline_errors}_html", inline_or_block) : ""
10
+ end
11
+
12
+ def error_sentence_html(inline_or_block)
13
+ error_class = if inline_or_block == :inline
14
+ options[:error_class] || builder.default_inline_error_class
15
+ else
16
+ options[:error_class] || builder.default_block_error_class
17
+ end
18
+ template.content_tag(:span, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => error_class)
19
+ end
20
+
21
+ def error_list_html(ignore)
22
+ super()
23
+ # error_class = options[:error_class] || builder.default_error_list_class
24
+ # list_elements = []
25
+ # errors.each do |error|
26
+ # list_elements << template.content_tag(:li, Formtastic::Util.html_safe(error.html_safe))
27
+ # end
28
+ # template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => error_class)
29
+ end
30
+
31
+ def error_first_html(inline_or_block = :inline)
32
+ error_class = if inline_or_block == :inline
33
+ options[:error_class] || builder.default_inline_error_class
34
+ else
35
+ options[:error_class] || builder.default_block_error_class
36
+ end
37
+ template.content_tag(:span, Formtastic::Util.html_safe(errors.first.untaint), :class => error_class)
38
+ end
39
+
40
+ def error_none_html(ignore)
41
+ # super
42
+ ""
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,27 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Inputs
3
+ module Base
4
+ module Hints
5
+
6
+ include Formtastic::Inputs::Base::Hints
7
+
8
+ def hint_html(inline_or_block = :inline)
9
+ if hint?
10
+ hint_class = if inline_or_block == :inline
11
+ options[:hint_class] || builder.default_inline_hint_class
12
+ else
13
+ options[:hint_class] || builder.default_block_hint_class
14
+ end
15
+ template.content_tag(
16
+ :span,
17
+ Formtastic::Util.html_safe(hint_text),
18
+ :class => hint_class
19
+ )
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,21 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Inputs
3
+ module Base
4
+ module Html
5
+
6
+ include Formtastic::Inputs::Base::Html
7
+
8
+ def input_html_options
9
+ if errors?
10
+ {
11
+ :class => "error"
12
+ }.merge(super)
13
+ else
14
+ super
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Inputs
3
+ module Base
4
+ module Labelling
5
+
6
+ include Formtastic::Inputs::Base::Labelling
7
+
8
+ def label_html_options
9
+ {}.tap do |opts|
10
+ opts[:for] ||= input_html_options[:id]
11
+ opts[:class] = [opts[:class]]
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # Alas, I need to duplicate code from Formtastic::Inputs::Base::Stringish because
2
+ # there's no way to re-import that module.
3
+ module FlexaFormtasticBootstrap
4
+ module Inputs
5
+ module Base
6
+ module Stringish
7
+
8
+ include Formtastic::Inputs::Base::Stringish
9
+
10
+ def wrapper_html_options
11
+ new_class = [super[:class], "stringish"].compact.join(" ")
12
+ super.merge(:class => new_class)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ module FlexaFormtasticBootstrap
2
+ module Inputs
3
+ module Base
4
+ module Timeish
5
+
6
+ def label_html
7
+ # TODO Supress the "for" field?
8
+ template.content_tag(:label, label_html_options) do
9
+ render_label? ? label_text : "".html_safe
10
+ end
11
+ end
12
+
13
+ def date_input_html
14
+ fragment_input_html(:date, "small")
15
+ end
16
+
17
+ def time_input_html
18
+ fragment_input_html(:time, "mini")
19
+ end
20
+
21
+ def fragment_id(fragment)
22
+ # TODO is this right?
23
+ # "#{input_html_options[:id]}_#{position(fragment)}i"
24
+ "#{input_html_options[:id]}[#{fragment}]"
25
+ end
26
+
27
+ def fragment_input_html(fragment, klass)
28
+ opts = input_options.merge(:prefix => object_name, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
29
+ template.send(:"text_field_#{fragment}", value, opts, input_html_options.merge(:id => fragment_id(fragment), :class => klass))
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end