fesplugas-typus 0.9.15 → 0.9.16

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.15
1
+ 0.9.16
@@ -1,5 +1,7 @@
1
1
  class Admin::MasterController < ApplicationController
2
2
 
3
+ unloadable
4
+
3
5
  layout 'admin'
4
6
 
5
7
  include Typus::Authentication
@@ -106,7 +108,7 @@ class Admin::MasterController < ApplicationController
106
108
 
107
109
  def edit
108
110
  item_params = params.dup
109
- %w( action controller model model_id back_to id resource resource_id ).each { |p| item_params.delete(p) }
111
+ %w( action controller model model_id back_to id resource resource_id page ).each { |p| item_params.delete(p) }
110
112
  # We assign the params passed trough the url
111
113
  @item.attributes = item_params
112
114
  @previous, @next = @item.previous_and_next(item_params)
@@ -263,7 +265,7 @@ private
263
265
 
264
266
  def check_ownership_of_items
265
267
 
266
- # If current_user is a root user, by-pass.
268
+ # By-pass if current_user is root.
267
269
  return if @current_user.is_root?
268
270
 
269
271
  # If current user is not root and @resource has a foreign_key which
@@ -337,7 +339,7 @@ private
337
339
  end
338
340
 
339
341
  flash[:success] = message || _("{{model_a}} successfully assigned to {{model_b}}.",
340
- :model_a => @item.class,
342
+ :model_a => @item.class.typus_human_name,
341
343
  :model_b => resource_class.name)
342
344
  redirect_to path || params[:back_to]
343
345
 
@@ -1,5 +1,7 @@
1
1
  class TypusController < ApplicationController
2
2
 
3
+ unloadable
4
+
3
5
  layout :select_layout
4
6
 
5
7
  include Typus::Authentication
@@ -83,8 +85,7 @@ class TypusController < ApplicationController
83
85
  session[:typus_user_id] = @user.id
84
86
  redirect_to admin_dashboard_path
85
87
  else
86
- flash[:error] = _("Passwords don't match.")
87
- redirect_to admin_reset_password_path(:token => params[:token])
88
+ render :action => 'reset_password'
88
89
  end
89
90
  end
90
91
  end
@@ -121,7 +122,7 @@ private
121
122
  end
122
123
 
123
124
  def select_layout
124
- [ 'sign_up', 'sign_in', 'sign_out', 'recover_password', 'reset_password' ].include?(action_name) ? 'typus' : 'admin'
125
+ %w( sign_up sign_in sign_out recover_password reset_password ).include?(action_name) ? 'typus' : 'admin'
125
126
  end
126
127
 
127
128
  end
@@ -243,16 +243,26 @@ module Admin::FormHelper
243
243
  { Typus.user_fk => @current_user }
244
244
  end
245
245
 
246
- items = @resource[:class].find(params[:id]).send(field).find(:all, :order => model_to_relate.typus_order_by, :conditions => conditions)
246
+ options = { :order => model_to_relate.typus_order_by, :conditions => conditions }
247
+ items_count = @resource[:class].find(params[:id]).send(field).count(:conditions => conditions)
248
+ items_per_page = model_to_relate.typus_options_for(:per_page).to_i
247
249
 
248
- unless items.empty?
250
+ @pager = ::Paginator.new(items_count, items_per_page) do |offset, per_page|
251
+ options.merge!({:limit => per_page, :offset => offset})
252
+ items = @resource[:class].find(params[:id]).send(field).find(:all, options)
253
+ end
254
+
255
+ @items = @pager.page(params[:page])
256
+
257
+ unless @items.empty?
249
258
  options = { :back_to => "#{@back_to}##{field}", :resource => @resource[:self], :resource_id => @item.id }
250
259
  html << build_list(model_to_relate,
251
260
  model_to_relate.typus_fields_for(:relationship),
252
- items,
261
+ @items,
253
262
  model_to_relate_as_resource,
254
263
  options,
255
264
  association)
265
+ html << pagination(:anchor => model_to_relate.name.tableize) unless pagination.nil?
256
266
  else
257
267
  html << <<-HTML
258
268
  <div id="flash" class="notice"><p>#{_("There are no {{records}}.", :records => model_to_relate.typus_human_name.pluralize.downcase)}</p></div>
@@ -65,6 +65,11 @@ module Admin::MasterHelper
65
65
 
66
66
  end
67
67
 
68
+ def pagination(*args)
69
+ @options = args.extract_options!
70
+ render 'admin/shared/pagination' if @items.prev || @items.next
71
+ end
72
+
68
73
  ##
69
74
  # Simple and clean pagination links
70
75
  #
@@ -22,17 +22,22 @@ module TypusHelper
22
22
  HTML
23
23
 
24
24
  available.compact.each do |model|
25
- description = Typus.module_description(model)
26
- admin_items_path = { :controller => "admin/#{model.tableize}" }
27
- new_admin_item_path = { :controller => "admin/#{model.tableize}", :action => 'new'}
25
+
26
+ klass = model.constantize
27
+ klass_resource = klass.name.tableize
28
+
29
+ admin_items_path = { :controller => "admin/#{klass_resource}" }
30
+ new_admin_item_path = { :controller => "admin/#{klass_resource}", :action => 'new'}
31
+
28
32
  html << <<-HTML
