formtastic_extensions 0.0.3

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Alexander Semyonov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = milk
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Alexander Semyonov. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "formtastic_extensions"
8
+ gem.summary = %Q{additional flexibility for formtastic}
9
+ gem.description = %Q{extension for formtastic, adding tag_list and others}
10
+ gem.email = "rotuka@tokak.ru"
11
+ gem.homepage = "http://github.com/krasivotokak/formtastic_extensions"
12
+ gem.authors = ["Alexander Semyonov"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ gem.add_dependency('justinfrench-formtastic', '0.2.4')
15
+ gem.add_dependency('redinger-validation_reflection', '0.3.3')
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/*_test.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/*_test.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+ task :push => ['gemcutter:release', 'install']
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ if File.exist?('VERSION')
51
+ version = File.read('VERSION')
52
+ else
53
+ version = ""
54
+ end
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "milk #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.3
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
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 = %q{formtastic_extensions}
8
+ s.version = "0.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alexander Semyonov"]
12
+ s.date = %q{2009-10-17}
13
+ s.description = %q{extension for formtastic, adding tag_list and others}
14
+ s.email = %q{rotuka@tokak.ru}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "formtastic_extensions.gemspec",
27
+ "lib/formtastic_extensions.rb",
28
+ "lib/formtastic_extensions/locales/en.yml",
29
+ "lib/formtastic_extensions/locales/ru.yml",
30
+ "lib/formtastic_extensions/semantic_form_builder.rb",
31
+ "milk.gemspec",
32
+ "rails/init.rb",
33
+ "test/formtastic-extensions_test.rb",
34
+ "test/milk_test.rb",
35
+ "test/test_helper.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/krasivotokak/formtastic_extensions}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.5}
41
+ s.summary = %q{additional flexibility for formtastic}
42
+ s.test_files = [
43
+ "test/formtastic-extensions_test.rb",
44
+ "test/milk_test.rb",
45
+ "test/test_helper.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ s.add_runtime_dependency(%q<justinfrench-formtastic>, ["= 0.2.4"])
55
+ s.add_runtime_dependency(%q<redinger-validation_reflection>, ["= 0.3.3"])
56
+ else
57
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
+ s.add_dependency(%q<justinfrench-formtastic>, ["= 0.2.4"])
59
+ s.add_dependency(%q<redinger-validation_reflection>, ["= 0.3.3"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
63
+ s.add_dependency(%q<justinfrench-formtastic>, ["= 0.2.4"])
64
+ s.add_dependency(%q<redinger-validation_reflection>, ["= 0.3.3"])
65
+ end
66
+ end
@@ -0,0 +1,9 @@
1
+ en:
2
+ formtastic:
3
+ yes: 'Yes'
4
+ no: 'No'
5
+ required: 'Required'
6
+ buttons:
7
+ create: 'Create'
8
+ save: 'Save'
9
+ submit: 'Submit'
@@ -0,0 +1,9 @@
1
+ ru:
2
+ formtastic:
3
+ yes: 'Да'
4
+ no: 'Нет'
5
+ required: 'Обязательно'
6
+ buttons:
7
+ create: 'Добавить'
8
+ save: 'Сохранить'
9
+ submit: 'Отправить'
@@ -0,0 +1,91 @@
1
+ module FormtasticExtensions
2
+ class SemanticFormBuilder < Formtastic::SemanticFormBuilder
3
+ @@all_fields_required_by_default = false
4
+ @@i18n_lookups_by_default = true
5
+ @@input_class = 'b_field'
6
+ @@inputs_class = 'b_fields_set'
7
+ @@buttons_class = 'b_buttons_set'
8
+ cattr_accessor :input_class, :inputs_class, :butons_class
9
+
10
+ def input(method, options = {})
11
+ options[:required] = method_required?(method) unless options.key?(:required)
12
+ options[:as] ||= default_input_type(method)
13
+
14
+ html_class = [ options[:as], (options[:required] ? :required : :optional) ]
15
+ html_class << 'error' if @object && @object.respond_to?(:errors) && @object.errors[method.to_sym]
16
+
17
+ wrapper_html = options.delete(:wrapper_html) || {}
18
+ wrapper_html[:id] ||= generate_html_id(method)
19
+ wrapper_html[:class] = "#{@@input_class} #{(html_class << wrapper_html[:class]).flatten.compact.map{ |klass| "#{@@input_class}-#{klass}" }.join(' ')}"
20
+
21
+ if [:boolean_select, :boolean_radio].include?(options[:as])
22
+ ::ActiveSupport::Deprecation.warn(":as => :#{options[:as]} is deprecated, use :as => :#{options[:as].to_s[8..-1]} instead", caller[3..-1])
23
+ end
24
+
25
+ if options[:input_html] && options[:input_html][:id]
26
+ options[:label_html] ||= {}
27
+ options[:label_html][:for] ||= options[:input_html][:id]
28
+ end
29
+
30
+ input_parts = @@inline_order.dup
31
+ input_parts.delete(:errors) if options[:as] == :hidden
32
+
33
+ list_item_content = input_parts.map do |type|
34
+ send(:"inline_#{type}_for", method, options)
35
+ end.compact.join("\n")
36
+
37
+ return template.content_tag(:li, list_item_content, wrapper_html)
38
+ end
39
+
40
+ def inputs(*args, &block)
41
+ html_options = args.extract_options!
42
+ html_options[:class] ||= @@inputs_class
43
+
44
+ if html_options[:for]
45
+ inputs_for_nested_attributes(args, html_options, &block)
46
+ elsif block_given?
47
+ field_set_and_list_wrapping(html_options, &block)
48
+ else
49
+ if @object && args.empty?
50
+ args = @object.class.reflections.map { |n,_| n if _.macro == :belongs_to }
51
+ args += @object.class.content_columns.map(&:name)
52
+ args -= %w[created_at updated_at created_on updated_on lock_version]
53
+ args.compact!
54
+ end
55
+ contents = args.map { |method| input(method.to_sym) }
56
+
57
+ field_set_and_list_wrapping(html_options, contents)
58
+ end
59
+ end
60
+
61
+ def buttons(*args, &block)
62
+ html_options = args.extract_options!
63
+ html_options[:class] ||= @@buttons_class
64
+
65
+ if block_given?
66
+ field_set_and_list_wrapping(html_options, &block)
67
+ else
68
+ args = [:commit] if args.empty?
69
+ contents = args.map { |button_name| send(:"#{button_name}_button") }
70
+ field_set_and_list_wrapping(html_options, contents)
71
+ end
72
+ end
73
+
74
+ def save_or_create_button_text(prefix = 'Submit')
75
+ if @object
76
+ prefix = @object.new_record? ? 'Create' : 'Save'
77
+ object_name = @object.class.name.underscore
78
+ i18n_prefix = prefix.downcase
79
+ else
80
+ object_name = @object_name.to_s.underscore
81
+ end
82
+
83
+ i18n_prefix = prefix.downcase
84
+ I18n.t("formtastic.buttons.#{object_name}.#{i18n_prefix}",
85
+ :default => [
86
+ :"formtastic.buttons.#{i18n_prefix}",
87
+ prefix])
88
+ end
89
+ end
90
+ end
91
+
@@ -0,0 +1,9 @@
1
+ require 'validation_reflection'
2
+ require 'formtastic'
3
+ require 'formtastic_extensions/semantic_form_builder'
4
+
5
+ module FormtasticExtensions
6
+ def self.locale_files
7
+ Dir[File.join(File.dirname(__FILE__), 'milk', 'locales', '*')]
8
+ end
9
+ end
data/milk.gemspec ADDED
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
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 = %q{milk}
8
+ s.version = "0.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alexander Semyonov"]
12
+ s.date = %q{2009-10-16}
13
+ s.description = %q{extension for formtastic, adding tag_list and others}
14
+ s.email = %q{rotuka@tokak.ru}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/milk.rb",
27
+ "lib/milk/locales/en.yml",
28
+ "lib/milk/locales/ru.yml",
29
+ "lib/milk/semantic_form_builder.rb",
30
+ "milk.gemspec",
31
+ "rails/init.rb",
32
+ "test/milk_test.rb",
33
+ "test/test_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/krasivotokak/milk}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.5}
39
+ s.summary = %q{additional form inputs for formtastic}
40
+ s.test_files = [
41
+ "test/milk_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ s.add_runtime_dependency(%q<justinfrench-formtastic>, ["= 0.2.4"])
52
+ s.add_runtime_dependency(%q<redinger-validation_reflection>, ["= 0.3.3"])
53
+ else
54
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ s.add_dependency(%q<justinfrench-formtastic>, ["= 0.2.4"])
56
+ s.add_dependency(%q<redinger-validation_reflection>, ["= 0.3.3"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
+ s.add_dependency(%q<justinfrench-formtastic>, ["= 0.2.4"])
61
+ s.add_dependency(%q<redinger-validation_reflection>, ["= 0.3.3"])
62
+ end
63
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'formtastic_extensions'
2
+
3
+ ActionView::Base.send :include, Formtastic::SemanticFormHelper
4
+ Formtastic::SemanticFormHelper.builder = FormtasticExtensions::SemanticFormBuilder
5
+ I18n.load_path.unshift(*FormtasticExtensions.locale_files)
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class FormtasticExtensionsTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
data/test/milk_test.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class MilkTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'milk'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: formtastic_extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Semyonov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-17 00:00:00 +04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: justinfrench-formtastic
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.4
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: redinger-validation_reflection
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.3.3
44
+ version:
45
+ description: extension for formtastic, adding tag_list and others
46
+ email: rotuka@tokak.ru
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - formtastic_extensions.gemspec
62
+ - lib/formtastic_extensions.rb
63
+ - lib/formtastic_extensions/locales/en.yml
64
+ - lib/formtastic_extensions/locales/ru.yml
65
+ - lib/formtastic_extensions/semantic_form_builder.rb
66
+ - milk.gemspec
67
+ - rails/init.rb
68
+ - test/formtastic-extensions_test.rb
69
+ - test/milk_test.rb
70
+ - test/test_helper.rb
71
+ has_rdoc: true
72
+ homepage: http://github.com/krasivotokak/formtastic_extensions
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --charset=UTF-8
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.5
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: additional flexibility for formtastic
99
+ test_files:
100
+ - test/formtastic-extensions_test.rb
101
+ - test/milk_test.rb
102
+ - test/test_helper.rb