cambium 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -3
  3. data/.ruby-version +1 -0
  4. data/README.md +301 -0
  5. data/Rakefile +20 -1
  6. data/app/assets/javascripts/cambium/admin/application.js.coffee +1 -0
  7. data/app/assets/javascripts/cambium/admin/routers/router.js.coffee +8 -17
  8. data/app/assets/javascripts/cambium/admin/templates/image_cropper.jst.ejs +20 -0
  9. data/app/assets/javascripts/cambium/admin/templates/modal.jst.ejs +3 -0
  10. data/app/assets/javascripts/cambium/admin/views/editor.js.coffee +14 -0
  11. data/app/assets/javascripts/cambium/admin/views/image_cropper.js.coffee +27 -0
  12. data/app/assets/javascripts/cambium/admin/views/keyboard_shortcuts.js.coffee +17 -0
  13. data/app/assets/javascripts/cambium/admin/views/media_picker.js.coffee +38 -0
  14. data/app/assets/stylesheets/cambium/admin/application.scss +4 -0
  15. data/app/assets/stylesheets/cambium/admin/partials/_globals.scss +14 -0
  16. data/app/assets/stylesheets/cambium/admin/partials/components.scss +5 -4
  17. data/app/assets/stylesheets/cambium/admin/partials/forms.scss +95 -2
  18. data/app/assets/stylesheets/cambium/admin/partials/modal.scss +40 -0
  19. data/app/assets/stylesheets/cambium/admin/partials/pagination.scss +28 -0
  20. data/app/assets/stylesheets/cambium/admin/partials/tables.scss +18 -27
  21. data/app/assets/stylesheets/cambium/admin/partials/tiles.scss +57 -0
  22. data/app/controllers/cambium/admin/documents_controller.rb +11 -0
  23. data/app/controllers/cambium/admin/pages_controller.rb +15 -0
  24. data/app/controllers/cambium/admin/settings_controller.rb +32 -0
  25. data/app/controllers/cambium/admin_controller.rb +21 -9
  26. data/app/controllers/cambium/pages_controller.rb +17 -0
  27. data/app/helpers/cambium/cambium_helper.rb +148 -116
  28. data/app/models/cambium/document.rb +59 -0
  29. data/app/models/cambium/page.rb +84 -0
  30. data/app/models/cambium/page_template.rb +85 -0
  31. data/app/models/cambium/setting.rb +40 -0
  32. data/app/models/concerns/publishable.rb +0 -21
  33. data/app/views/cambium/admin/documents/index.html.erb +21 -0
  34. data/app/views/cambium/admin/pages/edit.html.erb +16 -0
  35. data/app/views/cambium/admin/paper_trail/versions/_version.html.erb +1 -1
  36. data/app/views/cambium/admin/search/index.html.erb +2 -1
  37. data/app/views/cambium/admin/settings/index.html.erb +15 -0
  38. data/app/views/cambium/pages/home_missing.html.erb +2 -0
  39. data/app/views/layouts/admin.html.erb +1 -1
  40. data/app/views/pages/default.html.erb +13 -0
  41. data/bin/rails +12 -0
  42. data/cambium.gemspec +9 -3
  43. data/config/routes.rb +12 -0
  44. data/db/migrate/20160107161039_create_cambium_pages.rb +19 -0
  45. data/db/migrate/20160108160638_create_cambium_documents.rb +11 -0
  46. data/db/migrate/20160108185904_create_cambium_settings.rb +10 -0
  47. data/db/migrate/20160111154240_add_is_home_to_pages.rb +5 -0
  48. data/db/migrate/20160125174822_add_page_path_to_pages.rb +5 -0
  49. data/db/migrate/20160205190935_add_upload_gravity_to_documents.rb +5 -0
  50. data/lib/cambium.rb +3 -0
  51. data/lib/cambium/engine.rb +21 -0
  52. data/lib/cambium/version.rb +1 -1
  53. data/lib/generators/cambium/admin_generator.rb +1 -1
  54. data/lib/generators/templates/config/admin/documents.yml +23 -0
  55. data/lib/generators/templates/config/admin/pages.yml +56 -0
  56. data/lib/generators/templates/config/admin/settings.yml +19 -0
  57. data/lib/generators/templates/config/admin/sidebar.yml +15 -0
  58. data/lib/generators/templates/config/initializers/assets.rb +3 -1
  59. data/spec/controllers/cambium/admin/documents_controller_spec.rb +7 -0
  60. data/spec/controllers/cambium/admin/pages_controller_spec.rb +7 -0
  61. data/spec/controllers/cambium/admin/settings_controller_spec.rb +7 -0
  62. data/spec/controllers/cambium/pages_controller_spec.rb +7 -0
  63. data/spec/dummy/README.rdoc +28 -0
  64. data/spec/dummy/Rakefile +6 -0
  65. data/spec/dummy/app/assets/images/.keep +0 -0
  66. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  67. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  68. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  69. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  70. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  71. data/spec/dummy/app/mailers/.keep +0 -0
  72. data/spec/dummy/app/models/.keep +0 -0
  73. data/spec/dummy/app/models/concerns/.keep +0 -0
  74. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  75. data/spec/dummy/bin/bundle +3 -0
  76. data/spec/dummy/bin/rails +4 -0
  77. data/spec/dummy/bin/rake +4 -0
  78. data/spec/dummy/bin/setup +29 -0
  79. data/spec/dummy/config.ru +4 -0
  80. data/spec/dummy/config/application.rb +32 -0
  81. data/spec/dummy/config/boot.rb +5 -0
  82. data/spec/dummy/config/database.yml +25 -0
  83. data/spec/dummy/config/environment.rb +5 -0
  84. data/spec/dummy/config/environments/development.rb +41 -0
  85. data/spec/dummy/config/environments/production.rb +79 -0
  86. data/spec/dummy/config/environments/test.rb +42 -0
  87. data/spec/dummy/config/initializers/assets.rb +11 -0
  88. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  89. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  90. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  91. data/spec/dummy/config/initializers/inflections.rb +16 -0
  92. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  93. data/spec/dummy/config/initializers/session_store.rb +3 -0
  94. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  95. data/spec/dummy/config/locales/en.yml +23 -0
  96. data/spec/dummy/config/routes.rb +4 -0
  97. data/spec/dummy/config/secrets.yml +22 -0
  98. data/spec/dummy/lib/assets/.keep +0 -0
  99. data/spec/dummy/log/.keep +0 -0
  100. data/spec/dummy/public/404.html +67 -0
  101. data/spec/dummy/public/422.html +67 -0
  102. data/spec/dummy/public/500.html +66 -0
  103. data/spec/dummy/public/favicon.ico +0 -0
  104. data/spec/factories/cambium_documents.rb +7 -0
  105. data/spec/factories/cambium_pages.rb +6 -0
  106. data/spec/factories/cambium_settings.rb +7 -0
  107. data/spec/models/cambium/document_spec.rb +7 -0
  108. data/spec/models/cambium/page_spec.rb +7 -0
  109. data/spec/models/cambium/setting_spec.rb +7 -0
  110. data/spec/spec_helper.rb +18 -0
  111. metadata +219 -11
  112. data/test/controllers/cambium/admin/dashboard_controller_test.rb +0 -9
  113. data/test/controllers/cambium/admin/users_controller_test.rb +0 -9
  114. data/test/controllers/cambium/admin_controller_test.rb +0 -9