29
33
  <tr class="#{cycle('even', 'odd')}">
30
- <td>#{link_to model.constantize.typus_human_name.pluralize, admin_items_path}<br /><small>#{description}</small></td>
34
+ <td>#{link_to klass.typus_human_name.pluralize, admin_items_path}<br /><small>#{klass.typus_description}</small></td>
31
35
  <td class="right"><small>
32
- #{link_to _("Add"), new_admin_item_path if @current_user.can_perform?(model, 'create')}
36
+ #{link_to _("Add"), new_admin_item_path if @current_user.can_perform?(klass, 'create')}
33
37
  </small></td>
34
38
  </tr>
35
39
  HTML
40
+
36
41
  end
37
42
 
38
43
  html << <<-HTML
@@ -142,10 +147,12 @@ module TypusHelper
142
147
  :action => 'edit',
143
148
  :id => user.id }
144
149
 
150
+ message = _("Are you sure you want to sign out and end your session?")
151
+
145
152
  <<-HTML
146
153
  <ul>
147
154
  <li>#{_("Logged as")} #{link_to user.name, admin_edit_typus_user_path, :title => "#{user.email} (#{user.role})"}</li>
148
- <li>#{link_to _("Sign out"), admin_sign_out_path }</li>
155
+ <li>#{link_to _("Sign out"), admin_sign_out_path, { :confirm => message } }</li>
149
156
  </ul>
150
157
  HTML
151
158
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  <% unless @items.count.zero? -%>
13
13
  <%= build_list(@resource[:class], @fields, @items) %>
14
- <%= render :partial => 'admin/shared/pagination' if @items.prev || @items.next %>
14
+ <%= pagination %>
15
15
  <% else %>
16
16
  <div id="flash" class="notice">
17
17
  <% if @resource[:class].count.zero? %>
@@ -1,7 +1,7 @@
1
1
  <div class="pagination">
2
2
 
3
3
  <% if @items.prev? %>
4
- <%= link_to _("&larr; Previous"), params.merge(:page => @items.prev.number) %>
4
+ <%= link_to _("&larr; Previous"), params.merge(:page => @items.prev.number, :anchor => @options[:anchor]) %>
5
5
  <% else %>
6
6
  <span class="disabled"><%= _("&larr; Previous") %></span>
7
7
  <% end %>
@@ -13,14 +13,14 @@
13
13
  <span class="current"><%= n %></span>
14
14
  <% else -%>
15
15
  <%= "..." if last_page + 1 < n %>
16
- <%= link_to n, params.merge(:page => n) %>
16
+ <%= link_to n, params.merge(:page => n, :anchor => @options[:anchor]) %>
17
17
  <% end -%>
18
18
  <% last_page = n -%>
19
19
 
20
20
  <% end -%>
21
21
 
22
22
  <% if @items.next? %>
23
- <%= link_to _("Next &rarr;"), params.merge(:page => @items.next.number) %>
23
+ <%= link_to _("Next &rarr;"), params.merge(:page => @items.next.number, :anchor => @options[:anchor]) %>
24
24
  <% else %>
25
25
  <span class="disabled"><%= _("Next &rarr;") %></span>
26
26
  <% end %>
@@ -2,6 +2,8 @@
2
2
 
3
3
  <%= hidden_field_tag :token, @user.token %>
4
4
 
5
+ <%= error_messages_for :user, :header_message => nil, :message => nil %>
6
+
5
7
  <ul>
6
8
  <li><label for="password"><%= _("Password") %></label>
7
9
  <%= password_field :user, :password, :size => 20, :class => 'text' %></li>
@@ -12,7 +12,6 @@ es:
12
12
  "That doesn't seem like a valid email address": "Eso no parecia una dirección válida de correo electrónico."
13
13
  "I remember my password": "Recuerdo mi contraseña"
14
14
  "Password recovery link sent to your email": "Enlace de recuperación de contraseña enviado a tu correo electrónico."
15
- "Passwords don't match": "Las Contraseñas no coinciden."
16
15
  "A valid token is required": "Se requiere un token válido."
17
16
  "The email and/or password you entered is invalid": "El correo y/o la contraseña proporcionadas no son válidas."
18
17
  "There are not defined applications in config/typus/*.yml": "There are not defined applications in config/typus/*.yml"
@@ -106,4 +105,5 @@ es:
106
105
  "{{model}} filtered by {{filtered_by}}": "{{model}} filtrados por {{filtered_by}}"
107
106
  "True": "Verdadero"
108
107
  "False": "Falso"
109
- "Set language to": "Idioma"
108
+ "Set language to": "Idioma"
109
+ "Are you sure you want to sign out and end your session?":
@@ -16,7 +16,6 @@
16
16
  "That doesn't seem like a valid email address":
17
17
  "I remember my password":
18
18
  "Password recovery link sent to your email":
19
- "Passwords don't match":
20
19
  "A valid token is required":
21
20
  "The email and/or password you entered is invalid":
22
21
  "There are not defined applications in config/typus/*.yml":
@@ -110,4 +109,5 @@
110
109
  "{{model}} filtered by {{filtered_by}}":
