typus-rails4 4.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +488 -0
- data/Gemfile +57 -0
- data/Gemfile.lock +253 -0
- data/MIT-LICENSE +20 -0
- data/README.md +101 -0
- data/Rakefile +51 -0
- data/app/assets/javascripts/typus/application.js +11 -0
- data/app/assets/javascripts/typus/custom.js +2 -0
- data/app/assets/javascripts/typus/jquery-2.1.1.min.js +4 -0
- data/app/assets/javascripts/typus/jquery.application.js +30 -0
- data/app/assets/stylesheets/typus/application.css +6 -0
- data/app/assets/stylesheets/typus/custom.scss +4 -0
- data/app/assets/stylesheets/typus/overrides.scss +10 -0
- data/app/assets/stylesheets/typus/signin.scss +45 -0
- data/app/controllers/admin/account_controller.rb +47 -0
- data/app/controllers/admin/base_controller.rb +40 -0
- data/app/controllers/admin/dashboard_controller.rb +6 -0
- data/app/controllers/admin/resource_controller.rb +8 -0
- data/app/controllers/admin/resources_controller.rb +268 -0
- data/app/controllers/admin/session_controller.rb +43 -0
- data/app/controllers/concerns/admin/actions.rb +88 -0
- data/app/controllers/concerns/admin/acts_as_list.rb +35 -0
- data/app/controllers/concerns/admin/ancestry.rb +26 -0
- data/app/controllers/concerns/admin/autocomplete.rb +11 -0
- data/app/controllers/concerns/admin/bulk.rb +76 -0
- data/app/controllers/concerns/admin/featured_image.rb +22 -0
- data/app/controllers/concerns/admin/filters.rb +57 -0
- data/app/controllers/concerns/admin/format.rb +49 -0
- data/app/controllers/concerns/admin/headless.rb +23 -0
- data/app/controllers/concerns/admin/hooks.rb +4 -0
- data/app/controllers/concerns/admin/multisite.rb +10 -0
- data/app/controllers/concerns/admin/navigation.rb +27 -0
- data/app/controllers/concerns/admin/trash.rb +65 -0
- data/app/helpers/admin/base_helper.rb +78 -0
- data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +88 -0
- data/app/helpers/admin/resources/data_types/boolean_helper.rb +33 -0
- data/app/helpers/admin/resources/data_types/date_helper.rb +16 -0
- data/app/helpers/admin/resources/data_types/datetime_helper.rb +19 -0
- data/app/helpers/admin/resources/data_types/dragonfly_helper.rb +49 -0
- data/app/helpers/admin/resources/data_types/float_helper.rb +2 -0
- data/app/helpers/admin/resources/data_types/has_and_belongs_to_many_helper.rb +59 -0
- data/app/helpers/admin/resources/data_types/has_many_helper.rb +76 -0
- data/app/helpers/admin/resources/data_types/has_one_helper.rb +44 -0
- data/app/helpers/admin/resources/data_types/integer_helper.rb +13 -0
- data/app/helpers/admin/resources/data_types/paperclip_helper.rb +49 -0
- data/app/helpers/admin/resources/data_types/selector_helper.rb +11 -0
- data/app/helpers/admin/resources/data_types/string_helper.rb +38 -0
- data/app/helpers/admin/resources/data_types/text_helper.rb +6 -0
- data/app/helpers/admin/resources/data_types/transversal_helper.rb +8 -0
- data/app/helpers/admin/resources/data_types/tree_helper.rb +28 -0
- data/app/helpers/admin/resources/display_helper.rb +27 -0
- data/app/helpers/admin/resources/filters_helper.rb +18 -0
- data/app/helpers/admin/resources/form_helper.rb +85 -0
- data/app/helpers/admin/resources/list_helper.rb +31 -0
- data/app/helpers/admin/resources/pagination_helper.rb +28 -0
- data/app/helpers/admin/resources/relationships_helper.rb +33 -0
- data/app/helpers/admin/resources/sidebar_helper.rb +34 -0
- data/app/helpers/admin/resources/table_helper.rb +69 -0
- data/app/helpers/admin/resources_helper.rb +25 -0
- data/app/mailers/admin/mailer.rb +19 -0
- data/app/views/admin/account/_form.html.erb +17 -0
- data/app/views/admin/account/forgot_password.html.erb +16 -0
- data/app/views/admin/account/new.html.erb +10 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +14 -0
- data/app/views/admin/dashboard/index.html.erb +8 -0
- data/app/views/admin/dashboard/styles.html.erb +153 -0
- data/app/views/admin/dashboard/widgets/_applications.html.erb +44 -0
- data/app/views/admin/dashboard/widgets/_default.html.erb +43 -0
- data/app/views/admin/dashboard/widgets/_models.html.erb +23 -0
- data/app/views/admin/dashboard/widgets/_models_extended.html.erb +25 -0
- data/app/views/admin/dashboard/widgets/_resources.html.erb +23 -0
- data/app/views/admin/dashboard/widgets/_users.html.erb +23 -0
- data/app/views/admin/mailer/reset_password_instructions.html.erb +7 -0
- data/app/views/admin/mailer/reset_password_instructions.text.erb +7 -0
- data/app/views/admin/resource/_sidebar.html.erb +14 -0
- data/app/views/admin/resources/_edit.html.erb +0 -0
- data/app/views/admin/resources/_form.html.erb +28 -0
- data/app/views/admin/resources/_form_javascripts.html.erb +0 -0
- data/app/views/admin/resources/_form_modal.html.erb +13 -0
- data/app/views/admin/resources/_index.html.erb +0 -0
- data/app/views/admin/resources/_new.html.erb +0 -0
- data/app/views/admin/resources/_pagination.html.erb +15 -0
- data/app/views/admin/resources/_show.html.erb +0 -0
- data/app/views/admin/resources/_sidebar.html.erb +1 -0
- data/app/views/admin/resources/destroy.html.erb +16 -0
- data/app/views/admin/resources/edit.html.erb +22 -0
- data/app/views/admin/resources/edit/_actions.html.erb +7 -0
- data/app/views/admin/resources/edit/_recently_edited.html.erb +8 -0
- data/app/views/admin/resources/index.html.erb +29 -0
- data/app/views/admin/resources/new.html.erb +20 -0
- data/app/views/admin/resources/show.html.erb +26 -0
- data/app/views/admin/session/new.html.erb +18 -0
- data/app/views/admin/shared/_head.html.erb +24 -0
- data/app/views/admin/shared/_modals.html.erb +3 -0
- data/app/views/admin/shared/_sidebar_placeholder.html.erb +0 -0
- data/app/views/admin/templates/README.md +5 -0
- data/app/views/admin/templates/_belongs_to.html.erb +8 -0
- data/app/views/admin/templates/_boolean.html.erb +7 -0
- data/app/views/admin/templates/_date.html.erb +6 -0
- data/app/views/admin/templates/_datetime.html.erb +8 -0
- data/app/views/admin/templates/_dragonfly.html.erb +6 -0
- data/app/views/admin/templates/_dragonfly_form_preview.html.erb +21 -0
- data/app/views/admin/templates/_dragonfly_preview.html.erb +12 -0
- data/app/views/admin/templates/_has_and_belongs_to_many.html.erb +21 -0
- data/app/views/admin/templates/_has_many.html.erb +18 -0
- data/app/views/admin/templates/_has_one.html.erb +14 -0
- data/app/views/admin/templates/_json.html.erb +11 -0
- data/app/views/admin/templates/_paperclip.html.erb +5 -0
- data/app/views/admin/templates/_paperclip_form_preview.html.erb +21 -0
- data/app/views/admin/templates/_paperclip_preview.html.erb +12 -0
- data/app/views/admin/templates/_password.html.erb +6 -0
- data/app/views/admin/templates/_position.html.erb +5 -0
- data/app/views/admin/templates/_profile_sidebar.html.erb +4 -0
- data/app/views/admin/templates/_selector.html.erb +4 -0
- data/app/views/admin/templates/_string.html.erb +4 -0
- data/app/views/admin/templates/_string_with_preview.html.erb +11 -0
- data/app/views/admin/templates/_text.html.erb +11 -0
- data/app/views/admin/templates/_text_with_ckeditor.html.erb +24 -0
- data/app/views/admin/templates/_text_with_ckeditor_and_assets.html.erb +38 -0
- data/app/views/admin/templates/_time.html.erb +9 -0
- data/app/views/admin/templates/_tree.html.erb +6 -0
- data/app/views/admin/templates/modals/_belongs_to.html.erb +60 -0
- data/app/views/admin/templates/modals/_dragonfly.html.erb +13 -0
- data/app/views/admin/templates/modals/_has_and_belongs_to_many.html.erb +25 -0
- data/app/views/admin/templates/modals/_has_many.html.erb +59 -0
- data/app/views/admin/templates/modals/_paperclip.html.erb +13 -0
- data/app/views/helpers/admin/base/_apps.html.erb +86 -0
- data/app/views/helpers/admin/base/_breadcrumbs.html.erb +6 -0
- data/app/views/helpers/admin/base/_flash_message.html.erb +3 -0
- data/app/views/helpers/admin/base/_login_info.html.erb +0 -0
- data/app/views/helpers/admin/dashboard/_resources.html.erb +19 -0
- data/app/views/helpers/admin/resources/_actions.html.erb +18 -0
- data/app/views/helpers/admin/resources/_errors.html.erb +12 -0
- data/app/views/helpers/admin/resources/_filters.html.erb +16 -0
- data/app/views/helpers/admin/resources/_search.html.erb +17 -0
- data/app/views/helpers/admin/resources/_sidebar.html.erb +4 -0
- data/app/views/helpers/admin/resources/_table.html.erb +45 -0
- data/app/views/helpers/admin/resources/sidebar/_item.html.erb +26 -0
- data/app/views/helpers/admin/resources/sidebar/_items.html.erb +14 -0
- data/app/views/helpers/admin/resources/sidebar/_items_index.html.erb +57 -0
- data/app/views/layouts/admin/base.html.erb +30 -0
- data/app/views/layouts/admin/headless.html.erb +1 -0
- data/app/views/layouts/admin/session.html.erb +26 -0
- data/bin/run-tests +7 -0
- data/bin/setup +9 -0
- data/config/locales/typus.en.yml +125 -0
- data/config/routes.rb +46 -0
- data/lib/generators/templates/config/initializers/typus.rb +34 -0
- data/lib/generators/templates/config/initializers/typus_authentication.rb +18 -0
- data/lib/generators/templates/config/initializers/typus_resources.rb +24 -0
- data/lib/generators/templates/config/typus/README +58 -0
- data/lib/generators/templates/config/typus/application.yml +3 -0
- data/lib/generators/templates/config/typus/application_roles.yml +4 -0
- data/lib/generators/templates/config/typus/typus.yml +15 -0
- data/lib/generators/templates/config/typus/typus_roles.yml +4 -0
- data/lib/generators/templates/controller.erb +2 -0
- data/lib/generators/templates/migration.erb +22 -0
- data/lib/generators/templates/view.html.erb +13 -0
- data/lib/generators/typus/config_generator.rb +67 -0
- data/lib/generators/typus/controller_generator.rb +26 -0
- data/lib/generators/typus/initializers_generator.rb +20 -0
- data/lib/generators/typus/migration_generator.rb +94 -0
- data/lib/generators/typus/model_generator.rb +93 -0
- data/lib/generators/typus/typus_generator.rb +54 -0
- data/lib/generators/typus/views_generator.rb +19 -0
- data/lib/support/active_record.rb +42 -0
- data/lib/support/fake_user.rb +47 -0
- data/lib/support/hash.rb +8 -0
- data/lib/support/object.rb +9 -0
- data/lib/support/string.rb +40 -0
- data/lib/tasks/typus.rake +11 -0
- data/lib/typus.rb +215 -0
- data/lib/typus/authentication/base.rb +39 -0
- data/lib/typus/authentication/devise.rb +19 -0
- data/lib/typus/authentication/http_basic.rb +18 -0
- data/lib/typus/authentication/none.rb +15 -0
- data/lib/typus/authentication/none_with_role.rb +15 -0
- data/lib/typus/authentication/session.rb +123 -0
- data/lib/typus/configuration.rb +43 -0
- data/lib/typus/engine.rb +4 -0
- data/lib/typus/orm/active_record.rb +10 -0
- data/lib/typus/orm/active_record/admin_user.rb +65 -0
- data/lib/typus/orm/active_record/class_methods.rb +104 -0
- data/lib/typus/orm/active_record/instance_methods.rb +76 -0
- data/lib/typus/orm/active_record/search.rb +43 -0
- data/lib/typus/orm/base/class_methods.rb +188 -0
- data/lib/typus/orm/base/search.rb +70 -0
- data/lib/typus/regex.rb +11 -0
- data/lib/typus/resources.rb +55 -0
- data/lib/typus/version.rb +10 -0
- data/typus.gemspec +27 -0
- data/vendor/assets/chosen/LICENSE.md +24 -0
- data/vendor/assets/chosen/chosen-sprite.png +0 -0
- data/vendor/assets/chosen/chosen-sprite@2x.png +0 -0
- data/vendor/assets/chosen/chosen.jquery.js +1239 -0
- data/vendor/assets/chosen/chosen.scss +437 -0
- metadata +271 -0
data/config/routes.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
routes_block = lambda do
|
4
|
+
|
5
|
+
dashboard = Typus.subdomain ? '/dashboard' : '/admin/dashboard'
|
6
|
+
|
7
|
+
get '/' => redirect(dashboard)
|
8
|
+
get 'dashboard' => 'dashboard#index', as: 'dashboard_index'
|
9
|
+
get 'dashboard/:application' => 'dashboard#show', as: 'dashboard'
|
10
|
+
|
11
|
+
if Typus.authentication == :session
|
12
|
+
resource :session, only: [:new, :create], controller: :session do
|
13
|
+
delete :destroy, as: 'destroy'
|
14
|
+
end
|
15
|
+
|
16
|
+
resources :account, only: [:new, :create, :show] do
|
17
|
+
collection do
|
18
|
+
get :forgot_password
|
19
|
+
post :send_password
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Typus.models.map(&:to_resource).each do |_resource|
|
25
|
+
get "#{_resource}(/:action(/:id))(.:format)", controller: _resource
|
26
|
+
post "#{_resource}(/:action(/:id))(.:format)", controller: _resource
|
27
|
+
patch "#{_resource}(/:action(/:id))(.:format)", controller: _resource
|
28
|
+
delete "#{_resource}(/:action(/:id))(.:format)", controller: _resource
|
29
|
+
end
|
30
|
+
|
31
|
+
Typus.resources.map(&:underscore).each do |_resource|
|
32
|
+
get "#{_resource}(/:action(/:id))(.:format)", controller: _resource
|
33
|
+
post "#{_resource}(/:action(/:id))(.:format)", controller: _resource
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
if Typus.subdomain
|
39
|
+
constraints :subdomain => Typus.subdomain do
|
40
|
+
namespace :admin, path: '', &routes_block
|
41
|
+
end
|
42
|
+
else
|
43
|
+
scope 'admin', {module: :admin, as: 'admin'}, &routes_block
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Typus.setup do |config|
|
2
|
+
|
3
|
+
# Application name.
|
4
|
+
# config.admin_title = "Typus"
|
5
|
+
|
6
|
+
# When mailer_sender is set, password recover is enabled. This email
|
7
|
+
# address will be used in Admin::Mailer.
|
8
|
+
#
|
9
|
+
# Remember to setup the default url options for your specific environment
|
10
|
+
# Here is an example of development environment:
|
11
|
+
#
|
12
|
+
# config.action_mailer.default_url_options = { host: 'localhost:3000' }
|
13
|
+
#
|
14
|
+
# This is a required Rails configuration. In production it must be the actual
|
15
|
+
# actual host of your application.
|
16
|
+
#
|
17
|
+
# config.mailer_sender = "admin@example.com"
|
18
|
+
|
19
|
+
# Define paperclip attachment styles.
|
20
|
+
# config.file_preview = :medium
|
21
|
+
# config.file_thumbnail = :thumb
|
22
|
+
|
23
|
+
# Define authentication: +:none+, +:http_basic+, +:session+
|
24
|
+
# Run `rails g typus:migration` if want +:session+
|
25
|
+
# config.authentication = :none
|
26
|
+
|
27
|
+
# Define username and password for +:http_basic+ authentication.
|
28
|
+
# config.username = "admin"
|
29
|
+
# config.password = "columbia"
|
30
|
+
|
31
|
+
# Define subdomain to use instead of additional path.
|
32
|
+
# config.subdomain = "admin"
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Typus.setup do |config|
|
2
|
+
|
3
|
+
# Define authentication: +:none+, +:http_basic+, +:session+
|
4
|
+
config.authentication = :session
|
5
|
+
|
6
|
+
# Define master_role.
|
7
|
+
# config.master_role = "admin"
|
8
|
+
|
9
|
+
# Define relationship.
|
10
|
+
# config.relationship = "typus_users"
|
11
|
+
|
12
|
+
# Define user_class_name.
|
13
|
+
config.user_class_name = "<%= options[:user_class_name] %>"
|
14
|
+
|
15
|
+
# Define user_foreign_key.
|
16
|
+
config.user_foreign_key = "<%= options[:user_foreign_key] %>"
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Typus::Resources.setup do |config|
|
2
|
+
|
3
|
+
# Defines default_action_on_item.
|
4
|
+
# config.default_action_on_item = "edit"
|
5
|
+
|
6
|
+
# Defines end_year.
|
7
|
+
# config.end_year = nil
|
8
|
+
|
9
|
+
# Defines form_rows.
|
10
|
+
# config.form_rows = 15
|
11
|
+
|
12
|
+
# Defines minute_step.
|
13
|
+
# config.minute_step = 5
|
14
|
+
|
15
|
+
# Defines only_user_items.
|
16
|
+
# config.only_user_items = false
|
17
|
+
|
18
|
+
# Defines per_page.
|
19
|
+
# config.per_page = 25
|
20
|
+
|
21
|
+
# Defines start_year.
|
22
|
+
# config.start_year = nil
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Models
|
2
|
+
|
3
|
+
This is an example of a **Typus** enabled model with all available options.
|
4
|
+
Use this example as reference to customize your YAML files.
|
5
|
+
|
6
|
+
Entry:
|
7
|
+
fields:
|
8
|
+
default: id, title, category_id, created_at, is_published?
|
9
|
+
list: id, title, category_id, created_at, is_published?
|
10
|
+
form: title, body, is_published?, created_at
|
11
|
+
show: title, category, is_published?
|
12
|
+
relationship: title, status
|
13
|
+
options:
|
14
|
+
booleans:
|
15
|
+
is_published: ["Yes, it is", "No, it isn't"]
|
16
|
+
date_formats:
|
17
|
+
created_at: post_long
|
18
|
+
selectors:
|
19
|
+
templates:
|
20
|
+
body: rich_text
|
21
|
+
actions:
|
22
|
+
index: cleanup
|
23
|
+
edit: send_as_newsletter
|
24
|
+
show: rebuild
|
25
|
+
order_by: created_at
|
26
|
+
relationships:
|
27
|
+
filters: is_published?, created_at, category_id
|
28
|
+
search: title, body
|
29
|
+
application: Application
|
30
|
+
description: Some text to describe the model
|
31
|
+
options:
|
32
|
+
default_action_on_item: show
|
33
|
+
end_year: 2015
|
34
|
+
form_rows: 25
|
35
|
+
minute_step: 15
|
36
|
+
only_user_items: true
|
37
|
+
per_page: 25
|
38
|
+
start_year: 1990
|
39
|
+
|
40
|
+
# Roles
|
41
|
+
|
42
|
+
This is an example of a roles file. Use this example as reference to customize
|
43
|
+
your YAML files.
|
44
|
+
|
45
|
+
admin:
|
46
|
+
Entry: create, read, update, delete
|
47
|
+
Category: create, read, update, delete
|
48
|
+
AdminUser: all
|
49
|
+
|
50
|
+
editor:
|
51
|
+
Entry: create, read, update
|
52
|
+
Category: read, update
|
53
|
+
|
54
|
+
You can also define `resources` which are not related to a model, for example
|
55
|
+
to control `Redis`.
|
56
|
+
|
57
|
+
admin:
|
58
|
+
Redis: index, flush_all
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Use the README file as a reference to customize settings.
|
2
|
+
|
3
|
+
<%= options[:user_class_name] %>:
|
4
|
+
fields:
|
5
|
+
default: first_name, last_name, role, email, locale
|
6
|
+
list: email, role, status
|
7
|
+
form: first_name, last_name, role, email, password, password_confirmation, locale, status
|
8
|
+
options:
|
9
|
+
selectors: role, locale
|
10
|
+
booleans:
|
11
|
+
status: Active, Inactive
|
12
|
+
filters: status, role
|
13
|
+
search: first_name, last_name, email, role
|
14
|
+
application: Admin
|
15
|
+
description: Users Administration
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :<%= admin_users_table_name %> do |t|
|
5
|
+
t.string :first_name, :default => "", :null => false
|
6
|
+
t.string :last_name, :default => "", :null => false
|
7
|
+
t.string :role, :null => false
|
8
|
+
t.string :email, :null => false
|
9
|
+
t.boolean :status, :default => false
|
10
|
+
t.string :token, :null => false
|
11
|
+
t.string :password_digest, :null => false
|
12
|
+
t.string :preferences
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
add_index :<%= admin_users_table_name %>, :email, :unique => true
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
drop_table :<%= admin_users_table_name %>
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% content_for :main_grid do %>
|
2
|
+
<h2><%= resource.titleize %></h2>
|
3
|
+
|
4
|
+
<p>Find me in app/views/<%= resource.underscore %>/index.html.erb</p>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
<div class="grid_2">
|
8
|
+
<%= sidebar %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div class="grid_8">
|
12
|
+
<%= yield :main_grid %>
|
13
|
+
</div>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Typus
|
2
|
+
module Generators
|
3
|
+
class ConfigGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path("../../templates", __FILE__)
|
6
|
+
|
7
|
+
desc <<-MSG
|
8
|
+
Description:
|
9
|
+
Creates configuration files.
|
10
|
+
|
11
|
+
MSG
|
12
|
+
|
13
|
+
def generate_config
|
14
|
+
copy_file "config/typus/README"
|
15
|
+
generate_yaml.each do |key, value|
|
16
|
+
if (@configuration = value)[:base].present?
|
17
|
+
template "config/typus/application.yml", "config/typus/#{key}.yml"
|
18
|
+
template "config/typus/application_roles.yml", "config/typus/#{key}_roles.yml"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def configuration
|
26
|
+
@configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
def fields_for(model, *defaults)
|
30
|
+
rejections = %w( ^id$ _type$ type created_at created_on updated_at updated_on deleted_at ).join("|")
|
31
|
+
fields = model.table_exists? ? model.columns.map(&:name) : defaults
|
32
|
+
fields.reject { |f| f.match(rejections) }.join(", ")
|
33
|
+
end
|
34
|
+
|
35
|
+
def generate_yaml
|
36
|
+
Typus.reload!
|
37
|
+
|
38
|
+
configuration = {}
|
39
|
+
models = Typus.application_models.reject { |m| Typus.models.include?(m) }.map(&:constantize)
|
40
|
+
|
41
|
+
models.each do |model|
|
42
|
+
key = model.name.underscore
|
43
|
+
|
44
|
+
configuration[key] = {}
|
45
|
+
|
46
|
+
relationships = [ :has_many, :has_one ].map do |relationship|
|
47
|
+
model.reflect_on_all_associations(relationship).map { |i| i.name.to_s }
|
48
|
+
end.flatten.join(", ")
|
49
|
+
|
50
|
+
configuration[key][:base] = <<-RAW
|
51
|
+
#{model}:
|
52
|
+
fields:
|
53
|
+
default: #{fields_for(model, 'to_label')}
|
54
|
+
form: #{fields_for(model)}
|
55
|
+
relationships: #{relationships}
|
56
|
+
application: Application
|
57
|
+
RAW
|
58
|
+
|
59
|
+
configuration[key][:roles] = "#{model}: create, read, update, delete"
|
60
|
+
end
|
61
|
+
|
62
|
+
configuration
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
module Typus
|
3
|
+
module Generators
|
4
|
+
class ControllerGenerator < Rails::Generators::NamedBase
|
5
|
+
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
|
8
|
+
alias_method :resource, :name
|
9
|
+
|
10
|
+
desc <<-MSG
|
11
|
+
Description:
|
12
|
+
Generates admin controllers for the given resource.
|
13
|
+
|
14
|
+
MSG
|
15
|
+
|
16
|
+
def generate_controller
|
17
|
+
template "controller.erb", "app/controllers/admin/#{file_name}_controller.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
hook_for :test_framework do |instance, generator|
|
21
|
+
instance.invoke generator, ["admin/#{instance.name}"]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Typus
|
2
|
+
module Generators
|
3
|
+
class InitializersGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path("../../templates", __FILE__)
|
6
|
+
|
7
|
+
desc <<-MSG
|
8
|
+
Description:
|
9
|
+
Copies Typus initializers into your application.
|
10
|
+
|
11
|
+
MSG
|
12
|
+
|
13
|
+
def generate_initializers
|
14
|
+
template "config/initializers/typus.rb", "config/initializers/typus.rb"
|
15
|
+
template "config/initializers/typus_resources.rb", "config/initializers/typus_resources.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "rails/generators/migration"
|
2
|
+
require "generators/typus/controller_generator"
|
3
|
+
|
4
|
+
module Typus
|
5
|
+
module Generators
|
6
|
+
class MigrationGenerator < Rails::Generators::Base
|
7
|
+
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
|
10
|
+
source_root File.expand_path("../../templates", __FILE__)
|
11
|
+
|
12
|
+
class_option :user_class_name, default: "AdminUser", aliases: "-u"
|
13
|
+
class_option :user_foreign_key, default: "admin_user_id", aliases: "-fk"
|
14
|
+
|
15
|
+
desc <<-DESC
|
16
|
+
Description:
|
17
|
+
This generator creates required configuration files and a migration to
|
18
|
+
enable authentication on the admin panel.
|
19
|
+
|
20
|
+
Examples:
|
21
|
+
|
22
|
+
`rails generate typus:migration`
|
23
|
+
|
24
|
+
creates needed files with `AdminUser` as the Typus user.
|
25
|
+
|
26
|
+
`rails generate typus:migration -u User`
|
27
|
+
|
28
|
+
creates needed files with `User` as the Typus user.
|
29
|
+
|
30
|
+
DESC
|
31
|
+
|
32
|
+
def self.next_migration_number(path)
|
33
|
+
Time.zone.now.to_s(:number)
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_model
|
37
|
+
unless model_exists?
|
38
|
+
invoke "active_record:model", [options[:user_class_name]], migration: false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def inject_mixins_into_model
|
43
|
+
inject_into_class "app/models/#{model_filename}.rb", options[:user_class_name] do
|
44
|
+
<<-MSG
|
45
|
+
include Typus::Orm::ActiveRecord::AdminUser
|
46
|
+
MSG
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def generate_initializer
|
51
|
+
template "config/initializers/typus_authentication.rb", "config/initializers/typus_authentication.rb"
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate_typus_yaml
|
55
|
+
template "config/typus/typus.yml", "config/typus/typus.yml"
|
56
|
+
end
|
57
|
+
|
58
|
+
def generate_typus_roles_yaml
|
59
|
+
template "config/typus/typus_roles.yml", "config/typus/typus_roles.yml"
|
60
|
+
end
|
61
|
+
|
62
|
+
def generate_controller
|
63
|
+
Typus::Generators::ControllerGenerator.new([options[:user_class_name].pluralize]).invoke_all
|
64
|
+
end
|
65
|
+
|
66
|
+
def generate_migration
|
67
|
+
migration_template "migration.erb", "db/migrate/create_#{admin_users_table_name}.rb"
|
68
|
+
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
def admin_users_table_name
|
73
|
+
options[:user_class_name].tableize
|
74
|
+
end
|
75
|
+
|
76
|
+
def migration_name
|
77
|
+
"Create#{options[:user_class_name]}s"
|
78
|
+
end
|
79
|
+
|
80
|
+
def model_exists?
|
81
|
+
File.exists?(File.join(destination_root, model_path))
|
82
|
+
end
|
83
|
+
|
84
|
+
def model_path
|
85
|
+
@model_path ||= File.join("app", "models", "#{model_filename}.rb")
|
86
|
+
end
|
87
|
+
|
88
|
+
def model_filename
|
89
|
+
options[:user_class_name].underscore
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|