hobo 1.3.0.pre31 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/CHANGES-1.1.txt +5253 -0
  2. data/CHANGES.txt +255 -5095
  3. data/VERSION +1 -1
  4. data/hobo.gemspec +1 -2
  5. data/lib/generators/hobo/admin_subsite/USAGE +25 -0
  6. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +2 -1
  7. data/lib/generators/hobo/assets/USAGE +5 -0
  8. data/lib/generators/hobo/assets/templates/application.dryml.erb +1 -1
  9. data/lib/generators/hobo/controller/USAGE +3 -0
  10. data/lib/generators/hobo/i18n/USAGE +3 -0
  11. data/lib/generators/hobo/i18n/templates/app.fr.yml +26 -0
  12. data/lib/generators/hobo/i18n/templates/app.nb.yml +25 -0
  13. data/lib/generators/hobo/i18n/templates/hobo.de.yml +1 -0
  14. data/lib/generators/hobo/i18n/templates/hobo.en.yml +3 -2
  15. data/lib/generators/hobo/i18n/templates/hobo.es.yml +1 -0
  16. data/lib/generators/hobo/i18n/templates/hobo.fr.yml +195 -0
  17. data/lib/generators/hobo/i18n/templates/hobo.it.yml +1 -0
  18. data/lib/generators/hobo/i18n/templates/hobo.nb.yml +198 -0
  19. data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +1 -0
  20. data/lib/generators/hobo/i18n/templates/hobo.ru.yml +1 -0
  21. data/lib/generators/hobo/model/USAGE +2 -2
  22. data/lib/generators/hobo/rapid/templates/hobo-rapid.js +15 -30
  23. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +1 -0
  24. data/lib/generators/hobo/resource/USAGE +39 -0
  25. data/lib/generators/hobo/routes/router.rb +2 -2
  26. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +23 -9
  27. data/lib/generators/hobo/subsite.rb +13 -2
  28. data/lib/generators/hobo/subsite/USAGE +24 -0
  29. data/lib/generators/hobo/subsite_taglib/USAGE +4 -0
  30. data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +1 -1
  31. data/lib/generators/hobo/test_framework/USAGE +2 -0
  32. data/lib/generators/hobo/user_controller/USAGE +3 -0
  33. data/lib/generators/hobo/user_controller/templates/controller.rb.erb +3 -0
  34. data/lib/generators/hobo/user_mailer/USAGE +2 -0
  35. data/lib/generators/hobo/user_model/USAGE +2 -9
  36. data/lib/generators/hobo/user_resource/USAGE +10 -0
  37. data/lib/hobo.rb +1 -1
  38. data/lib/hobo/controller/authentication_support.rb +0 -22
  39. data/lib/hobo/controller/model.rb +15 -13
  40. data/lib/hobo/controller/{user.rb → user_base.rb} +43 -32
  41. data/lib/hobo/extensions/action_controller/hobo_methods.rb +25 -1
  42. data/lib/hobo/extensions/active_record/associations/collection.rb +12 -3
  43. data/lib/hobo/extensions/active_record/associations/reflection.rb +1 -1
  44. data/lib/hobo/extensions/active_record/relation_with_origin.rb +4 -0
  45. data/lib/hobo/helper.rb +6 -1
  46. data/lib/hobo/helper/translations.rb +1 -1
  47. data/lib/hobo/model.rb +55 -19
  48. data/lib/hobo/model/lifecycles.rb +3 -3
  49. data/lib/hobo/model/lifecycles/lifecycle.rb +7 -3
  50. data/lib/hobo/model/permissions.rb +1 -0
  51. data/lib/hobo/model/scopes/automatic_scopes.rb +0 -2
  52. data/lib/hobo/model/view_hints.rb +1 -0
  53. data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +2 -1
  54. data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +10 -11
  55. data/lib/hobo/rapid/helper.rb +4 -3
  56. data/lib/hobo/rapid/taglibs/rapid_core.dryml +92 -67
  57. data/lib/hobo/rapid/taglibs/rapid_editing.dryml +35 -15
  58. data/lib/hobo/rapid/taglibs/rapid_forms.dryml +46 -22
  59. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +103 -37
  60. data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +3 -1
  61. data/lib/hobo/rapid/taglibs/rapid_pages.dryml +3 -3
  62. data/lib/hobo/rapid/taglibs/rapid_plus.dryml +49 -45
  63. data/test/irt/generators/partials/_subsite_taglib_variables.rb +1 -1
  64. metadata +38 -33
@@ -91,6 +91,7 @@
91
91
  save: "Gravar %{model}"