111
110
  "True":
112
111
  "False":
113
- "Set language to":
112
+ "Set language to":
113
+ "Are you sure you want to sign out and end your session?":
@@ -12,7 +12,6 @@ pt-BR:
12
12
  "That doesn't seem like a valid email address": "Este não parece um email válido"
13
13
  "I remember my password": "Lembro minha senha"
14
14
  "Password recovery link sent to your email": "Link para recuperar senha enviado para seu email."
15
- "Passwords don't match": "As senhas não conferem."
16
15
  "A valid token is required": "É necessário um token válido."
17
16
  "The email and/or password you entered is invalid": "O email e/ou a senha que você colocou são inválidos."
18
17
  "There are not defined applications in config/typus/*.yml": "Não há aplicativos definidos em config/typus/*.yml"
@@ -108,4 +107,5 @@ pt-BR:
108
107
  "{{model}} filtered by {{filtered_by}}":
109
108
  "True":
110
109
  "False":
111
- "Set language to":
110
+ "Set language to":
111
+ "Are you sure you want to sign out and end your session?":
@@ -12,7 +12,6 @@ ru:
12
12
  "That doesn't seem like a valid email address": "E-Mail некорректен"
13
13
  "I remember my password": "Запомнить пароль"
14
14
  "Password recovery link sent to your email": "Ссылка для восставновления пароля выслана по указанному E-Mail"
15
- "Passwords don't match": "Пароли не совпадают"
16
15
  "A valid token is required": "Необходим корректный ключ"
17
16
  "The email and/or password you entered is invalid": "E-Mail или пароль введены неверно"
18
17
  "There are not defined applications in config/typus/*.yml": "Ни одного приложения не определено в config/typus/*.yml"
@@ -108,4 +107,5 @@ ru:
108
107
  "{{model}} filtered by {{filtered_by}}":
109
108
  "True":
110
109
  "False":
111
- "Set language to":
110
+ "Set language to":
111
+ "Are you sure you want to sign out and end your session?":
@@ -0,0 +1,9 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ begin
4
+ ActionController::Routing::Routes.recognize_path '/admin/typus_users'
5
+ rescue
6
+ map.connect ':controller/:action/:id'
7
+ end
8
+
9
+ end
@@ -523,6 +523,15 @@ input#search {
523
523
  margin: 0.5em 0em;
524
524
  }
525
525
 
526
+ #dialog .errorExplanation ul {
527
+ margin: 10px 0 10px 0px!important;
528
+ }
529
+
530
+ #dialog .errorExplanation li {
531
+ font-weight: bold;
532
+ list-style: none!important;
533
+ }
534
+
526
535
  /* @end */
527
536
 
528
537
  /* @group Pagination */
@@ -6,9 +6,7 @@ module Typus
6
6
 
7
7
  module ClassMethods
8
8
 
9
- ##
10
9
  # Return model fields as a OrderedHash
11
- #
12
10
  def model_fields
13
11
  hash = ActiveSupport::OrderedHash.new
14
12
  columns.map { |u| hash[u.name.to_sym] = u.type.to_sym }
@@ -35,9 +33,11 @@ module Typus
35
33
  human_name(:default => self.name.underscore.humanize)
36
34
  end
37
35
 
38
- ##
36
+ def typus_description
37
+ Typus::Configuration.config[self.name]['description']
38
+ end
39
+
39
40
  # Form and list fields
40
- #
41
41
  def typus_fields_for(filter)
42
42
 
43
43
  fields_with_type = ActiveSupport::OrderedHash.new
@@ -92,27 +92,21 @@ module Typus
92
92
 
93
93
  end
94
94
 
95
- ##
96
95
  # Return tiny_mce options of the model merged into the default options
97
- #
98
96
  def typus_tiny_mce_options
99
97
  typus_options_for(:tiny_mce).merge(Typus::Configuration.config[name]['fields']['options']['tiny_mce']['options'].symbolize_keys.delete_if { |key,value| value == nil})
100
98
  rescue
101
99
  typus_options_for(:tiny_mce)
102
100
  end
103
101
 
104
- ##
105
102
  # Tiny_mce fields of the model
106
- #
107
103
  def typus_tiny_mce_fields
108
104
  Typus::Configuration.config[name]['fields']['options']['tiny_mce']['fields'].split(', ')
109
105
  rescue
110
106
  []
111
107
  end
112
108
 
113
- ##
114
109
  # Typus sidebar filters.
115
- #
116
110
  def typus_filters
117
111
 
118
112
  fields_with_type = ActiveSupport::OrderedHash.new
@@ -133,35 +127,26 @@ module Typus
133
127
 
134
128
  end
135
129
 
136
- ##
137
130
  # Extended actions for this model on Typus.
138
- #
139
131
  def typus_actions_for(filter)
140
132
  Typus::Configuration.config[name]['actions'][filter.to_s].split(', ')
141
133
  rescue
142
134
  []
143
135
  end
144
136
 
145
- ##
146
137
  # Used for +search+, +relationships+
147
- #
148
138
  def typus_defaults_for(filter)
149
139
  data = Typus::Configuration.config[name][filter.to_s]
150
140
  return (!data.nil?) ? data.split(', ') : []
