hobo 1.3.0.RC4 → 1.3.0.pre10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/CHANGES.txt +234 -282
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/app/controllers/dev_controller.rb +2 -2
  5. data/bin/hobo +3 -3
  6. data/config/routes.rb +1 -1
  7. data/doctests/hobo/lifecycles.rdoctest +1 -0
  8. data/doctests/hobo/model.rdoctest +5 -0
  9. data/doctests/hobo/multi_model_forms.rdoctest +5 -4
  10. data/doctests/hobo/scopes.rdoctest +8 -11
  11. data/doctests/prepare_testapp.rb +1 -2
  12. data/hobo.gemspec +2 -2
  13. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +11 -5
  14. data/lib/generators/hobo/admin_subsite/templates/admin.css +2 -20
  15. data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +1 -3
  16. data/lib/generators/hobo/admin_subsite/templates/controller.rb.erb +5 -5
  17. data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +1 -3
  18. data/lib/generators/hobo/basic/basic_generator.rb +17 -0
  19. data/lib/generators/hobo/{assets → basic}/templates/application.css +0 -0
  20. data/lib/generators/hobo/{assets → basic}/templates/application.dryml.erb +1 -1
  21. data/lib/generators/hobo/{assets → basic}/templates/dryml-support.js +2 -2
  22. data/lib/generators/hobo/{assets → basic}/templates/en_injection.yml +0 -0
  23. data/lib/generators/hobo/{assets → basic}/templates/guest.rb +0 -0
  24. data/lib/generators/hobo/controller.rb +1 -6
  25. data/lib/generators/hobo/front_controller/front_controller_generator.rb +3 -2
  26. data/{app/views/dev → lib/generators/hobo/front_controller/templates}/summary.dryml +10 -7
  27. data/lib/generators/hobo/hints/hints_generator.rb +12 -0
  28. data/lib/generators/hobo/hints/templates/hints.rb.erb +5 -0
  29. data/lib/generators/hobo/hints/templates/model_injection.rb.erb +36 -0
  30. data/lib/generators/hobo/i18n/i18n_generator.rb +9 -1
  31. data/lib/generators/hobo/i18n/templates/app.en.yml +1 -1
  32. data/lib/generators/hobo/i18n/templates/app.es-DO.yml +24 -0
  33. data/lib/generators/hobo/i18n/templates/app.it.yml +1 -5
  34. data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +0 -1
  35. data/lib/generators/hobo/i18n/templates/default_count_injection.rb +10 -0
  36. data/lib/generators/hobo/i18n/templates/hobo.en.yml +10 -26
  37. data/lib/generators/hobo/i18n/templates/{hobo.es.yml → hobo.es-DO.yml} +10 -27
  38. data/lib/generators/hobo/i18n/templates/hobo.it.yml +4 -20
  39. data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +9 -25
  40. data/lib/generators/hobo/model.rb +13 -0
  41. data/lib/generators/hobo/model/USAGE +3 -2
  42. data/lib/generators/hobo/model/model_generator.rb +1 -2
  43. data/lib/generators/hobo/rapid/rapid_generator.rb +0 -2
  44. data/lib/generators/hobo/rapid/templates/hobo-rapid.js +93 -78
  45. data/lib/generators/hobo/rapid/templates/ie7-recalc.js +21 -21
  46. data/lib/generators/hobo/rapid/templates/lowpro.js +31 -31
  47. data/lib/generators/hobo/rapid/templates/reset.css +1 -1
  48. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +16 -17
  49. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
  50. data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +1 -1
  51. data/lib/generators/hobo/resource/resource_generator.rb +1 -1
  52. data/lib/generators/hobo/routes/router.rb +4 -4
  53. data/lib/generators/hobo/routes/routes_generator.rb +1 -12
  54. data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +1 -1
  55. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +43 -88
  56. data/lib/generators/hobo/subsite.rb +5 -18
  57. data/lib/generators/hobo/subsite/subsite_generator.rb +1 -1
  58. data/lib/generators/hobo/subsite/templates/controller.rb.erb +1 -1
  59. data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +2 -2
  60. data/lib/generators/hobo/test_framework/test_framework_generator.rb +7 -7
  61. data/lib/generators/hobo/user_controller/templates/controller.rb.erb +3 -8
  62. data/lib/generators/hobo/user_mailer/templates/activation.erb +2 -2
  63. data/lib/generators/hobo/user_mailer/templates/forgot_password.erb +2 -2
  64. data/lib/generators/hobo/user_mailer/templates/invite.erb +2 -2
  65. data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +17 -10
  66. data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +1 -1
  67. data/lib/generators/hobo/user_model/USAGE +9 -2
  68. data/lib/generators/hobo/user_model/user_model_generator.rb +1 -2
  69. data/lib/hobo.rb +7 -13
  70. data/lib/hobo/controller.rb +14 -21
  71. data/lib/hobo/controller/authentication_support.rb +23 -1
  72. data/lib/hobo/controller/model.rb +53 -48
  73. data/lib/hobo/controller/{user_base.rb → user.rb} +36 -47
  74. data/lib/hobo/engine.rb +11 -25
  75. data/lib/hobo/extensions/action_controller/hobo_methods.rb +1 -25
  76. data/lib/hobo/extensions/active_model/translation.rb +1 -1
  77. data/lib/hobo/extensions/active_record/{associations/collection.rb → association_collection.rb} +3 -12
  78. data/lib/hobo/extensions/active_record/{associations/proxy.rb → association_proxy.rb} +7 -6
  79. data/lib/hobo/extensions/active_record/association_reflection.rb +19 -0
  80. data/lib/hobo/extensions/active_record/hobo_methods.rb +1 -1
  81. data/lib/hobo/extensions/active_record/scopes.rb +31 -0
  82. data/lib/hobo/extensions/array.rb +1 -13
  83. data/lib/hobo/helper.rb +6 -27
  84. data/lib/hobo/helper/translations.rb +90 -39
  85. data/lib/hobo/model.rb +20 -72
  86. data/lib/hobo/model/lifecycles.rb +11 -12
  87. data/lib/hobo/model/lifecycles/lifecycle.rb +4 -12
  88. data/lib/hobo/model/lifecycles/transition.rb +0 -1
  89. data/lib/hobo/model/permissions.rb +3 -2
  90. data/lib/hobo/model/scopes/apply_scopes.rb +1 -1
  91. data/lib/hobo/model/scopes/automatic_scopes.rb +80 -78
  92. data/lib/hobo/model/{user_base.rb → user.rb} +7 -9
  93. data/lib/hobo/rapid/generators/rapid/cards.dryml.erb +2 -2
  94. data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +4 -5
  95. data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +27 -26
  96. data/lib/hobo/rapid/helper.rb +5 -10
  97. data/lib/hobo/rapid/taglibs/rapid.dryml +1 -1
  98. data/lib/hobo/rapid/taglibs/rapid_core.dryml +42 -72
  99. data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +2 -2
  100. data/lib/hobo/rapid/taglibs/rapid_editing.dryml +16 -36
  101. data/lib/hobo/rapid/taglibs/rapid_forms.dryml +49 -87
  102. data/lib/hobo/rapid/taglibs/rapid_generics.dryml +2 -2
  103. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +75 -50
  104. data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +5 -7
  105. data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +2 -2
  106. data/lib/hobo/rapid/taglibs/rapid_pages.dryml +7 -8
  107. data/lib/hobo/rapid/taglibs/rapid_plus.dryml +43 -66
  108. data/lib/hobo/rapid/taglibs/rapid_summary.dryml +45 -16
  109. data/lib/hobo/rapid/taglibs/rapid_translations.dryml +36 -0
  110. data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +8 -8
  111. data/lib/hobo/routes.rb +23 -22
  112. data/lib/hobo/view_hints.rb +101 -0
  113. data/test/irt/generators/admin_subsite.irt +1 -1
  114. data/test/irt/generators/{assets.irt → basic.irt} +2 -2
  115. data/test/irt/generators/front_controller.irt +4 -2
  116. data/test/irt/generators/partials/_subsite_taglib_variables.rb +1 -1
  117. data/test/irt/generators/subsite.irt +1 -1
  118. data/test/permissions/test_permissions.rb +103 -103
  119. metadata +108 -69
  120. data/lib/generators/hobo/admin_subsite/USAGE +0 -25
  121. data/lib/generators/hobo/admin_subsite/templates/application.dryml +0 -1
  122. data/lib/generators/hobo/assets/USAGE +0 -5
  123. data/lib/generators/hobo/assets/assets_generator.rb +0 -18
  124. data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +0 -1
  125. data/lib/generators/hobo/controller/USAGE +0 -3
  126. data/lib/generators/hobo/i18n/USAGE +0 -3
  127. data/lib/generators/hobo/i18n/templates/app.de.yml +0 -30
  128. data/lib/generators/hobo/i18n/templates/app.es.yml +0 -31
  129. data/lib/generators/hobo/i18n/templates/app.fr.yml +0 -26
  130. data/lib/generators/hobo/i18n/templates/app.nb.yml +0 -25
  131. data/lib/generators/hobo/i18n/templates/app.ru.yml +0 -24
  132. data/lib/generators/hobo/i18n/templates/hobo.de.yml +0 -204
  133. data/lib/generators/hobo/i18n/templates/hobo.fr.yml +0 -195
  134. data/lib/generators/hobo/i18n/templates/hobo.nb.yml +0 -198
  135. data/lib/generators/hobo/i18n/templates/hobo.ru.yml +0 -200
  136. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
  137. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
  138. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
  139. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/spinner.gif +0 -0
  140. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +0 -81
  141. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +0 -30
  142. data/lib/generators/hobo/resource/USAGE +0 -39
  143. data/lib/generators/hobo/subsite/USAGE +0 -24
  144. data/lib/generators/hobo/subsite_taglib/USAGE +0 -4
  145. data/lib/generators/hobo/test_framework/USAGE +0 -2
  146. data/lib/generators/hobo/user_controller/USAGE +0 -3
  147. data/lib/generators/hobo/user_mailer/USAGE +0 -2
  148. data/lib/generators/hobo/user_resource/USAGE +0 -10
  149. data/lib/hobo/extensions/action_view/translation_helper.rb +0 -25
  150. data/lib/hobo/extensions/active_record/associations/reflection.rb +0 -23
  151. data/lib/hobo/extensions/active_record/associations/scope.rb +0 -35
  152. data/lib/hobo/extensions/active_record/relation_with_origin.rb +0 -32
  153. data/lib/hobo/extensions/i18n.rb +0 -17
  154. data/lib/hobo/helper/translations/normalizer.rb +0 -39
  155. data/lib/hobo/model/view_hints.rb +0 -123
