puffer 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/app/views/puffer/index.html.erb +7 -7
- data/app/views/puffer/show.html.erb +3 -3
- data/lib/generators/puffer/install/install_generator.rb +9 -0
- data/lib/generators/puffer/install/templates/puffer/javascripts/application.js +2 -0
- data/lib/generators/puffer/install/templates/puffer/javascripts/controls.js +965 -0
- data/lib/generators/puffer/install/templates/puffer/javascripts/dragdrop.js +974 -0
- data/lib/generators/puffer/install/templates/puffer/javascripts/effects.js +1123 -0
- data/lib/generators/puffer/install/templates/puffer/javascripts/prototype.js +6001 -0
- data/lib/generators/puffer/install/templates/puffer/javascripts/rails.js +175 -0
- data/lib/generators/puffer/install/templates/puffer.rb +0 -0
- data/lib/puffer/base.rb +1 -1
- data/lib/puffer/controller/dsl.rb +9 -10
- data/lib/puffer/controller/helpers.rb +1 -9
- data/lib/puffer/controller/mutate.rb +0 -4
- data/lib/puffer/fields/field.rb +58 -0
- data/lib/puffer/fields.rb +17 -0
- data/lib/puffer/resource/scoping.rb +6 -0
- data/lib/puffer/resource.rb +5 -5
- data/puffer.gemspec +17 -8
- data/spec/dummy/app/controllers/admin/categories_controller.rb +10 -0
- data/spec/dummy/app/controllers/admin/posts_controller.rb +12 -0
- data/spec/dummy/app/controllers/admin/profiles_controller.rb +14 -0
- data/spec/dummy/app/controllers/admin/tags_controller.rb +8 -0
- data/spec/lib/fields_spec.rb +54 -0
- data/spec/lib/params_spec.rb +1 -1
- data/spec/lib/resource_spec.rb +37 -3
- data/spec/spec_helper.rb +2 -1
- metadata +30 -19
- data/lib/puffer/field.rb +0 -88
data/spec/lib/resource_spec.rb
CHANGED
@@ -156,36 +156,59 @@ describe Puffer::Resource do
|
|
156
156
|
resource = Puffer::Resource.new default_params
|
157
157
|
|
158
158
|
Category.stub(:new) {@category}
|
159
|
+
|
159
160
|
resource.new_member.should == @category
|
160
161
|
end
|
161
162
|
|
163
|
+
it "no parent with attributes" do
|
164
|
+
resource = Puffer::Resource.new default_params.merge(:category => {:title => 'my new title'})
|
165
|
+
|
166
|
+
resource.new_member.title.should == 'my new title'
|
167
|
+
end
|
168
|
+
|
162
169
|
it "plural parent" do
|
163
170
|
resource = Puffer::Resource.new default_params.merge(:ancestors => [:posts], :post_id => 42)
|
164
171
|
|
165
172
|
@categories = @post.categories
|
166
|
-
|
167
173
|
Post.stub(:find).with(42) {@post}
|
168
174
|
@categories.stub(:new) {@category}
|
175
|
+
|
169
176
|
resource.new_member.should == @category
|
170
177
|
end
|
171
178
|
|
179
|
+
it "plural parent with attributes" do
|
180
|
+
resource = Puffer::Resource.new default_params.merge(:ancestors => [:posts], :post_id => 42, :category => {:title => 'my new title'})
|
181
|
+
|
182
|
+
@categories = @post.categories
|
183
|
+
Post.stub(:find).with(42) {@post}
|
184
|
+
|
185
|
+
resource.new_member.title.should == 'my new title'
|
186
|
+
end
|
187
|
+
|
172
188
|
it "singular" do
|
173
189
|
resource = Puffer::Resource.new default_params.merge(:controller => 'admin/profiles', :plural => false, :ancestors => [:users], :user_id => 42)
|
174
190
|
|
175
191
|
@profile = @user.profile
|
176
|
-
|
177
192
|
User.stub(:find).with(42) {@user}
|
178
193
|
@user.stub(:build_profile) {@profile}
|
179
194
|
|
180
195
|
resource.new_member.should == @profile
|
181
196
|
end
|
182
197
|
|
198
|
+
it "singular with attributes" do
|
199
|
+
resource = Puffer::Resource.new default_params.merge(:controller => 'admin/profiles', :plural => false, :ancestors => [:users], :user_id => 42, :profile => {:name => 'my new name'})
|
200
|
+
|
201
|
+
@profile = @user.profile
|
202
|
+
User.stub(:find).with(42) {@user}
|
203
|
+
|
204
|
+
resource.new_member.name.should == 'my new name'
|
205
|
+
end
|
206
|
+
|
183
207
|
it "singular parent" do
|
184
208
|
resource = Puffer::Resource.new default_params.merge(:controller => 'admin/tags', :ancestors => [:users, :profile], :user_id => 42)
|
185
209
|
|
186
210
|
@profile = @user.profile
|
187
211
|
@tag = @profile.tags.first
|
188
|
-
|
189
212
|
User.stub(:find).with(42) {@user}
|
190
213
|
@user.stub(:profile) {@profile}
|
191
214
|
@profile.tags.stub(:new) {@tag}
|
@@ -193,6 +216,17 @@ describe Puffer::Resource do
|
|
193
216
|
resource.new_member.should == @tag
|
194
217
|
end
|
195
218
|
|
219
|
+
it "singular parent with attributes" do
|
220
|
+
resource = Puffer::Resource.new default_params.merge(:controller => 'admin/tags', :ancestors => [:users, :profile], :user_id => 42, :tag => {:name => 'my new name'})
|
221
|
+
|
222
|
+
@profile = @user.profile
|
223
|
+
@tag = @profile.tags.first
|
224
|
+
User.stub(:find).with(42) {@user}
|
225
|
+
@user.stub(:profile) {@profile}
|
226
|
+
|
227
|
+
resource.new_member.name.should == 'my new name'
|
228
|
+
end
|
229
|
+
|
196
230
|
end
|
197
231
|
|
198
232
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puffer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pyromaniac
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-03 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -32,24 +32,25 @@ dependencies:
|
|
32
32
|
version: 3.0.3
|
33
33
|
requirement: *id001
|
34
34
|
prerelease: false
|
35
|
-
type: :runtime
|
36
35
|
name: rails
|
36
|
+
type: :runtime
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
43
|
+
hash: 1923831917
|
44
44
|
segments:
|
45
45
|
- 3
|
46
46
|
- 0
|
47
|
-
-
|
48
|
-
|
47
|
+
- pre
|
48
|
+
- 2
|
49
|
+
version: 3.0.pre2
|
49
50
|
requirement: *id002
|
50
51
|
prerelease: false
|
51
|
-
type: :runtime
|
52
52
|
name: will_paginate
|
53
|
+
type: :runtime
|
53
54
|
- !ruby/object:Gem::Dependency
|
54
55
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
56
|
none: false
|
@@ -64,8 +65,8 @@ dependencies:
|
|
64
65
|
version: 0.4.0
|
65
66
|
requirement: *id003
|
66
67
|
prerelease: false
|
67
|
-
type: :development
|
68
68
|
name: capybara
|
69
|
+
type: :development
|
69
70
|
- !ruby/object:Gem::Dependency
|
70
71
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
72
|
none: false
|
@@ -78,8 +79,8 @@ dependencies:
|
|
78
79
|
version: "0"
|
79
80
|
requirement: *id004
|
80
81
|
prerelease: false
|
81
|
-
type: :development
|
82
82
|
name: sqlite3-ruby
|
83
|
+
type: :development
|
83
84
|
- !ruby/object:Gem::Dependency
|
84
85
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
85
86
|
none: false
|
@@ -92,8 +93,8 @@ dependencies:
|
|
92
93
|
version: "0"
|
93
94
|
requirement: *id005
|
94
95
|
prerelease: false
|
95
|
-
type: :development
|
96
96
|
name: rspec-rails
|
97
|
+
type: :development
|
97
98
|
- !ruby/object:Gem::Dependency
|
98
99
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
99
100
|
none: false
|
@@ -106,8 +107,8 @@ dependencies:
|
|
106
107
|
version: "0"
|
107
108
|
requirement: *id006
|
108
109
|
prerelease: false
|
109
|
-
type: :development
|
110
110
|
name: autotest
|
111
|
+
type: :development
|
111
112
|
- !ruby/object:Gem::Dependency
|
112
113
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
113
114
|
none: false
|
@@ -120,8 +121,8 @@ dependencies:
|
|
120
121
|
version: "0"
|
121
122
|
requirement: *id007
|
122
123
|
prerelease: false
|
123
|
-
type: :development
|
124
124
|
name: forgery
|
125
|
+
type: :development
|
125
126
|
- !ruby/object:Gem::Dependency
|
126
127
|
version_requirements: &id008 !ruby/object:Gem::Requirement
|
127
128
|
none: false
|
@@ -134,8 +135,8 @@ dependencies:
|
|
134
135
|
version: "0"
|
135
136
|
requirement: *id008
|
136
137
|
prerelease: false
|
137
|
-
type: :development
|
138
138
|
name: fabrication
|
139
|
+
type: :development
|
139
140
|
- !ruby/object:Gem::Dependency
|
140
141
|
version_requirements: &id009 !ruby/object:Gem::Requirement
|
141
142
|
none: false
|
@@ -148,8 +149,8 @@ dependencies:
|
|
148
149
|
version: "0"
|
149
150
|
requirement: *id009
|
150
151
|
prerelease: false
|
151
|
-
type: :development
|
152
152
|
name: jeweler
|
153
|
+
type: :development
|
153
154
|
description: In Soviet Russia puffer admins you
|
154
155
|
email: kinwizard@gmail.com
|
155
156
|
executables: []
|
@@ -186,6 +187,13 @@ files:
|
|
186
187
|
- lib/generators/puffer/controller/templates/controller.rb
|
187
188
|
- lib/generators/puffer/install/USAGE
|
188
189
|
- lib/generators/puffer/install/install_generator.rb
|
190
|
+
- lib/generators/puffer/install/templates/puffer.rb
|
191
|
+
- lib/generators/puffer/install/templates/puffer/javascripts/application.js
|
192
|
+
- lib/generators/puffer/install/templates/puffer/javascripts/controls.js
|
193
|
+
- lib/generators/puffer/install/templates/puffer/javascripts/dragdrop.js
|
194
|
+
- lib/generators/puffer/install/templates/puffer/javascripts/effects.js
|
195
|
+
- lib/generators/puffer/install/templates/puffer/javascripts/prototype.js
|
196
|
+
- lib/generators/puffer/install/templates/puffer/javascripts/rails.js
|
189
197
|
- lib/puffer.rb
|
190
198
|
- lib/puffer/base.rb
|
191
199
|
- lib/puffer/controller/actions.rb
|
@@ -197,7 +205,8 @@ files:
|
|
197
205
|
- lib/puffer/extensions/controller.rb
|
198
206
|
- lib/puffer/extensions/core.rb
|
199
207
|
- lib/puffer/extensions/mapper.rb
|
200
|
-
- lib/puffer/
|
208
|
+
- lib/puffer/fields.rb
|
209
|
+
- lib/puffer/fields/field.rb
|
201
210
|
- lib/puffer/railtie.rb
|
202
211
|
- lib/puffer/resource.rb
|
203
212
|
- lib/puffer/resource/routing.rb
|
@@ -260,6 +269,7 @@ files:
|
|
260
269
|
- spec/fabricators/tags_fabricator.rb
|
261
270
|
- spec/fabricators/users_fabricator.rb
|
262
271
|
- spec/integration/navigation_spec.rb
|
272
|
+
- spec/lib/fields_spec.rb
|
263
273
|
- spec/lib/params_spec.rb
|
264
274
|
- spec/lib/render_fallback_spec.rb
|
265
275
|
- spec/lib/resource/routing_spec.rb
|
@@ -296,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
296
306
|
requirements: []
|
297
307
|
|
298
308
|
rubyforge_project:
|
299
|
-
rubygems_version: 1.
|
309
|
+
rubygems_version: 1.4.1
|
300
310
|
signing_key:
|
301
311
|
specification_version: 3
|
302
312
|
summary: Admin interface builder
|
@@ -341,6 +351,7 @@ test_files:
|
|
341
351
|
- spec/fabricators/tags_fabricator.rb
|
342
352
|
- spec/fabricators/users_fabricator.rb
|
343
353
|
- spec/integration/navigation_spec.rb
|
354
|
+
- spec/lib/fields_spec.rb
|
344
355
|
- spec/lib/params_spec.rb
|
345
356
|
- spec/lib/render_fallback_spec.rb
|
346
357
|
- spec/lib/resource/routing_spec.rb
|
data/lib/puffer/field.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
module Puffer
|
2
|
-
class Field
|
3
|
-
|
4
|
-
attr_accessor :name, :options, :main_model
|
5
|
-
|
6
|
-
def initialize(model, name, options = {})
|
7
|
-
@main_model = model
|
8
|
-
@name = name
|
9
|
-
@options = options
|
10
|
-
end
|
11
|
-
|
12
|
-
def order
|
13
|
-
@order ||= options[:order] || query_column
|
14
|
-
end
|
15
|
-
|
16
|
-
def label
|
17
|
-
@label ||= options[:label] || @name.to_s.humanize
|
18
|
-
end
|
19
|
-
|
20
|
-
def [](key)
|
21
|
-
@options[key]
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_s
|
25
|
-
@name.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
def own?
|
29
|
-
model == main_model
|
30
|
-
end
|
31
|
-
|
32
|
-
def toggable?
|
33
|
-
options[:toggable] = true if options[:toggable].nil?
|
34
|
-
own? && type == :boolean && options[:toggable]
|
35
|
-
end
|
36
|
-
|
37
|
-
def association
|
38
|
-
@association ||= main_model.reflect_on_association(to_s.split('.').first.to_sym)
|
39
|
-
end
|
40
|
-
|
41
|
-
def association?
|
42
|
-
!!association
|
43
|
-
end
|
44
|
-
|
45
|
-
def collection?
|
46
|
-
association? && [:has_many, :has_and_belongs_to_many].include?(association.macro)
|
47
|
-
end
|
48
|
-
|
49
|
-
def association_fields
|
50
|
-
@association_fields ||= @options[:fields].map {|sym| self.class.new(association.klass, sym) }
|
51
|
-
end
|
52
|
-
|
53
|
-
def association_key
|
54
|
-
association.primary_key_name
|
55
|
-
end
|
56
|
-
|
57
|
-
def record
|
58
|
-
name.split('.')[0..-2].join('.')
|
59
|
-
end
|
60
|
-
|
61
|
-
def model
|
62
|
-
unless @model
|
63
|
-
try_model = to_s.split('.')[-2]
|
64
|
-
@model = try_model.classify.constantize rescue nil if try_model
|
65
|
-
@model ||= main_model
|
66
|
-
end
|
67
|
-
@model
|
68
|
-
end
|
69
|
-
|
70
|
-
def type
|
71
|
-
@options[:type] = :association if association?
|
72
|
-
@options[:type].to_sym || swallow_nil{column.type}
|
73
|
-
end
|
74
|
-
|
75
|
-
def column
|
76
|
-
@column ||= model.columns.detect { |c| c.name == to_s.split('.').last}
|
77
|
-
end
|
78
|
-
|
79
|
-
def column?
|
80
|
-
!!column
|
81
|
-
end
|
82
|
-
|
83
|
-
def query_column
|
84
|
-
"#{model.to_s.tableize}.#{to_s.split('.').last}" if column
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|