92
92
  cancel: "Cancelar"
93
93
  edit: "Editar %{model}"
94
+ edit_control: "Editar"
94
95
  back: "Voltar para"
95
96
  back_to_parent: "Voltar para %{parent} %{name}"
96
97
  send: "Enviar"
@@ -95,6 +95,7 @@ ru:
95
95
  save: "Сохранить"
96
96
  cancel: "Отменить"
97
97
  edit: "Изменить %{model}"
98
+ edit_control: "Изменить"
98
99
  back: "Назад к"
99
100
  back_to_parent: "Назад к %{parent} %{name}"
100
101
  send: "Отослать"
@@ -15,5 +15,5 @@ Examples:
15
15
 
16
16
  creates a Post model with a string title, text body, and published flag.
17
17
 
18
- After the model is created, and the fields are specified, use hobo:migration
19
- to create the migrations incrementally.
18
+ After the model is created, and the fields are specified, use hobo:migration
19
+ to create the migrations incrementally.
@@ -34,6 +34,7 @@ var Hobo = {
34
34
  var params = Hobo.fieldSetParam(el, val)
35
35
  var p = el.getAttribute("hobo-ajax-params")
36
36
  if (p) params = params + "&" + p
37
+ params = params + '&_method=PUT'
37
38
 
38
39
  var opts = Object.merge(options || {}, { params: params, message: el.getAttribute("hobo-ajax-message")})
39
40
  Hobo.ajaxRequest(Hobo.putUrl(el), updates, opts)
@@ -257,8 +258,9 @@ var Hobo = {
257
258
 
258
259
 
259
260
  putUrl: function(el) {
261
+ /* we used to append _method=put here, but it doesn't work in Rails 3 */
260
262
  var spec = Hobo.modelSpecForElement(el)
261
- return urlBase + "/" + Hobo.pluralise(spec.name) + "/" + spec.id + "?_method=PUT"
263
+ return urlBase + "/" + Hobo.pluralise(spec.name) + "/" + spec.id
262
264
  },
263
265
 
264
266
 
@@ -444,23 +446,6 @@ var Hobo = {
444
446
  },
445
447
 
446
448
 
447
- fixSectionGroup: function(e) {
448
- rows = e.childElements().map(function(e, i) {
449
- cells = e.childElements().map(function(e, i) {
450
- return e.outerHTML.sub("<DIV", "<td valign='top'").sub(/<\/DIV>$/i, "</td>")
451
- }).join('')
452
-
453
- var attrs = e.outerHTML.match(/<DIV([^>]+)/)[1]
454
- return "<tr" + attrs + ">" + cells + "</tr>"
455
- }).join("\n")
456
-
457
- var attrs = e.outerHTML.match(/<DIV([^>]+)/)[1]
458
-
459
- var table= "<table cellpadding='0' cellspacing='0' border='0' style='border-collapse: collapse; border-spacing: 0'" + attrs + ">" +
460
- rows + "</table>"
461
- e.outerHTML = table
462
- },
463
-
464
449
  makeHtmlEditor: function(textarea) {
465
450
  // do nothing - plugins can overwrite this method
466
451
  }
@@ -571,17 +556,21 @@ HoboInputMany = {
571
556
 
572
557
  initialize: function(ev) {
573
558
  /* the second clause should be sufficient, but it isn't in IE7. See bug 603 */
574
- Element.select(ev.target, ".input-many-template input:hidden, .input-many-template select:hidden, .input-many-template textarea:hidden, .input-many-template button:hidden").each(function(input) {
575
- if(!input.disabled) {
576
- input.disabled = true;
577
- input.addClassName("input_many_template_input");
578
- }
559
+ Element.select(ev.target, ".input-many-template").each(function (templ) {
560
+ templ.select("input:hidden,select:hidden,textarea:hidden,button:hidden").each(function(input) {
561
+ if(!input.disabled) {
562
+ input.disabled = true;
563
+ input.addClassName("input_many_template_input");
564
+ }
565
+ })
579
566
  });
580
567
 
581
568
  // disable all elements inside our template, and mark them so we can find them later.
582
- Element.select(ev.target, ".input-many-template input:enabled, .input-many-template select:enabled, .input-many-template textarea:enabled, .input-many-template button:enabled").each(function(input) {
583
- input.disabled = true;
584
- input.addClassName("input_many_template_input");
569
+ Element.select(ev.target, ".input-many-template").each(function (templ) {
570
+ templ.select("input:enabled,select:enabled,textarea:enabled,button:enabled").each(function(input) {
571
+ input.disabled = true;
572
+ input.addClassName("input_many_template_input");
573
+ });
585
574
  });
586
575
 
587
576
  Element.select(ev.target, ".sortable-input-many").each(function(el) {
@@ -909,10 +898,6 @@ AutocompleteBehavior = Behavior.create({
909
898
  Event.addBehavior.reassignAfterAjax = true;
910
899
  Event.addBehavior({
911
900
 
912
- 'div.section-group' : function() {
913
- if (Prototype.Browser.IE) Hobo.fixSectionGroup(this);
914
- },
915
-
916
901
  'div.select-many.input' : SelectManyInput(),
917
902
 
918
903
  'textarea.html' : function() {
@@ -14,6 +14,7 @@ body {color: #193440; background: url(../images/300-ACD3E6-fff.png) repeat-x #ff
14
14
  .section.content {background: #FCFFF5;}
15
15
  .button {color: white; background: #5B8BA0;}
16
16
  .button:hover {background-color: #193440;}
17
+ .button[disabled] { background-color: #CCCCCC; }
17
18
  .add-to-collection {background: #E6E7DE;}
18
19
  .aside { background: #E5E5E5;}
19
20
 
@@ -0,0 +1,39 @@
1
+ Description:
2
+ The model generator creates stubs for a new model, corresponding
3
+ controller and it's views.
4
+
5
+ The generator takes a model name as its argument. The model name
6
+ may be given in CamelCase or under_score and should not be
7
+ suffixed with anything.
8
+
9
+ As additional parameters, the generator will take attribute pairs
10
+ described by name and type. These attributes will be used to
11
+ prepopulate the migration to create the table for the model and
12
+ give you a set of predefined fixture. You don't have to think up
13
+ all attributes up front, but it's a good idea to add just the
14
+ baseline of what's needed to start really working with the
15
+ resource.
16
+
17
+ The generator creates a model class in app/models, a test suite in
18
+ test/unit and test fixtures in test/fixtures/singular_name.yml.
19
+ The generator creates a controller class in app/controllers with
20
+ view templates in app/views/controller_name, a helper class in
21
+ app/helpers, and a functional test suite in test/functional.
22
+
23
+ Examples:
24
+ rails generate hobo:resource account
25
+
26
+ This will create an Account model:
27
+ Model: app/models/account.rb
28
+ Controller: app/controllers/accounts_controller.rb
29
+ Helper: app/helpers/accounts_helper.rb
30
+ Views: app/views/accounts
31
+ Test: test/unit/account_test.rb
32
+ Test: test/functions/accounts_controller_test.rb
33
+ Fixtures: test/fixtures/accounts.yml
34
+
35
+ (files generated may vary depending on test suite & fixture configuration)
36
+
37
+ rails generate hobo:resource post title:string created_on:date body:text published:boolean
38
+
39
+ Creates post model, controller & views with predefined attributes.
@@ -34,7 +34,7 @@ module Generators
34
34
  routes << link("put '#{records}/:id/#{transition}(.:format)' => '#{records}#do_#{transition}', :as => 'do_#{record}_#{transition}'", transition, :put)
35
35
  routes << link("get '#{records}/:id/#{transition}(.:format)' => '#{records}##{transition}', :as => '#{record}_#{transition}'", transition)
36
36
  end
37
- routes.compact
37
+ routes.compact.uniq
38
38
  end
39
39
 
40
40
  def resource_routes
@@ -92,7 +92,7 @@ module Generators
92
92
  end
93
93
 
94
94
  def user_routes
95
- return [] unless controller < ::Hobo::Controller::User
95
+ return [] unless controller < ::Hobo::Controller::UserBase
96
96
  prefix = records == "users" ? "" : "#{record}_"
97
97
  [
98
98
  link("match '#{prefix}login(.:format)' => '#{records}#login', :as => '#{record}_login'", 'login'),
@@ -23,9 +23,15 @@ module Hobo
23
23
  class_option :front_controller_name, :type => :string,
24
24
  :desc => "Front Controller Name", :default => 'front'
25
25
 
26
+ class_option :add_admin_subsite, :type => :boolean,
27
+ :desc => "Add an Admin Subsite"
28
+
26
29
  class_option :admin_subsite_name, :type => :string,
27
30
  :desc => "Admin Subsite Name", :default => 'admin'
28
31
 
32
+ class_option :make_front_site, :type => :boolean,
33
+ :desc => "Rename application.dryml to front_site.dryml", :default => 'true'
34
+
29
35
  class_option :private_site, :type => :boolean,
30
36
  :desc => "Make the site unaccessible to non-members"
31
37
 
@@ -113,7 +119,8 @@ NOTE: You might want to sign up as the administrator before adding this!
113
119
  end
114
120
  inject_into_file 'app/controllers/application_controller.rb', <<EOI, :after => "protect_from_forgery\n" if private_site
115
121
  include Hobo::Controller::AuthenticationSupport
116
- before_filter :except => [:login, :forgot_password, :accept_invitation, :do_accept_invitation, :reset_password] do
122
+ before_filter :except => [:login, :forgot_password, :accept_invitation, :do_accept_invitation, :reset_password,
123
+ :do_reset_password] do
117
124
  login_required unless #{@user_resource_name.camelize}.count == 0
118
125
  end
119
126
  EOI
@@ -153,12 +160,17 @@ EOI
153
160
  end
154
161
 
155
162
  def admin_subsite
156
- return unless @invite_only
157
163
  if wizard?
158
164
  say_title 'Admin Subsite'
159
- @admin_subsite_name = ask("Choose a name for the admin subsite: [<enter>=admin|<custom_name>]", 'admin')
165
+ if @invite_only || (@add_admin_subsite = yes_no?("Do you want an admin subsite?"))
166
+ @admin_subsite_name = ask("Choose a name for the admin subsite: [<enter>=admin|<custom_name>]", 'admin')
167
+ @make_front_site = yes_no?("Do you want to use a separate front_site.dryml?")
168
+ end
160
169
  else
161
- @admin_subsite_name = options[:admin_subsite_name]
170
+ if @invite_only || (@add_admin_subsite = options[:add_admin_subsite])
171
+ @admin_subsite_name = options[:admin_subsite_name]
172
+ @make_front_site = options[:make_front_site]
173
+ end
162
174
  end
163
175
  end
164
176
 
@@ -168,11 +180,13 @@ EOI
168
180
  :invite_only => @invite_only,
169
181
  :activation_email => @activation_email,
170
182
  :admin_subsite_name => @admin_subsite_name
171
- return unless @invite_only
172
- say "Installing admin subsite..."
173
- invoke 'hobo:admin_subsite', [@admin_subsite_name],
174
- :user_resource_name => @user_resource_name,
175
- :invite_only => @invite_only
183
+ if @invite_only || @add_admin_subsite
184
+ say "Installing admin subsite..."
185
+ invoke 'hobo:admin_subsite', [@admin_subsite_name],
186
+ :user_resource_name => @user_resource_name,
187
+ :invite_only => @invite_only,
188
+ :make_front_site => @make_front_site
189
+ end
176
190
  end
177
191
 
178
192
  def generate_migration
@@ -1,4 +1,14 @@
1
1
  require 'fileutils'
2
+ require 'thor/parser/option'
3
+
4
+ # we want the option :make_front_site required even if it is boolean
5
+ # Thor does not allow it, so we patch it
6
+ class Thor
7
+ class Option
8
+ def validate!; end
9
+ end
10
+ end
11
+
2
12
  module Generators
3
13
  module Hobo
4
14
  Subsite = classy_module do
@@ -7,8 +17,9 @@ module Generators
7
17
  include Generators::Hobo::Taglib
8
18
 
9
19
  class_option :make_front_site,
10
- :type => :boolean,
11
- :desc => "Rename application.dryml to front_site.dryml"
20
+ :type => :boolean,
21
+ :required => true,
22
+ :desc => "Rename application.dryml to front_site.dryml"
12
23
 
13
24
  # check_class_collision :suffix => 'SiteController'
14
25
 
@@ -0,0 +1,24 @@
1
+ Description:
2
+
3
+ Creates a subsite, a namespaced section of your application.
4
+
5
+ Controllers for the subsite are created in
6
+ app/controllers/<subsite_name>/ and views are also in their own
7
+ subdirectory. This allows you to have two different controllers
8
+ and two different sets of views for the same model.
9
+
10
+ The subsite will use app/views/taglibs/<subsite_name>_site.dryml
11
+ as well as app/views/taglibs/application.dryml. This allows you
12
+ to customize the look and feel of a portion of your site. The
13
+ remaining views of your application that are not under a subsite
14
+ load both application.dryml and front_site.dryml.
15
+
16
+ It is thus recommended that you ensure that
17
+ <subsite_name>_site.dryml and application.dryml do not repeat
18
+ code, such as the inclusion of rapid or the setting of the theme.
19
+ One easy way of ensuring this is to use the --make-front-site
20
+ option. If you have already accounted for this, use
21
+ --make-front-site=false.
22
+
23
+ The difference between hobo:admin_site and hobo:subsite is that
24
+ hobo:admin_site limits the subsite to use by administrators only.
@@ -0,0 +1,4 @@
1
+ Description:
2
+ This generator is used to generate
3
+ app/views/taglibs/<subsite_name>_site.dryml, and is used by the
4
+ subsite and admin_site generators. Do not use directly.
@@ -1,6 +1,6 @@
1
1
  <!-- Tag definitions for the <%= file_name %> subsite -->
2
2
 
3
- <include src="rapid" plugin="hobo"/>
3
+ <include src="rapid" gem="hobo"/>
4
4
 
5
5
  <include src="taglibs/auto/<%= file_name %>/rapid/cards"/>
6
6
  <include src="taglibs/auto/<%= file_name %>/rapid/pages"/>
@@ -0,0 +1,2 @@
1
+ Description:
2
+ This generator is used by the setup_wizard generator to set up the test framework.
@@ -0,0 +1,3 @@
1
+ USAGE:
2
+ This generator is used by the user_resource generator to generate
3
+ app/controllers/users_controller.rb
@@ -4,6 +4,9 @@ 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.
7
10
  def create
8
11
  hobo_create do
9
12
  if valid?
@@ -0,0 +1,2 @@
1
+ Description:
2
+ This generator is used by the user_resource generator to generate user_mailer.rb.
@@ -1,12 +1,5 @@
1
1
  Description:
2
- The model generator creates stubs for a new user model.
3
2
 
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'.
3
+ This generator is used by the user_resource generator to generate a
4
+ user model file into app/models.
7
5
 
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
@@ -0,0 +1,10 @@
1
+ Description:
2
+
3
+ This generator invokes the user_model, user_mailer and
4
+ user_controller generators. It is invoked by the setup_wizard
5
+ generator.
6
+
7
+ Usage:
8
+
9
+ rails generate hobo:user_resource [NAME=user] [options]
10
+
@@ -6,7 +6,7 @@ require 'hobo/extensions/enumerable'
6
6
  require 'hobo/extensions/array'
7
7
 
8
8
  ActiveSupport::Dependencies.autoload_paths |= [File.dirname(__FILE__)]
9
-
9
+ ActiveSupport::Dependencies.autoload_once_paths |= [File.dirname(__FILE__)]
10
10
 
11
11
  module Hobo
12
12
 
@@ -50,28 +50,6 @@ 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 => t("hobo.messages.unauthenticated", :default=>["Couldn't authenticate you"]), :status => '401 Unauthorized'
71
- end
72
- end
73
- false
74
- end
75
53
 
76
54
  # Store the URI of the current request in the session.
77
55
  #
@@ -129,13 +129,15 @@ module Hobo
129
129
  def auto_actions(*args)
130
130
  options = args.extract_options!
131
131
 
132
- @auto_actions = case args.first
132
+ @auto_actions = args.map do |arg|
133
+ case arg
133
134
  when :all then available_auto_actions
134
- when :write_only then available_auto_write_actions + args.rest
135
- when :read_only then available_auto_read_actions + args.rest
136
- when :lifecycle then available_auto_lifecycle_actions + args.rest
137
- else args
138
- end
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
139
141
 
140
142
  except = Array(options[:except])
141
143
  except_actions = except.map do |arg|
@@ -143,9 +145,9 @@ module Hobo
143
145
  when :lifecycle then available_auto_lifecycle_actions
144
146
  else arg
145
147
  end
146
- end
148
+ end.flatten.uniq
147
149
 
148
- @auto_actions -= except_actions.flatten
150
+ @auto_actions -= except_actions
149
151
 
150
152
  def_auto_actions
151
153
  end
@@ -785,16 +787,16 @@ module Hobo
785
787
 
786
788
 
787
789
  def this
788
- @this ||= (instance_variable_get("@#{model.name.underscore}") ||
789
- instance_variable_get("@#{model.name.underscore.pluralize}"))
790
+ @this ||= (instance_variable_get("@#{model.name.demodulize.underscore}") ||
791
+ instance_variable_get("@#{model.name.demodulize.underscore.pluralize}"))
790
792
  end
791
793
 
792
794
 
793
795
  def this=(object)
794
- ivar = if object.is_a?(Array)
795
- (object.try.member_class || model).name.underscore.pluralize
796
+ ivar = if object.is_a?(Array) || object.respond_to?(:member_class)
797
+ (object.try.member_class || model).name.demodulize.underscore.pluralize
796
798
  else
797
- object.class.name.underscore
799
+ object.class.name.demodulize.underscore
798
800
  end
799
801
  @this = instance_variable_set("@#{ivar}", object)
800
802
  end