@@ -4,14 +4,11 @@ class <%= class_name %>Controller < ApplicationController
4
4
 
5
5
  auto_actions :all, :except => [ :index, :new, :create ]
6
6
 
7
- # Normally, users should be created via the user lifecycle, except
8
- # for the initial user created via the form on the front screen on
9
- # first run. This method creates the initial user.
10
7
  def create
11
8
  hobo_create do
12
9
  if valid?
13
10
  self.current_user = this
14
- flash[:notice] = t("hobo.messages.you_are_site_admin", :default=>"You are now the site administrator")
11
+ flash[:notice] = I18n.t("hobo.messages.you_are_site_admin", :default=>"You are now the site administrator")
15
12
  redirect_to home_page
16
13
  end
17
14
  end
@@ -20,10 +17,8 @@ class <%= class_name %>Controller < ApplicationController
20
17
 
21
18
  def do_accept_invitation
22
19
  do_transition_action :accept_invitation do
23
- if this.valid?
24
- self.current_user = this
25
- flash[:notice] = t("hobo.messages.you_signed_up", :default=>"You have signed up")
26
- end
20
+ self.current_user = this
21
+ flash[:notice] = I18n.t("hobo.messages.you_signed_up", :default=>"You have signed up")
27
22
  end
28
23
  end
