formtastic 1.2.2 → 1.2.3.beta

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.
@@ -135,6 +135,7 @@ The difference is subtle, with most blocks in Rails 3 requiring the addition of
135
135
  ...
136
136
  <% end %>
137
137
  <% end %>
138
+ </pre>
138
139
 
139
140
  This README is currently documenting the Rails 2 way only. If you're using Rails 3 and your forms aren't rendering everything as expected, try changing @<%@ to @<%=@.
140
141
 
@@ -649,20 +650,13 @@ We currently support both Rails 2 and Rails 3, under Ruby 1.8.7-ish (and 1.9.2-i
649
650
 
650
651
  <pre>
651
652
  $ cd ~/code/formtastic
652
- $ rvm gemset create formtastic-rails3
653
- $ rvm gemset use formtastic-rails3
654
- $ gem install bundler
655
- $ bundle install
656
- $ rake spec
657
- $ rm Gemfile.lock
658
- $ rvm gemset create formtastic-rails2
659
- $ rvm gemset use formtastic-rails2
660
- $ gem install bundler
661
- $ RAILS_2=true bundle install
662
- $ rake spec
663
- $ touch .rvmrc
664
- $ echo "rvm gemset use formtastic-rails-3" > .rvmrc
665
- $ cd ~/code/formtastic
653
+ $ rvm gemset create formtastic # If that's your thing
654
+ $ rvm gemset use formtastic # Add that to your .rvmrc too
655
+ $ bundle install # Initial bundle command to build Gemfile.lock
656
+ $ RAILS_2=true bundle update rails # Updates gemfile to run agains rails 2
657
+ $ RAILS_2=true rake # Run tests against rails 2
658
+ $ bundle update rails # Updates gemfile to run agains rails 3
659
+ $ rake # Run tests against rails 3
666
660
  </pre>
667
661
 
668
662
 
@@ -105,7 +105,7 @@ class FormGenerator < Rails::Generator::NamedBase
105
105
  end
106
106
 
107
107
  def source_root
108
- File.expand_path('../../../lib/generators/templates', __FILE__)
108
+ File.expand_path('../../../lib/generators/templates/rails2', __FILE__)
109
109
  end
110
110
 
111
111
  end
@@ -6,11 +6,20 @@ require File.join(File.dirname(__FILE__), *%w[formtastic railtie]) if defined?(:
6
6
  module Formtastic #:nodoc:
7
7
 
8
8
  class SemanticFormBuilder < ActionView::Helpers::FormBuilder
9
- class_inheritable_accessor :default_text_field_size, :default_text_area_height, :default_text_area_width, :all_fields_required_by_default, :include_blank_for_select_by_default,
10
- :required_string, :optional_string, :inline_errors, :label_str_method, :collection_value_methods, :collection_label_methods, :file_metadata_suffixes,
11
- :inline_order, :custom_inline_order, :file_methods, :priority_countries, :i18n_lookups_by_default, :escape_html_entities_in_hints_and_labels,
12
- :default_commit_button_accesskey, :default_inline_error_class, :default_hint_class, :default_error_list_class, :instance_reader => false
13
-
9
+
10
+ configurables = [
11
+ :default_text_field_size, :default_text_area_height, :default_text_area_width, :all_fields_required_by_default, :include_blank_for_select_by_default,
12
+ :required_string, :optional_string, :inline_errors, :label_str_method, :collection_value_methods, :collection_label_methods, :file_metadata_suffixes,
13
+ :inline_order, :custom_inline_order, :file_methods, :priority_countries, :i18n_lookups_by_default, :escape_html_entities_in_hints_and_labels,
14
+ :default_commit_button_accesskey, :default_inline_error_class, :default_hint_class, :default_error_list_class
15
+ ]
16
+
17
+ if respond_to?(:class_attribute)
18
+ class_attribute *configurables
19
+ else
20
+ class_inheritable_accessor *configurables
21
+ end
22
+
14
23
  cattr_accessor :custom_namespace
15
24
 
16
25
  self.default_text_field_size = nil
@@ -88,9 +97,9 @@ module Formtastic #:nodoc:
88
97
  #
89
98
  # <% semantic_form_for @employee do |form| %>
90
99
  # <% form.inputs do -%>
91
- # <%= form.input :secret, :value => "Hello" %>
92
100
  # <%= form.input :name, :label => "Full Name" %>
93
- # <%= form.input :manager_id, :as => :radio %>
101
+ # <%= form.input :manager, :as => :radio %>
102
+ # <%= form.input :secret, :as => :password, :input_html => { :value => "xxxx" } %>
94
103
  # <%= form.input :hired_at, :as => :date, :label => "Date Hired" %>
95
104
  # <%= form.input :phone, :required => false, :hint => "Eg: +1 555 1234" %>
96
105
  # <%= form.input :email %>
@@ -99,6 +108,8 @@ module Formtastic #:nodoc:
99
108
  # <% end %>
100
109
  #
101
110
  def input(method, options = {})
111
+ options = options.dup # Allow options to be shared without being tainted by Formtastic
112
+
102
113
  options[:required] = method_required?(method) unless options.key?(:required)
103
114
  options[:as] ||= default_input_type(method, options)
104
115
 
@@ -114,7 +125,7 @@ module Formtastic #:nodoc:
114
125
  options[:label_html][:for] ||= options[:input_html][:id]
115
126
  end
116
127
 
117
- input_parts = (self.class.custom_inline_order[options[:as]] || self.class.inline_order).dup
128
+ input_parts = (custom_inline_order[options[:as]] || inline_order).dup
118
129
  input_parts = input_parts - [:errors, :hints] if options[:as] == :hidden
119
130
 
120
131
  list_item_content = input_parts.map do |type|
@@ -282,8 +293,8 @@ module Formtastic #:nodoc:
282
293
  field_set_and_list_wrapping(*(args << html_options), &block)
283
294
  else
284
295
  if @object && args.empty?
285
- args = self.association_columns(:belongs_to)
286
- args += self.content_columns
296
+ args = association_columns(:belongs_to)
297
+ args += content_columns
287
298
  args -= RESERVED_COLUMNS
288
299
  args.compact!
289
300
  end
@@ -351,10 +362,10 @@ module Formtastic #:nodoc:
351
362
  end
352
363
  else
353
364
  key = :submit
354
- object_name = @object_name.to_s.send(self.class.label_str_method)
365
+ object_name = @object_name.to_s.send(label_str_method)
355
366
  end
356
367
 
357
- text = (self.localized_string(key, text, :action, :model => object_name) ||
368
+ text = (localized_string(key, text, :action, :model => object_name) ||
358
369
  ::Formtastic::I18n.t(key, :model => object_name)) unless text.is_a?(::String)
359
370
 
360
371
  button_html = options.delete(:button_html) || {}
@@ -364,9 +375,9 @@ module Formtastic #:nodoc:
364
375
  wrapper_html = options.delete(:wrapper_html) || {}
365
376
  wrapper_html[:class] = (wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')
366
377
 
367
- accesskey = (options.delete(:accesskey) || self.class.default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
378
+ accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
368
379
  button_html = button_html.merge(:accesskey => accesskey) if accesskey
369
- template.content_tag(:li, Formtastic::Util.html_safe(self.submit(text, button_html)), wrapper_html)
380
+ template.content_tag(:li, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html)
370
381
  end
371
382
 
372
383
  # A thin wrapper around #fields_for to set :builder => Formtastic::SemanticFormBuilder
@@ -451,7 +462,7 @@ module Formtastic #:nodoc:
451
462
  def inline_errors_for(method, options = {}) #:nodoc:
452
463
  if render_inline_errors?
453
464
  errors = error_keys(method, options).map{|x| @object.errors[x] }.flatten.compact.uniq
454
- send(:"error_#{self.class.inline_errors}", [*errors], options) if errors.any?
465
+ send(:"error_#{inline_errors}", [*errors], options) if errors.any?
455
466
  else
456
467
  nil
457
468
  end
@@ -490,7 +501,7 @@ module Formtastic #:nodoc:
490
501
  @methods_for_error ||= {}
491
502
  @methods_for_error[method] ||= begin
492
503
  methods_for_error = [method.to_sym]
493
- methods_for_error << self.class.file_metadata_suffixes.map{|suffix| "#{method}_#{suffix}".to_sym} if is_file?(method, options)
504
+ methods_for_error << file_metadata_suffixes.map{|suffix| "#{method}_#{suffix}".to_sym} if is_file?(method, options)
494
505
  methods_for_error << [association_primary_key(method)] if association_macro_for_method(method) == :belongs_to
495
506
  methods_for_error.flatten.compact.uniq
496
507
  end
@@ -502,13 +513,13 @@ module Formtastic #:nodoc:
502
513
  end
503
514
 
504
515
  def render_inline_errors?
505
- @object && @object.respond_to?(:errors) && INLINE_ERROR_TYPES.include?(self.class.inline_errors)
516
+ @object && @object.respond_to?(:errors) && INLINE_ERROR_TYPES.include?(inline_errors)
506
517
  end
507
518
 
508
519
  # Collects content columns (non-relation columns) for the current form object class.
509
520
  #
510
521
  def content_columns #:nodoc:
511
- self.model_name.constantize.content_columns.collect { |c| c.name.to_sym }.compact rescue []
522
+ model_name.constantize.content_columns.collect { |c| c.name.to_sym }.compact rescue []
512
523
  end
513
524
 
514
525
  # Collects association columns (relation columns) for the current form object class.
@@ -529,12 +540,12 @@ module Formtastic #:nodoc:
529
540
 
530
541
  # Returns nil, or a symbol like :belongs_to or :has_many
531
542
  def association_macro_for_method(method) #:nodoc:
532
- reflection = self.reflection_for(method)
543
+ reflection = reflection_for(method)
533
544
  reflection.macro if reflection
534
545
  end
535
546
 
536
547
  def association_primary_key(method)
537
- reflection = self.reflection_for(method)
548
+ reflection = reflection_for(method)
538
549
  reflection.options[:foreign_key] if reflection && !reflection.options[:foreign_key].blank?
539
550
  :"#{method}_id"
540
551
  end
@@ -610,7 +621,7 @@ module Formtastic #:nodoc:
610
621
  if @object && @object.class.respond_to?(:validators_on)
611
622
  !@object.class.validators_on(attribute_sym).find{|validator| (validator.kind == :presence || validator.kind == :inclusion) && (validator.options.present? ? options_require_validation?(validator.options) : true)}.nil?
612
623
  else
613
- self.class.all_fields_required_by_default
624
+ all_fields_required_by_default
614
625
  end
615
626
  end
616
627
  end
@@ -640,8 +651,8 @@ module Formtastic #:nodoc:
640
651
  html_options[:id] ||= field_id
641
652
  label_options = options_for_label(options)
642
653
  label_options[:for] ||= html_options[:id]
643
- self.label(method, label_options) <<
644
- self.send(self.respond_to?(form_helper_method) ? form_helper_method : :text_field, method, html_options)
654
+ label(method, label_options) <<
655
+ send(respond_to?(form_helper_method) ? form_helper_method : :text_field, method, html_options)
645
656
  end
646
657
 
647
658
  # Outputs a label and standard Rails text field inside the wrapper.
@@ -698,7 +709,7 @@ module Formtastic #:nodoc:
698
709
  options ||= {}
699
710
  html_options = options.delete(:input_html) || strip_formtastic_options(options)
700
711
  html_options[:id] ||= generate_html_id(method, "")
701
- self.hidden_field(method, html_options)
712
+ hidden_field(method, html_options)
702
713
  end
703
714
 
704
715
  # Outputs a label and a select box containing options from the parent
@@ -802,7 +813,7 @@ module Formtastic #:nodoc:
802
813
  html_options[:multiple] = html_options[:multiple] || options.delete(:multiple)
803
814
  html_options.delete(:multiple) if html_options[:multiple].nil?
804
815
 
805
- reflection = self.reflection_for(method)
816
+ reflection = reflection_for(method)
806
817
  if reflection && [ :has_many, :has_and_belongs_to_many ].include?(reflection.macro)
807
818
  html_options[:multiple] = true if html_options[:multiple].nil?
808
819
  html_options[:size] ||= 5
@@ -823,19 +834,19 @@ module Formtastic #:nodoc:
823
834
  group_association = options[:group_association] || detect_group_association(method, options[:group_by])
824
835
 
825
836
  # Here comes the monster with 8 arguments
826
- self.grouped_collection_select(input_name, group_collection,
837
+ grouped_collection_select(input_name, group_collection,
827
838
  group_association, group_label_method,
828
839
  value, label,
829
840
  strip_formtastic_options(options), html_options)
830
841
  else
831
842
  collection = find_collection_for_column(method, options)
832
843
 
833
- self.select(input_name, collection, strip_formtastic_options(options), html_options)
844
+ select(input_name, collection, strip_formtastic_options(options), html_options)
834
845
  end
835
846
 
836
847
  label_options = options_for_label(options).merge(:input_name => input_name)
837
848
  label_options[:for] ||= html_options[:id]
838
- self.label(method, label_options) << select_html
849
+ label(method, label_options) << select_html
839
850
  end
840
851
 
841
852
  # Outputs a timezone select input as Rails' time_zone_select helper. You
@@ -850,8 +861,8 @@ module Formtastic #:nodoc:
850
861
  html_options[:id] ||= field_id
851
862
  label_options = options_for_label(options)
852
863
  label_options[:for] ||= html_options[:id]
853
- self.label(method, label_options) <<
854
- self.time_zone_select(method, options.delete(:priority_zones),
864
+ label(method, label_options) <<
865
+ time_zone_select(method, options.delete(:priority_zones),
855
866
  strip_formtastic_options(options), html_options)
856
867
  end
857
868
 
@@ -928,7 +939,7 @@ module Formtastic #:nodoc:
928
939
  html_options[:id] = input_id
929
940
 
930
941
  li_content = template.content_tag(:label,
931
- Formtastic::Util.html_safe("#{self.radio_button(input_name, value, html_options)} #{escape_html_entities(label)}"),
942
+ Formtastic::Util.html_safe("#{radio_button(input_name, value, html_options)} #{escape_html_entities(label)}"),
932
943
  :for => input_id
933
944
  )
934
945
 
@@ -1167,7 +1178,7 @@ module Formtastic #:nodoc:
1167
1178
  html_options[:id] = input_id
1168
1179
 
1169
1180
  li_content = template.content_tag(:label,
1170
- Formtastic::Util.html_safe("#{self.create_check_boxes(input_name, html_options, value, unchecked_value, hidden_fields)} #{escape_html_entities(label)}"),
1181
+ Formtastic::Util.html_safe("#{create_check_boxes(input_name, html_options, value, unchecked_value, hidden_fields)} #{escape_html_entities(label)}"),
1171
1182
  :for => input_id
1172
1183
  )
1173
1184
 
@@ -1176,7 +1187,7 @@ module Formtastic #:nodoc:
1176
1187
  end
1177
1188
 
1178
1189
  fieldset_content = legend_tag(method, options)
1179
- fieldset_content << self.create_hidden_field_for_check_boxes(input_name, value_as_class) unless hidden_fields
1190
+ fieldset_content << create_hidden_field_for_check_boxes(input_name, value_as_class) unless hidden_fields
1180
1191
  fieldset_content << template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
1181
1192
  template.content_tag(:fieldset, fieldset_content)
1182
1193
  end
@@ -1207,7 +1218,7 @@ module Formtastic #:nodoc:
1207
1218
  # otherwise the helper uses the output generated by the rails check_box method.
1208
1219
  def create_check_boxes(input_name, html_options = {}, checked_value = "1", unchecked_value = "0", hidden_fields = false) #:nodoc:
1209
1220
  return template.check_box_tag(input_name, checked_value, html_options[:checked], html_options) unless hidden_fields == true
1210
- self.check_box(input_name, html_options, checked_value, unchecked_value)
1221
+ check_box(input_name, html_options, checked_value, unchecked_value)
1211
1222
  end
1212
1223
 
1213
1224
  # Outputs a country select input, wrapping around a regular country_select helper.
@@ -1225,18 +1236,18 @@ module Formtastic #:nodoc:
1225
1236
  # f.input :location, :as => :country, :priority_countries => /Australia/ # set your own
1226
1237
  #
1227
1238
  def country_input(method, options)
1228
- raise "To use the :country input, please install a country_select plugin, like this one: http://github.com/rails/iso-3166-country-select" unless self.respond_to?(:country_select)
1239
+ raise "To use the :country input, please install a country_select plugin, like this one: http://github.com/rails/iso-3166-country-select" unless respond_to?(:country_select)
1229
1240
 
1230
1241
  html_options = options.delete(:input_html) || {}
1231
- priority_countries = options.delete(:priority_countries) || self.class.priority_countries
1242
+ priority_countries = options.delete(:priority_countries) || self.priority_countries
1232
1243
 
1233
1244
  field_id = generate_html_id(method, "")
1234
1245
  html_options[:id] ||= field_id
1235
1246
  label_options = options_for_label(options)
1236
1247
  label_options[:for] ||= html_options[:id]
1237
1248
 
1238
- self.label(method, label_options) <<
1239
- self.country_select(method, priority_countries, strip_formtastic_options(options), html_options)
1249
+ label(method, label_options) <<
1250
+ country_select(method, priority_countries, strip_formtastic_options(options), html_options)
1240
1251
  end
1241
1252
 
1242
1253
  # Outputs a label containing a checkbox and the label text. The label defaults
@@ -1261,7 +1272,7 @@ module Formtastic #:nodoc:
1261
1272
  # the label() method will insert this nested input into the label at the last minute
1262
1273
  options[:label_prefix_for_nested_input] = input
1263
1274
 
1264
- template.hidden_field_tag("#{@object_name}[#{method}]", unchecked_value, :id => nil) << self.label(method, options)
1275
+ template.hidden_field_tag("#{@object_name}[#{method}]", unchecked_value, :id => nil) << label(method, options)
1265
1276
  end
1266
1277
 
1267
1278
  # Generates an input for the given method using the type supplied with :as.
@@ -1274,21 +1285,21 @@ module Formtastic #:nodoc:
1274
1285
  def inline_hints_for(method, options) #:nodoc:
1275
1286
  options[:hint] = localized_string(method, options[:hint], :hint)
1276
1287
  return if options[:hint].blank? or options[:hint].kind_of? Hash
1277
- hint_class = options[:hint_class] || self.class.default_hint_class
1288
+ hint_class = options[:hint_class] || default_hint_class
1278
1289
  template.content_tag(:p, Formtastic::Util.html_safe(options[:hint]), :class => hint_class)
1279
1290
  end
1280
1291
 
1281
1292
  # Creates an error sentence by calling to_sentence on the errors array.
1282
1293
  #
1283
1294
  def error_sentence(errors, options = {}) #:nodoc:
1284
- error_class = options[:error_class] || self.class.default_inline_error_class
1295
+ error_class = options[:error_class] || default_inline_error_class
1285
1296
  template.content_tag(:p, Formtastic::Util.html_safe(errors.to_sentence.untaint), :class => error_class)
1286
1297
  end
1287
1298
 
1288
1299
  # Creates an error li list.
1289
1300
  #
1290
1301
  def error_list(errors, options = {}) #:nodoc:
1291
- error_class = options[:error_class] || self.class.default_error_list_class
1302
+ error_class = options[:error_class] || default_error_list_class
1292
1303
  list_elements = []
1293
1304
  errors.each do |error|
1294
1305
  list_elements << template.content_tag(:li, Formtastic::Util.html_safe(error.untaint))
@@ -1299,7 +1310,7 @@ module Formtastic #:nodoc:
1299
1310
  # Creates an error sentence containing only the first error
1300
1311
  #
1301
1312
  def error_first(errors, options = {}) #:nodoc:
1302
- error_class = options[:error_class] || self.class.default_inline_error_class
1313
+ error_class = options[:error_class] || default_inline_error_class
1303
1314
  template.content_tag(:p, Formtastic::Util.html_safe(errors.first.untaint), :class => error_class)
1304
1315
  end
1305
1316
 
@@ -1309,9 +1320,9 @@ module Formtastic #:nodoc:
1309
1320
  def required_or_optional_string(required) #:nodoc:
1310
1321
  string_or_proc = case required
1311
1322
  when true
1312
- self.class.required_string
1323
+ required_string
1313
1324
  when false
1314
- self.class.optional_string
1325
+ optional_string
1315
1326
  else
1316
1327
  required
1317
1328
  end
@@ -1375,7 +1386,7 @@ module Formtastic #:nodoc:
1375
1386
 
1376
1387
  if title.blank?
1377
1388
  valid_name_classes = [::String, ::Symbol]
1378
- valid_name_classes.delete(::Symbol) if !block_given? && (args.first.is_a?(::Symbol) && self.content_columns.include?(args.first))
1389
+ valid_name_classes.delete(::Symbol) if !block_given? && (args.first.is_a?(::Symbol) && content_columns.include?(args.first))
1379
1390
  title = args.shift if valid_name_classes.any? { |valid_name_class| args.first.is_a?(valid_name_class) }
1380
1391
  end
1381
1392
  title = localized_string(title, title, :title) if title.is_a?(::Symbol)
@@ -1390,7 +1401,7 @@ module Formtastic #:nodoc:
1390
1401
 
1391
1402
  template.content_tag(:fieldset,
1392
1403
  template.content_tag(:legend,
1393
- self.label(method, options_for_label(options).merge(:for => options.delete(:label_for))), :class => 'label'
1404
+ label(method, options_for_label(options).merge(:for => options.delete(:label_for))), :class => 'label'
1394
1405
  ) <<
1395
1406
  template.content_tag(:ol, Formtastic::Util.html_safe(contents))
1396
1407
  )
@@ -1417,7 +1428,7 @@ module Formtastic #:nodoc:
1417
1428
  # default is a :string, a similar behaviour to Rails' scaffolding.
1418
1429
  #
1419
1430
  def default_input_type(method, options = {}) #:nodoc:
1420
- if column = self.column_for(method)
1431
+ if column = column_for(method)
1421
1432
  # Special cases where the column type doesn't map to an input method.
1422
1433
  case column.type
1423
1434
  when :string
@@ -1429,7 +1440,7 @@ module Formtastic #:nodoc:
1429
1440
  return :phone if method.to_s =~ /(phone|fax)/
1430
1441
  return :search if method.to_s =~ /^search$/
1431
1442
  when :integer
1432
- return :select if self.reflection_for(method)
1443
+ return :select if reflection_for(method)
1433
1444
  return :numeric
1434
1445
  when :float, :decimal
1435
1446
  return :numeric
@@ -1443,7 +1454,7 @@ module Formtastic #:nodoc:
1443
1454
  return column.type
1444
1455
  else
1445
1456
  if @object
1446
- return :select if self.reflection_for(method)
1457
+ return :select if reflection_for(method)
1447
1458
 
1448
1459
  return :file if is_file?(method, options)
1449
1460
  end
@@ -1458,7 +1469,7 @@ module Formtastic #:nodoc:
1458
1469
  @files ||= {}
1459
1470
  @files[method] ||= (options[:as].present? && options[:as] == :file) || begin
1460
1471
  file = @object.send(method) if @object && @object.respond_to?(method)
1461
- file && self.class.file_methods.any?{|m| file.respond_to?(m)}
1472
+ file && file_methods.any?{|m| file.respond_to?(m)}
1462
1473
  end
1463
1474
  end
1464
1475
 
@@ -1493,7 +1504,7 @@ module Formtastic #:nodoc:
1493
1504
  def find_raw_collection_for_column(column, options) #:nodoc:
1494
1505
  collection = if options[:collection]
1495
1506
  options.delete(:collection)
1496
- elsif reflection = self.reflection_for(column)
1507
+ elsif reflection = reflection_for(column)
1497
1508
  options[:find_options] ||= {}
1498
1509
 
1499
1510
  if conditions = reflection.options[:conditions]
@@ -1532,8 +1543,8 @@ module Formtastic #:nodoc:
1532
1543
  end
1533
1544
 
1534
1545
  # Order of preference: user supplied method, class defaults, auto-detect
1535
- label = options[:label_method] || label || self.class.collection_label_methods.find { |m| sample.respond_to?(m) }
1536
- value = options[:value_method] || value || self.class.collection_value_methods.find { |m| sample.respond_to?(m) }
1546
+ label = options[:label_method] || label || collection_label_methods.find { |m| sample.respond_to?(m) }
1547
+ value = options[:value_method] || value || collection_value_methods.find { |m| sample.respond_to?(m) }
1537
1548
 
1538
1549
  [label, value]
1539
1550
  end
@@ -1548,7 +1559,7 @@ module Formtastic #:nodoc:
1548
1559
  # Detects the method to call for fetching group members from the groups when grouping select options
1549
1560
  #
1550
1561
  def detect_group_association(method, group_by)
1551
- object_to_method_reflection = self.reflection_for(method)
1562
+ object_to_method_reflection = reflection_for(method)
1552
1563
  method_class = object_to_method_reflection.klass
1553
1564
 
1554
1565
  method_to_group_association = method_class.reflect_on_association(group_by)
@@ -1606,7 +1617,7 @@ module Formtastic #:nodoc:
1606
1617
  # has_and_belongs_to_many will act like has_many
1607
1618
  #
1608
1619
  def generate_association_input_name(method) #:nodoc:
1609
- if reflection = self.reflection_for(method)
1620
+ if reflection = reflection_for(method)
1610
1621
  if [:has_and_belongs_to_many, :has_many].include?(reflection.macro)
1611
1622
  "#{method.to_s.singularize}_ids"
1612
1623
  else
@@ -1678,16 +1689,17 @@ module Formtastic #:nodoc:
1678
1689
  end
1679
1690
 
1680
1691
  validation_max_limit = get_maxlength_for(method)
1681
- column = self.column_for(method)
1692
+ column = column_for(method)
1682
1693
 
1683
1694
  if type == :text
1684
- { :rows => self.class.default_text_area_height, :cols => self.class.default_text_area_width }
1685
- elsif type == :numeric || column.nil? || column.limit.nil?
1695
+ { :rows => default_text_area_height,
1696
+ :cols => default_text_area_width }
1697
+ elsif type == :numeric || column.nil? || !column.respond_to?(:limit) || column.limit.nil?
1686
1698
  { :maxlength => validation_max_limit,
1687
- :size => self.class.default_text_field_size }
1699
+ :size => default_text_field_size }
1688
1700
  else
1689
1701
  { :maxlength => validation_max_limit || column.limit,
1690
- :size => self.class.default_text_field_size }
1702
+ :size => default_text_field_size }
1691
1703
  end
1692
1704
  end
1693
1705
 
@@ -1733,12 +1745,12 @@ module Formtastic #:nodoc:
1733
1745
  if @object && @object.class.respond_to?(:human_attribute_name)
1734
1746
  humanized_name = @object.class.human_attribute_name(method.to_s)
1735
1747
  if humanized_name == method.to_s.send(:humanize)
1736
- method.to_s.send(self.class.label_str_method)
1748
+ method.to_s.send(label_str_method)
1737
1749
  else
1738
1750
  humanized_name
1739
1751
  end
1740
1752
  else
1741
- method.to_s.send(self.class.label_str_method)
1753
+ method.to_s.send(label_str_method)
1742
1754
  end
1743
1755
  end
1744
1756
 
@@ -1769,7 +1781,7 @@ module Formtastic #:nodoc:
1769
1781
  if value.is_a?(::String)
1770
1782
  escape_html_entities(value)
1771
1783
  else
1772
- use_i18n = value.nil? ? self.class.i18n_lookups_by_default : (value != false)
1784
+ use_i18n = value.nil? ? i18n_lookups_by_default : (value != false)
1773
1785
 
1774
1786
  if use_i18n
1775
1787
  model_name, nested_model_name = normalize_model_name(self.model_name.underscore)
@@ -1828,13 +1840,13 @@ module Formtastic #:nodoc:
1828
1840
 
1829
1841
  def set_include_blank(options)
1830
1842
  unless options.key?(:include_blank) || options.key?(:prompt)
1831
- options[:include_blank] = self.class.include_blank_for_select_by_default
1843
+ options[:include_blank] = include_blank_for_select_by_default
1832
1844
  end
1833
1845
  options
1834
1846
  end
1835
1847
 
1836
1848
  def escape_html_entities(string) #:nodoc:
1837
- if self.class.escape_html_entities_in_hints_and_labels
1849
+ if escape_html_entities_in_hints_and_labels
1838
1850
  # Acceppt html_safe flag as indicator to skip escaping
1839
1851
  string = template.escape_once(string) unless string.respond_to?(:html_safe?) && string.html_safe? == true
1840
1852
  end
@@ -1898,7 +1910,7 @@ module Formtastic #:nodoc:
1898
1910
 
1899
1911
  def semantic_remote_form_for_wrapper(record_or_name_or_array, *args, &proc)
1900
1912
  options = args.extract_options!
1901
- if self.respond_to? :remote_form_for
1913
+ if respond_to? :remote_form_for
1902
1914
  semantic_remote_form_for_real(record_or_name_or_array, *(args << options), &proc)
1903
1915
  else
1904
1916
  options[:remote] = true
@@ -6,10 +6,8 @@ module Formtastic
6
6
  source_root File.expand_path('../../../templates', __FILE__)
7
7
 
8
8
  def copy_files
9
- empty_directory 'config/initializers'
10
9
  template 'formtastic.rb', 'config/initializers/formtastic.rb'
11
10
 
12
- empty_directory 'public/stylesheets'
13
11
  template 'formtastic.css', 'public/stylesheets/formtastic.css'
14
12
  template 'formtastic_changes.css', 'public/stylesheets/formtastic_changes.css'
15
13
  end
@@ -1,4 +1,4 @@
1
- <%% f.inputs do %>
1
+ <%%= f.inputs do %>
2
2
  <% attributes.each do |attribute| -%>
3
3
  <%%= f.input :<%= attribute.name %> %>
4
4
  <% end -%>
@@ -1,4 +1,4 @@
1
- - f.inputs do
1
+ = f.inputs do
2
2
  <% attributes.each do |attribute| -%>
3
3
  = f.input :<%= attribute.name %>
4
4
  <% end -%>
@@ -1,5 +1,13 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # --------------------------------------------------------------------------------------------------
4
+ # Please note: If you're subclassing Formtastic::SemanticFormBuilder in a Rails 3 project,
5
+ # Formtastic uses class_attribute for these configuration attributes instead of the deprecated
6
+ # class_inheritable_attribute. The behaviour is slightly different with subclasses (especially
7
+ # around attributes with Hash or Array) values, so make sure you understand what's happening.
8
+ # See the documentation for class_attribute in ActiveSupport for more information.
9
+ # --------------------------------------------------------------------------------------------------
10
+
3
11
  # Set the default text field size when input is a string. Default is nil.
4
12
  # Formtastic::SemanticFormBuilder.default_text_field_size = 50
5
13
 
@@ -0,0 +1,5 @@
1
+ <%% f.inputs do %>
2
+ <% attributes.each do |attribute| -%>
3
+ <%%= f.input :<%= attribute.name %> %>
4
+ <% end -%>
5
+ <%% end %>
@@ -0,0 +1,4 @@
1
+ - f.inputs do
2
+ <% attributes.each do |attribute| -%>
3
+ = f.input :<%= attribute.name %>
4
+ <% end -%>
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 31098189
5
+ prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 2
10
- version: 1.2.2
9
+ - 3
10
+ - beta
11
+ version: 1.2.3.beta
11
12
  platform: ruby
12
13
  authors:
13
14
  - Justin French
@@ -154,6 +155,8 @@ files:
154
155
  - lib/generators/templates/formtastic.css
155
156
  - lib/generators/templates/formtastic.rb
156
157
  - lib/generators/templates/formtastic_changes.css
158
+ - lib/generators/templates/rails2/_form.html.erb
159
+ - lib/generators/templates/rails2/_form.html.haml
157
160
  - lib/locale/en.yml
158
161
  - rails/init.rb
159
162
  - MIT-LICENSE