@@ -0,0 +1,11 @@
1
+ class Cambium::Admin::DocumentsController < Cambium::AdminController
2
+
3
+ private
4
+
5
+ def create_params
6
+ obj = admin_model.to_s.gsub(/Cambium::/, '').tableize.singularize.to_sym
7
+ p = params.require(obj)
8
+ .permit(admin_form.fields.to_h.keys + [:upload_gravity])
9
+ end
10
+
11
+ end
@@ -0,0 +1,15 @@
1
+ class Cambium::Admin::PagesController < Cambium::AdminController
2
+
3
+ private
4
+
5
+ def create_params
6
+ obj = admin_model.to_s.gsub(/Cambium::/, '').tableize.singularize.to_sym
7
+ p = params.require(obj).permit(admin_form.fields.to_h.keys)
8
+ if params[:page][:template_data].present?
9
+ data = @object.template_data.merge(params[:page][:template_data])
10
+ p = p.merge(:template_data => data)
11
+ end
12
+ p
13
+ end
14
+
15
+ end
@@ -0,0 +1,32 @@
1
+ class Cambium::Admin::SettingsController < Cambium::AdminController
2
+
3
+ before_filter :not_found, :except => [:index, :update]
4
+
5
+ def index
6
+ expected_keys = admin_view.form.edit.fields.to_h.stringify_keys.keys
7
+ current_keys = Cambium::Setting.keys
8
+ # Add anything that's missing
9
+ (expected_keys - current_keys).each do |key|
10
+ Cambium::Setting.create(:key => key)
11
+ end
12
+ @collection = admin_model.alpha
13
+ # Remove anything extra
14
+ extra_keys = @collection.collect(&:key) - expected_keys
15
+ if extra_keys.size > 0
16
+ Cambium::Setting.where(:key => extra_keys).destroy_all
17
+ @collection = admin_model.alpha
18
+ end
19
+ respond_to do |format|
20
+ format.html
21
+ format.csv { send_data admin.to_csv(@collection) }
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def create_params
28
+ obj = admin_model.to_s.gsub(/Cambium::/, '').tableize.singularize.to_sym
29
+ p = params.require(obj).permit(:value)
30
+ end
31
+
32
+ end
@@ -10,16 +10,22 @@ class Cambium::AdminController < Cambium::BaseController
10
10
  def index