29
24
  <% end -%>
@@ -1,8 +1,8 @@
1
- <%%= @<%= name.underscore -%> %>,
1
+ <%%= @user %>,
2
2
 
3
3
  To activate your account for <%%= @app_name %>, click on this link:
4
4
 
5
- <%%= <%= name.underscore -%>_activate_url :id => @<%= name.underscore -%>, :key => @key %>
5
+ <%%= user_activate_url :id => @user, :key => @key %>
6
6
 
7
7
  Thank you,
8
8
 
@@ -1,9 +1,9 @@
1
- <%%= @<%= name.underscore -%> %>,
1
+ <%%= @user %>,
2
2
 
3
3
  If you have forgotten your password for <%%= @app_name %>, you can choose
4
4
  a new one by clicking on this link:
5
5
 
6
- <%%= <%= name.underscore -%>_reset_password_url :id => @<%= name.underscore -%>, :key => @key %>
6
+ <%%= <%= name.underscore -%>_reset_password_url :id => @user, :key => @key %>
7
7
 
8
8
  Thank you,
9
9
 
@@ -1,8 +1,8 @@
1
- <%%= @<%= name.underscore %> %>,
1
+ <%%= @user %>,
2
2
 
3
3
  You have been invited to join <%%= @app_name %>. If you wish to accept, please click on the following link
4
4
 
5
- <%%= <%= name.underscore %>_accept_invitation_url :id => @<%= name.underscore %>, :key => @key %>
5
+ <%%= user_accept_invitation_url :id => @user, :key => @key %>
6
6
 
7
7
  Thank you,
8
8
 
@@ -1,25 +1,32 @@
1
1
  class <%= class_name -%>Mailer < ActionMailer::Base
2
2
  default :from => "no-reply@#{host}"
3
3
 
4
- def forgot_password(<%= name.underscore %>, key)
5
- @<%= name.underscore %>, @key = <%= name.underscore %>, key
4
+ def forgot_password(user, key)
5
+ set_variables(user, key)
6
6
  mail( :subject => "#{app_name} -- forgotten password",
7
- :to => <%= name.underscore %>.email_address )
7
+ :to => user.email_address )
8
8
  end
9
9
 
10
10
  <% if invite_only? -%>