151
141
  end
152
142
 
153
- ##
154
- #
155
- #
156
143
  def typus_field_options_for(filter)
157
144
  Typus::Configuration.config[name]['fields']['options'][filter.to_s].split(', ').collect { |i| i.to_sym }
158
145
  rescue
159
146
  []
160
147
  end
161
148
 
162
- ##
163
149
  # We should be able to overwrite options by model.
164
- #
165
150
  def typus_options_for(filter)
166
151
 
167
152
  data = Typus::Configuration.config[name]
@@ -178,9 +163,7 @@ module Typus
178
163
  !data['export'].nil? ? data['export'].split(', ') : []
179
164
  end
180
165
 
181
- ##
182
- # Used for order_by
183
- #
166
+ # Used for `order_by`.
184
167
  def typus_order_by
185
168
 
186
169
  fields = typus_defaults_for(:order_by)
@@ -194,9 +177,7 @@ module Typus
194
177
 
195
178
  end
196
179
 
197
- ##
198
180
  # We are able to define our own booleans.
199
- #
200
181
  def typus_boolean(attribute = :default)
201
182
 
202
183
  boolean = Typus::Configuration.config[name]['fields']['options']['booleans'][attribute.to_s] rescue nil
@@ -216,28 +197,21 @@ module Typus
216
197
 
217
198
  end
218
199
 
219
- ##
220
200
  # We are able to define how to display dates on Typus
221
- #
222
201
  def typus_date_format(attribute = :default)
223
202
  date_format = Typus::Configuration.config[name]['fields']['options']['date_formats'][attribute.to_s].to_sym rescue nil
224
203
  date_format = :db if date_format.nil?
225
204
  return date_format
226
205
  end
227
206
 
228
- ##
229
207
  # We are able to define which template to use to render the attribute
230
208
  # within the form
231
- #
232
209
  def typus_template(attribute)
233
210
  Typus::Configuration.config[name]['fields']['options']['templates'][attribute.to_s]
234
211
  rescue
235
212
  nil
236
213
  end
237
214
 
238
- ##
239
- # Build conditions
240
- #
241
215
  def build_conditions(params)
242
216
 
243
217
  conditions, joins = merge_conditions, []
@@ -260,9 +234,9 @@ module Typus
260
234
  ##
261
235
  # Sidebar filters:
262
236
  #
263
- # - Booleans: true, false
264
- # - Datetime: today, past_7_days, this_month, this_year
265
- # - Integer & String: *_id and "selectors" (P.ej. category_id)
237
+ # - Booleans: true, false
238
+ # - Datetime: today, past_7_days, this_month, this_year
239
+ # - Integer & String: *_id and "selectors" (p.ej. category_id)
266
240
  #
267
241
  case filter_type
268
242
  when :boolean
@@ -4,30 +4,25 @@ module Typus
4
4
 
5
5
  protected
6
6
 
7
- ##
8
7
  # Require login checks if the user is logged on Typus, otherwise
9
8
  # is sent to the sign in page with a :back_to param to return where
10
9
  # she tried to go.
11
- #
12
- # Use this for demo!
13
- #
14
- # session[:typus_user_id] = Typus.user_class.find(:first)
15
- #
16
10
  def require_login
11
+
12
+ # Uncomment the following line for demo purpouses.
13
+ # session[:typus_user_id] = Typus.user_class.find(:first)
14
+
17
15
  if session[:typus_user_id]
18
16
  set_current_user
19
17
  else
20
18
  back_to = (request.env['REQUEST_URI'] == '/admin') ? nil : request.env['REQUEST_URI']
21
19
  redirect_to admin_sign_in_path(:back_to => back_to)
22
20
  end
21
+
23
22
  end
24
23
 
25
- ##
26
- # Return the current user.
27
- #
28
- # NOTE: If role does not longer exist on the system the user will
29
- # be signed out from Typus.
30
- #
24
+ # Return the current user. If role does not longer exist on the
25
+ # system @current_user will be signed out from Typus.
31
26
  def set_current_user
32
27
 
33
28
  @current_user = Typus.user_class.find(session[:typus_user_id])
@@ -51,11 +46,7 @@ module Typus
51
46
  redirect_to admin_sign_in_path(:back_to => back_to)
52
47
  end
53
48
 
54
- ##
55
- # Action is available on:
56
- #
57
- # edit, update, toggle and destroy
58
- #
49
+ # Action is available on: edit, update, toggle and destroy
59
50
  def check_if_user_can_perform_action_on_user
60
51
 
61
52
  return unless @item.kind_of?(Typus.user_class)
@@ -104,10 +95,8 @@ module Typus
104
95
 
105
96
  end
106
97
 
107
- ##
108
98
  # This method checks if the user can perform the requested action.
109
99
  # It works on models, so its available on the admin_controller.
110
- #
111
100
  def check_if_user_can_perform_action_on_resource
112
101
 
113
102
  message = case params[:action]
@@ -133,11 +122,9 @@ module Typus
133
122
 
134
123
  end
135
124
 
136
- ##
137
125
  # This method checks if the user can perform the requested action.
138
126
  # It works on resources, which are not models, so its available on
139
127
  # the typus_controller.
