administrate 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of administrate might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/views/fields/form/_has_one.html.erb +7 -0
- data/app/views/fields/index/_has_one.html.erb +3 -0
- data/app/views/fields/show/_has_one.html.erb +3 -0
- data/lib/administrate/base_dashboard.rb +4 -22
- data/lib/administrate/fields/base.rb +8 -1
- data/lib/administrate/fields/deferred.rb +20 -0
- data/lib/administrate/fields/has_many.rb +1 -1
- data/lib/administrate/fields/has_one.rb +11 -0
- data/lib/administrate/page/base.rb +1 -1
- data/lib/administrate/version.rb +1 -1
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +29 -4
- data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 683ee0c8cf867c553a2c367063d9112cd8ff968f
|
4
|
+
data.tar.gz: be6336fc10bc73444eb2d42a5c95f7519252dc42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84a3b33e1464a4aff24661891d7333c71bd1809131994cb7af9993735230e81765fffcf0f90dc861e79fa006a06a26ca8dda37b5a045221b1e6ac13c55d0d669
|
7
|
+
data.tar.gz: ca89ca985db441fb3aa69bf6dfe4e5ddee6d268a1c1b034a64eac8b0a5b0b6bb27986a7f9ed359d4c48fac6c9ce0238edee87ced64bf667f89fefa783ab98c01
|
@@ -1,36 +1,18 @@
|
|
1
1
|
require "administrate/fields/belongs_to"
|
2
2
|
require "administrate/fields/email"
|
3
3
|
require "administrate/fields/has_many"
|
4
|
+
require "administrate/fields/has_one"
|
4
5
|
require "administrate/fields/image"
|
5
6
|
require "administrate/fields/string"
|
6
7
|
|
7
8
|
module Administrate
|
8
9
|
class BaseDashboard
|
10
|
+
include Administrate
|
11
|
+
|
9
12
|
def permitted_attributes
|
10
13
|
form_attributes.map do |attr|
|
11
|
-
|
14
|
+
attribute_types[attr].permitted_attribute(attr)
|
12
15
|
end.uniq
|
13
16
|
end
|
14
|
-
|
15
|
-
def field_class(attr)
|
16
|
-
field_registry.fetch(attribute_types[attr])
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def field_registry
|
22
|
-
{
|
23
|
-
belongs_to: Administrate::Field::BelongsTo,
|
24
|
-
boolean: Administrate::Field::String,
|
25
|
-
datetime: Administrate::Field::String,
|
26
|
-
email: Administrate::Field::Email,
|
27
|
-
float: Administrate::Field::String,
|
28
|
-
has_many: Administrate::Field::HasMany,
|
29
|
-
image: Administrate::Field::Image,
|
30
|
-
integer: Administrate::Field::String,
|
31
|
-
string: Administrate::Field::String,
|
32
|
-
text: Administrate::Field::String,
|
33
|
-
}
|
34
|
-
end
|
35
17
|
end
|
36
18
|
end
|
@@ -1,10 +1,17 @@
|
|
1
|
+
require_relative "deferred"
|
2
|
+
|
1
3
|
module Administrate
|
2
4
|
module Field
|
3
5
|
class Base
|
4
|
-
def
|
6
|
+
def self.with_options(options = {})
|
7
|
+
Deferred.new(self, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(attribute, data, page, options = {})
|
5
11
|
@attribute = attribute
|
6
12
|
@data = data
|
7
13
|
@page = page
|
14
|
+
@options = options
|
8
15
|
end
|
9
16
|
|
10
17
|
def self.permitted_attribute(attr)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Administrate
|
2
|
+
module Field
|
3
|
+
class Deferred
|
4
|
+
def initialize(klass, options = {})
|
5
|
+
@klass = klass
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def new(*args)
|
10
|
+
klass.new(*args, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
delegate :permitted_attribute, to: :klass
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :klass, :options
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/administrate/version.rb
CHANGED
@@ -25,22 +25,47 @@ module Administrate
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def field_type(attribute)
|
28
|
-
klass.type_for_attribute(attribute).type
|
28
|
+
if klass.type_for_attribute(attribute).type
|
29
|
+
default_field_type
|
30
|
+
else
|
29
31
|
association_type(attribute)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_field_type
|
36
|
+
"Field::String"
|
30
37
|
end
|
31
38
|
|
32
39
|
def association_type(attribute)
|
33
40
|
reflection = klass.reflections[attribute.to_s]
|
34
|
-
if reflection.
|
35
|
-
|
41
|
+
if reflection.has_one?
|
42
|
+
"Field::HasOne"
|
43
|
+
elsif reflection.collection?
|
44
|
+
"Field::HasMany" + has_many_options_string(reflection)
|
36
45
|
else
|
37
|
-
|
46
|
+
"Field::BelongsTo"
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
41
50
|
def klass
|
42
51
|
@klass ||= Object.const_get(class_name)
|
43
52
|
end
|
53
|
+
|
54
|
+
def has_many_options_string(reflection)
|
55
|
+
if reflection.class_name != reflection.name.to_s.classify
|
56
|
+
options_string(class_name: reflection.class_name)
|
57
|
+
else
|
58
|
+
""
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def options_string(options)
|
63
|
+
".with_options(#{inspect_hash_as_ruby(options)})"
|
64
|
+
end
|
65
|
+
|
66
|
+
def inspect_hash_as_ruby(hash)
|
67
|
+
hash.map { |key, value| "#{key}: #{value.inspect}" }.join(", ")
|
68
|
+
end
|
44
69
|
end
|
45
70
|
end
|
46
71
|
end
|
@@ -10,7 +10,7 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
|
|
10
10
|
# on pages throughout the dashboard.
|
11
11
|
def attribute_types
|
12
12
|
{<% attributes.each do |attr| %>
|
13
|
-
<%= attr %>:
|
13
|
+
<%= attr %>: <%= field_type(attr) %>,<% end %>
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: administrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grayson Wright
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neat
|
@@ -141,16 +141,19 @@ files:
|
|
141
141
|
- app/views/fields/form/_belongs_to.html.erb
|
142
142
|
- app/views/fields/form/_email.html.erb
|
143
143
|
- app/views/fields/form/_has_many.html.erb
|
144
|
+
- app/views/fields/form/_has_one.html.erb
|
144
145
|
- app/views/fields/form/_image.html.erb
|
145
146
|
- app/views/fields/form/_string.html.erb
|
146
147
|
- app/views/fields/index/_belongs_to.html.erb
|
147
148
|
- app/views/fields/index/_email.html.erb
|
148
149
|
- app/views/fields/index/_has_many.html.erb
|
150
|
+
- app/views/fields/index/_has_one.html.erb
|
149
151
|
- app/views/fields/index/_image.html.erb
|
150
152
|
- app/views/fields/index/_string.html.erb
|
151
153
|
- app/views/fields/show/_belongs_to.html.erb
|
152
154
|
- app/views/fields/show/_email.html.erb
|
153
155
|
- app/views/fields/show/_has_many.html.erb
|
156
|
+
- app/views/fields/show/_has_one.html.erb
|
154
157
|
- app/views/fields/show/_image.html.erb
|
155
158
|
- app/views/fields/show/_string.html.erb
|
156
159
|
- app/views/layouts/administrate/application.html.erb
|
@@ -161,8 +164,10 @@ files:
|
|
161
164
|
- lib/administrate/engine.rb
|
162
165
|
- lib/administrate/fields/base.rb
|
163
166
|
- lib/administrate/fields/belongs_to.rb
|
167
|
+
- lib/administrate/fields/deferred.rb
|
164
168
|
- lib/administrate/fields/email.rb
|
165
169
|
- lib/administrate/fields/has_many.rb
|
170
|
+
- lib/administrate/fields/has_one.rb
|
166
171
|
- lib/administrate/fields/image.rb
|
167
172
|
- lib/administrate/fields/string.rb
|
168
173
|
- lib/administrate/namespace.rb
|