11
- def invite(<%= name.underscore %>, key)
12
- @<%= name.underscore %>, @key = <%= name.underscore %>, key
11
+ def invite(user, key)
12
+ set_variables(user, key)
13
13
  mail( :subject => "Invitation to #{app_name}",
14
- :to => <%= name.underscore %>.email_address )
14
+ :to => user.email_address )
15
15
  end
16
16
 
17
17
  <% elsif options[:activation_email] %>
18
- def activation(<%= name.underscore %>, key)
19
- @<%= name.underscore %>, @key = <%= name.underscore %>, key
20
- mail( :subject => "#{app_name} -- activate",
21
- :to => <%= name.underscore %>.email_address )
18
+ def activation(user, key)
19
+ set_variables(user, key)
20
+ mail :subject => "#{app_name} -- activate",
21
+ :to => user.email_address
22
22
  end
23
23
 
24
24
  <% end -%>
25
+ private
26
+
27
+ def set_variables(user, key)
28
+ @user = user
29
+ @key = key
30
+ end
31
+
25
32
  end
@@ -12,7 +12,7 @@ module Hobo
12
12
  "rails generate hobo:user_mailer [NAME=user] [options]"
13
13
  end
14
14
 
15
- # check_class_collision :suffix => 'Mailer'
15
+ check_class_collision :suffix => 'Mailer'
16
16
 
17
17
  def generate_mailer
18
18
  template 'mailer.rb.erb', File.join('app/mailers', "#{file_path}_mailer.rb")
@@ -1,5 +1,12 @@
1
1
  Description:
2
+ The model generator creates stubs for a new user model.
2
3
 
3
- This generator is used by the user_resource generator to generate a
4
- user model file into app/models.
4
+ The generator takes a model name as its argument. The
5
+ model name may be given in CamelCase or under_score and
6
+ should not be suffixed with 'Model'.
5
7
 
8
+ The generator creates a model class in app/models, invokes
9
+ the hobo:user_mailer andgenerator the test framework.
10
+
11
+ Examples:
12
+ $ rails generate hobo:user_model User
@@ -1,4 +1,3 @@
1
- require 'generators/hobo_support/model'
2
1
  module Hobo
3
2
  class UserModelGenerator < Rails::Generators::NamedBase
4
3
  source_root File.expand_path('../templates', __FILE__)
@@ -6,7 +5,7 @@ module Hobo
6
5
  # overrides the default
7
6
  argument :name, :type => :string, :default => 'user', :optional => true
8
7
 
9
- include Generators::HoboSupport::Model
8
+ include Generators::Hobo::Model
10
9
  include Generators::Hobo::InviteOnly
11
10
  include Generators::Hobo::ActivationEmail
12
11
 
@@ -5,19 +5,18 @@ require 'will_paginate'
5
5
  require 'hobo/extensions/enumerable'
6
6
  require 'hobo/extensions/array'
7
7
 
8
- ActiveSupport::Dependencies.autoload_paths |= [File.dirname(__FILE__)]
9
- ActiveSupport::Dependencies.autoload_once_paths |= [File.dirname(__FILE__)]
8
+ ActiveSupport::Dependencies.autoload_paths |= [ File.dirname(__FILE__)]
9
+
10
10
 
11
11
  module Hobo
12
12
 
13
13
  VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
14
- @@root = Pathname.new File.expand_path('../..', __FILE__)
14
+ @@root = Pathname.new File.expand_path(File.dirname(__FILE__) + "/..")
15
15
  def self.root; @@root; end
16
16
 
17
17
  class Error < RuntimeError; end
18
18
  class PermissionDeniedError < RuntimeError; end
19
19
  class UndefinedAccessError < RuntimeError; end
20
- class I18nError < RuntimeError; end
21
20
 
22
21
  # Empty class to represent the boolean type.
23
22
  class Boolean; end
@@ -25,7 +24,7 @@ module Hobo
25
24
 
26
25
  class << self
27
26
 
28
- attr_accessor :current_theme, :engines
27
+ attr_accessor :current_theme
29
28
 
30
29
  def raw_js(s)
31
30
  RawJs.new(s)
@@ -64,18 +63,13 @@ module Hobo
64
63
 
65
64
  def subsites
66
65
  # Any directory inside app/controllers defines a subsite
67
- app_dirs = ["#{Rails.root}/app"] + Hobo.engines.map { |e| "#{e}/app" }
68
- @subsites ||= app_dirs.map do |app|
69
- Dir["#{app}/controllers/*"].map do |f|
70
- File.basename(f) if File.directory?(f)
71
- end.compact
72
- end.flatten
66
+ @subsites ||= Dir["#{Rails.root}/app/controllers/*"].map do |f|
67
+ File.basename(f) if File.directory?(f)
68
+ end.compact
73
69
  end
74
70
 
75
71
  end
76
72
 
77
- self.engines = []
78
-
79
73
  end
80
74
 
81
75
  require 'hobo/engine'
@@ -27,7 +27,7 @@ module Hobo
27
27
  end