11
11
  respond_to do |format|
12
12
  scope = admin_table.scope
13
- if scope.split('.').size > 1
14
- @collection = admin_model
15
- scope.split('.').each do |s|
16
- @collection = @collection.send(s)
17
- end
13
+ if params[:sort_by]
14
+ @collection = admin_model.unscoped
15
+ .order("#{params[:sort_by]} #{params[:order] || 'asc'}")
18
16
  else
19
- @collection = admin_model.send(admin_table.scope)
17
+ if scope.split('.').size > 1
18
+ @collection = admin_model
19
+ scope.split('.').each do |s|
20
+ @collection = @collection.send(s)
21
+ end
22
+ else
23
+ @collection = admin_model.send(admin_table.scope)
24
+ end
20
25
  end
21
26
  format.html do
22
27
  @collection = @collection.page(params[:page] || 1).per(15)
28
+ render :layout => false if params[:no_layout]
23
29
  end
24
30
  format.csv do
25
31
  send_data admin.to_csv(@collection)
@@ -39,7 +45,9 @@ class Cambium::AdminController < Cambium::BaseController
39
45
  def create
40
46
  @object = admin_model.new(create_params)
41
47
  if @object.save
42
- redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} created!")
48
+ redirect_to(
49
+ admin_routes.index,
50
+ :notice => "#{admin_model.to_s.gsub(/Cambium::/, '')} created!")
43
51
  else
44
52
  render 'new'
45
53
  end
@@ -52,7 +60,9 @@ class Cambium::AdminController < Cambium::BaseController
52
60
  def update
53
61
  set_object
54
62
  if @object.update(update_params)
55
- redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} updated!")
63
+ redirect_to(
64
+ admin_routes.index,
65
+ :notice => "#{admin_model.to_s.gsub(/Cambium::/, '')} updated!")
56
66
  else
57
67
  render 'edit'
58
68
  end
@@ -61,7 +71,9 @@ class Cambium::AdminController < Cambium::BaseController
61
71
  def destroy
62
72
  set_object
63
73
  @object.destroy
64
- redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} deleted!")
74
+ redirect_to(
75
+ admin_routes.index,
76
+ :notice => "#{admin_model.to_s.gsub(/Cambium::/, '')} deleted!")
65
77
  end
66
78
 
67
79
  private
@@ -0,0 +1,17 @@
1
+ class Cambium::PagesController < ApplicationController
2
+
3
+ def show
4
+ @page = Cambium::Page.find_by_page_path(request.path)
5
+ render :inline => @page.template.content, :layout => 'application'
6
+ end
7
+
8
+ def home
9
+ @page = Cambium::Page.home
10
+ if @page.nil?
11
+ render 'home_missing'
12
+ else
13
+ render :inline => @page.template.content, :layout => 'application'
14
+ end
15
+ end
16
+
17
+ end
@@ -40,7 +40,11 @@ module Cambium
40
40
  end
41
41
 
42
42
  def admin_model
43
- @admin_model ||= admin_view.model.constantize
43
+ @admin_model ||= begin
44
+ admin_view.model.constantize
45
+ rescue
46
+ "Cambium::#{admin_view.model}".constantize
47
+ end
44
48
  end
45
49
 
46
50
  def cambium_page_title(title)
@@ -49,21 +53,21 @@ module Cambium
49
53
  if is_index? && has_new_form?