140
- #
141
128
  def check_if_user_can_perform_action_on_resource_without_model
142
129
  controller = params[:controller].split('/').last
143
130
  action = params[:action]
@@ -2,20 +2,7 @@ module Typus
2
2
 
3
3
  module Configuration
4
4
 
5
- ##
6
- # Default Typus options which can be overwritten from the
7
- # initializer. Example:
8
- #
9
- # Typus::Configuration.options[:recover_password]
10
- #
11
- # Special cases:
12
- #
13
- # Typus::Configuration.options[:user_fk]
14
- # Typus.user_fk
15
- #
16
- # Typus::Configuration.options[:user_class_name]
17
- # Typus.user_class
18
- #
5
+ # Default options which can be overwritten from the initializer.
19
6
  typus_options = { :app_name => 'Typus',
20
7
  :config_folder => 'config/typus',
21
8
  :email => 'admin@example.com',
@@ -27,12 +14,7 @@ module Typus
27
14
  :user_class_name => 'TypusUser',
28
15
  :user_fk => 'typus_user_id' }
29
16
 
30
- ##
31
- # Default model options which can be overwritten from the
32
- # initializer. Example:
33
- #
34
- # Model.typus_options_for(:default_action_on_item)
35
- #
17
+ # Default options which can be overwritten from the initializer.
36
18
  model_options = { :default_action_on_item => 'edit',
37
19
  :end_year => nil,
38
20
  :form_rows => 10,
@@ -54,11 +36,7 @@ module Typus
54
36
 
55
37
  mattr_accessor :options
56
38
 
57
- ##
58
39
  # Read Typus Configuration files placed on <tt>config/typus/**/*.yml</tt>.
59
- #
60
- # Typus::Configuration.config! overwrites @@config
61
- #
62
40
  def self.config!
63
41
 
64
42
  files = Dir["#{Rails.root}/#{options[:config_folder]}/**/*.yml"].sort
@@ -76,11 +54,7 @@ module Typus
76
54
 
77
55
  mattr_accessor :config
78
56
 
79
- ##
80
57
  # Read Typus Roles from configuration files placed on <tt>config/typus/**/*_roles.yml</tt>.
81
- #
82
- # Typus::Configuration.roles! overwrites @@roles
83
- #
84
58
  def self.roles!
85
59
 
86
60
  files = Dir["#{Rails.root}/#{options[:config_folder]}/**/*_roles.yml"].sort
data/lib/typus/format.rb CHANGED
@@ -26,9 +26,7 @@ module Typus
26
26
  fields = @resource[:class].typus_fields_for(:csv).collect { |i| i.first }
27
27
  csv_string = FasterCSV.generate do |csv|
28
28
  csv << fields.map { |f| _(f.humanize) }
29
- data.each do |item|
30
- csv << fields.map { |f| item.send(f) }
31
- end
29
+ data.each { |i| csv << fields.map { |f| i.send(f) } }
32
30
  end
33
31
 
34
32
  filename = "#{Time.now.strftime("%Y%m%d%H%M%S")}_#{@resource[:self]}.csv"
@@ -46,7 +44,8 @@ module Typus
46
44
  end
47
45
 
48
46
  def data(*args)
49
- options = { :joins => @joins, :conditions => @conditions, :order => @order }
47
+ eager_loading = @resource[:class].reflect_on_all_associations(:belongs_to).map { |i| i.name }
48
+ options = { :joins => @joins, :conditions => @conditions, :order => @order, :include => eager_loading }
50
49
  options.merge!(args.extract_options!)
51
50
  @resource[:class].find(:all, options)
52
51
  end
@@ -8,7 +8,7 @@ module Typus
8
8
  admin_controllers_folder = "#{Rails.root}/app/controllers/admin"
9
9
  Dir.mkdir(admin_controllers_folder) unless File.directory?(admin_controllers_folder)
10
10
 
11
- # Get a list of all available app/controllers/admin
11
+ # Get a list of controllers under `app/controllers/admin`.
12
12
  admin_controllers = Dir["#{Rails.root}/vendor/plugins/*/app/controllers/admin/*.rb", "#{admin_controllers_folder}/*.rb"]
13
13
  admin_controllers = admin_controllers.map { |i| File.basename(i) }
14
14
 
@@ -22,27 +22,25 @@ module Typus
22
22
  Dir.mkdir(admin_controller_tests_folder) unless File.directory?(admin_controller_tests_folder)
23
23
  end
24
24
 
25
- # Get a list of all available functional test for admin.
25
+ # Get a list of functional tests under `test/functional/admin`.
26
26
  admin_controller_tests = Dir["#{Rails.root}/vendor/plugins/*/test/functional/admin/*.rb", "#{admin_controller_tests_folder}/*.rb"]
27
27
  admin_controller_tests = admin_controller_tests.map { |i| File.basename(i) }
28
28
 
29
- # Generate unexisting controllers for resources which are not tied to
30
- # a model.
29
+ # Generate controllers for tableless models.
31
30
  resources.each do |resource|
32
31
 
33
32
  controller_filename = "#{resource.underscore}_controller.rb"
34
33
  controller_location = "#{admin_controllers_folder}/#{controller_filename}"
35
34
 
36
35
  if !admin_controllers.include?(controller_filename)
37
- controller = File.open(controller_location, "w+")
36
+
38
37
  content = <<-RAW
39
38
  # Controller generated by Typus, use it to extend admin functionality.
40
39
  class Admin::#{resource}Controller < TypusController
41
40
 
42
41
  ##
43
42
  # This controller was generated because you have defined a resource
44
- # which is not tied to a model on your <tt>config/typus/XXXXXX_roles.yml</tt>
45
- # configuration file.
43
+ # on <tt>config/typus/XXXXXX_roles.yml</tt> which is a tableless model.
46
44
  #
47
45
  # admin:
48
46
  # #{resource}: index
@@ -54,8 +52,7 @@ class Admin::#{resource}Controller < TypusController
54
52
  end
55
53
  RAW
56
54
 
57
- controller.puts(content)
58
- controller.close
55
+ File.open(controller_location, "w+") { |f| f << content }
59
56
  logger.info "=> [typus] Admin::#{resource}Controller successfully created."
60
57
 
61
58
  end
@@ -66,7 +63,7 @@ end
66
63
 
67
64
  if !File.exist?("#{view_folder}/#{view_filename}")
68
65
  Dir.mkdir(view_folder) unless File.directory?(view_folder)
69
- view = File.open("#{view_folder}/#{view_filename}", "w+")
66
+
70
67
  content = <<-RAW
71
68
  <!-- Sidebar -->
72
69
 
@@ -81,9 +78,10 @@ end
81
78
  <p>And here we do whatever we want to ...</p>
82
79
 
83
80
  RAW
84
- view.puts(content)
85
- view.close
81
+
82
+ File.open("#{view_folder}/#{view_filename}", "w+") { |f| f << content}
86
83
  logger.info "=> [typus] app/views/admin/#{resource.underscore}/index.html.erb successfully created."
84
+
87
85
  end
88
86
 
89
87
  end
@@ -97,7 +95,6 @@ end
97
95
  controller_location = "#{admin_controllers_folder}/#{controller_filename}"
98
96
 
99
97
  if !admin_controllers.include?(controller_filename)
100
- controller = File.open(controller_location, "w+")
101
98
 
102
99
  content = <<-RAW
103
100
  # Controller generated by Typus, use it to extend admin functionality.
@@ -106,19 +103,9 @@ class Admin::#{model.pluralize}Controller < Admin::MasterController
106
103
  =begin
107
104
 
108
105
  ##
109
- # You can overwrite any Admin::MasterController methods.
110
- #
111
- def index
112
- end
113
-
114
- =end
115
-
116
- =begin
117
-
118
- ##
119
- # You can extend Admin::MasterController with your methods.
106
+ # You can overwrite and extend Admin::MasterController with your methods.
120
107
  #
121
- # This actions have to be defined in <tt>config/typus/application.yml</tt>:
108
+ # Actions have to be defined in <tt>config/typus/application.yml</tt>:
122
109
  #
123
110
  # #{model}:
124
111
  # actions:
@@ -134,7 +121,10 @@ class Admin::#{model.pluralize}Controller < Admin::MasterController
134
121
  # editor:
135
122
  # #{model}: create, read, update, custom_action_for_an_item
136
123
  #
137
- #
124
+
125
+ def index
126
+ end
127
+
138
128
  def custom_action
139
129
  end
140
130
 
@@ -146,9 +136,9 @@ class Admin::#{model.pluralize}Controller < Admin::MasterController
146
136
  end
147
137
  RAW
148
138
 
149
- controller.puts(content)
150
- controller.close
139
+ File.open(controller_location, "w+") { |f| f << content }
151
140
  logger.info "=> [typus] Admin::#{model.pluralize}Controller successfully created."
141
+
152
142
  end
153
143
 
154
144
  # Test test/functional/admin/*_test.rb
@@ -156,7 +146,6 @@ end
156
146
  test_location = "#{admin_controller_tests_folder}/#{test_filename}"
157
147
 
158
148
  if !admin_controller_tests.include?(test_filename) && File.directory?("#{Rails.root}/test")
159
- test = File.open(test_location, "w+")
160
149
 
161
150
  content = <<-RAW
162
151
  require 'test_helper'
@@ -171,9 +160,9 @@ class Admin::#{model.pluralize}ControllerTest < ActionController::TestCase
171
160
  end
172
161
  RAW
173
162
 
174
- test.puts(content)
175
- test.close
163
+ File.open(test_location, "w+") { |f| f << content }
176
164
  logger.info "=> [typus] Admin::#{model.pluralize}ControllerTest successfully created."
165
+
177
166
  end
178
167
 
179
168
  end
data/lib/typus/hash.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  class Hash
2
2
 
3
- ##
4
3
  # Remove nil and empty keys.
5
- #
6
4
  def compact
7
5
  delete_if { |key, value| value.nil? || value.empty? }
8
6
  end
data/lib/typus/object.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  class Object
2
2
 
3
- ##
4
3
  # Instead of having to translate strings and defining a default value:
5
4
  #
6
5
  # t("Hello World!", :default => 'Hello World!')
@@ -6,7 +6,7 @@ module Typus
6
6
 
7
7
  render :text => '' and return unless session[:typus_user_id]
8
8
 
9
- links = [[ "Dashboard", admin_dashboard_path ] ]
9
+ links = [[ "Dashboard", admin_dashboard_path ]]
10
10
  links << [ params[:message], "/admin/#{params[:path]}" ] if params[:message] && params[:path]
11
11
 
12
12
  options = links.reverse.map do |link|
@@ -2,9 +2,7 @@ module Typus
2
2
 
3
3
  module Reloader
4
4
 
5
- ##
6
5
  # Reload config and roles when app is running in development.
7
- #
8
6
  def reload_config_et_roles
9
7
  return if Rails.env.production?
10
8
  logger.info "=> [typus] Configuration files have been reloaded."
data/lib/typus.rb CHANGED
@@ -1,3 +1,16 @@
1
+ class ActionController::Routing::RouteSet
2
+
3
+ def load_routes_with_typus!
4
+ lib_path = File.dirname(__FILE__)
5
+ typus_routes = File.join(lib_path, *%w[ .. config routes_hack.rb ])
6
+ add_configuration_file(typus_routes) unless configuration_files.include?(typus_routes)
7
+ load_routes_without_typus!
8
+ end
9
+
10
+ alias_method_chain :load_routes!, :typus
11
+
12
+ end
13
+
1
14
  module Typus
2
15
 
3
16
  class << self
@@ -22,9 +35,7 @@ module Typus
22
35
  Typus::Configuration.config.collect { |i| i.last['application'] }.compact.uniq.sort
23
36
  end
24
37
 
25
- ##
26
- # Returns a list of the modules of an application.
27
- #
38
+ # List of the modules of an application.
28
39
  def application(name)
29
40
  Typus::Configuration.config.collect { |i| i.first if i.last['application'] == name }.compact.uniq.sort
30
41
  end
@@ -37,9 +48,7 @@ module Typus
37
48
  models.collect { |m| m if m.constantize.typus_options_for(:on_header) }.compact
38
49
  end
39
50
 
40
- ##
41
- # Return a list of resources, which are models tableless.
42
- #
51
+ # List of resources, which are tableless models.
43
52
  def resources(models = get_model_names)
44
53
 
45
54
  all_resources = Typus::Configuration.roles.keys.map do |key|
@@ -55,10 +64,6 @@ module Typus
55
64
  "#{Rails.root}/vendor/plugins/**/app/models/**/*.rb" ].collect { |m| File.basename(m).sub(/\.rb$/,'').camelize }