28
28
  before_filter :set_mailer_default_url_options
29
29
  @included_taglibs = []
30
- rescue_from ActionController::RoutingError, :with => :not_found unless Rails.env.development?
30
+ rescue_from ActionController::RoutingError, :with => :not_found
31
31
  end
32
32
  Hobo::Helper.add_to_controller(klass)
33
33
  end
@@ -49,7 +49,7 @@ module Hobo
49
49
 
50
50
  def redirect_to_with_object_url(destination, *args)
51
51
  if destination.is_one_of?(String, Hash, Symbol)
52
- redirect_to_without_object_url(destination, *args)
52
+ redirect_to_without_object_url(destination)
53
53
  else
54
54
  redirect_to_without_object_url(object_url(destination, *args))
55
55
  end
@@ -58,9 +58,10 @@ module Hobo
58
58
 
59
59
  def hobo_ajax_response(*args)
60
60
  results = args.extract_options!
61
+ page_path = params[:page_path]
61
62
  r = params[:render]
62
63
  if r
63
- ajax_update_response(r.values, results)
64
+ ajax_update_response(page_path, r.values, results)
64
65
  true
65
66
  else
66
67
  false
@@ -68,16 +69,12 @@ module Hobo
68
69
  end
69
70
 
70
71
 
71
- def ajax_update_response(render_specs, results={}, options={})
72
- controller, action = controller_action_from_page_path
73
- identifier = view_context.view_paths.find( action,
74
- controller,
75
- false,
76
- view_context.lookup_context.instance_variable_get('@details')).identifier
77
- renderer = Dryml.page_renderer(view_context, identifier, [], controller)
72
+ def ajax_update_response(page_path, render_specs, results={})
73
+ @template.send(:_evaluate_assigns_and_ivars)
74
+ renderer = Dryml.page_renderer(@template, [], page_path) if page_path
78
75
 
79
76
  render :update do |page|
80
- page << (options[:preamble] || "var _update = typeof Hobo == 'undefined' ? Element.update : Hobo.updateElement;")
77
+ page << "var _update = typeof Hobo == 'undefined' ? Element.update : Hobo.updateElement;"
81
78
  for spec in render_specs
82
79
  function = spec[:function] || "_update"
83
80
  dom_id = spec[:id]
@@ -93,17 +90,10 @@ module Hobo
93
90
  end
94
91
  end
95
92
  page << renderer.part_contexts_storage if renderer
96
- page << options[:postamble] if options[:postamble]
97
93
  end
98
94
  end
99
95
 
100
96
 
101
- # dryml does not use layouts
102
- def action_has_layout?
103
- false
104
- end
105
-
106
-
107
97
  def dryml_context
108
98
  @this
109
99
  end
@@ -123,7 +113,10 @@ module Hobo
123
113
 
124
114
 
125
115
  def tag_renderer
126
- @tag_renderer ||= Dryml.empty_page_renderer(view_context)
116
+ @tag_renderer ||= begin
117
+ @template.send(:_evaluate_assigns_and_ivars)
118
+ Dryml.empty_page_renderer(@template)
119
+ end
127
120
  end
128
121
 
129
122
 
@@ -135,7 +128,7 @@ module Hobo
135
128
  results_hash = Hobo.find_by_search(query)
136
129
  all_results = results_hash.values.flatten.select { |r| r.viewable_by?(current_user) }
137
130
  if all_results.empty?
138
- render :text => "<p>"+ t("hobo.live_search.no_results", :default=>["Your search returned no matches."]) + "</p>"
131
+ render :text => "<p>"+ I18n.t("hobo.live_search.no_results", :default=>["Your search returned no matches."]) + "</p>"
139
132
  else
140
133
  # TODO: call one tag that renders all the search results with headings for each model
141
134
  render_tags(all_results, :search_card, :for_type => true)
@@ -160,7 +153,7 @@ module Hobo
160
153
  elsif render :not_found, :status => 404
161
154
  # cool
162
155
  else
163
- render(:text => t("hobo.messages.not_found", :default=>["The page you requested cannot be found."]) , :status => 404)
156
+ render(:text => I18n.t("hobo.messages.not_found", :default=>["The page you requested cannot be found."]) , :status => 404)
164
157
  end
165
158
  end
166
159
 
@@ -38,7 +38,7 @@ module Hobo
38
38
  # skip_before_filter :login_required
39
39
  #
40
40
  def login_required(user_model=nil)
41
- auth_model = user_model || Hobo::Model::UserBase.default_user_model
41
+ auth_model = user_model || Hobo::Model::User.default_user_model
42
42
  if current_user.guest?
43
43
  username, passwd = get_auth_data
44
44
  self.current_user = auth_model.authenticate(username, passwd) || nil if username && passwd && auth_model
@@ -50,6 +50,28 @@ module Hobo
50
50
  end