50
54
  o += link_to(
51
55
  admin_view.form.new.title,
52
- admin_routes.new,
56
+ cambium_route(:new),
53
57
  :class => 'button new'
54
58
  )
55
59
  end
56
60
  if is_index? && admin_view.export.present?
57
61
  o += link_to(
58
62
  admin_view.export.button || "Export #{admin_table.title}",
59
- "#{admin_routes.index}.csv",
63
+ "#{cambium_route(:index)}.csv",
60
64
  :class => 'button export'
61
65
  )
62
66
  end
63
67
  if is_edit? && can_delete?
64
68
  o += link_to(
65
69
  admin_view.form.buttons.delete,
66
- admin_routes.delete,
70
+ cambium_route(:delete, @object),
67
71
  :class => 'button delete',
68
72
  :method => :delete,
69
73
  :data => { :confirm => 'Are you sure?' }
@@ -81,8 +85,28 @@ module Cambium
81
85
  content_tag(:tr) do
82
86
  o2 = ''
83
87
  columns.to_h.each do |col|
84
- obj_methods << col.first.to_s
85
- o2 += content_tag(:th, col.last.heading)
88
+ obj_methods << (col.last.display_method || col.first.to_s)
89
+ if col.last.sortable
90
+ o2 += content_tag(:th) do
91
+ path = "admin_#{controller_name}_path"
92
+ args = {
93
+ :page => params[:page] || 1,
94
+ :sort_by => col.first,
95
+ :order => (params[:order] == 'asc' &&
96
+ params[:sort_by] == col.first) ? :desc : :asc
97
+ }
98
+ begin
99
+ route = cambium.send(path, args)
100
+ rescue
101
+ route = main_app.send(path, args)
102
+ end
103
+ klass = args[:order].to_s
104
+ klass += ' active' if params[:sort_by] == col.first.to_s
105
+ link_to(col.last.heading, route, :class => klass)
106
+ end
107
+ else
108
+ o2 += content_tag(:th, col.last.heading)
109
+ end
86
110
  end
87
111
  o2 += content_tag(:th, nil)
88
112
  o2.html_safe
@@ -96,13 +120,8 @@ module Cambium
96
120
  obj_methods.each do |method|
97
121
  o3 += content_tag(:td, obj.send(method))
98
122
  end
99
- path = "edit_admin_#{controller_name.singularize}_path"
100
- begin
101
- route = cambium.send(path, obj)
102
- rescue
103
- route = main_app.send(path, obj)
104
- end
105
- o3 += content_tag(:td, link_to('', route), :class => 'actions')
123
+ o3 += content_tag(:td, link_to('', cambium_route(:edit, obj)),
124
+ :class => 'actions')
106
125
  o3.html_safe
107
126
  end
108
127
  end
@@ -114,7 +133,7 @@ module Cambium
114
133
  end
115
134
  end
116
135
 
117
- def cambium_form(obj, fields, url=nil)
136
+ def cambium_form(obj, fields, url=nil, &block)
118
137
  content_tag(:section, :class => 'form') do
119
138
  if url.nil?
120
139
  case action_name
@@ -125,126 +144,133 @@ module Cambium
125
144
  end
126
145
  end
127
146
  simple_form_for obj, :url => url do |f|
128
- cambium_form_fields(f, obj, fields)
147
+ o = cambium_form_fields(f, obj, fields)
148
+ o += capture(f, &block) if block_given?
149
+ o += f.submit
150
+ o
129
151
  end
130
152
  end
131
153
  end
132
154
 
133
155
  def cambium_form_fields(f, obj, fields)
134
156
  o = ''
135
- fields.to_h.each do |data|
136
- attr = data.first.to_s
137
- options = data.last
138
- readonly = options.readonly || false
139
- label = options.label || attr.titleize
140
- if options.type == 'heading'
141
- o += content_tag(:h2, options.label || attr.titleize)
142
- elsif ['select','check_boxes','radio_buttons'].include?(options.type)
143
- parts = options.options.split('.')
144
- if parts.size > 1
145
- collection = parts[0].constantize.send(parts[1])
146
- else
147
- collection = options.options
148
- end
149
- o += f.input(
150
- attr.to_sym,
151
- :as => options.type,
152
- :collection => collection,
153
- :label => label,
154
- :readonly => readonly
155
- )
156
- elsif ['date','time'].include?(options.type)
157
- if obj.send(attr).present?
158
- val = (options.type == 'date') ?
159
- obj.send(attr).strftime("%d %B, %Y") :
160
- obj.send(attr).strftime("%l:%M %p")
161
- end
162
- o += f.input(
163
- attr.to_sym,
164
- :as => :string,
165
- :label => label,
166
- :input_html => {
167
- :class => "picka#{options.type}",
168
- :value => val.nil? ? nil : val
169
- },
170
- :readonly => readonly
171
- )
172
- elsif options.type == 'datetime'
173
- o += content_tag(:div, :class => 'input string pickadatetime') do
174
- o2 = content_tag(:label, attr.to_s.humanize.titleize)
175
- o2 += content_tag(
176
- :input,
177
- '',
178
- :label => label,
179
- :placeholder => 'Date',
180
- :type => 'text',
181
- :class => 'pickadatetime-date',
182
- :value => obj.send(attr).present? ?
183
- obj.send(attr).strftime("%d %B, %Y") : '',
184
- :readonly => readonly
185
- )
186
- o2 += content_tag(
187
- :input,
188
- '',
189
- :label => label,
190
- :placeholder => 'Time',
191
- :type => 'text',
192
- :class => 'pickadatetime-time',
193
- :value => obj.send(attr).present? ?
194
- obj.send(attr).strftime("%l:%M %p") : '',
195
- :readonly => readonly
196
- )
197
- o2 += f.input(
198
- attr.to_sym,
199
- :as => :hidden,
200
- :wrapper => false,
201
- :label => false,
202
- :input_html => { :class => 'pickadatetime' }
203
- )
157
+ fields.to_h.each do |field|
158
+ o += cambium_field(f, obj, field)
159
+ end
160
+ o.html_safe
161
+ end
162
+
163
+ def cambium_field(f, obj, field)
164
+ attr = field.first.to_s
165
+ options = field.last
166
+ options = options.to_ostruct unless options.class == OpenStruct
167
+ readonly = options.readonly || false
168
+ label = options.label || attr.titleize
169
+ required = options.required || false
170
+ if options.type == 'heading'
171
+ content_tag(:h2, options.label || attr.titleize)
172
+ elsif ['select','check_boxes','radio_buttons'].include?(options.type)
173
+ parts = options.options.split('.')
174
+ if parts.size > 1
175
+ collection = parts[0].constantize.send(parts[1])
176
+ else
177
+ collection = options.options
178
+ end
179
+ f.input(attr.to_sym, :as => options.type, :collection => collection,
180
+ :label => label, :readonly => readonly)
181
+ elsif ['date','time'].include?(options.type)
182
+ if obj.send(attr).present?
183
+ val = (options.type == 'date') ?
184
+ obj.send(attr).strftime("%d %B, %Y") :
185
+ obj.send(attr).strftime("%l:%M %p")
186
+ end
187
+ f.input(attr.to_sym, :as => :string, :label => label,
188
+ :input_html => {
189
+ :class => "picka#{options.type}",
190
+ :value => val.nil? ? nil : val
191
+ }, :readonly => readonly)
192
+ elsif options.type == 'datetime'
193
+ content_tag(:div, :class => 'input string pickadatetime') do
194
+ o2 = content_tag(:label, label)
195
+ o2 += content_tag(:input, '', :label => label, :placeholder => 'Date',
196
+ :type => 'text', :class => 'pickadatetime-date',
197
+ :value => obj.send(attr).present? ?
198
+ obj.send(attr).strftime("%d %B, %Y") : '',
199
+ :readonly => readonly)
200
+ o2 += content_tag(:input, '', :label => label, :placeholder => 'Time',
201
+ :type => 'text', :class => 'pickadatetime-time',
202
+ :value => obj.send(attr).present? ?
203
+ obj.send(attr).strftime("%l:%M %p") : '',
204
+ :readonly => readonly)
205
+ o2 += f.input(attr.to_sym, :as => :hidden, :wrapper => false,
206
+ :label => false,
207
+ :input_html => { :class => 'pickadatetime' })
208
+ end
209
+ elsif options.type == 'markdown'
210
+ content_tag(:div, :class => "input text optional #{attr}") do
211
+ o2 = content_tag(:label, label, :for => attr)
212
+ o2 += content_tag(:div, f.markdown(attr.to_sym), :class => 'markdown')
213
+ end
214
+ elsif options.type == 'wysiwyg'
215
+ f.input(attr.to_sym, :as => :text, :label => label,
216
+ :input_html => { :class => 'editor' })
217
+ elsif options.type == 'media'
218
+ content_tag(:div, :class => 'input media-picker file') do
219
+ o2 = content_tag(:label, label)
220
+ o2 += link_to('Choose File', '#', :class => 'add')
221
+ o2 += link_to('Remove File', '#',
222
+ :class => "remove #{'active' unless obj.send(attr).blank? }")
223
+ unless obj.send(attr).blank?
224
+ ext = obj.send(attr).upload.ext.downcase
225
+ if ['jpg','jpeg','gif','png'].include?(ext)
226
+ o2 += image_tag(obj.send(attr).image_url(400, 400))
227
+ end
228
+ o2 += link_to(obj.send(attr).upload.name,
229
+ obj.send(attr).upload.url,
230
+ :class => 'file', :target => :blank)
204
231
  end
205
- elsif options.type == 'markdown'
206
- o += content_tag(:div, :class => "input text optional #{attr}") do
207
- o2 = content_tag(:label, label, :for => attr)
208
- o2 += content_tag(
209
- :div,
210
- f.markdown(attr.to_sym),
211
- :class => 'markdown'
212
- )
232
+ o2 += f.input(attr.to_sym, :as => :hidden, :wrapper => false)
233
+ end
234
+ elsif options.type == 'file'
235
+ o = f.input(attr.to_sym, :as => options.type, :label => label,
236
+ :readonly => readonly, :required => required)
237
+ unless obj.send(attr).blank?
238
+ if ['jpg','jpeg','gif','png'].include?(obj.send(attr).ext.downcase)
239
+ o += image_tag obj.send(attr)
240
+ .thumb("200x200##{obj.send("#{attr}_gravity")}")
241
+ .url
242
+ o += content_tag(:div, :class => 'image-actions') do
243
+ o2 = ''.html_safe
244
+ o2 += link_to('Crop Image', '#', :class => 'crop',
245
+ :target => :blank, :data => {
246
+ :url => obj.send(attr).url,
247
+ :width => obj.send(attr).width,
248
+ :height => obj.send(attr).height }) if options.crop
249
+ o2 += link_to(obj.send(attr).name, obj.send(attr).url,
250
+ :class => 'file', :target => :blank)
251
+ o2 += f.input :"#{attr}_gravity", :as => :hidden
252
+ end
253
+ else
254
+ o += link_to(obj.send(attr).name, obj.send(attr).url,
255
+ :class => 'file', :target => :blank)
213
256
  end
214
- elsif options.type == 'file'
215
- o += f.input(
216
- attr.to_sym,
217
- :as => options.type,
218
- :label => label,
219
- :readonly => readonly
220
- )
221
- o += link_to(
222
- obj.send(attr).name,
223
- obj.send(attr).url,
224
- :class => 'file',
225
- :target => :blank
226
- ) unless obj.send(attr).blank?
227
- else
228
- o += f.input(
229
- attr.to_sym,
230
- :as => options.type,
231
- :label => label,
232
- :readonly => readonly
233
- )
234
257
  end
258
+ o
259
+ else
260
+ f.input(attr.to_sym, :as => options.type, :label => label,
261
+ :readonly => readonly)
235
262
  end
236
- o += f.submit
237
- o.html_safe
238
263
  end
239
264
 
240
265
  def cambium_route(action, obj = nil)
266
+ c_name = controller_name.singularize
241
267
  case action
242
268
  when :index
243
269
  begin
244
270
  main_app
245
- .polymorphic_path [:admin, obj.class.to_s.tableize.pluralize.to_sym]
271
+ .polymorphic_path [:admin, controller_name.to_sym]
246
272
  rescue
247
- cambium.polymorphic_path [:admin, obj.class.to_s.tableize.pluralize.to_sym]
273
+ cambium.polymorphic_path [:admin, controller_name.to_sym]
248
274
  end
249
275
  when :edit
250
276
  begin
@@ -252,6 +278,12 @@ module Cambium
252
278
  rescue
253
279
  cambium.polymorphic_path [:edit, :admin, obj]
254
280
  end
281
+ when :new
282
+ begin
283
+ main_app.polymorphic_path [:new, :admin, c_name.to_sym]
284
+ rescue
285
+ cambium.polymorphic_path [:new, :admin, c_name.to_sym]
286
+ end
255
287
  else
256
288
  begin
257
289
  main_app.polymorphic_path [:admin, obj]