cambium 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 151475ac069e0a44ad489ab9340b9041d3c3ba20
4
- data.tar.gz: 2fd26503a744a7dd999eed2a40a72617b5f46323
3
+ metadata.gz: ff5677f58125f1cad2a98e1904ca8047bdf37252
4
+ data.tar.gz: 8316b5eb6d5bae1ef353b24cea093c9898de9412
5
5
  SHA512:
6
- metadata.gz: eed0446889aa382fcd3eb124c23622bb6757e0e7e0ef1693edc51ba10dae9797050f91152bd2abc49095bdab0bf2641380ccf147857ecb2ded8c9c8db2d4d8d2
7
- data.tar.gz: f53a44e5a2cd9cd47ca57c69a0186208a8397e7e5404c69f3af6d4be533bf9feab67e1d20d58a0ef57aadf6201776fc9ecada8a65240dbefefbaa7a51fc44f4a
6
+ metadata.gz: 22120069c0f33717fd8a4348c43b42d4ab9af23ae1631709abbd33c96f67e41833ef1e87bffed5e1ab47ce18d5a063e8507533e602843a4c7afb4222147e1e90
7
+ data.tar.gz: 537b2a2e28c4e62643100babeb1f41e03962acf5466f1c89f9138c9706270399cd7cd1b20abfca78166c1387123b79a1c5168e251ea2fec218485617600207f0
data/README.md CHANGED
@@ -231,6 +231,7 @@ form:
231
231
  type: string
232
232
  email:
233
233
  type: string
234
+ readonly: true
234
235
  password:
235
236
  type: password
236
237
  password_confirmation:
@@ -271,13 +272,42 @@ Every setting plays a role. Let's step through each one.
271
272
  * `form:[new/edit]:fields:[field]`: Each form field gets its own unique key to
272
273
  set it apart from the others.
273
274
  * `form:[new/edit]:fields:[field]:type`: The type of the HTML field to render,