56
65
  end
57
66
 
58
- def module_description(modulo)
59
- Typus::Configuration.config[modulo]['description']
60
- end
61
-
62
67
  def user_class
63
68
  Typus::Configuration.options[:user_class_name].constantize
64
69
  end
@@ -75,11 +80,7 @@ module Typus
75
80
  File.exist?("#{Rails.root}/vendor/plugins/typus")
76
81
  end
77
82
 
78
- ##
79
83
  # Enable application. This is used at boot time.
80
- #
81
- # Typus.enable
82
- #
83
84
  def enable
84
85
 
85
86
  # Ruby Extensions
@@ -127,8 +127,7 @@ class TypusControllerTest < ActionController::TestCase
127
127
  def test_should_be_redirected_if_password_does_not_match_confirmation
128
128
  typus_user = typus_users(:admin)
129
129
  post :reset_password, { :token => typus_user.token, :user => { :password => 'drowssap', :password_confirmation => 'drowssap2' } }
130
- assert_response :redirect
131
- assert_redirected_to admin_reset_password_path(:token => typus_user.token)
130
+ assert_response :success
132
131
  end
133
132
 
134
133
  def test_should_only_be_allowed_to_reset_password
@@ -3,6 +3,7 @@ require 'test/helper'
3
3
  class Admin::FormHelperTest < ActiveSupport::TestCase
