formtastic-globalize3 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Appraisals +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +18 -0
- data/formtastic-globalize3.gemspec +29 -0
- data/gemfiles/rails_3.1.gemfile +7 -0
- data/gemfiles/rails_3.2.gemfile +7 -0
- data/lib/formtastic/globalize3/helpers/input_helper.rb +33 -0
- data/lib/formtastic/globalize3/version.rb +5 -0
- data/lib/formtastic-globalize3.rb +7 -0
- data/spec/data/models.rb +7 -0
- data/spec/data/schema.rb +22 -0
- data/spec/helpers/input_helper_spec.rb +52 -0
- data/spec/spec_helper.rb +61 -0
- metadata +191 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 emjot GmbH & Co. KG
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Formtastic::Globalize3
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/emjot/formtastic-globalize3.png?branch=master)](https://travis-ci.org/emjot/formtastic-globalize3)
|
4
|
+
|
5
|
+
Transparently use globalize3 translated model fields in formtastic forms.
|
6
|
+
|
7
|
+
Without this gem, formtastic can't detect the column type of translated columns correctly (for example, you get a text field instead of a checkbox for a boolean column).
|
8
|
+
|
9
|
+
This gem patches `column_for` in the `Formtastic::Helpers::InputHelper`.
|
10
|
+
|
11
|
+
## Compatibility
|
12
|
+
|
13
|
+
Currently, formtastic 2.x and globalize3 0.3 are supported.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'formtastic-globalize3'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install formtastic-globalize3
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
You don't need to do anything, just include it in your Gemfile.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'appraisal'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
|
7
|
+
desc 'Default: run all tests with all supported Rails versions'
|
8
|
+
task :default => :all
|
9
|
+
|
10
|
+
desc 'Run tests with all supported Rails versions.'
|
11
|
+
task :all => ["appraisal:install"] do
|
12
|
+
exec('rake appraisal spec')
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run all tests'
|
16
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
17
|
+
t.pattern = FileList['spec/**/*_spec.rb']
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'formtastic/globalize3/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "formtastic-globalize3"
|
8
|
+
spec.version = Formtastic::Globalize3::VERSION
|
9
|
+
spec.authors = ["Maximilian Herold"]
|
10
|
+
spec.email = ["herold@emjot.de"]
|
11
|
+
spec.description = %q{patch for formtastic to make its magical column type determination work with globalize3 translated models}
|
12
|
+
spec.summary = %q{formtastic features for globalize3 translated models}
|
13
|
+
spec.homepage = "https://github.com/emjot/formtastic-globalize3"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "formtastic", "~> 2.0"
|
22
|
+
spec.add_runtime_dependency "globalize3", "~> 0.3"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "appraisal", "~> 0.5.1"
|
26
|
+
spec.add_development_dependency "rspec-rails", "~> 2.8.0"
|
27
|
+
spec.add_development_dependency "sqlite3"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Globalize3
|
3
|
+
module Helpers
|
4
|
+
# Make formtastic support globalize3 translated fields when working the magical type determination for columns
|
5
|
+
module InputHelper
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.send :include, InstanceMethods
|
9
|
+
base.send :alias_method_chain, :column_for, :globalize3_support
|
10
|
+
end
|
11
|
+
|
12
|
+
module InstanceMethods
|
13
|
+
|
14
|
+
def column_for_with_globalize3_support(method)
|
15
|
+
column = column_for_without_globalize3_support(method)
|
16
|
+
|
17
|
+
if column.nil? && @object.respond_to?(:translations)
|
18
|
+
translation_obj = @object.translations.empty? ? @object.translations.new : @object.translations.first
|
19
|
+
|
20
|
+
if translation_obj.try(:respond_to?, :column_for_attribute)
|
21
|
+
column = translation_obj.column_for_attribute(method)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
column
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/data/models.rb
ADDED
data/spec/data/schema.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
ActiveRecord::Migration.verbose = false
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define do
|
4
|
+
create_table :posts, :force => true do |t|
|
5
|
+
t.integer :rating
|
6
|
+
end
|
7
|
+
|
8
|
+
create_table :post_translations, :force => true do |t|
|
9
|
+
t.string :locale
|
10
|
+
t.references :post
|
11
|
+
t.string :title
|
12
|
+
t.text :content
|
13
|
+
t.boolean :published
|
14
|
+
t.datetime :published_at
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table :untranslateds, :force => true do |t|
|
18
|
+
t.string :name
|
19
|
+
t.integer :rating
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe 'Formtastic::FormBuilder#input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
def posts_path(*args); "/posts"; end
|
9
|
+
def untranslateds_path(*args); "/untranslateds"; end
|
10
|
+
|
11
|
+
describe 'column_for' do
|
12
|
+
|
13
|
+
describe 'on an untranslated model' do
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@untranslated = Untranslated.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should detect the type' do
|
20
|
+
semantic_form_for(@untranslated) do |builder|
|
21
|
+
builder.send(:column_for, :name).type.should == :string
|
22
|
+
builder.send(:column_for, :rating).type.should == :integer
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'on a translated model' do
|
29
|
+
|
30
|
+
before(:each) do
|
31
|
+
@post = Post.new
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should detect the type of a translated column' do
|
35
|
+
semantic_form_for(@post) do |builder|
|
36
|
+
builder.send(:column_for, :title).type.should == :string
|
37
|
+
builder.send(:column_for, :published).type.should == :boolean
|
38
|
+
builder.send(:column_for, :published_at).type.should == :datetime
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should detect the type of an untranslated column' do
|
43
|
+
semantic_form_for(@post) do |builder|
|
44
|
+
builder.send(:column_for, :rating).type.should == :integer
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.mock_with :rspec
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'active_support'
|
6
|
+
require 'action_pack'
|
7
|
+
require 'action_view'
|
8
|
+
require 'action_controller'
|
9
|
+
require 'action_dispatch'
|
10
|
+
|
11
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic-globalize3'))
|
12
|
+
|
13
|
+
# set up globalize3 and models (borrowed from globalize3)
|
14
|
+
require 'fileutils'
|
15
|
+
require 'logger'
|
16
|
+
tmpdir = File.join(File.dirname(__FILE__), "../tmp")
|
17
|
+
FileUtils.mkdir(tmpdir) unless File.exist?(tmpdir)
|
18
|
+
log = File.expand_path(File.join(tmpdir, "globalize3_test.log"))
|
19
|
+
FileUtils.touch(log) unless File.exists?(log)
|
20
|
+
ActiveRecord::Base.logger = Logger.new(log)
|
21
|
+
ActiveRecord::LogSubscriber.attach_to(:active_record)
|
22
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
23
|
+
require File.expand_path('../data/schema', __FILE__)
|
24
|
+
require File.expand_path('../data/models', __FILE__)
|
25
|
+
I18n.locale = I18n.default_locale = :en
|
26
|
+
Globalize.locale = nil
|
27
|
+
|
28
|
+
# set up formtastic helper (borrowed from formtastic)
|
29
|
+
module FormtasticSpecHelper
|
30
|
+
include ActionPack
|
31
|
+
include ActionView::Context if defined?(ActionView::Context)
|
32
|
+
include ActionController::RecordIdentifier
|
33
|
+
include ActionView::Helpers::FormHelper
|
34
|
+
include ActionView::Helpers::FormTagHelper
|
35
|
+
include ActionView::Helpers::FormOptionsHelper
|
36
|
+
include ActionView::Helpers::UrlHelper
|
37
|
+
include ActionView::Helpers::TagHelper
|
38
|
+
include ActionView::Helpers::TextHelper
|
39
|
+
include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper)
|
40
|
+
include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper)
|
41
|
+
include ActionView::Helpers::DateHelper
|
42
|
+
include ActionView::Helpers::CaptureHelper
|
43
|
+
include ActionView::Helpers::AssetTagHelper
|
44
|
+
include ActiveSupport
|
45
|
+
include ActionController::PolymorphicRoutes if defined?(ActionController::PolymorphicRoutes)
|
46
|
+
include ActionDispatch::Routing::PolymorphicRoutes
|
47
|
+
include AbstractController::UrlFor if defined?(AbstractController::UrlFor)
|
48
|
+
include ActionView::RecordIdentifier if defined?(ActionView::RecordIdentifier)
|
49
|
+
|
50
|
+
include Formtastic::Helpers::FormHelper
|
51
|
+
|
52
|
+
def self.included(base)
|
53
|
+
base.class_eval do
|
54
|
+
|
55
|
+
def protect_against_forgery?
|
56
|
+
false
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: formtastic-globalize3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Maximilian Herold
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-03-21 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: formtastic
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
version: "2.0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: globalize3
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 13
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 3
|
47
|
+
version: "0.3"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: bundler
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 9
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 3
|
62
|
+
version: "1.3"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: appraisal
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 9
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
- 5
|
77
|
+
- 1
|
78
|
+
version: 0.5.1
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rspec-rails
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 47
|
90
|
+
segments:
|
91
|
+
- 2
|
92
|
+
- 8
|
93
|
+
- 0
|
94
|
+
version: 2.8.0
|
95
|
+
type: :development
|
96
|
+
version_requirements: *id005
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
prerelease: false
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
type: :development
|
110
|
+
version_requirements: *id006
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
prerelease: false
|
114
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
type: :development
|
124
|
+
version_requirements: *id007
|
125
|
+
description: patch for formtastic to make its magical column type determination work with globalize3 translated models
|
126
|
+
email:
|
127
|
+
- herold@emjot.de
|
128
|
+
executables: []
|
129
|
+
|
130
|
+
extensions: []
|
131
|
+
|
132
|
+
extra_rdoc_files: []
|
133
|
+
|
134
|
+
files:
|
135
|
+
- .gitignore
|
136
|
+
- .rspec
|
137
|
+
- .travis.yml
|
138
|
+
- Appraisals
|
139
|
+
- Gemfile
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- formtastic-globalize3.gemspec
|
144
|
+
- gemfiles/rails_3.1.gemfile
|
145
|
+
- gemfiles/rails_3.2.gemfile
|
146
|
+
- lib/formtastic-globalize3.rb
|
147
|
+
- lib/formtastic/globalize3/helpers/input_helper.rb
|
148
|
+
- lib/formtastic/globalize3/version.rb
|
149
|
+
- spec/data/models.rb
|
150
|
+
- spec/data/schema.rb
|
151
|
+
- spec/helpers/input_helper_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
homepage: https://github.com/emjot/formtastic-globalize3
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
hash: 3
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
version: "0"
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
hash: 3
|
176
|
+
segments:
|
177
|
+
- 0
|
178
|
+
version: "0"
|
179
|
+
requirements: []
|
180
|
+
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 1.8.15
|
183
|
+
signing_key:
|
184
|
+
specification_version: 3
|
185
|
+
summary: formtastic features for globalize3 translated models
|
186
|
+
test_files:
|
187
|
+
- spec/data/models.rb
|
188
|
+
- spec/data/schema.rb
|
189
|
+
- spec/helpers/input_helper_spec.rb
|
190
|
+
- spec/spec_helper.rb
|
191
|
+
has_rdoc:
|