274
- which uses [SimpleForm](https://github.com/plataformatec/simple_form).
275
+ which uses [SimpleForm](https://github.com/plataformatec/simple_form). *You
276
+ can use `heading` here to break up your fields.*
277
+ * `form:[new/edit]:fields:[field]:readonly`: If set to `true`, it will add the
278
+ `readonly` attribute to the input field. *Not supported for markdown fields*.
275
279
 
276
280
  > Note: Aside from the usual form field types, Cambium uses [Mark It
277
281
  > Zero!](https://github.com/seancdavis/mark_it_zero) to render markdown
278
282
  > editors. You can pass `markdown` as the `type` option and it will give you a
279
283
  > markdown editor.
280
284
 
285
+ ### Overriding the Base Controller
286
+
287
+ I've rearranged Cambium's CMS controllers so there is a blank `BaseController`
288
+ from which it inherits. You can manually override this in your app by creating
289
+ a `Cambium::BaseController` and loading the appropriate files.
290
+
291
+ First, generate the controller.
292
+
293
+ ```text
294
+ $ bundle exec rails g controller cambium/base
295
+ ```
296
+
297
+ That controller can inherit from any other controller in your app. The only
298
+ thing you need to ensure is that it loads the `CambiumHelper` from the
299
+ `Cambium` namespace. So, the base file should look like this:
300
+
301
+ ```ruby
302
+ class Cambium::BaseController < ApplicationController
303
+ helper Cambium::CambiumHelper
304
+ end
305
+ ```
306
+
307
+ You can change `ApplicationController` to any other controller in your
308
+ application.
309
+
310
+
281
311
  Model Options
282
312
  ----------
283
313
 
@@ -37,8 +37,8 @@ div.status{
37
37
  }
38
38
  }
39
39
 
40
- .button {
41
- &.new, &.export {
40
+ a {
41
+ &.new, &.export, &.file {
42
42
  &:before {
43
43
  font-family: 'icomoon';
44
44
  font-size: inherit;
@@ -48,6 +48,7 @@ div.status{
48
48
  }
49
49
  &.new:before { content: "\e702"; }
50
50
  &.export:before { content: "\e65e"; }
51
+ &.file:before { content: "\e622"; }
51
52
  }
52
53
 
53
54
  .avatar-container {
@@ -1,9 +1,31 @@
1
1
  section.form {
2
2
  form {
3
3
 
4
+ h2 {
5
+ margin: 10px 0;
6
+ font-size: 22px;
7
+ line-height: 28px;
8
+ color: $color-dark-lightest;
9
+ font-weight: 400;
10
+ }
11
+
4
12
  div.input {
5
13
  font-size: 0;
6
14
  padding: 20px 0;
15
+ &.file {
16
+ padding: 20px 0 0 0;
17
+ & + a.file {
18
+ display: block;
19
+ width: 100%;
20
+ padding: 5px 0 20px 0;
21
+ font-size: 14px;
22
+ line-height: 14px;
23
+ text-align: right;
24
+ }
25
+ & + div.input {
26
+ padding-top: 40px;
27
+ }
28
+ }
7
29
  label {
8
30
  position: relative;
9
31
  display: inline-block;
@@ -35,6 +57,11 @@ section.form {
35
57
  vertical-align: bottom;
36
58
  font-size: 16px;
37
59
  border: none;
60
+ @include box-sizing(border-box);
61
+ &[readonly=readonly] {
62
+ background-color: $color-light-dark;
63
+ border-bottom-color: $color-light-dark;
64
+ }
38
65
  }
39
66
  input {
40
67
  border-bottom: 1px solid $color-light-darker;
@@ -1,12 +1,10 @@
1
- module Cambium
2
- class Admin::DashboardController < AdminController
1
+ class Cambium::Admin::DashboardController < Cambium::AdminController
3
2
 
4
- def index
5
- redirect_to admin_dashboard_path
6
- end
7
-
8
- def show
9
- end
3
+ def index
4
+ redirect_to admin_dashboard_path
5
+ end
10
6
 
7
+ def show
11
8
  end
9
+
12
10
  end
@@ -1,9 +1,7 @@
1
- module Cambium
2
- class Admin::SearchController < AdminController
3
-
4
- def index
5
- @collection = PgSearch.multisearch(params[:q]).includes(:searchable)
6
- end
1
+ class Cambium::Admin::SearchController < Cambium::AdminController
7
2
 
3
+ def index
4
+ @collection = PgSearch.multisearch(params[:q]).includes(:searchable)
8
5
  end
9
- end
6
+
7
+ end
@@ -1,30 +1,28 @@
1
- module Cambium
2
- class Admin::UsersController < AdminController
1
+ class Cambium::Admin::UsersController < Cambium::AdminController
3
2
 
4
- def update
5
- set_object
6
- # To make this run smoothly, we remove the password
7
- # fields from the update_params if they are both
8
- # missing, that way we don't try to set a blank
9
- # password.
10
- p = update_params
11
- if p[:password].blank? && p[:password_confirmation].blank?
12
- p = p.except('password','password_confirmation')
13
- end
14
- # Now we use the cleansed params `p` and we're ready
15
- # to try to save the user
16
- if @object.update(p)
17
- # If we have successfully saved the user, we're
18
- # going to sign them back in automatically.
19
- if @object == current_user
20
- sign_in(@object, :bypass => true)
21
- end
22
- # And then we oome back to regular behavior
23
- redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} updated!")
24
- else
25
- render 'edit'
3
+ def update
4
+ set_object
5
+ # To make this run smoothly, we remove the password
6
+ # fields from the update_params if they are both
7
+ # missing, that way we don't try to set a blank
8
+ # password.
9
+ p = update_params
10
+ if p[:password].blank? && p[:password_confirmation].blank?
11
+ p = p.except('password','password_confirmation')
12
+ end
13
+ # Now we use the cleansed params `p` and we're ready
14
+ # to try to save the user
15
+ if @object.update(p)
16
+ # If we have successfully saved the user, we're
17
+ # going to sign them back in automatically.
18
+ if @object == current_user
19
+ sign_in(@object, :bypass => true)
26
20
  end
21
+ # And then we oome back to regular behavior
22
+ redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} updated!")
23
+ else
24
+ render 'edit'
27
25
  end
28
-
29
26
  end
27
+
30
28
  end
@@ -1,90 +1,90 @@
1
- module Cambium
2
- class AdminController < ActionController::Base
3
-
4
- before_filter :authenticate_admin!
5
- before_filter :set_activities
6
-
7
- layout "admin"
8
-
9
- include CambiumHelper
10
-
11
- def index
12
- respond_to do |format|
13
- format.html do
14
- @collection = admin_model.send(admin_table.scope)
15
- .page(params[:page] || 1).per(15)
16
- end
17
- format.csv do
18
- @collection = admin_model.send(admin_table.scope)
19
- send_data admin.to_csv(@collection)
20
- end
21
- end
22
- end
1
+ class Cambium::AdminController < Cambium::BaseController
23
2
 
24
- def show
25
- set_object
26
- redirect_to(admin_routes.edit)
27
- end
3
+ before_filter :authenticate_admin!
4
+ before_filter :set_activities
28
5
 
29
- def new
30
- @object = admin_model.new
31
- end
6
+ layout "admin"
32
7
 
33
- def create
34
- set_object
35
- @object = admin_model.new(create_params)
36
- if @object.save
37
- redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} created!")
38
- else
39
- render 'new'
8
+ include Cambium::CambiumHelper
9
+
10
+ def index
11
+ respond_to do |format|
12
+ format.html do
13
+ @collection = admin_model.send(admin_table.scope)
14
+ .page(params[:page] || 1).per(15)
15
+ end
16
+ format.csv do
17
+ @collection = admin_model.send(admin_table.scope)
18
+ send_data admin.to_csv(@collection)
40
19
  end
41
20
  end
21
+ end
42
22
 
43
- def edit
44
- set_object
23
+ def show
24
+ set_object
25
+ redirect_to(admin_routes.edit)
26
+ end
27
+
28
+ def new
29
+ @object = admin_model.new
30
+ end
31
+
32
+ def create
33
+ set_object
34
+ @object = admin_model.new(create_params)
35
+ if @object.save
36
+ redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} created!")
37
+ else
38
+ render 'new'
45
39
  end
40
+ end
46
41
 
47
- def update
48
- set_object
49
- if @object.update(update_params)
50
- redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} updated!")
51
- else
52
- render 'edit'
53
- end
42
+ def edit
43
+ set_object
44
+ end
45
+
46
+ def update
47
+ set_object
48
+ if @object.update(update_params)
49
+ redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} updated!")
50
+ else
51
+ render 'edit'
54
52
  end
53
+ end
55
54
 
56
- private
55
+ private
57
56
 
58
- def set_object
59
- if @object.respond_to?(:slug) && params[:slug]
60
- @object = admin_model.find_by_slug(params[:slug])
61
- else
62
- @object = admin_model.find_by_id(params[:id])
63
- end
64
- @obj = @object
57
+ def set_object
58
+ if admin_model.new.respond_to?(:slug) && params[:slug]
59
+ slug = params[:"#{admin_model.to_s.underscore}_slug"] || params[:slug]
60
+ @object = admin_model.find_by_slug(slug)
61
+ else
62
+ id = params[:"#{admin_model.to_s.underscore}_id"] || params[:id]
63
+ @object = admin_model.find_by_id(id.to_i)
65
64
  end
65
+ @obj = @object
66
+ end
66
67
 
67
- def authenticate_admin!
68
- authenticate_user!
69
- not_found unless current_user.is_admin?
70
- end
68
+ def authenticate_admin!
69
+ authenticate_user!
70
+ not_found unless current_user.is_admin?
71
+ end
71
72
 
72
- def create_params
73
- params
74
- .require(admin_model.to_s.humanize.downcase.to_sym)
75
- .permit(admin_form.fields.to_h.keys)
76
- end
73
+ def create_params
74
+ params
75
+ .require(admin_model.to_s.humanize.downcase.to_sym)
76
+ .permit(admin_form.fields.to_h.keys)
77
+ end
77
78
 
78
- def update_params
79
- create_params
80
- end
79
+ def update_params
80
+ create_params
81
+ end
81
82
 
82
- def set_activities
83
- @activities = PaperTrail::Version.order(:created_at => :desc)
84
- .includes(:item).limit(20)
85
- @users = User.where(:id => @activities.collect(&:whodunnit)
86
- .reject(&:blank?).map(&:to_i))
87
- end
83
+ def set_activities
84
+ @activities = PaperTrail::Version.order(:created_at => :desc)
85
+ .includes(:item).limit(20)
86
+ @users = User.where(:id => @activities.collect(&:whodunnit)
87
+ .reject(&:blank?).map(&:to_i))
88
+ end
88
89
 
89
- end
90
90
  end
@@ -0,0 +1,2 @@
1
+ class Cambium::BaseController < ActionController::Base
2
+ end
@@ -107,92 +107,139 @@ module Cambium
107
107
 
108
108
  def cambium_form(obj, fields)
109
109
  content_tag(:section, :class => 'form') do
110
- simple_form_for [:admin, obj] do |f|
111
- o = ''
112
- fields.to_h.each do |data|
113
- attr = data.first.to_s
114
- options = data.last
115
- if ['select','check_boxes','radio_buttons'].include?(options.type)
116
- o += f.input(
117
- attr.to_sym,
118
- :as => options.type,
119
- :collection => options.options
120
- )
121
- elsif ['date','time'].include?(options.type)
122
- if obj.send(attr).present?
123
- val = (options.type == 'date') ?
124
- obj.send(attr).strftime("%d %B, %Y") :
125
- obj.send(attr).strftime("%l:%M %p")
126
- end
127
- o += f.input(
128
- attr.to_sym,
129
- :as => :string,
130
- :input_html => {
131
- :class => "picka#{options.type}",
132
- :value => val.nil? ? nil : val
133
- }
134
- )
135
- elsif options.type == 'datetime'
136
- o += content_tag(:div, :class => 'input string pickadatetime') do
137
- o2 = content_tag(:label, attr.to_s.humanize.titleize)
138
- o2 += content_tag(
139
- :input,
140
- '',
141
- :placeholder => 'Date',
142
- :type => 'text',
143
- :class => 'pickadatetime-date',
144
- :value => obj.send(attr).present? ?
145
- obj.send(attr).strftime("%d %B, %Y") : ''
146
- )
147
- o2 += content_tag(
148
- :input,
149
- '',
150
- :placeholder => 'Time',
151
- :type => 'text',
152
- :class => 'pickadatetime-time',
153
- :value => obj.send(attr).present? ?
154
- obj.send(attr).strftime("%l:%M %p") : ''
155
- )
156
- o2 += f.input(
157
- attr.to_sym,
158
- :as => :hidden,
159
- :wrapper => false,
160
- :label => false,
161
- :input_html => { :class => 'pickadatetime' }
162
- )
163
- end
164
- elsif options.type == 'markdown'
165
- o += content_tag(:div, :class => "input text optional #{attr}") do
166
- o2 = content_tag(:label, attr.titleize, :for => attr)
167
- o2 += content_tag(
168
- :div,
169
- f.markdown(attr.to_sym),
170
- :class => 'markdown'
171
- )
172
- end
173
- else
174
- o += f.input(
175
- attr.to_sym,
176
- :as => options.type
177
- )
178
- end
110
+ case action_name
111
+ when 'edit', 'update'
112
+ url = cambium_route(:show, obj)
113
+ else
114
+ url = cambium_route(:index, obj)
115
+ end
116
+ simple_form_for obj, :url => url do |f|
117
+ cambium_form_fields(f, obj, fields)
118
+ end
119
+ end
120
+ end
121
+
122
+ def cambium_form_fields(f, obj, fields)
123
+ o = ''
124
+ fields.to_h.each do |data|
125
+ attr = data.first.to_s
126
+ options = data.last
127
+ readonly = options.readonly || false
128
+ label = options.label || attr.titleize
129
+ if options.type == 'heading'
130
+ o += content_tag(:h2, options.label || attr.titleize)
131
+ elsif ['select','check_boxes','radio_buttons'].include?(options.type)
132
+ o += f.input(
133
+ attr.to_sym,
134
+ :as => options.type,
135
+ :collection => options.options,
136
+ :label => label,
137
+ :readonly => readonly
138
+ )
139
+ elsif ['date','time'].include?(options.type)
140
+ if obj.send(attr).present?
141
+ val = (options.type == 'date') ?
142
+ obj.send(attr).strftime("%d %B, %Y") :
143
+ obj.send(attr).strftime("%l:%M %p")
179
144
  end
180
- o += f.submit
181
- o.html_safe
145
+ o += f.input(
146
+ attr.to_sym,
147
+ :as => :string,
148
+ :label => label,
149
+ :input_html => {
150
+ :class => "picka#{options.type}",
151
+ :value => val.nil? ? nil : val
152
+ },
153
+ :readonly => readonly
154
+ )
155
+ elsif options.type == 'datetime'
156
+ o += content_tag(:div, :class => 'input string pickadatetime') do
157
+ o2 = content_tag(:label, attr.to_s.humanize.titleize)
158
+ o2 += content_tag(
159
+ :input,
160
+ '',
161
+ :label => label,
162
+ :placeholder => 'Date',
163
+ :type => 'text',
164
+ :class => 'pickadatetime-date',
165
+ :value => obj.send(attr).present? ?
166
+ obj.send(attr).strftime("%d %B, %Y") : '',
167
+ :readonly => readonly
168
+ )
169
+ o2 += content_tag(
170
+ :input,
171
+ '',
172
+ :label => label,
173
+ :placeholder => 'Time',
174
+ :type => 'text',
175
+ :class => 'pickadatetime-time',
176
+ :value => obj.send(attr).present? ?
177
+ obj.send(attr).strftime("%l:%M %p") : '',
178
+ :readonly => readonly
179
+ )
180
+ o2 += f.input(
181
+ attr.to_sym,
182
+ :as => :hidden,
183
+ :wrapper => false,
184
+ :label => false,
185
+ :input_html => { :class => 'pickadatetime' }
186
+ )
187
+ end
188
+ elsif options.type == 'markdown'
189
+ o += content_tag(:div, :class => "input text optional #{attr}") do
190
+ o2 = content_tag(:label, attr.titleize, :for => attr)
191
+ o2 += content_tag(
192
+ :div,
193
+ f.markdown(attr.to_sym),
194
+ :class => 'markdown'
195
+ )
196
+ end
197
+ elsif options.type == 'file'
198
+ o += f.input(
199
+ attr.to_sym,
200
+ :as => options.type,
201
+ :label => label,
202
+ :readonly => readonly
203
+ )
204
+ o += link_to(
205
+ obj.send(attr).name,
206
+ obj.send(attr).url,
207
+ :class => 'file',
208
+ :target => :blank
209
+ ) unless obj.send(attr).blank?
210
+ else
211
+ o += f.input(
212
+ attr.to_sym,
213
+ :as => options.type,
214
+ :label => label,
215
+ :readonly => readonly
216
+ )
182
217
  end
183
218
  end
219
+ o += f.submit
220
+ o.html_safe
184
221
  end
185
222
 
186
- def cambium_edit_route(obj)
187
- controller = obj.class.to_s.humanize.singularize.downcase
188
- path = "admin_#{controller}_path"
189
- begin
190
- cambium.send(path, obj)
191
- rescue
223
+ def cambium_route(action, obj = nil)
224
+ case action
225
+ when :index
226
+ begin
227
+ main_app
228
+ .polymorphic_path [:admin, obj.class.to_s.downcase.pluralize.to_sym]
229
+ rescue
230
+ polymorphic_path [:admin, obj.class.to_s.downcase.pluralize.to_sym]
231
+ end
232
+ when :edit
233
+ begin
234
+ main_app.polymorphic_path [:edit, :admin, obj]
235
+ rescue
236
+ polymorphic_path [:edit, :admin, obj]
237
+ end
238
+ else
192
239
  begin
193
- main_app.send(path, obj)
240
+ main_app.polymorphic_path [:admin, obj]
194
241
  rescue
195
- nil
242
+ polymorphic_path [:admin, obj]
196
243
  end
197
244
  end
198
245
  end
@@ -10,12 +10,12 @@
10
10
  <%= content_tag(:strong, user.name.present? ? user.name : user.email) %>
11
11
  <%= "#{version.event}d" %>
12
12
  <%= version.item_type.downcase %>
13
- <% if cambium_edit_route(version.item).nil? %>
13
+ <% if cambium_route(:edit, version.item).nil? %>
14
14
  <%= content_tag(:strong, version.item.to_s) %>
15
15
  <% else %>
16
16
  <%= content_tag(
17
17
  :strong,
18
- link_to(version.item.to_s, cambium_edit_route(version.item))
18
+ link_to(version.item.to_s, cambium_route(:edit, version.item))
19
19
  ) %>
20
20
  <% end %>
21
21
  </p>
@@ -20,7 +20,7 @@
20
20
  <%= content_tag(:td, item.searchable.to_s) %>
21
21
  <%= content_tag(
22
22
  :td,
23
- link_to('', cambium_edit_route(item.searchable)),
23
+ link_to('', cambium_route(:edit, item.searchable)),
24
24
  :class => 'actions'
25
25
  ) %>
26
26
  </tr>
@@ -1,3 +1,3 @@
1
1
  module Cambium
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cambium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean C Davis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-30 00:00:00.000000000 Z
12
+ date: 2015-05-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -200,6 +200,7 @@ files:
200
200
  - app/controllers/cambium/admin/search_controller.rb
201
201
  - app/controllers/cambium/admin/users_controller.rb
202
202
  - app/controllers/cambium/admin_controller.rb
203
+ - app/controllers/cambium/base_controller.rb
203
204
  - app/helpers/cambium/cambium_helper.rb
204
205
  - app/models/concerns/idx.rb
205
206
  - app/models/concerns/image_cropper.rb