hobo 0.7.5 → 0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/{hobo_files/plugin/CHANGES.txt → CHANGES.txt} +391 -0
- data/Manifest +146 -0
- data/{hobo_files/plugin/README → README} +0 -0
- data/bin/hobo +13 -26
- data/dryml_generators/rapid/cards.dryml.erb +55 -0
- data/dryml_generators/rapid/forms.dryml.erb +43 -0
- data/dryml_generators/rapid/pages.dryml.erb +284 -0
- data/hobo.gemspec +168 -0
- data/init.rb +9 -0
- data/lib/action_view_extensions/helpers/tag_helper.rb +7 -0
- data/lib/active_record/association_collection.rb +54 -0
- data/{hobo_files/plugin/lib → lib}/active_record/association_proxy.rb +12 -4
- data/{hobo_files/plugin/lib → lib}/active_record/association_reflection.rb +7 -1
- data/{hobo_files/plugin/lib → lib}/extensions/test_case.rb +17 -17
- data/{hobo_files/plugin/lib → lib}/hobo.rb +193 -100
- data/{hobo_files/plugin/lib → lib}/hobo/authentication_support.rb +8 -8
- data/{hobo_files/plugin/lib → lib}/hobo/bundle.rb +90 -89
- data/{hobo_files/plugin/lib → lib}/hobo/composite_model.rb +21 -21
- data/{hobo_files/plugin/lib → lib}/hobo/controller.rb +38 -25
- data/{hobo_files/plugin/lib → lib}/hobo/dev_controller.rb +10 -6
- data/lib/hobo/dryml.rb +167 -0
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/dryml_builder.rb +28 -25
- data/lib/hobo/dryml/dryml_generator.rb +210 -0
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/dryml_support_controller.rb +1 -1
- data/lib/hobo/dryml/parser.rb +3 -0
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/attribute.rb +6 -6
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/base_parser.rb +16 -16
- data/lib/hobo/dryml/parser/document.rb +57 -0
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/element.rb +7 -7
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/elements.rb +9 -9
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/source.rb +3 -3
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/text.rb +3 -3
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/tree_parser.rb +3 -3
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/part_context.rb +26 -26
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/scoped_variables.rb +15 -15
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/tag_parameters.rb +10 -10
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/taglib.rb +43 -37
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/template.rb +290 -208
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/template_environment.rb +173 -115
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/template_handler.rb +19 -24
- data/lib/hobo/find_for.rb +95 -0
- data/{hobo_files/plugin/lib → lib}/hobo/generator.rb +2 -1
- data/{hobo_files/plugin/lib → lib}/hobo/guest.rb +12 -4
- data/{hobo_files/plugin/lib → lib}/hobo/hobo_helper.rb +146 -117
- data/lib/hobo/include_in_save.rb +43 -0
- data/lib/hobo/lifecycles.rb +94 -0
- data/lib/hobo/lifecycles/actions.rb +73 -0
- data/lib/hobo/lifecycles/creator.rb +76 -0
- data/lib/hobo/lifecycles/lifecycle.rb +205 -0
- data/lib/hobo/lifecycles/state.rb +23 -0
- data/lib/hobo/lifecycles/transition.rb +66 -0
- data/{hobo_files/plugin/lib → lib}/hobo/model.rb +306 -217
- data/{hobo_files/plugin/lib → lib}/hobo/model_controller.rb +342 -213
- data/{hobo_files/plugin/lib → lib}/hobo/model_router.rb +151 -120
- data/{hobo_files/plugin/lib → lib}/hobo/model_support.rb +9 -9
- data/{hobo_files/plugin/lib → lib}/hobo/rapid_helper.rb +30 -23
- data/{hobo_files/plugin/lib → lib}/hobo/scopes.rb +22 -68
- data/{hobo_files/plugin/lib → lib}/hobo/scopes/apply_scopes.rb +5 -5
- data/lib/hobo/scopes/association_proxy_extensions.rb +47 -0
- data/{hobo_files/plugin/lib → lib}/hobo/scopes/automatic_scopes.rb +104 -79
- data/lib/hobo/scopes/named_scope_extensions.rb +27 -0
- data/{hobo_files/plugin/lib → lib}/hobo/static_tags +1 -11
- data/{hobo_files/plugin/lib → lib}/hobo/undefined.rb +1 -1
- data/{hobo_files/plugin/lib → lib}/hobo/undefined_access_error.rb +0 -0
- data/{hobo_files/plugin/lib → lib}/hobo/user.rb +27 -25
- data/{hobo_files/plugin/lib → lib}/hobo/user_controller.rb +80 -34
- data/{hobo_files/plugin/generators → rails_generators}/hobo/hobo_generator.rb +7 -7
- data/rails_generators/hobo/templates/application.css +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/application.dryml +0 -2
- data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/dryml-support.js +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/guest.rb +0 -0
- data/rails_generators/hobo/templates/initializer.rb +9 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/USAGE +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/hobo_front_controller_generator.rb +1 -3
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/controller.rb +1 -1
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/functional_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/helper.rb +0 -0
- data/rails_generators/hobo_front_controller/templates/index.dryml +25 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/USAGE +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/hobo_model_generator.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/fixtures.yml +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/model.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/unit_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/USAGE +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/hobo_model_controller_generator.rb +0 -7
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/controller.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/functional_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/helper.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/hobo_model_resource_generator.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/controller.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/functional_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/helper.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/hobo_rapid_generator.rb +21 -11
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/IE7.js +1 -1
- data/rails_generators/hobo_rapid/templates/blank.gif +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/hobo-rapid.css +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/hobo-rapid.js +175 -104
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/lowpro.js +0 -0
- data/rails_generators/hobo_rapid/templates/nicEditorIcons.gif +0 -0
- data/rails_generators/hobo_rapid/templates/nicedit.js +91 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/reset.css +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/fieldbg.gif +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/pencil.png +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/small_close.png +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/spinner.gif +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/stylesheets/clean.css +80 -71
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +6 -1
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/views/clean.dryml +4 -4
- data/rails_generators/hobo_subsite/hobo_subsite_generator.rb +73 -0
- data/rails_generators/hobo_subsite/templates/application.dryml +1 -0
- data/rails_generators/hobo_subsite/templates/controller.rb +5 -0
- data/rails_generators/hobo_subsite/templates/site_taglib.dryml +13 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/USAGE +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/hobo_user_controller_generator.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/controller.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/functional_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/helper.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/USAGE +0 -0
- data/rails_generators/hobo_user_model/hobo_user_model_generator.rb +30 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/templates/fixtures.yml +0 -0
- data/rails_generators/hobo_user_model/templates/forgot_password.erb +10 -0
- data/rails_generators/hobo_user_model/templates/mailer.rb +14 -0
- data/rails_generators/hobo_user_model/templates/model.rb +55 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/templates/unit_test.rb +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/{hobo_files/plugin/taglibs → taglibs}/core.dryml +6 -7
- data/{hobo_files/plugin/taglibs → taglibs}/rapid.dryml +36 -67
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_document_tags.dryml +7 -24
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_editing.dryml +51 -50
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_forms.dryml +62 -56
- data/taglibs/rapid_generics.dryml +33 -0
- data/taglibs/rapid_lifecycles.dryml +43 -0
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_navigation.dryml +23 -23
- data/taglibs/rapid_pages.dryml +183 -0
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_plus.dryml +30 -5
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_support.dryml +3 -4
- data/taglibs/rapid_user_pages.dryml +179 -0
- data/{hobo_files/plugin/tasks → tasks}/environments.rake +0 -0
- data/{hobo_files/plugin/tasks → tasks}/fix_dryml.rake +0 -0
- data/{hobo_files/plugin/tasks → tasks}/generate_tag_reference.rb +21 -22
- data/tasks/hobo_tasks.rake +32 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_helper.rb +1 -0
- data/test/test_hobo_model_controller_generator.rb +56 -0
- data/{hobo_files/plugin/uninstall.rb → uninstall.rb} +0 -0
- metadata +240 -225
- data/README.txt +0 -18
- data/hobo_files/plugin/LICENSE.txt +0 -22
- data/hobo_files/plugin/Rakefile +0 -96
- data/hobo_files/plugin/generators/hobo_front_controller/templates/index.dryml +0 -24
- data/hobo_files/plugin/generators/hobo_front_controller/templates/search.dryml +0 -19
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/banner.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-bodytop.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-01.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-02.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-03.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-04.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-bottom.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-left.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-right.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-top.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-blue.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-dblue.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-green.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-purple.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-red.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/logo.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/plus.png +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/spinner.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-dblue.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-green.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-purple.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-red.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-01.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-02.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-03.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-04.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-bottom.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-left.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-right.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-top.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/stylesheets/application.css +0 -400
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/views/application.dryml +0 -96
- data/hobo_files/plugin/generators/hobo_user_model/hobo_user_model_generator.rb +0 -25
- data/hobo_files/plugin/generators/hobo_user_model/templates/model.rb +0 -56
- data/hobo_files/plugin/init.rb +0 -101
- data/hobo_files/plugin/lib/action_view_extensions/base.rb +0 -15
- data/hobo_files/plugin/lib/active_record/has_many_association.rb +0 -55
- data/hobo_files/plugin/lib/active_record/has_many_through_association.rb +0 -20
- data/hobo_files/plugin/lib/hobo/dryml.rb +0 -165
- data/hobo_files/plugin/lib/hobo/dryml/parser/document.rb +0 -53
- data/hobo_files/plugin/lib/hobo/scopes/association_proxy_extensions.rb +0 -33
- data/hobo_files/plugin/lib/hobo/scopes/defined_scope_proxy_extender.rb +0 -90
- data/hobo_files/plugin/lib/hobo/scopes/scope_reflection.rb +0 -18
- data/hobo_files/plugin/lib/hobo/scopes/scoped_proxy.rb +0 -55
- data/hobo_files/plugin/taglib-docs/core.markdown +0 -165
- data/hobo_files/plugin/taglib-docs/rapid.markdown +0 -677
- data/hobo_files/plugin/taglib-docs/rapid_document_tags.markdown +0 -240
- data/hobo_files/plugin/taglib-docs/rapid_editing.markdown +0 -418
- data/hobo_files/plugin/taglib-docs/rapid_forms.markdown +0 -562
- data/hobo_files/plugin/taglib-docs/rapid_generics.markdown +0 -187
- data/hobo_files/plugin/taglib-docs/rapid_navigation.markdown +0 -214
- data/hobo_files/plugin/taglib-docs/rapid_pages.markdown +0 -530
- data/hobo_files/plugin/taglib-docs/rapid_plus.markdown +0 -65
- data/hobo_files/plugin/taglib-docs/rapid_support.markdown +0 -50
- data/hobo_files/plugin/taglib-docs/rapid_user_pages.markdown +0 -129
- data/hobo_files/plugin/taglibs/rapid_generics.dryml +0 -117
- data/hobo_files/plugin/taglibs/rapid_pages.dryml +0 -359
- data/hobo_files/plugin/taglibs/rapid_user_pages.dryml +0 -104
- data/hobo_files/plugin/tasks/dump_fixtures.rake +0 -70
- data/hobo_files/plugin/tasks/hobo_tasks.rake +0 -17
@@ -1,130 +1,134 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
if defined? ActionController::Routing::RouteSet
|
2
|
+
|
3
|
+
class ActionController::Routing::RouteSet
|
4
|
+
# Monkey patch this method so routes are reloaded on *every*
|
5
|
+
# request. Without this Rails checks the mtime of config/routes.rb
|
6
|
+
# which doesn't take into account Hobo's auto routing
|
7
|
+
|
8
|
+
def reload_with_hobo_routes
|
9
|
+
if Hobo::ModelRouter.reload_routes_on_every_request
|
10
|
+
load!
|
11
|
+
else
|
12
|
+
reload_without_hobo_routes
|
13
|
+
end
|
14
|
+
end
|
15
|
+
alias_method_chain :reload, :hobo_routes
|
16
|
+
|
17
|
+
# temporay hack -- reload assemble.rb whenever routes need reloading
|
18
|
+
def reload_with_hobo_assemble
|
19
|
+
if defined? ::ApplicationController
|
20
|
+
load "#{RAILS_ROOT}/app/assemble.rb" if File.exists? "#{RAILS_ROOT}/app/assemble.rb"
|
21
|
+
end
|
15
22
|
reload_without_hobo_assemble
|
16
23
|
end
|
24
|
+
alias_method_chain :reload, :hobo_assemble
|
25
|
+
|
17
26
|
end
|
18
|
-
|
19
|
-
|
27
|
+
|
20
28
|
end
|
21
29
|
|
22
30
|
module Hobo
|
23
|
-
|
31
|
+
|
24
32
|
class ModelRouter
|
25
|
-
|
26
|
-
APP_ROOT = "#{RAILS_ROOT}/app"
|
27
|
-
|
33
|
+
|
28
34
|
class << self
|
29
35
|
|
36
|
+
attr_accessor :reload_routes_on_every_request
|
37
|
+
|
30
38
|
def reset_linkables
|
31
|
-
@linkable =Set.new
|
39
|
+
@linkable = Set.new
|
32
40
|
end
|
33
|
-
|
41
|
+
|
34
42
|
def linkable_key(klass, action, options)
|
43
|
+
subsite = options[:subsite] || options['subsite']
|
44
|
+
method = options[:method] || options['method']
|
35
45
|
opts = options.map { |k, v| "#{k}=#{v}" unless v.blank? }.compact.join(',')
|
36
|
-
"#{klass.name}/#{action}/#{
|
46
|
+
"#{subsite}/#{klass.name}/#{action}/#{method}"
|
37
47
|
end
|
38
|
-
|
48
|
+
|
39
49
|
def linkable!(klass, action, options={})
|
40
50
|
options[:method] ||= :get
|
41
51
|
@linkable << linkable_key(klass, action, options)
|
42
52
|
end
|
43
|
-
|
53
|
+
|
44
54
|
def linkable?(klass, action, options={})
|
45
55
|
options[:method] ||= :get
|
46
56
|
@linkable.member? linkable_key(klass, action, options)
|
47
57
|
end
|
48
58
|
|
59
|
+
def called_from_generator?
|
60
|
+
caller[-1] =~ /script[\/\\]generate:\d+$/ || caller[-1] =~ /script[\/\\]destroy:\d+$/
|
61
|
+
end
|
62
|
+
|
49
63
|
def add_routes(map)
|
50
64
|
# Don't create routes if it's a generator that's running
|
51
|
-
return if
|
52
|
-
|
65
|
+
return if called_from_generator?
|
66
|
+
|
53
67
|
reset_linkables
|
54
|
-
|
55
|
-
begin
|
68
|
+
|
69
|
+
begin
|
56
70
|
ActiveRecord::Base.connection.reconnect! unless ActiveRecord::Base.connection.active?
|
57
71
|
rescue
|
58
72
|
# No database, no routes
|
59
73
|
return
|
60
74
|
end
|
61
75
|
|
62
|
-
require "#{
|
63
|
-
load "#{APP_ROOT}/assemble.rb" if File.exists? "#{APP_ROOT}/assemble.rb"
|
76
|
+
require "#{RAILS_ROOT}/app/controllers/application" unless Object.const_defined? :ApplicationController
|
64
77
|
|
65
|
-
# Add non-subsite routes
|
66
|
-
add_routes_for(map,
|
78
|
+
# Add non-subsite, and all subsite routes
|
79
|
+
[nil, *Hobo.subsites].each { |subsite| add_routes_for(map, subsite) }
|
67
80
|
|
68
|
-
# Any directory inside app/controllers defines a subsite
|
69
|
-
subsites = Dir["#{APP_ROOT}/controllers/*"].map { |f| File.basename(f) if File.directory?(f) }.compact
|
70
|
-
subsites.each { |subsite| add_routes_for(map, subsite) }
|
71
|
-
|
72
81
|
add_developer_routes(map) if Hobo.developer_features?
|
73
|
-
|
82
|
+
|
83
|
+
# Run the DRYML generators
|
84
|
+
# TODO: This needs a proper home
|
85
|
+
Hobo::Dryml::DrymlGenerator.run unless caller[-1] =~ /[\/\\]rake:\d+$/
|
86
|
+
rescue ActiveRecord::StatementInvalid => e
|
74
87
|
# Database problem? Just continue without routes
|
88
|
+
ActiveRecord::Base.logger.warn "!! Database exception during Hobo routing -- continuing without routes"
|
89
|
+
ActiveRecord::Base.logger.warn "!! #{e.to_s}"
|
75
90
|
end
|
76
|
-
|
77
|
-
|
91
|
+
|
92
|
+
|
78
93
|
def add_routes_for(map, subsite)
|
79
|
-
|
80
|
-
|
81
|
-
# FIXME: This should go directly to the controllers, not load the models first.
|
82
|
-
Hobo.models.each do |model|
|
83
|
-
controller_name = "#{model.name.pluralize}Controller"
|
84
|
-
is_defined = if subsite
|
85
|
-
Object.const_defined?(module_name) && module_name.constantize.const_defined?(controller_name)
|
86
|
-
else
|
87
|
-
Object.const_defined?(controller_name)
|
88
|
-
end
|
89
|
-
controller_filename = File.join(*["#{APP_ROOT}/controllers", subsite, "#{controller_name.underscore}.rb"].compact)
|
90
|
-
if is_defined || File.exists?(controller_filename)
|
91
|
-
controller = (subsite ? "#{module_name}::#{controller_name}" : controller_name).constantize
|
92
|
-
ModelRouter.new(map, model, controller, subsite)
|
93
|
-
end
|
94
|
-
end
|
94
|
+
Hobo::ModelController.all_controllers(subsite, :force).each { |controller| ModelRouter.new(map, controller, subsite) }
|
95
95
|
end
|
96
|
-
|
97
|
-
|
96
|
+
|
97
|
+
|
98
98
|
def add_developer_routes(map)
|
99
99
|
map.dryml_support "dryml/:action", :controller => "hobo/dryml/dryml_support"
|
100
100
|
map.dev_support "dev/:action", :controller => "hobo/dev"
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
end
|
104
|
-
|
105
104
|
|
106
|
-
|
105
|
+
|
106
|
+
def initialize(map, controller, subsite)
|
107
107
|
@map = map
|
108
|
-
@model = model
|
109
108
|
@controller = controller
|
110
109
|
@subsite = subsite
|
111
110
|
add_routes
|
112
111
|
end
|
113
|
-
|
112
|
+
|
114
113
|
|
115
114
|
attr_reader :map, :model, :controller, :subsite
|
116
115
|
|
117
116
|
|
117
|
+
def model
|
118
|
+
controller.model
|
119
|
+
end
|
120
|
+
|
121
|
+
|
118
122
|
def plural
|
119
123
|
model.name.underscore.pluralize
|
120
124
|
end
|
121
|
-
|
122
|
-
|
125
|
+
|
126
|
+
|
123
127
|
def singular
|
124
128
|
model.name.underscore
|
125
129
|
end
|
126
|
-
|
127
|
-
|
130
|
+
|
131
|
+
|
128
132
|
def add_routes
|
129
133
|
# Simple support for composite models, we might later need a CompositeModelController
|
130
134
|
if model < Hobo::CompositeModel
|
@@ -133,122 +137,149 @@ module Hobo
|
|
133
137
|
elsif controller < Hobo::ModelController
|
134
138
|
# index routes need to be first so the index names don't get
|
135
139
|
# taken as IDs
|
136
|
-
index_action_routes
|
140
|
+
index_action_routes
|
141
|
+
lifecycle_routes if defined? model::Lifecycle
|
137
142
|
resource_routes
|
138
|
-
|
143
|
+
owner_routes
|
139
144
|
web_method_routes
|
140
145
|
show_action_routes
|
141
|
-
reorder_route
|
142
146
|
|
143
|
-
|
147
|
+
reorder_route
|
144
148
|
user_routes if controller < Hobo::UserController
|
145
149
|
end
|
146
150
|
end
|
147
|
-
|
148
|
-
|
151
|
+
|
152
|
+
|
149
153
|
def resource_routes
|
150
154
|
# We re-implement resource routing - routes are not created for
|
151
155
|
# actions that the controller does not provide
|
152
|
-
|
156
|
+
|
153
157
|
# FIX ME -- what about routes with formats (e.g. .xml)?
|
154
|
-
|
158
|
+
|
155
159
|
linkable_route(plural, plural, :index, :conditions => { :method => :get })
|
156
|
-
|
157
|
-
linkable_route("new_#{singular}", "#{plural}/new", :new, :conditions => { :method => :get })
|
158
|
-
linkable_route("edit_#{singular}", "#{plural}/:id/edit", :edit, :conditions => { :method => :get })
|
159
|
-
|
160
|
+
|
161
|
+
linkable_route("new_#{singular}", "#{plural}/new", :new, :conditions => { :method => :get })
|
162
|
+
linkable_route("edit_#{singular}", "#{plural}/:id/edit", :edit, :conditions => { :method => :get })
|
163
|
+
|
160
164
|
linkable_route(singular, "#{plural}/:id", :show, :conditions => { :method => :get })
|
161
|
-
|
165
|
+
|
162
166
|
linkable_route("create_#{singular}", plural, :create, :conditions => { :method => :post })
|
163
|
-
linkable_route("update_#{singular}", "#{plural}/:id", :update, :conditions => { :method => :put })
|
167
|
+
linkable_route("update_#{singular}", "#{plural}/:id", :update, :conditions => { :method => :put })
|
164
168
|
linkable_route("destroy_#{singular}", "#{plural}/:id", :destroy, :conditions => { :method => :delete })
|
165
169
|
end
|
166
|
-
|
167
|
-
|
168
|
-
def
|
169
|
-
controller.
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
170
|
+
|
171
|
+
|
172
|
+
def owner_routes
|
173
|
+
controller.owner_actions.each_pair do |owner, actions|
|
174
|
+
collection = model.reverse_reflection(owner).name
|
175
|
+
owner_singular = model.reflections[owner].klass.name.underscore
|
176
|
+
owner_plural = owner_singular.pluralize
|
177
|
+
|
178
|
+
actions.each do |action|
|
179
|
+
case action
|
180
|
+
when :index
|
181
|
+
linkable_route("#{plural}_for_#{owner}",
|
182
|
+
"#{owner_plural}/:#{owner_singular}_id/#{collection}",
|
183
|
+
"index_for_#{owner}",
|
184
|
+
:conditions => { :method => :get })
|
185
|
+
when :new
|
186
|
+
linkable_route("new_#{singular}_for_#{owner}",
|
187
|
+
"#{owner_plural}/:#{owner_singular}_id/#{collection}/new",
|
188
|
+
"new_for_#{owner}",
|
189
|
+
:conditions => { :method => :get })
|
190
|
+
when :create
|
191
|
+
linkable_route("create_#{singular}_for_#{owner}",
|
192
|
+
"#{owner_plural}/:#{owner_singular}_id/#{collection}",
|
193
|
+
"create_for_#{owner}",
|
194
|
+
:conditions => { :method => :post })
|
195
|
+
end
|
180
196
|
end
|
181
197
|
end
|
182
|
-
end
|
183
|
-
|
184
|
-
|
198
|
+
end
|
199
|
+
|
185
200
|
def web_method_routes
|
186
201
|
controller.web_methods.each do |method|
|
187
202
|
linkable_route("#{plural.singularize}_#{method}", "#{plural}/:id/#{method}", method.to_s, :conditions => { :method => :post })
|
188
203
|
end
|
189
204
|
end
|
190
|
-
|
191
|
-
|
205
|
+
|
206
|
+
|
192
207
|
def index_action_routes
|
193
208
|
controller.index_actions.each do |view|
|
194
209
|
linkable_route("#{view}_#{plural}", "#{plural}/#{view}", view.to_s, :conditions => { :method => :get })
|
195
210
|
end
|
196
211
|
end
|
197
212
|
|
198
|
-
|
213
|
+
|
199
214
|
def show_action_routes
|
200
215
|
controller.show_actions.each do |view|
|
201
216
|
linkable_route("#{plural.singularize}_#{view}", "#{plural}/:id/#{view}", view.to_s, :conditions => { :method => :get })
|
202
217
|
end
|
203
218
|
end
|
204
|
-
|
205
|
-
|
219
|
+
|
220
|
+
|
206
221
|
def reorder_route
|
207
222
|
linkable_route("reorder_#{plural}", "#{plural}/reorder", 'reorder', :conditions => { :method => :post })
|
208
223
|
end
|
209
|
-
|
210
|
-
|
224
|
+
|
225
|
+
|
226
|
+
def lifecycle_routes
|
227
|
+
model::Lifecycle.creators.values.where.publishable?.*.name.each do |creator|
|
228
|
+
linkable_route("do_#{singular}_#{creator}", "#{plural}/#{creator}", "do_#{creator}",
|
229
|
+
:conditions => { :method => :post }, :format => false, :linkable_action => creator)
|
230
|
+
linkable_route("#{singular}_#{creator}", "#{plural}/#{creator}", creator, :conditions => { :method => :get }, :format => false)
|
231
|
+
end
|
232
|
+
model::Lifecycle.transitions.where.publishable?.*.name.each do |transition|
|
233
|
+
linkable_route("do_#{singular}_#{transition}", "#{plural}/:id/#{transition}", "do_#{transition}",
|
234
|
+
:conditions => { :method => :put }, :format => false, :linkable_action => transition)
|
235
|
+
linkable_route("#{singular}_#{transition}", "#{plural}/:id/#{transition}", transition,
|
236
|
+
:conditions => { :method => :get }, :format => false)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
|
211
241
|
def user_routes
|
212
242
|
prefix = plural == "users" ? "" : "#{singular}_"
|
213
243
|
linkable_route("#{singular}_login", "#{prefix}login", 'login')
|
214
244
|
linkable_route("#{singular}_logout", "#{prefix}logout", 'logout')
|
215
|
-
linkable_route("#{singular}
|
245
|
+
linkable_route("#{singular}_forgot_password", "#{prefix}forgot_password", 'forgot_password')
|
216
246
|
end
|
217
|
-
|
218
|
-
|
247
|
+
|
248
|
+
|
219
249
|
def named_route(name, route, options={})
|
220
250
|
if controller.public_instance_methods.include?(options[:action].to_s)
|
221
251
|
options.reverse_merge!(:controller => route_with_subsite(plural))
|
222
252
|
name = name_with_subsite(name)
|
223
253
|
route = route_with_subsite(route)
|
224
|
-
map.named_route(name, route, options)
|
225
254
|
format_route = options.delete(:format) != false
|
255
|
+
map.named_route(name, route, options)
|
226
256
|
map.named_route("formatted_#{name}", "#{route}.:format", options) if format_route
|
227
257
|
true
|
228
258
|
else
|
229
259
|
false
|
230
260
|
end
|
231
261
|
end
|
232
|
-
|
233
|
-
|
262
|
+
|
263
|
+
|
234
264
|
def linkable_route(name, route, action, options={})
|
235
|
-
|
265
|
+
linkable_action = options.delete(:linkable_action) || action
|
266
|
+
named_route(name, route, options.merge(:action => action.to_s)) and
|
236
267
|
begin
|
237
268
|
linkable_options = { :method => options[:conditions]._?[:method], :subsite => subsite }
|
238
|
-
self.class.linkable!(model,
|
269
|
+
self.class.linkable!(model, linkable_action, linkable_options)
|
239
270
|
end
|
240
271
|
end
|
241
|
-
|
242
|
-
|
272
|
+
|
273
|
+
|
243
274
|
def name_with_subsite(name)
|
244
|
-
subsite ? "#{subsite}_#{name}" : name
|
275
|
+
subsite ? "#{subsite}_#{name}" : name
|
245
276
|
end
|
246
|
-
|
247
|
-
|
277
|
+
|
278
|
+
|
248
279
|
def route_with_subsite(route)
|
249
280
|
subsite ? "#{subsite}/#{route}" : route
|
250
281
|
end
|
251
|
-
|
282
|
+
|
252
283
|
end
|
253
|
-
|
284
|
+
|
254
285
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Hobo
|
2
|
-
|
2
|
+
|
3
3
|
module ModelSupport
|
4
|
-
|
4
|
+
|
5
5
|
# This module provides methods common to both Hobo::Model and Hobo::CompositeModel
|
6
|
-
|
6
|
+
|
7
7
|
def self.included(base)
|
8
8
|
base.extend(ClassMethods) if base.is_a? Class
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
module ClassMethods
|
12
|
-
|
12
|
+
|
13
13
|
def delegate_and_compose(*methods)
|
14
14
|
options = methods.pop
|
15
15
|
unless options.is_a?(Hash) && to = options[:to]
|
@@ -17,14 +17,14 @@ module Hobo
|
|
17
17
|
"with a :to key as the last argument (e.g. delegate :hello, :to => :greeter).")
|
18
18
|
end
|
19
19
|
use = options[:use]
|
20
|
-
|
20
|
+
|
21
21
|
methods.each do |method|
|
22
22
|
module_eval(<<-EOS, "(__COMPOSED_DELEGATION__)", 1)
|
23
23
|
def #{method}
|
24
24
|
@__#{method}_result__ ||= begin
|
25
25
|
obj = #{to}.__send__(#{method.inspect})
|
26
26
|
return nil if obj.nil?
|
27
|
-
|
27
|
+
|
28
28
|
if obj.nil?
|
29
29
|
nil
|
30
30
|
elsif obj.is_a?(Array)
|
@@ -37,8 +37,8 @@ module Hobo
|
|
37
37
|
EOS
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
44
44
|
end
|