4
4
 
5
5
  include Admin::FormHelper
6
+ include Admin::MasterHelper
6
7
 
7
8
  include ActionView::Helpers::FormHelper
8
9
  include ActionView::Helpers::FormOptionsHelper
@@ -50,6 +50,11 @@ class ActiveRecordTest < ActiveSupport::TestCase
50
50
  end
51
51
  end
52
52
 
53
+ def test_should_return_description_of_a_model
54
+ assert TypusUser.respond_to?(:typus_description)
55
+ assert_equal "System Users Administration", TypusUser.typus_description
56
+ end
57
+
53
58
  def test_should_return_typus_fields_for_list_for_typus_user
54
59
  expected_fields = [['email', :string],
55
60
  ['role', :selector],
@@ -54,11 +54,6 @@ class TypusTest < ActiveSupport::TestCase
54
54
  assert_equal %w( Git Order Status WatchDog ), Typus.resources(models)
55
55
  end
56
56
 
57
- def test_should_return_description_of_module
58
- assert Typus.respond_to?(:module_description)
59
- assert_equal 'System Users Administration', Typus.module_description('TypusUser')
60
- end
61
-
62
57
  def test_should_verify_enable_exists
63
58
  assert Typus.respond_to?(:enable)
64
59
  end
@@ -48,20 +48,20 @@ class TypusUserRolesTest < ActiveSupport::TestCase
48
48
  end
49
49
 
50
50
  # Category: create, read, update
51
- %w( create read update ).each { |action| assert typus_user.can_perform?(Category, action) }
52
- %w( delete ).each { |action| assert !typus_user.can_perform?(Category, action) }
51
+ %w( create read update ).each { |action| assert typus_user.can_perform?('Category', action) }
52
+ %w( delete ).each { |action| assert !typus_user.can_perform?('Category', action) }
53
53
 
54
54
  # Post: create, read, update
55
- %w( create read update ).each { |action| assert typus_user.can_perform?(Post, action) }
56
- %w( delete ).each { |action| assert !typus_user.can_perform?(Post, action) }
55
+ %w( create read update ).each { |action| assert typus_user.can_perform?('Post', action) }
56
+ %w( delete ).each { |action| assert !typus_user.can_perform?('Post', action) }
57
57
 
58
58
  # Comment: read, update, delete
59
- %w( read update delete ).each { |action| assert typus_user.can_perform?(Comment, action) }
60
- %w( create ).each { |action| assert !typus_user.can_perform?(Comment, action) }
59
+ %w( read update delete ).each { |action| assert typus_user.can_perform?('Comment', action) }
60
+ %w( create ).each { |action| assert !typus_user.can_perform?('Comment', action) }
61
61
 
62
62
  # TypusUser: read, update
63
- %w( read update ).each { |action| assert typus_user.can_perform?(TypusUser, action) }
64
- %w( create delete ).each { |action| assert !typus_user.can_perform?(TypusUser, action) }
63
+ %w( read update ).each { |action| assert typus_user.can_perform?('TypusUser', action) }
64
+ %w( create delete ).each { |action| assert !typus_user.can_perform?('TypusUser', action) }
65
65
 
66
66
  end
67
67
 
@@ -74,16 +74,16 @@ class TypusUserRolesTest < ActiveSupport::TestCase
74
74
  assert_equal models, typus_user.resources.map(&:first).sort
75
75
 
76
76
  # Category: read, update
77
- %w( read update ).each { |action| assert typus_user.can_perform?(Category, action) }
78
- %w( create delete ).each { |action| assert !typus_user.can_perform?(Category, action) }
77
+ %w( read update ).each { |action| assert typus_user.can_perform?('Category', action) }
78
+ %w( create delete ).each { |action| assert !typus_user.can_perform?('Category', action) }
79
79
 
80
80
  # Comment: read
81
- %w( read ).each { |action| assert typus_user.can_perform?(Comment, action) }
82
- %w( create update delete ).each { |action| assert !typus_user.can_perform?(Comment, action) }
81
+ %w( read ).each { |action| assert typus_user.can_perform?('Comment', action) }
82
+ %w( create update delete ).each { |action| assert !typus_user.can_perform?('Comment', action) }
83
83
 
84
84
  # Post: read
85
- %w( read ).each { |action| assert typus_user.can_perform?(Post, action) }
86
- %w( create update delete ).each { |action| assert !typus_user.can_perform?(Post, action) }
85
+ %w( read ).each { |action| assert typus_user.can_perform?('Post', action) }
86
+ %w( create update delete ).each { |action| assert !typus_user.can_perform?('Post', action) }
87
87
 
88
88
  end
89
89
 
@@ -167,4 +167,11 @@ this_is_chelm@example.com
167
167
  assert TypusUser.generate('demo@example.com', 'XXXX').invalid?
168
168
  end
169
169
 
170
+ def test_should_verify_can_perform?
171
+ assert TypusUser.instance_methods.include?('can_perform?')
172
+ @current_user = TypusUser.find(:first)
173
+ assert @current_user.can_perform?(TypusUser, 'delete')
174
+ assert @current_user.can_perform?('TypusUser', 'delete')
175
+ end
176
+
170
177
  end
data/typus.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{typus}
5
- s.version = "0.9.15"
5
+ s.version = "0.9.16"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Francesc Esplugas"]
9
- s.date = %q{2009-07-03}
9
+ s.date = %q{2009-07-09}
10
10
  s.description = %q{Effortless backend interface for Ruby on Rails applications. (Admin scaffold generator.)}
11
11
  s.email = %q{francesc@intraducibles.com}
12
12
  s.extra_rdoc_files = [
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
48
48
  "config/locales/typus/pt-BR.yml",
49
49
  "config/locales/typus/ru.yml",
50
50
  "config/routes.rb",
51
+ "config/routes_hack.rb",
51
52
  "generators/typus/templates/config/initializers/typus.rb",
52
53
  "generators/typus/templates/config/typus/README",
53
54
  "generators/typus/templates/config/typus/application.yml",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fesplugas-typus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.15
4
+ version: 0.9.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesc Esplugas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-03 00:00:00 -07:00
12
+ date: 2009-07-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -57,6 +57,7 @@ files:
57
57
  - config/locales/typus/pt-BR.yml
58
58
  - config/locales/typus/ru.yml
59
59
  - config/routes.rb
60
+ - config/routes_hack.rb
60
61
  - generators/typus/templates/config/initializers/typus.rb
61
62
  - generators/typus/templates/config/typus/README
62
63
  - generators/typus/templates/config/typus/application.yml