51
51
  end
52
52
 
53
+ # Redirect as appropriate when an access request fails.
54
+ #
55
+ # The default action is to redirect to the login screen.
56
+ #
57
+ # Override this method in your controllers if you want to have special
58
+ # behavior in case the user is not authorized
59
+ # to access the requested action. For example, a popup window might
60
+ # simply close itself.
61
+ def access_denied(user_model)
62
+ respond_to do |accepts|
63
+ accepts.html do
64
+ store_location
65
+ redirect_to(login_url(user_model))
66
+ end
67
+ accepts.xml do
68
+ headers["Status"] = "Unauthorized"
69
+ headers["WWW-Authenticate"] = %(Basic realm="Web Password")
70
+ render :text => I18n.t("hobo.messages.unauthenticated", :default=>["Couldn't authenticate you"]), :status => '401 Unauthorized'
71
+ end
72
+ end
73
+ false
74
+ end
53
75
 
54
76
  # Store the URI of the current request in the session.
55
77
  #
@@ -27,7 +27,7 @@ module Hobo
27
27
  helper_method :model, :current_user
28
28
  before_filter :set_no_cache_headers
29
29
 
30
- rescue_from ActiveRecord::RecordNotFound, :with => :not_found unless Rails.env.development?
30
+ rescue_from ActiveRecord::RecordNotFound, :with => :not_found
31
31
 
32
32
  rescue_from Hobo::PermissionDeniedError, :with => :permission_denied
33
33
  rescue_from Hobo::Model::Lifecycles::LifecycleKeyError, :with => :permission_denied
@@ -50,21 +50,15 @@ module Hobo
50
50
 
51
51
 
52
52
  def self.all_controllers(subsite=nil, force=false)
53
- controller_dirs = ["#{Rails.root}/app/controllers"] + Hobo.engines.map { |e| "#{e}/app/controllers" }
54
-
55
53
  # Load every controller in app/controllers/<subsite>...
56
54
  @controllers_loaded ||= {}
57
55
  if force || !@controllers_loaded[subsite]
58
- controller_dirs.each do |controller_dir|
59
- dir = "#{controller_dir}#{'/' + subsite if subsite}"
60
- if File.directory?(dir)
61
- Dir.entries(dir).each do |f|
62
- if f =~ /^[a-zA-Z_][a-zA-Z0-9_]*_controller\.rb$/
63
- name = f.remove(/.rb$/).camelize
64
- name = "#{subsite.camelize}::#{name}" if subsite
65
- name.constantize
66
- end
67
- end
56
+ dir = "#{Rails.root}/app/controllers#{'/' + subsite if subsite}"
57
+ Dir.entries(dir).each do |f|
58
+ if f =~ /^[a-zA-Z_][a-zA-Z0-9_]*_controller\.rb$/
59
+ name = f.remove(/.rb$/).camelize
60
+ name = "#{subsite.camelize}::#{name}" if subsite
61
+ name.constantize
68
62
  end
69
63
  end
70
64
  @controllers_loaded[subsite] = true
@@ -79,6 +73,7 @@ module Hobo
79
73
  end
80
74
 
81
75
 
76
+
82
77
  module ClassMethods
83
78
 
84
79
  attr_writer :model
@@ -129,15 +124,13 @@ module Hobo
129
124
  def auto_actions(*args)
130
125
  options = args.extract_options!
131
126
 
132
- @auto_actions = args.map do |arg|
133
- case arg
127
+ @auto_actions = case args.first
134
128
  when :all then available_auto_actions
135
- when :write_only then available_auto_write_actions
136
- when :read_only then available_auto_read_actions
137
- when :lifecycle then available_auto_lifecycle_actions
138
- else arg
139
- end
140
- end.flatten.uniq
129
+ when :write_only then available_auto_write_actions + args.rest
130
+ when :read_only then available_auto_read_actions + args.rest
131
+ when :lifecycle then available_auto_lifecycle_actions + args.rest
132
+ else args
133
+ end
141
134
 
142
135
  except = Array(options[:except])
143
136
  except_actions = except.map do |arg|
@@ -145,9 +138,9 @@ module Hobo
145
138
  when :lifecycle then available_auto_lifecycle_actions
146
139
  else arg
147
140
  end
148
- end.flatten.uniq
141
+ end
149
142
 
150
- @auto_actions -= except_actions
143
+ @auto_actions -= except_actions.flatten
151
144
 
152
145
  def_auto_actions
153
146
  end
@@ -363,15 +356,18 @@ module Hobo
363
356
  def re_render_form(default_action=nil)
364
357
  if params[:page_path]
365
358
  @invalid_record = this
366
- controller, action = controller_action_from_page_path
359
+ opt = ActionController::Routing::Routes.recognize_path(params[:page_path])
360
+ controller = opt[:controller]
361
+ view = opt[:action]
362
+ view = default_action if view == Dryml::EMPTY_PAGE
367
363
 
