typus 3.0.6 → 3.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +15 -0
- data/Gemfile +9 -5
- data/Rakefile +34 -21
- data/app/controllers/admin/base_controller.rb +0 -4
- data/app/controllers/admin/resources_controller.rb +77 -213
- data/app/controllers/admin/session_controller.rb +1 -1
- data/app/helpers/admin/base_helper.rb +4 -4
- data/app/helpers/admin/dashboard_helper.rb +1 -3
- data/app/helpers/admin/display_helper.rb +49 -0
- data/app/helpers/admin/file_preview_helper.rb +10 -12
- data/app/helpers/admin/filters_helper.rb +1 -1
- data/app/helpers/admin/form_helper.rb +2 -13
- data/app/helpers/admin/list_helper.rb +14 -3
- data/app/helpers/admin/relationships_helper.rb +79 -62
- data/app/helpers/admin/resources_helper.rb +17 -16
- data/app/helpers/admin/search_helper.rb +1 -1
- data/app/helpers/admin/sidebar_helper.rb +1 -2
- data/app/helpers/admin/table_helper.rb +9 -4
- data/app/views/admin/helpers/_file_preview.html.erb +1 -1
- data/app/views/admin/helpers/base/_apps.html.erb +23 -0
- data/app/views/admin/helpers/{_flash_message.html.erb → base/_flash_message.html.erb} +0 -0
- data/app/views/admin/helpers/{_header.html.erb → base/_header.html.erb} +0 -0
- data/app/views/admin/helpers/{_login_info.html.erb → base/_login_info.html.erb} +0 -0
- data/app/views/admin/helpers/resources/_display_link_to_previous.html.erb +1 -1
- data/app/views/admin/resources/show.html.erb +4 -27
- data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +11 -0
- data/app/views/admin/templates/_has_n.html.erb +1 -1
- data/app/views/admin/templates/_has_one.html.erb +3 -3
- data/app/views/admin/templates/_relate_form.html.erb +1 -1
- data/app/views/admin/templates/_relate_form_with_autocomplete.html.erb +24 -0
- data/app/views/layouts/admin/base.html.erb +15 -9
- data/app/views/layouts/admin/headless.html.erb +44 -0
- data/app/views/layouts/admin/session.html.erb +3 -2
- data/doc/hudson_setup.md +19 -0
- data/lib/generators/typus/assets_generator.rb +0 -4
- data/lib/generators/typus/config_generator.rb +107 -0
- data/lib/generators/typus/controller_generator.rb +0 -4
- data/lib/generators/typus/initializers_generator.rb +22 -0
- data/lib/generators/typus/migration_generator.rb +0 -4
- data/lib/generators/typus/typus_generator.rb +8 -101
- data/lib/generators/typus/views_generator.rb +0 -4
- data/lib/support/active_record.rb +8 -2
- data/lib/support/fake_user.rb +2 -0
- data/lib/support/hash.rb +1 -1
- data/lib/support/string.rb +3 -3
- data/lib/tasks/typus.rake +1 -1
- data/lib/typus.rb +15 -6
- data/lib/typus/controller/actions.rb +69 -0
- data/lib/typus/controller/associations.rb +82 -0
- data/lib/typus/controller/autocomplete.rb +16 -0
- data/lib/typus/controller/filters.rb +24 -0
- data/lib/typus/controller/format.rb +70 -0
- data/lib/typus/orm/active_record.rb +9 -240
- data/lib/typus/orm/active_record/class_methods.rb +227 -0
- data/lib/typus/orm/active_record/instance_methods.rb +13 -0
- data/lib/typus/orm/active_record/search.rb +17 -5
- data/lib/typus/orm/active_record/user.rb +157 -0
- data/lib/typus/regex.rb +11 -0
- data/lib/typus/version.rb +1 -1
- data/test/app/controllers/admin/account_controller_test.rb +104 -0
- data/test/app/controllers/admin/assets_controller_test.rb +153 -0
- data/test/app/controllers/admin/base_controller_test.rb +41 -0
- data/test/app/controllers/admin/birds_controller_test.rb +42 -0
- data/test/app/controllers/admin/cases_controller_test.rb +21 -0
- data/test/app/controllers/admin/categories_controller_test.rb +141 -0
- data/test/app/controllers/admin/comments_controller_test.rb +79 -0
- data/test/app/controllers/admin/dashboard_controller_test.rb +162 -0
- data/test/app/controllers/admin/image_holders_controller_test.rb +75 -0
- data/test/app/controllers/admin/invoices_controller_test.rb +78 -0
- data/test/app/controllers/admin/orders_controller_test.rb +18 -0
- data/test/app/controllers/admin/pages_controller_test.rb +37 -0
- data/test/app/controllers/admin/posts_controller_test.rb +745 -0
- data/test/app/controllers/admin/projects_controller_test.rb +52 -0
- data/test/app/controllers/admin/session_controller_test.rb +92 -0
- data/test/app/controllers/admin/status_controller_test.rb +54 -0
- data/test/app/controllers/admin/typus_users_controller_test.rb +160 -0
- data/test/app/controllers/admin/users_controller_test.rb +106 -0
- data/test/app/helpers/admin/base_helper_test.rb +83 -0
- data/test/app/helpers/admin/dashboard_helper_test.rb +32 -0
- data/test/app/helpers/admin/file_preview_helper_test.rb +82 -0
- data/test/app/helpers/admin/filters_helper_test.rb +161 -0
- data/test/app/helpers/admin/form_helper_test.rb +126 -0
- data/test/app/helpers/admin/list_helper_test.rb +59 -0
- data/test/app/helpers/admin/relationships_helper_test.rb +19 -0
- data/test/app/helpers/admin/resources_helper_test.rb +46 -0
- data/test/app/helpers/admin/search_helper_test.rb +60 -0
- data/test/app/helpers/admin/sidebar_helper_test.rb +34 -0
- data/test/app/helpers/admin/table_helper_test.rb +215 -0
- data/test/app/mailers/admin/mailer_test.rb +32 -0
- data/test/app/models/typus_user_roles_test.rb +124 -0
- data/test/app/models/typus_user_test.rb +194 -0
- data/test/config/routes_test.rb +29 -0
- data/test/factories.rb +111 -0
- data/test/fixtures/config/broken/application.yml +68 -0
- data/test/fixtures/config/broken/application_roles.yml +20 -0
- data/test/fixtures/config/broken/empty.yml +0 -0
- data/test/fixtures/config/broken/empty_roles.yml +0 -0
- data/test/fixtures/config/broken/undefined.yml +3 -0
- data/test/fixtures/config/broken/undefined_roles.yml +6 -0
- data/test/fixtures/config/default/typus.yml +13 -0
- data/test/fixtures/config/default/typus_roles.yml +2 -0
- data/test/fixtures/config/empty/empty_01.yml +0 -0
- data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
- data/test/fixtures/config/empty/empty_02.yml +0 -0
- data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
- data/test/fixtures/config/locales/es.yml +10 -0
- data/test/fixtures/config/namespaced/application.yml +5 -0
- data/test/fixtures/config/namespaced/application_roles.yml +2 -0
- data/test/fixtures/config/ordered/001_roles.yml +2 -0
- data/test/fixtures/config/ordered/002_roles.yml +2 -0
- data/test/fixtures/config/unordered/app_one_roles.yml +2 -0
- data/test/fixtures/config/unordered/app_two_roles.yml +2 -0
- data/test/fixtures/rails_app/.gitignore +4 -0
- data/test/fixtures/rails_app/Capfile +6 -0
- data/test/fixtures/rails_app/README +256 -0
- data/test/fixtures/rails_app/Rakefile +7 -0
- data/test/fixtures/rails_app/app/controllers/admin/animals_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/articles_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/assets_controller.rb +51 -0
- data/test/fixtures/rails_app/app/controllers/admin/birds_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/cases_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/categories_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/comments_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/dogs_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/entries_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/image_holders_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/invoices_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/orders_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/pages_controller.rb +7 -0
- data/test/fixtures/rails_app/app/controllers/admin/posts_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/project_collaborators_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/projects_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/status_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/typus_users_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/users_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/views_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/watch_dog_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/application_controller.rb +3 -0
- data/test/fixtures/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/fixtures/rails_app/app/helpers/form_helper.rb +3 -0
- data/test/fixtures/rails_app/app/models/animal.rb +21 -0
- data/test/fixtures/rails_app/app/models/article.rb +10 -0
- data/test/fixtures/rails_app/app/models/asset.rb +39 -0
- data/test/fixtures/rails_app/app/models/bird.rb +2 -0
- data/test/fixtures/rails_app/app/models/case.rb +2 -0
- data/test/fixtures/rails_app/app/models/category.rb +31 -0
- data/test/fixtures/rails_app/app/models/comment.rb +17 -0
- data/test/fixtures/rails_app/app/models/delayed/task.rb +5 -0
- data/test/fixtures/rails_app/app/models/dog.rb +2 -0
- data/test/fixtures/rails_app/app/models/entry.rb +23 -0
- data/test/fixtures/rails_app/app/models/image_holder.rb +21 -0
- data/test/fixtures/rails_app/app/models/invoice.rb +10 -0
- data/test/fixtures/rails_app/app/models/order.rb +9 -0
- data/test/fixtures/rails_app/app/models/page.rb +24 -0
- data/test/fixtures/rails_app/app/models/post.rb +32 -0
- data/test/fixtures/rails_app/app/models/project.rb +17 -0
- data/test/fixtures/rails_app/app/models/project_collaborator.rb +16 -0
- data/test/fixtures/rails_app/app/models/typus_user.rb +22 -0
- data/test/fixtures/rails_app/app/models/user.rb +10 -0
- data/test/fixtures/rails_app/app/models/view.rb +17 -0
- data/test/fixtures/rails_app/app/views/admin/assets/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/cases/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/categories/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/dashboard/_sidebar.html.erb +11 -0
- data/test/fixtures/rails_app/app/views/admin/entries/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/pages/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_edit.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_index.html.erb +5 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_new.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_show.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/resources/_sidebar.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/status/index.html.erb +9 -0
- data/test/fixtures/rails_app/app/views/admin/templates/_datepicker.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/watch_dog/index.html.erb +9 -0
- data/test/fixtures/rails_app/app/views/layouts/admin/headless.html.erb +38 -0
- data/test/fixtures/rails_app/config.ru +4 -0
- data/test/fixtures/rails_app/config/application.rb +44 -0
- data/test/fixtures/rails_app/config/boot.rb +13 -0
- data/test/fixtures/rails_app/config/database.yml +34 -0
- data/test/fixtures/rails_app/config/deploy.rb +32 -0
- data/test/fixtures/rails_app/config/environment.rb +5 -0
- data/test/fixtures/rails_app/config/environments/development.rb +32 -0
- data/test/fixtures/rails_app/config/environments/production.rb +54 -0
- data/test/fixtures/rails_app/config/environments/test.rb +40 -0
- data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/fixtures/rails_app/config/initializers/dragonfly.rb +1 -0
- data/test/fixtures/rails_app/config/initializers/inflections.rb +12 -0
- data/test/fixtures/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/fixtures/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/fixtures/rails_app/config/initializers/session_store.rb +8 -0
- data/test/fixtures/rails_app/config/initializers/typus.rb +5 -0
- data/test/fixtures/rails_app/config/initializers/typus_resources.rb +27 -0
- data/test/fixtures/rails_app/config/locales/en.yml +5 -0
- data/test/fixtures/rails_app/config/routes.rb +61 -0
- data/test/fixtures/rails_app/config/typus/README +68 -0
- data/test/fixtures/rails_app/config/typus/crud_basic.yml +10 -0
- data/test/fixtures/rails_app/config/typus/crud_basic_roles.yml +2 -0
- data/test/fixtures/rails_app/config/typus/crud_extended.yml +64 -0
- data/test/fixtures/rails_app/config/typus/crud_extended_roles.yml +18 -0
- data/test/fixtures/rails_app/config/typus/has_many.yml +0 -0
- data/test/fixtures/rails_app/config/typus/has_many_roles.yml +0 -0
- data/test/fixtures/rails_app/config/typus/has_many_through.yml +23 -0
- data/test/fixtures/rails_app/config/typus/has_many_through_roles.yml +4 -0
- data/test/fixtures/rails_app/config/typus/has_one.yml +12 -0
- data/test/fixtures/rails_app/config/typus/has_one_roles.yml +3 -0
- data/test/fixtures/rails_app/config/typus/polymorphic.yml +17 -0
- data/test/fixtures/rails_app/config/typus/polymorphic_roles.yml +5 -0
- data/test/fixtures/rails_app/config/typus/resource_roles.yml +7 -0
- data/test/fixtures/rails_app/config/typus/sti.yml +5 -0
- data/test/fixtures/rails_app/config/typus/sti_roles.yml +2 -0
- data/test/fixtures/rails_app/config/typus/typus.yml +13 -0
- data/test/fixtures/rails_app/config/typus/typus_roles.yml +2 -0
- data/test/fixtures/rails_app/config/typus/unknown.yml +3 -0
- data/test/fixtures/rails_app/config/typus/unknown_roles.yml +5 -0
- data/test/fixtures/rails_app/db/.gitkeep +0 -0
- data/test/fixtures/rails_app/db/schema.rb +174 -0
- data/test/fixtures/rails_app/db/seeds.rb +54 -0
- data/test/fixtures/rails_app/db/seeds/assets/000.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/001.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/002.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/003.jpg +0 -0
- data/test/fixtures/rails_app/db/seeds/assets/004.jpg +0 -0
- data/test/fixtures/rails_app/public/404.html +26 -0
- data/test/fixtures/rails_app/public/422.html +26 -0
- data/test/fixtures/rails_app/public/500.html +26 -0
- data/test/fixtures/rails_app/public/favicon.ico +0 -0
- data/test/fixtures/rails_app/public/images/rails.png +0 -0
- data/test/fixtures/rails_app/public/javascripts/application.js +2 -0
- data/test/fixtures/rails_app/public/javascripts/controls.js +965 -0
- data/test/fixtures/rails_app/public/javascripts/dragdrop.js +974 -0
- data/test/fixtures/rails_app/public/javascripts/effects.js +1123 -0
- data/test/fixtures/rails_app/public/javascripts/prototype.js +6001 -0
- data/test/fixtures/rails_app/public/javascripts/rails.js +175 -0
- data/test/fixtures/rails_app/public/robots.txt +5 -0
- data/test/fixtures/rails_app/public/stylesheets/.gitkeep +0 -0
- data/test/fixtures/rails_app/script/rails +6 -0
- data/test/lib/support/active_record_test.rb +150 -0
- data/test/lib/support/fake_user_test.rb +59 -0
- data/test/lib/support/hash_test.rb +29 -0
- data/test/lib/support/object_test.rb +17 -0
- data/test/lib/support/string_test.rb +116 -0
- data/test/lib/typus/configuration_test.rb +46 -0
- data/test/lib/typus/controller/actions_test.rb +141 -0
- data/test/lib/typus/controller/associations_test.rb +7 -0
- data/test/lib/typus/controller/autocomplete_test.rb +7 -0
- data/test/lib/typus/controller/filters_test.rb +73 -0
- data/test/lib/typus/controller/format_test.rb +7 -0
- data/test/lib/typus/i18n_test.rb +9 -0
- data/test/lib/typus/orm/active_record/class_methods_test.rb +378 -0
- data/test/lib/typus/orm/active_record/search_test.rb +330 -0
- data/test/lib/typus/regex_test.rb +53 -0
- data/test/lib/typus/resources_test.rb +41 -0
- data/test/lib/typus_test.rb +141 -0
- data/test/test_helper.rb +15 -0
- data/typus.gemspec +25 -0
- metadata +586 -64
- data/Gemfile.lock +0 -149
- data/app/views/admin/helpers/_apps.html.erb +0 -9
- data/lib/generators/templates/public/admin/javascripts/application.js +0 -2
- data/lib/generators/templates/public/admin/javascripts/jquery-1.4.4.min.js +0 -167
- data/lib/generators/templates/public/admin/javascripts/jquery.application.js +0 -16
- data/lib/generators/templates/public/admin/javascripts/jquery.rails.js +0 -160
- data/lib/generators/templates/public/admin/javascripts/jquery.searchField.js +0 -91
- data/lib/generators/templates/public/admin/stylesheets/application.css +0 -11
- data/lib/generators/templates/public/admin/stylesheets/screen.css +0 -367
- data/lib/generators/templates/public/admin/vendor/fancybox/blank.gif +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_close.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_loading.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_left.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_right.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_e.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_n.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_ne.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_nw.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_s.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_se.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_sw.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_w.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_left.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_main.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_over.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_right.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-x.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-y.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.easing-1.3.pack.js +0 -72
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.css +0 -359
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.js +0 -1156
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.pack.js +0 -46
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.4.pack.js +0 -14
- data/lib/typus/actions.rb +0 -41
- data/lib/typus/filters.rb +0 -12
- data/lib/typus/format.rb +0 -70
- data/lib/typus/user.rb +0 -157
@@ -0,0 +1,22 @@
|
|
1
|
+
module Typus
|
2
|
+
module Generators
|
3
|
+
class InitializersGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path("../../templates", __FILE__)
|
6
|
+
|
7
|
+
class_option :admin_title, :default => Rails.root.basename
|
8
|
+
|
9
|
+
desc <<-MSG
|
10
|
+
Description:
|
11
|
+
Copies all Typus initializers into your application.
|
12
|
+
|
13
|
+
MSG
|
14
|
+
|
15
|
+
def generate_initializers
|
16
|
+
template "config/initializers/typus.rb", "config/initializers/typus.rb"
|
17
|
+
template "config/initializers/typus_resources.rb", "config/initializers/typus_resources.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -2,9 +2,7 @@ require "rails/generators/migration"
|
|
2
2
|
require "generators/typus/controller_generator"
|
3
3
|
|
4
4
|
module Typus
|
5
|
-
|
6
5
|
module Generators
|
7
|
-
|
8
6
|
class MigrationGenerator < Rails::Generators::Base
|
9
7
|
|
10
8
|
include Rails::Generators::Migration
|
@@ -97,7 +95,5 @@ Examples:
|
|
97
95
|
end
|
98
96
|
|
99
97
|
end
|
100
|
-
|
101
98
|
end
|
102
|
-
|
103
99
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require "rails/generators/migration"
|
2
|
-
|
2
|
+
|
3
3
|
require "generators/typus/assets_generator"
|
4
|
+
require "generators/typus/config_generator"
|
5
|
+
require "generators/typus/controller_generator"
|
6
|
+
require "generators/typus/initializers_generator"
|
4
7
|
|
5
8
|
module Typus
|
6
|
-
|
7
9
|
module Generators
|
8
|
-
|
9
10
|
class TypusGenerator < Rails::Generators::Base
|
10
11
|
|
11
12
|
include Rails::Generators::Migration
|
@@ -14,8 +15,6 @@ module Typus
|
|
14
15
|
|
15
16
|
namespace "typus"
|
16
17
|
|
17
|
-
class_option :admin_title, :default => Rails.root.basename
|
18
|
-
|
19
18
|
desc <<-DESC
|
20
19
|
Description:
|
21
20
|
This generator creates required files to enable an admin panel which allows
|
@@ -25,16 +24,11 @@ Description:
|
|
25
24
|
|
26
25
|
DESC
|
27
26
|
|
28
|
-
def
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def generate_initializer
|
33
|
-
template "config/initializers/typus.rb", "config/initializers/typus.rb"
|
34
|
-
template "config/initializers/typus_resources.rb", "config/initializers/typus_resources.rb"
|
27
|
+
def generate_initializers
|
28
|
+
Typus::Generators::InitializersGenerator.new.invoke_all
|
35
29
|
end
|
36
30
|
|
37
|
-
def
|
31
|
+
def generate_assets
|
38
32
|
Typus::Generators::AssetsGenerator.new.invoke_all
|
39
33
|
end
|
40
34
|
|
@@ -45,19 +39,11 @@ Description:
|
|
45
39
|
end
|
46
40
|
|
47
41
|
def generate_config
|
48
|
-
|
49
|
-
%w(application.yml application_roles.yml).each do |file|
|
50
|
-
template "config/typus/#{file}", "config/typus/#{timestamp}_#{file}"
|
51
|
-
end
|
52
|
-
end
|
42
|
+
Typus::Generators::ConfigGenerator.new.invoke_all
|
53
43
|
end
|
54
44
|
|
55
45
|
protected
|
56
46
|
|
57
|
-
def configuration
|
58
|
-
@configuration
|
59
|
-
end
|
60
|
-
|
61
47
|
def resource
|
62
48
|
@resource
|
63
49
|
end
|
@@ -66,85 +52,6 @@ Description:
|
|
66
52
|
@sidebar
|
67
53
|
end
|
68
54
|
|
69
|
-
def timestamp
|
70
|
-
Time.zone.now.to_s(:number)
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def generate_yaml_files
|
76
|
-
Typus.reload!
|
77
|
-
|
78
|
-
configuration = { :base => "", :roles => "" }
|
79
|
-
|
80
|
-
Typus.application_models.sort { |x,y| x <=> y }.each do |model|
|
81
|
-
|
82
|
-
next if Typus.models.include?(model)
|
83
|
-
|
84
|
-
klass = model.constantize
|
85
|
-
|
86
|
-
# Detect all relationships except polymorphic belongs_to using reflection.
|
87
|
-
relationships = [ :belongs_to, :has_and_belongs_to_many, :has_many, :has_one ].map do |relationship|
|
88
|
-
klass.reflect_on_all_associations(relationship).reject { |i| i.options[:polymorphic] }.map { |i| i.name.to_s }
|
89
|
-
end.flatten.sort
|
90
|
-
|
91
|
-
##
|
92
|
-
# Model fields for:
|
93
|
-
#
|
94
|
-
# - Default
|
95
|
-
# - Form
|
96
|
-
#
|
97
|
-
|
98
|
-
rejections = %w( ^id$
|
99
|
-
created_at created_on updated_at updated_on deleted_at
|
100
|
-
salt crypted_password
|
101
|
-
password_salt persistence_token single_access_token perishable_token
|
102
|
-
_type$ type
|
103
|
-
_file_size$ )
|
104
|
-
|
105
|
-
default_rejections = (rejections + %w( password password_confirmation )).join("|")
|
106
|
-
form_rejections = (rejections + %w( position )).join("|")
|
107
|
-
|
108
|
-
fields = klass.columns.map(&:name)
|
109
|
-
default = fields.reject { |f| f.match(default_rejections) }
|
110
|
-
form = fields.reject { |f| f.match(form_rejections) }
|
111
|
-
|
112
|
-
# Model defaults.
|
113
|
-
order_by = "position" if default.include?("position")
|
114
|
-
filters = "created_at" if fields.include?("created_at")
|
115
|
-
search = ( %w(name title) & default ).join(", ")
|
116
|
-
|
117
|
-
# We want attributes of belongs_to relationships to be shown in our
|
118
|
-
# field collections if those are not polymorphic.
|
119
|
-
[ default, form ].each do |fields|
|
120
|
-
fields << klass.reflect_on_all_associations(:belongs_to).reject { |i| i.options[:polymorphic] }.map { |i| i.name.to_s }
|
121
|
-
fields.flatten!
|
122
|
-
end
|
123
|
-
|
124
|
-
configuration[:base] << <<-RAW
|
125
|
-
#{klass}:
|
126
|
-
fields:
|
127
|
-
default: #{default.join(", ")}
|
128
|
-
form: #{form.join(", ")}
|
129
|
-
order_by: #{order_by}
|
130
|
-
relationships: #{relationships.join(", ")}
|
131
|
-
filters: #{filters}
|
132
|
-
search: #{search}
|
133
|
-
application: #{options[:admin_title]}
|
134
|
-
|
135
|
-
RAW
|
136
|
-
|
137
|
-
configuration[:roles] << <<-RAW
|
138
|
-
#{klass}: create, read, update, delete
|
139
|
-
RAW
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
configuration
|
144
|
-
end
|
145
|
-
|
146
55
|
end
|
147
|
-
|
148
56
|
end
|
149
|
-
|
150
57
|
end
|
@@ -37,11 +37,17 @@ class ActiveRecord::Base
|
|
37
37
|
def mapping(attribute)
|
38
38
|
values = self.class::const_get(attribute.to_s.upcase).to_a
|
39
39
|
array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
|
40
|
-
|
40
|
+
|
41
|
+
value = array.rassoc(send(attribute))
|
42
|
+
value ? value.first : send(attribute)
|
41
43
|
end
|
42
44
|
|
43
45
|
def to_label
|
44
|
-
respond_to?(:name)
|
46
|
+
if respond_to?(:name) && send(:name).present?
|
47
|
+
send(:name)
|
48
|
+
else
|
49
|
+
[self.class, id].join("#")
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
53
|
end
|
data/lib/support/fake_user.rb
CHANGED
data/lib/support/hash.rb
CHANGED
data/lib/support/string.rb
CHANGED
@@ -19,7 +19,7 @@ class String
|
|
19
19
|
def action_mapper
|
20
20
|
case self
|
21
21
|
when "index" then :list
|
22
|
-
when "new", "create", "edit", "update" then :form
|
22
|
+
when "new", "create", "edit", "update", "toggle" then :form
|
23
23
|
else self
|
24
24
|
end
|
25
25
|
end
|
@@ -28,9 +28,9 @@ class String
|
|
28
28
|
case self
|
29
29
|
when "new", "create"
|
30
30
|
"create"
|
31
|
-
when "index", "show"
|
31
|
+
when "index", "show", "autocomplete"
|
32
32
|
"read"
|
33
|
-
when "edit", "update", "position", "toggle", "relate", "unrelate"
|
33
|
+
when "edit", "update", "position", "toggle", "relate", "unrelate"
|
34
34
|
"update"
|
35
35
|
when "destroy", "trash"
|
36
36
|
"delete"
|
data/lib/tasks/typus.rake
CHANGED
@@ -3,7 +3,7 @@ namespace :typus do
|
|
3
3
|
desc "List current roles."
|
4
4
|
task :roles => :environment do
|
5
5
|
Typus::Configuration.roles.each do |role|
|
6
|
-
puts "#{role.first
|
6
|
+
puts "'#{role.first}' role has access to:"
|
7
7
|
role.last.each { |k, v| puts "- #{k}: #{v}" }
|
8
8
|
end
|
9
9
|
end
|
data/lib/typus.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
require "support/active_record"
|
4
4
|
require "support/hash"
|
@@ -8,7 +8,7 @@ require "support/string"
|
|
8
8
|
require "typus/engine"
|
9
9
|
require "typus/i18n"
|
10
10
|
require "typus/orm/active_record"
|
11
|
-
require "typus/
|
11
|
+
require "typus/regex"
|
12
12
|
require "typus/version"
|
13
13
|
|
14
14
|
require "render_inheritable"
|
@@ -21,9 +21,15 @@ module Typus
|
|
21
21
|
autoload :Configuration, "typus/configuration"
|
22
22
|
autoload :Resources, "typus/resources"
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
module Controller
|
25
|
+
|
26
|
+
autoload :Actions, "typus/controller/actions"
|
27
|
+
autoload :Associations, "typus/controller/associations"
|
28
|
+
autoload :Autocomplete, "typus/controller/autocomplete"
|
29
|
+
autoload :Filters, "typus/controller/filters"
|
30
|
+
autoload :Format, "typus/controller/format"
|
31
|
+
|
32
|
+
end
|
27
33
|
|
28
34
|
module Authentication
|
29
35
|
autoload :Base, "typus/authentication/base"
|
@@ -32,6 +38,9 @@ module Typus
|
|
32
38
|
autoload :Session, "typus/authentication/session"
|
33
39
|
end
|
34
40
|
|
41
|
+
mattr_accessor :autocomplete
|
42
|
+
@@autocomplete = 100
|
43
|
+
|
35
44
|
mattr_accessor :admin_title
|
36
45
|
@@admin_title = "Typus"
|
37
46
|
|
@@ -96,7 +105,7 @@ module Typus
|
|
96
105
|
@@image_preview_size = 'x450'
|
97
106
|
|
98
107
|
mattr_accessor :image_thumb_size
|
99
|
-
@@image_thumb_size = '
|
108
|
+
@@image_thumb_size = '150x150#'
|
100
109
|
|
101
110
|
##
|
102
111
|
# Defines the default relationship table.
|
@@ -0,0 +1,69 @@
|
|
1
|
+
##
|
2
|
+
# FIXME: Somehow I want to cleanup this module, for the moment has tests and
|
3
|
+
# works as expected, but there's a lot of duplication here.
|
4
|
+
#
|
5
|
+
|
6
|
+
module Typus
|
7
|
+
module Controller
|
8
|
+
module Actions
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
##
|
13
|
+
# @resource_actions is used to customize the actions which appear under
|
14
|
+
# each item on the tables. This is really a nice feature because allows
|
15
|
+
# us to enable actions for items without much effort. For example adding
|
16
|
+
# a "Recover from Trash" action:
|
17
|
+
#
|
18
|
+
# def index
|
19
|
+
# add_resource_action('Recover', {:action => 'untrash'}, {:confirm => Typus::I18n.t("Recover %{resource}?", :resource => @resource.model_name.human)})
|
20
|
+
# super
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
|
24
|
+
def add_resource_action(*args)
|
25
|
+
@resource_actions ||= []
|
26
|
+
@resource_actions << args unless args.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
def prepend_resource_action(*args)
|
30
|
+
@resource_actions ||= []
|
31
|
+
@resource_actions = @resource_actions.unshift(args) unless args.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def append_resource_action(*args)
|
35
|
+
@resource_actions ||= []
|
36
|
+
@resource_actions = @resource_actions.concat([args]) unless args.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# @resources_actions is used to build a list of custom actions which will
|
41
|
+
# be appended beside "<h2></h2>" all the actions.
|
42
|
+
#
|
43
|
+
# Let's say for example that I want to be able to run the application
|
44
|
+
# without sidebars and headers (headless mode). In this case I need to
|
45
|
+
# somehow add custom actions to the page so I can navigate.
|
46
|
+
#
|
47
|
+
# Instead of having this code here, maybe it's better to duplicate the
|
48
|
+
# actions on the pages. So for example: Admin::PostsController#index will
|
49
|
+
# show a link to add new in the sidebar and beside the "<h2>" header.
|
50
|
+
#
|
51
|
+
|
52
|
+
def add_resources_action(*args)
|
53
|
+
@resources_actions ||= []
|
54
|
+
@resources_actions << args unless args.empty?
|
55
|
+
end
|
56
|
+
|
57
|
+
def prepend_resources_action(*args)
|
58
|
+
@resources_actions ||= []
|
59
|
+
@resources_actions = @resources_actions.unshift(args) unless args.empty?
|
60
|
+
end
|
61
|
+
|
62
|
+
def append_resources_action(*args)
|
63
|
+
@resources_actions ||= []
|
64
|
+
@resources_actions = @resources_actions.concat([args]) unless args.empty?
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Typus
|
2
|
+
module Controller
|
3
|
+
module Associations
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
##
|
8
|
+
# >> Order.relationship_with(Invoice)
|
9
|
+
# => :has_one
|
10
|
+
#
|
11
|
+
def set_has_one_association(item_class, options)
|
12
|
+
association_name = item_class.model_name.underscore.to_sym
|
13
|
+
options.merge!(:action => 'edit', :id => @item.send(association_name).id)
|
14
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
|
15
|
+
|
16
|
+
redirect_to options, :notice => notice
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# >> Entry.relationship_with(Comment)
|
21
|
+
# => :has_many
|
22
|
+
#
|
23
|
+
def set_has_many_association(item_class, options)
|
24
|
+
item = item_class.find(params[:resource_id])
|
25
|
+
association_name = @resource.model_name.tableize.to_sym
|
26
|
+
|
27
|
+
if item.send(association_name).push(@item)
|
28
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
|
29
|
+
else
|
30
|
+
alert = @item.errors.full_messages
|
31
|
+
end
|
32
|
+
|
33
|
+
options.merge!(:action => 'edit', :id => item.id)
|
34
|
+
|
35
|
+
redirect_to options, :notice => notice, :alert => alert
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# >> Entry.relationship_with(Category)
|
40
|
+
# => :has_and_belongs_to_many
|
41
|
+
#
|
42
|
+
def set_has_and_belongs_to_many_association(item_class, options)
|
43
|
+
# In this case we DO need to get the remote item to make to association.
|
44
|
+
item = item_class.find(params[:resource_id])
|
45
|
+
association_name = @resource.model_name.tableize.to_sym
|
46
|
+
options.merge!(:action => 'edit', :id => item.id)
|
47
|
+
|
48
|
+
if item.send(association_name).push(@item)
|
49
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
|
50
|
+
else
|
51
|
+
alert = @item.errors.full_messages
|
52
|
+
end
|
53
|
+
|
54
|
+
redirect_to options, :notice => notice, :alert => alert
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# >> Invoice.relationship_with(Order)
|
59
|
+
# => :belongs_to
|
60
|
+
#
|
61
|
+
def set_belongs_to_association(item_class, options)
|
62
|
+
association_name = item_class.model_name.tableize.to_sym
|
63
|
+
foreign_key = @resource.reflect_on_association(association_name).primary_key_name
|
64
|
+
|
65
|
+
if params[:resource_id]
|
66
|
+
item = item_class.find(params[:resource_id])
|
67
|
+
options.merge!(:action => 'edit', :id => item.id)
|
68
|
+
if @item.send(association_name).push(item)
|
69
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
|
70
|
+
else
|
71
|
+
alert = @item.errors.full_messages
|
72
|
+
end
|
73
|
+
else
|
74
|
+
options.merge!(:action => 'new', foreign_key => @item.id)
|
75
|
+
end
|
76
|
+
|
77
|
+
redirect_to options, :notice => notice, :alert => alert
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|