custom_fields 1.1.0.rc1 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README.textile +14 -6
- data/config/locales/fr.yml +5 -1
- data/lib/custom_fields.rb +11 -37
- data/lib/custom_fields/extensions/carrierwave.rb +25 -0
- data/lib/custom_fields/extensions/mongoid/document.rb +12 -50
- data/lib/custom_fields/extensions/mongoid/factory.rb +20 -0
- data/lib/custom_fields/extensions/mongoid/fields.rb +29 -0
- data/lib/custom_fields/extensions/mongoid/fields/i18n.rb +53 -0
- data/lib/custom_fields/extensions/mongoid/fields/internal/localized.rb +84 -0
- data/lib/custom_fields/extensions/mongoid/relations/referenced/many.rb +29 -0
- data/lib/custom_fields/field.rb +44 -175
- data/lib/custom_fields/source.rb +333 -0
- data/lib/custom_fields/target.rb +90 -0
- data/lib/custom_fields/types/boolean.rb +26 -3
- data/lib/custom_fields/types/date.rb +36 -24
- data/lib/custom_fields/types/default.rb +44 -24
- data/lib/custom_fields/types/file.rb +35 -17
- data/lib/custom_fields/types/select.rb +184 -0
- data/lib/custom_fields/types/string.rb +25 -6
- data/lib/custom_fields/types/text.rb +35 -8
- data/lib/custom_fields/types_old/boolean.rb +13 -0
- data/lib/custom_fields/{types → types_old}/category.rb +0 -0
- data/lib/custom_fields/types_old/date.rb +49 -0
- data/lib/custom_fields/types_old/default.rb +44 -0
- data/lib/custom_fields/types_old/file.rb +27 -0
- data/lib/custom_fields/{types → types_old}/has_many.rb +0 -0
- data/lib/custom_fields/{types → types_old}/has_many/proxy_collection.rb +0 -0
- data/lib/custom_fields/{types → types_old}/has_many/reverse_lookup_proxy_collection.rb +0 -0
- data/lib/custom_fields/{types → types_old}/has_one.rb +0 -0
- data/lib/custom_fields/types_old/string.rb +13 -0
- data/lib/custom_fields/types_old/text.rb +15 -0
- data/lib/custom_fields/version.rb +1 -1
- metadata +115 -91
- data/lib/custom_fields/custom_fields_for.rb +0 -350
- data/lib/custom_fields/extensions/mongoid/relations/accessors.rb +0 -31
- data/lib/custom_fields/extensions/mongoid/relations/builders.rb +0 -30
- data/lib/custom_fields/proxy_class/base.rb +0 -112
- data/lib/custom_fields/proxy_class/builder.rb +0 -60
- data/lib/custom_fields/proxy_class/helper.rb +0 -57
- data/lib/custom_fields/self_metadata.rb +0 -30
@@ -1,13 +1,32 @@
|
|
1
1
|
module CustomFields
|
2
|
+
|
2
3
|
module Types
|
4
|
+
|
3
5
|
module String
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
|
7
|
+
module Field; end
|
8
|
+
|
9
|
+
module Target
|
10
|
+
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
|
15
|
+
# Adds a string field
|
16
|
+
#
|
17
|
+
# @param [ Class ] klass The class to modify
|
18
|
+
# @param [ Hash ] rule It contains the name of the field and if it is required or not
|
19
|
+
#
|
20
|
+
def apply_string_custom_field(klass, rule)
|
21
|
+
apply_custom_field(klass, rule)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
9
26
|
end
|
10
|
-
|
27
|
+
|
11
28
|
end
|
29
|
+
|
12
30
|
end
|
31
|
+
|
13
32
|
end
|
@@ -1,15 +1,42 @@
|
|
1
1
|
module CustomFields
|
2
|
+
|
2
3
|
module Types
|
4
|
+
|
3
5
|
module Text
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
|
7
|
+
module Field
|
8
|
+
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
|
13
|
+
field :text_formatting, :default => 'html'
|
14
|
+
|
15
|
+
end
|
16
|
+
|
11
17
|
end
|
12
|
-
|
18
|
+
|
19
|
+
module Target
|
20
|
+
|
21
|
+
extend ActiveSupport::Concern
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
|
25
|
+
# Adds a text field (simply a string field)
|
26
|
+
#
|
27
|
+
# @param [ Class ] klass The class to modify
|
28
|
+
# @param [ Hash ] rule It contains the name of the field and if it is required or not
|
29
|
+
#
|
30
|
+
def apply_text_custom_field(klass, rule)
|
31
|
+
apply_custom_field(klass, rule)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
13
38
|
end
|
39
|
+
|
14
40
|
end
|
41
|
+
|
15
42
|
end
|
File without changes
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module CustomFields
|
2
|
+
module Types
|
3
|
+
module Date
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
register_type :date, ::Date
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
|
13
|
+
def apply_date_type(klass)
|
14
|
+
|
15
|
+
klass.class_eval <<-EOF
|
16
|
+
|
17
|
+
def #{self.safe_alias}
|
18
|
+
self.#{self._name}
|
19
|
+
end
|
20
|
+
|
21
|
+
def #{self.safe_alias}=(value)
|
22
|
+
if value.is_a?(::String) && !value.blank?
|
23
|
+
date = ::Date._strptime(value, I18n.t('date.formats.default'))
|
24
|
+
value = ::Date.new(date[:year], date[:mon], date[:mday])
|
25
|
+
end
|
26
|
+
|
27
|
+
self.#{self._name} = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def formatted_#{self.safe_alias}
|
31
|
+
self.#{self._name}.strftime(I18n.t('date.formats.default')) rescue nil
|
32
|
+
end
|
33
|
+
|
34
|
+
alias formatted_#{self.safe_alias}= #{self.safe_alias}=
|
35
|
+
EOF
|
36
|
+
|
37
|
+
def add_date_validation(klass)
|
38
|
+
if self.required?
|
39
|
+
klass.validates_presence_of self.safe_alias.to_sym, :"formatted_#{self.safe_alias}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module CustomFields
|
2
|
+
module Types
|
3
|
+
module Default
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
cattr_accessor :field_types
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
|
12
|
+
def apply_default_type(klass)
|
13
|
+
klass.class_eval <<-EOF
|
14
|
+
alias :#{self.safe_alias} :#{self._name}
|
15
|
+
alias :#{self.safe_alias}= :#{self._name}=
|
16
|
+
EOF
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_default_validation(klass)
|
20
|
+
# add validation if required field
|
21
|
+
if self.required?
|
22
|
+
klass.validates_presence_of self.safe_alias.to_sym
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
module ClassMethods
|
29
|
+
|
30
|
+
def register_type(kind, klass = ::String)
|
31
|
+
self.field_types ||= {}
|
32
|
+
self.field_types[kind.to_sym] = klass unless klass.nil?
|
33
|
+
|
34
|
+
self.class_eval <<-EOF
|
35
|
+
def #{kind.to_s}?
|
36
|
+
self.kind.downcase == '#{kind}' rescue false
|
37
|
+
end
|
38
|
+
EOF
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module CustomFields
|
2
|
+
module Types
|
3
|
+
module File
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
register_type :file, nil # do not create the default field
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
|
13
|
+
def apply_file_type(klass)
|
14
|
+
|
15
|
+
klass.mount_uploader self._name, FileUploader
|
16
|
+
|
17
|
+
self.apply_default_type(klass)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class FileUploader < ::CarrierWave::Uploader::Base
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,151 +1,179 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: custom_fields
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0.rc1
|
4
5
|
prerelease: 6
|
5
|
-
version: 1.1.0.rc1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Didier Lafforgue
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-01-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: mongoid
|
17
|
-
requirement: &
|
16
|
+
requirement: &2158024560 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.4.0
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
26
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *2158024560
|
25
|
+
- !ruby/object:Gem::Dependency
|
27
26
|
name: activesupport
|
28
|
-
requirement: &
|
27
|
+
requirement: &2158023800 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
|
-
requirements:
|
29
|
+
requirements:
|
31
30
|
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 3.1.
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.1.3
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
37
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *2158023800
|
36
|
+
- !ruby/object:Gem::Dependency
|
38
37
|
name: carrierwave-mongoid
|
39
|
-
requirement: &
|
38
|
+
requirement: &2158023040 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
|
-
requirements:
|
40
|
+
requirements:
|
42
41
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
42
|
+
- !ruby/object:Gem::Version
|
44
43
|
version: 0.1.3
|
45
44
|
type: :runtime
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
48
|
-
- !ruby/object:Gem::Dependency
|
46
|
+
version_requirements: *2158023040
|
47
|
+
- !ruby/object:Gem::Dependency
|
49
48
|
name: yard
|
50
|
-
requirement: &
|
49
|
+
requirement: &2158021900 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
|
-
requirements:
|
51
|
+
requirements:
|
53
52
|
- - ~>
|
54
|
-
- !ruby/object:Gem::Version
|
53
|
+
- !ruby/object:Gem::Version
|
55
54
|
version: 0.7.3
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
59
|
-
- !ruby/object:Gem::Dependency
|
57
|
+
version_requirements: *2158021900
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bson
|
60
|
+
requirement: &2158021300 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.3.1
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2158021300
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mongo
|
71
|
+
requirement: &2158020100 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.3.1
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2158020100
|
80
|
+
- !ruby/object:Gem::Dependency
|
60
81
|
name: bson_ext
|
61
|
-
requirement: &
|
82
|
+
requirement: &2158018640 !ruby/object:Gem::Requirement
|
62
83
|
none: false
|
63
|
-
requirements:
|
84
|
+
requirements:
|
64
85
|
- - ~>
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 1.
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.3.1
|
67
88
|
type: :development
|
68
89
|
prerelease: false
|
69
|
-
version_requirements: *
|
70
|
-
- !ruby/object:Gem::Dependency
|
90
|
+
version_requirements: *2158018640
|
91
|
+
- !ruby/object:Gem::Dependency
|
71
92
|
name: mocha
|
72
|
-
requirement: &
|
93
|
+
requirement: &2158033920 !ruby/object:Gem::Requirement
|
73
94
|
none: false
|
74
|
-
requirements:
|
95
|
+
requirements:
|
75
96
|
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
97
|
+
- !ruby/object:Gem::Version
|
77
98
|
version: 0.9.12
|
78
99
|
type: :development
|
79
100
|
prerelease: false
|
80
|
-
version_requirements: *
|
81
|
-
- !ruby/object:Gem::Dependency
|
101
|
+
version_requirements: *2158033920
|
102
|
+
- !ruby/object:Gem::Dependency
|
82
103
|
name: rspec
|
83
|
-
requirement: &
|
104
|
+
requirement: &2158032420 !ruby/object:Gem::Requirement
|
84
105
|
none: false
|
85
|
-
requirements:
|
106
|
+
requirements:
|
86
107
|
- - ~>
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version:
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '2.6'
|
89
110
|
type: :development
|
90
111
|
prerelease: false
|
91
|
-
version_requirements: *
|
92
|
-
- !ruby/object:Gem::Dependency
|
112
|
+
version_requirements: *2158032420
|
113
|
+
- !ruby/object:Gem::Dependency
|
93
114
|
name: database_cleaner
|
94
|
-
requirement: &
|
115
|
+
requirement: &2158031400 !ruby/object:Gem::Requirement
|
95
116
|
none: false
|
96
|
-
requirements:
|
117
|
+
requirements:
|
97
118
|
- - ~>
|
98
|
-
- !ruby/object:Gem::Version
|
119
|
+
- !ruby/object:Gem::Version
|
99
120
|
version: 0.6.7
|
100
121
|
type: :development
|
101
122
|
prerelease: false
|
102
|
-
version_requirements: *
|
103
|
-
- !ruby/object:Gem::Dependency
|
123
|
+
version_requirements: *2158031400
|
124
|
+
- !ruby/object:Gem::Dependency
|
104
125
|
name: RedCloth
|
105
|
-
requirement: &
|
126
|
+
requirement: &2158029200 !ruby/object:Gem::Requirement
|
106
127
|
none: false
|
107
|
-
requirements:
|
128
|
+
requirements:
|
108
129
|
- - ~>
|
109
|
-
- !ruby/object:Gem::Version
|
130
|
+
- !ruby/object:Gem::Version
|
110
131
|
version: 4.2.8
|
111
132
|
type: :development
|
112
133
|
prerelease: false
|
113
|
-
version_requirements: *
|
114
|
-
description: Manage custom fields to a mongoid document or a collection. This module
|
115
|
-
|
134
|
+
version_requirements: *2158029200
|
135
|
+
description: Manage custom fields to a mongoid document or a collection. This module
|
136
|
+
is one of the core features we implemented in our custom cms named Locomotive.
|
137
|
+
email:
|
116
138
|
- didier@nocoffee.fr
|
117
139
|
executables: []
|
118
|
-
|
119
140
|
extensions: []
|
120
|
-
|
121
|
-
extra_rdoc_files:
|
141
|
+
extra_rdoc_files:
|
122
142
|
- MIT-LICENSE
|
123
143
|
- README.textile
|
124
|
-
files:
|
144
|
+
files:
|
125
145
|
- init.rb
|
126
146
|
- MIT-LICENSE
|
127
147
|
- README.textile
|
128
|
-
- lib/custom_fields/custom_fields_for.rb
|
129
148
|
- lib/custom_fields/extensions/active_support.rb
|
149
|
+
- lib/custom_fields/extensions/carrierwave.rb
|
130
150
|
- lib/custom_fields/extensions/mongoid/document.rb
|
131
|
-
- lib/custom_fields/extensions/mongoid/
|
132
|
-
- lib/custom_fields/extensions/mongoid/
|
151
|
+
- lib/custom_fields/extensions/mongoid/factory.rb
|
152
|
+
- lib/custom_fields/extensions/mongoid/fields/i18n.rb
|
153
|
+
- lib/custom_fields/extensions/mongoid/fields/internal/localized.rb
|
154
|
+
- lib/custom_fields/extensions/mongoid/fields.rb
|
155
|
+
- lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
|
133
156
|
- lib/custom_fields/field.rb
|
134
|
-
- lib/custom_fields/
|
135
|
-
- lib/custom_fields/
|
136
|
-
- lib/custom_fields/proxy_class/helper.rb
|
137
|
-
- lib/custom_fields/self_metadata.rb
|
157
|
+
- lib/custom_fields/source.rb
|
158
|
+
- lib/custom_fields/target.rb
|
138
159
|
- lib/custom_fields/types/boolean.rb
|
139
|
-
- lib/custom_fields/types/category.rb
|
140
160
|
- lib/custom_fields/types/date.rb
|
141
161
|
- lib/custom_fields/types/default.rb
|
142
162
|
- lib/custom_fields/types/file.rb
|
143
|
-
- lib/custom_fields/types/
|
144
|
-
- lib/custom_fields/types/has_many/reverse_lookup_proxy_collection.rb
|
145
|
-
- lib/custom_fields/types/has_many.rb
|
146
|
-
- lib/custom_fields/types/has_one.rb
|
163
|
+
- lib/custom_fields/types/select.rb
|
147
164
|
- lib/custom_fields/types/string.rb
|
148
165
|
- lib/custom_fields/types/text.rb
|
166
|
+
- lib/custom_fields/types_old/boolean.rb
|
167
|
+
- lib/custom_fields/types_old/category.rb
|
168
|
+
- lib/custom_fields/types_old/date.rb
|
169
|
+
- lib/custom_fields/types_old/default.rb
|
170
|
+
- lib/custom_fields/types_old/file.rb
|
171
|
+
- lib/custom_fields/types_old/has_many/proxy_collection.rb
|
172
|
+
- lib/custom_fields/types_old/has_many/reverse_lookup_proxy_collection.rb
|
173
|
+
- lib/custom_fields/types_old/has_many.rb
|
174
|
+
- lib/custom_fields/types_old/has_one.rb
|
175
|
+
- lib/custom_fields/types_old/string.rb
|
176
|
+
- lib/custom_fields/types_old/text.rb
|
149
177
|
- lib/custom_fields/version.rb
|
150
178
|
- lib/custom_fields.rb
|
151
179
|
- config/locales/de.yml
|
@@ -154,33 +182,29 @@ files:
|
|
154
182
|
- config/locales/pt-BR.yml
|
155
183
|
homepage: http://github.com/locomotivecms/custom_fields
|
156
184
|
licenses: []
|
157
|
-
|
158
185
|
post_install_message:
|
159
186
|
rdoc_options: []
|
160
|
-
|
161
|
-
require_paths:
|
187
|
+
require_paths:
|
162
188
|
- lib
|
163
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
190
|
none: false
|
165
|
-
requirements:
|
166
|
-
- -
|
167
|
-
- !ruby/object:Gem::Version
|
168
|
-
|
169
|
-
segments:
|
191
|
+
requirements:
|
192
|
+
- - ! '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
segments:
|
170
196
|
- 0
|
171
|
-
|
172
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
|
+
hash: 159417792925729594
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
199
|
none: false
|
174
|
-
requirements:
|
175
|
-
- -
|
176
|
-
- !ruby/object:Gem::Version
|
200
|
+
requirements:
|
201
|
+
- - ! '>='
|
202
|
+
- !ruby/object:Gem::Version
|
177
203
|
version: 1.3.6
|
178
204
|
requirements: []
|
179
|
-
|
180
205
|
rubyforge_project: nowarning
|
181
206
|
rubygems_version: 1.8.10
|
182
207
|
signing_key:
|
183
208
|
specification_version: 3
|
184
209
|
summary: Custom fields extension for Mongoid
|
185
210
|
test_files: []
|
186
|
-
|