368
364
  # Hack fix for Bug 477. See also bug 489.
369
- if self.class.name == "#{controller.camelize}Controller" && action == "index"
365
+ if self.class.name == "#{controller.camelize}Controller" && view == "index"
370
366
  params['action'] = 'index'
371
367
  self.action_name = 'index'
372
368
  index
373
369
  else
374
- render :template => "#{controller}/#{action}"
370
+ render :template => "#{controller}/#{view}"
375
371
  end
376
372
  else
377
373
  render :action => default_action
@@ -404,6 +400,16 @@ module Hobo
404
400
  end
405
401
 
406
402
 
403
+ def url_for_page_path
404
+ url_for ActionController::Routing::Routes.recognize_path(params[:page_path])
405
+ end
406
+
407
+ # TODO: Get rid of this joke of an idea that fails miserably if you open another browser window.
408
+ def previous_page_path
409
+ session[:previous_page_path]
410
+ end
411
+
412
+
407
413
  def redirect_after_submit(*args)
408
414
  options = args.extract_options!
409
415
  o = options[:redirect]
@@ -446,7 +452,7 @@ module Hobo
446
452
  do_pagination = options.delete(:paginate) && finder.respond_to?(:paginate)
447
453
  finder = Array.wrap(options.delete(:scope)).inject(finder) { |a, v| a.send(*Array.wrap(v).flatten) }
448
454
 
449
- options[:order] = finder.default_order unless options[:order] || finder.try.order_values.present?
455
+ options[:order] = :default unless options[:order] || finder.send(:scope, :find)._?[:order]
450
456
 
451
457
  if do_pagination
452
458
  options.reverse_merge!(:page => params[:page] || 1)
@@ -516,7 +522,7 @@ module Hobo
516
522
  this.user_update_attributes(current_user, attributes)
517
523
  else
518
524
  self.this = new_for_create(attributes)
519
- this.user_save(current_user)
525
+ this.save
520
526
  end
521
527
  create_response(:new, options, &b)
522
528
  end
@@ -559,7 +565,7 @@ module Hobo
559
565
 
560
566
 
561
567
  def create_response(new_action, options={}, &b)
562
- flash_notice (ht( :"#{@this.class.to_s.underscore}.messages.create.success", :default=>["The #{@this.class.model_name.human} was created successfully"])) if valid?
568
+ flash_notice (ht( :"#{@this.class.name.tableize}.messages.create.success", :default=>["The #{@this.class.model_name.human} was created successfully"])) if valid?
563
569
 
564
570
  response_block(&b) or
565
571
  if valid?
@@ -573,7 +579,7 @@ module Hobo
573
579
  errors = this.errors.full_messages.join("\n")
574
580
  wants.html { re_render_form(new_action) }
575
581
  wants.js { render(:status => 500,
576
- :text => ht( :"#{this.class.to_s.underscore}.messages.create.error", :errors=>errors,:default=>["Couldn't create the #{this.class.name.titleize.downcase}.\n #{errors}"])
582
+ :text => ht( :"#{this.class.name.pluralize.underscore}.messages.create.error", :errors=>errors,:default=>["Couldn't create the #{this.class.name.titleize.downcase}.\n #{errors}"])
577
583
  )}
578
584
  end
579
585
  end
@@ -584,12 +590,11 @@ module Hobo
584
590
  options = args.extract_options!
585
591
 
586
592
  self.this ||= args.first || find_instance
587
- changes = options[:attributes] || attribute_parameters or raise RuntimeError, t("hobo.messages.update.no_attribute_error", :default=>["No update specified in params"])
593
+ changes = options[:attributes] || attribute_parameters or raise RuntimeError, I18n.t("hobo.messages.update.no_attribute_error", :default=>["No update specified in params"])
594
+ this.user_update_attributes(current_user, changes)
588
595
 
589
- if this.user_update_attributes(current_user, changes)
590
- # Ensure current_user isn't out of date
591
- @current_user = @this if @this == current_user
592
- end
596
+ # Ensure current_user isn't out of date
597
+ @current_user = @this if @this == current_user
593
598
 
594
599
  in_place_edit_field = changes.keys.first if changes.size == 1 && params[:render]
595
600
  update_response(in_place_edit_field, options, &b)
@@ -598,7 +603,7 @@ module Hobo
598
603
 
599
604
  def update_response(in_place_edit_field=nil, options={}, &b)
600
605
 
601
- flash_notice (ht(:"#{@this.class.to_s.underscore}.messages.update.success", :default=>["Changes to the #{@this.class.model_name.human} were saved"])) if valid?
606
+ flash_notice (ht(:"#{@this.class.name.pluralize.underscore}.messages.update.success", :default=>["Changes to the #{@this.class.model_name.human} were saved"])) if valid?
602
607
 
603
608
  response_block(&b) or
604
609
  if valid?
@@ -625,7 +630,7 @@ module Hobo
625
630
  errors = @this.errors.full_messages.join("\n")
626
631
  wants.html { re_render_form(:edit) }
627
632
  wants.js { render(:status => 500,
628
- :text => ht(:"#{@this.class.to_s.underscore}.messages.update.error",:default=>["There was a problem with that change.\n#{errors}"], :errors=>errors)
633
+ :text => ht(:"#{@this.class.name.pluralize.underscore}.messages.update.error",:default=>["There was a problem with that change.\n#{errors}"], :errors=>errors)
629
634
  ) }
630
635
  end
631
636
  end
@@ -636,7 +641,7 @@ module Hobo
636
641
  options = args.extract_options!
637
642
  self.this ||= args.first || find_instance
638
643
  this.user_destroy(current_user)
639
- flash_notice ht( :"#{model.to_s.underscore}.messages.destroy.success", :default=>["The #{model.name.titleize.downcase} was deleted"])
644
+ flash_notice ht( :"#{model.name.pluralize.underscore}.messages.destroy.success", :default=>["The #{model.name.titleize.downcase} was deleted"])
640
645
  destroy_response(options, &b)
641
646
  end
642
647
 
@@ -677,7 +682,7 @@ module Hobo
677
682
  errors = this.errors.full_messages.join("\n")
678
683
  wants.html { re_render_form(name) }
679
684
  wants.js { render(:status => 500,
680
- :text => ht(:"#{@this.class.to_s.underscore}.messages.creator.error", :default=>["Couldn't do creator #{name}.\n#{errors}"], :name=>name, :errors=>errors)
685
+ :text => ht(:"#{@this.class.name.pluralize.underscore}.messages.creator.error", :default=>["Couldn't do creator #{name}.\n#{errors}"], :name=>name, :errors=>errors)
681
686
  )}
682
687
  end
683
688
  end
@@ -719,7 +724,7 @@ module Hobo
719
724
  errors = this.errors.full_messages.join("\n")
720
725
  wants.html { re_render_form(name) }
721
726
  wants.js { render(:status => 500,
722
- :text => ht(:"#{@this.class.to_s.underscore}.messages.transition.error", :default=>["Couldn't do transition #{name}.\n#{errors}"], :name=>name, :errors=>errors)
727
+ :text => ht(:"#{@this.class.name.pluralize.underscore}.messages.transition.error", :default=>["Couldn't do transition #{name}.\n#{errors}"], :name=>name, :errors=>errors)
723
728
  )}
724
729
  end
725
730
  end
@@ -730,7 +735,7 @@ module Hobo
730
735
 
731
736
  def hobo_completions(attribute, finder, options={})
732
737
  options = options.reverse_merge(:limit => 10, :param => :query, :query_scope => "#{attribute}_contains")
733
- finder = finder.limit(options[:limit]) unless finder.try.limit_value
738
+ finder = finder.limit(options[:limit]) unless finder.send(:scope, :find, :limit)
734
739
 
735
740
  begin
736
741
  finder = finder.send(options[:query_scope], params[options[:param]])
@@ -775,11 +780,11 @@ module Hobo
775
780
  if render :permission_denied, :status => 403
776
781
  # job done
777
782
  else
778
- render :text => t("hobo.messages.permission_denied", :default=>["Permission Denied"]), :status => 403
783
+ render :text => I18n.t("hobo.messages.permission_denied", :default=>["Permission Denied"]), :status => 403
779
784
  end
780
785
  end
781
786
  wants.js do
782
- render :text => t("hobo.messages.permission_denied", :default=>["Permission Denied"]), :status => 403
787
+ render :text => I18n.t("hobo.messages.permission_denied", :default=>["Permission Denied"]), :status => 403
783
788
  end
784
789
  end
785
790
  end
@@ -787,16 +792,16 @@ module Hobo
787
792
 
788
793
 
789
794
  def this
790
- @this ||= (instance_variable_get("@#{model.name.demodulize.underscore}") ||
791
- instance_variable_get("@#{model.name.demodulize.underscore.pluralize}"))
795
+ @this ||= (instance_variable_get("@#{model.name.underscore}") ||
796
+ instance_variable_get("@#{model.name.underscore.pluralize}"))
792
797
  end
793
798
 
794
799
 
795
800
  def this=(object)
796
- ivar = if object.is_a?(Array) || object.respond_to?(:member_class)
797
- (object.try.member_class || model).name.demodulize.underscore.pluralize
801
+ ivar = if object.is_a?(Array)
802
+ (object.try.member_class || model).name.underscore.pluralize
798
803
  else
799
- object.class.name.demodulize.underscore
804
+ object.class.name.underscore
800
805
  end
801
806
  @this = instance_variable_set("@#{ivar}", object)
802
807
  end