brainsome_typus 4.0.0.beta1
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 +60 -0
- data/Gemfile.lock +205 -0
- data/MIT-LICENSE +20 -0
- data/README.md +94 -0
- data/Rakefile +33 -0
- data/TODO.md +32 -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-1.8.3-min.js +2 -0
- data/app/assets/javascripts/typus/jquery.application.js +33 -0
- data/app/assets/stylesheets/typus/application.css +5 -0
- data/app/assets/stylesheets/typus/custom.css +4 -0
- data/app/assets/stylesheets/typus/overrides.css.scss +46 -0
- data/app/controllers/admin/account_controller.rb +47 -0
- data/app/controllers/admin/base_controller.rb +44 -0
- data/app/controllers/admin/dashboard_controller.rb +5 -0
- data/app/controllers/admin/resource_controller.rb +7 -0
- data/app/controllers/admin/resources_controller.rb +256 -0
- data/app/controllers/admin/session_controller.rb +42 -0
- data/app/controllers/concerns/admin/actions.rb +88 -0
- data/app/controllers/concerns/admin/acts_as_list.rb +26 -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 +48 -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 +26 -0
- data/app/controllers/concerns/admin/trash.rb +65 -0
- data/app/helpers/admin/base_helper.rb +59 -0
- data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +91 -0
- data/app/helpers/admin/resources/data_types/boolean_helper.rb +28 -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 +56 -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 +53 -0
- data/app/helpers/admin/resources/data_types/has_many_helper.rb +66 -0
- data/app/helpers/admin/resources/data_types/has_one_helper.rb +36 -0
- data/app/helpers/admin/resources/data_types/integer_helper.rb +10 -0
- data/app/helpers/admin/resources/data_types/paperclip_helper.rb +36 -0
- data/app/helpers/admin/resources/data_types/position_helper.rb +20 -0
- data/app/helpers/admin/resources/data_types/selector_helper.rb +11 -0
- data/app/helpers/admin/resources/data_types/string_helper.rb +32 -0
- data/app/helpers/admin/resources/data_types/text_helper.rb +7 -0
- data/app/helpers/admin/resources/data_types/transversal_helper.rb +8 -0
- data/app/helpers/admin/resources/data_types/tree_helper.rb +26 -0
- data/app/helpers/admin/resources/display_helper.rb +27 -0
- data/app/helpers/admin/resources/filters_helper.rb +28 -0
- data/app/helpers/admin/resources/form_helper.rb +84 -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 +34 -0
- data/app/helpers/admin/resources/sidebar_helper.rb +40 -0
- data/app/helpers/admin/resources/table_helper.rb +66 -0
- data/app/helpers/admin/resources_helper.rb +25 -0
- data/app/mailers/admin/mailer.rb +20 -0
- data/app/views/admin/account/_form.html.erb +11 -0
- data/app/views/admin/account/forgot_password.html.erb +19 -0
- data/app/views/admin/account/new.html.erb +13 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +14 -0
- data/app/views/admin/dashboard/index.html.erb +6 -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 +46 -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/resources/_actions.html.erb +23 -0
- data/app/views/admin/resources/_edit.html.erb +0 -0
- data/app/views/admin/resources/_form.html.erb +41 -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/edit/_actions.html.erb +7 -0
- data/app/views/admin/resources/edit/_recently_edited.html.erb +8 -0
- data/app/views/admin/resources/edit.html.erb +22 -0
- data/app/views/admin/resources/index.html.erb +81 -0
- data/app/views/admin/resources/new.html.erb +21 -0
- data/app/views/admin/resources/show.html.erb +27 -0
- data/app/views/admin/session/new.html.erb +21 -0
- data/app/views/admin/shared/_head.html.erb +15 -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 +13 -0
- data/app/views/admin/templates/_boolean.html.erb +6 -0
- data/app/views/admin/templates/_date.html.erb +6 -0
- data/app/views/admin/templates/_datetime.html.erb +7 -0
- data/app/views/admin/templates/_dragonfly.html.erb +8 -0
- data/app/views/admin/templates/_dragonfly_form_preview.html.erb +23 -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 +20 -0
- data/app/views/admin/templates/_has_one.html.erb +14 -0
- data/app/views/admin/templates/_paperclip.html.erb +7 -0
- data/app/views/admin/templates/_paperclip_preview.html.erb +3 -0
- data/app/views/admin/templates/_password.html.erb +6 -0
- data/app/views/admin/templates/_position.html.erb +6 -0
- data/app/views/admin/templates/_profile_sidebar.html.erb +4 -0
- data/app/views/admin/templates/_selector.html.erb +6 -0
- data/app/views/admin/templates/_string.html.erb +6 -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 +56 -0
- data/app/views/admin/templates/modals/_dragonfly.html.erb +9 -0
- data/app/views/admin/templates/modals/_has_and_belongs_to_many.html.erb +19 -0
- data/app/views/admin/templates/modals/_has_many.html.erb +53 -0
- data/app/views/helpers/admin/base/_apps.html.erb +38 -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 +37 -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 +14 -0
- data/app/views/helpers/admin/resources/_search.html.erb +14 -0
- data/app/views/helpers/admin/resources/_sidebar.html.erb +17 -0
- data/app/views/helpers/admin/resources/_table.html.erb +47 -0
- data/app/views/layouts/admin/base.html.erb +40 -0
- data/app/views/layouts/admin/headless.html.erb +1 -0
- data/app/views/layouts/admin/session.html.erb +44 -0
- data/config/locales/typus.ca.models.yml +17 -0
- data/config/locales/typus.ca.yml +78 -0
- data/config/locales/typus.de.models.yml +17 -0
- data/config/locales/typus.de.yml +98 -0
- data/config/locales/typus.el.models.yml +17 -0
- data/config/locales/typus.el.yml +79 -0
- data/config/locales/typus.es.models.yml +18 -0
- data/config/locales/typus.es.yml +91 -0
- data/config/locales/typus.fr.models.yml +18 -0
- data/config/locales/typus.fr.yml +83 -0
- data/config/locales/typus.hu.models.yml +17 -0
- data/config/locales/typus.hu.yml +77 -0
- data/config/locales/typus.it.models.yml +18 -0
- data/config/locales/typus.it.yml +86 -0
- data/config/locales/typus.locale.models.yml.template +17 -0
- data/config/locales/typus.locale.yml.template +78 -0
- data/config/locales/typus.pt-BR.models.yml +17 -0
- data/config/locales/typus.pt-BR.yml +77 -0
- data/config/locales/typus.pt-PT.models.yml +17 -0
- data/config/locales/typus.pt-PT.yml +85 -0
- data/config/locales/typus.ru.models.yml +17 -0
- data/config/locales/typus.ru.yml +77 -0
- data/config/locales/typus.zh-CN.models.yml +17 -0
- data/config/locales/typus.zh-CN.yml +76 -0
- data/config/routes.rb +46 -0
- data/lib/generators/templates/config/initializers/typus.rb +35 -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 +25 -0
- data/lib/generators/typus/initializers_generator.rb +20 -0
- data/lib/generators/typus/migration_generator.rb +94 -0
- data/lib/generators/typus/typus_generator.rb +52 -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 +12 -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/authentication/base.rb +24 -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 +41 -0
- data/lib/typus/engine.rb +17 -0
- data/lib/typus/i18n.rb +48 -0
- data/lib/typus/orm/active_record/admin_user.rb +84 -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 +44 -0
- data/lib/typus/orm/active_record.rb +10 -0
- data/lib/typus/orm/base/class_methods.rb +184 -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/lib/typus.rb +212 -0
- data/typus.gemspec +32 -0
- data/vendor/assets/adapt/css/1200.css +357 -0
- data/vendor/assets/adapt/css/1200.min.css +1 -0
- data/vendor/assets/adapt/css/1560.css +357 -0
- data/vendor/assets/adapt/css/1560.min.css +1 -0
- data/vendor/assets/adapt/css/720.css +357 -0
- data/vendor/assets/adapt/css/720.min.css +1 -0
- data/vendor/assets/adapt/css/960.css +357 -0
- data/vendor/assets/adapt/css/960.min.css +1 -0
- data/vendor/assets/adapt/css/fluid.css +345 -0
- data/vendor/assets/adapt/css/fluid.min.css +1 -0
- data/vendor/assets/adapt/css/master.css +120 -0
- data/vendor/assets/adapt/css/mobile.css +20 -0
- data/vendor/assets/adapt/css/mobile.min.css +1 -0
- data/vendor/assets/adapt/css/reset.css +202 -0
- data/vendor/assets/adapt/css/text.css +81 -0
- data/vendor/assets/adapt/images/h1.png +0 -0
- data/vendor/assets/adapt/js/adapt.js +135 -0
- data/vendor/assets/adapt/js/adapt.min.js +1 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap-responsive.css +1109 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap-responsive.min.css +9 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap.css +6167 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap.min.css +9 -0
- data/vendor/assets/bootstrap-2.3.2/img/glyphicons-halflings-white.png +0 -0
- data/vendor/assets/bootstrap-2.3.2/img/glyphicons-halflings.png +0 -0
- data/vendor/assets/bootstrap-2.3.2/js/bootstrap.js +2280 -0
- data/vendor/assets/bootstrap-2.3.2/js/bootstrap.min.js +6 -0
- data/vendor/assets/chosen/LICENSE.md +24 -0
- data/vendor/assets/chosen/chosen-sprite.png +0 -0
- data/vendor/assets/chosen/chosen.css +390 -0
- data/vendor/assets/chosen/chosen.jquery.js +902 -0
- data/vendor/assets/formalize/css/formalize.css +395 -0
- data/vendor/assets/formalize/images/button.png +0 -0
- data/vendor/assets/formalize/images/select_arrow.gif +0 -0
- data/vendor/assets/formalize/js/jquery.formalize.min.js +1 -0
- metadata +329 -0
@@ -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,25 @@
|
|
1
|
+
module Typus
|
2
|
+
module Generators
|
3
|
+
class ControllerGenerator < Rails::Generators::NamedBase
|
4
|
+
|
5
|
+
source_root File.expand_path("../../templates", __FILE__)
|
6
|
+
|
7
|
+
alias_method :resource, :name
|
8
|
+
|
9
|
+
desc <<-MSG
|
10
|
+
Description:
|
11
|
+
Generates admin controllers for the given resource.
|
12
|
+
|
13
|
+
MSG
|
14
|
+
|
15
|
+
def generate_controller
|
16
|
+
template "controller.erb", "app/controllers/admin/#{file_name}_controller.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
hook_for :test_framework do |instance, generator|
|
20
|
+
instance.invoke generator, ["admin/#{instance.name}"]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
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}"
|
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
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "rails/generators/migration"
|
2
|
+
|
3
|
+
require "generators/typus/config_generator"
|
4
|
+
require "generators/typus/controller_generator"
|
5
|
+
require "generators/typus/initializers_generator"
|
6
|
+
|
7
|
+
module Typus
|
8
|
+
module Generators
|
9
|
+
class TypusGenerator < Rails::Generators::Base
|
10
|
+
|
11
|
+
include Rails::Generators::Migration
|
12
|
+
|
13
|
+
source_root File.expand_path("../../templates", __FILE__)
|
14
|
+
|
15
|
+
namespace "typus"
|
16
|
+
|
17
|
+
desc <<-DESC
|
18
|
+
Description:
|
19
|
+
This generator creates required files to enable an admin panel which allows
|
20
|
+
trusted users to edit structured content.
|
21
|
+
|
22
|
+
To enable session authentication run `rails generate typus:migration`.
|
23
|
+
|
24
|
+
DESC
|
25
|
+
|
26
|
+
def generate_initializers
|
27
|
+
Typus::Generators::InitializersGenerator.new.invoke_all
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_controllers
|
31
|
+
Typus.application_models.each do |model|
|
32
|
+
Typus::Generators::ControllerGenerator.new([model.pluralize]).invoke_all
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_config
|
37
|
+
Typus::Generators::ConfigGenerator.new.invoke_all
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def resource
|
43
|
+
@resource
|
44
|
+
end
|
45
|
+
|
46
|
+
def sidebar
|
47
|
+
@sidebar
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Typus
|
2
|
+
module Generators
|
3
|
+
class ViewsGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path("../../../../app", __FILE__)
|
6
|
+
|
7
|
+
desc <<-MSG
|
8
|
+
Description:
|
9
|
+
Copies Typus views into your application.
|
10
|
+
|
11
|
+
MSG
|
12
|
+
|
13
|
+
def copy_views
|
14
|
+
directory "views", "app/views"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
|
3
|
+
#--
|
4
|
+
# On a model:
|
5
|
+
#
|
6
|
+
# class Post < ActiveRecord::Base
|
7
|
+
# def self.statuses
|
8
|
+
# { t("Published") => "published",
|
9
|
+
# t("Pending") => "pending",
|
10
|
+
# t("Draft") => "draft" }
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# >> Post.first.status
|
15
|
+
# => "published"
|
16
|
+
# >> Post.first.mapping(:status)
|
17
|
+
# => "Published"
|
18
|
+
# >> I18n.locale = :es
|
19
|
+
# => :es
|
20
|
+
# >> Post.first.mapping(:status)
|
21
|
+
# => "Publicado"
|
22
|
+
#++
|
23
|
+
def mapping(attribute)
|
24
|
+
values = self.class.send(attribute.to_s.pluralize)
|
25
|
+
array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
|
26
|
+
value = array.to_a.rassoc(send(attribute))
|
27
|
+
value ? value.first : send(attribute)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_label
|
31
|
+
if respond_to?(:name) && name.present?
|
32
|
+
name
|
33
|
+
else
|
34
|
+
[self.class, id].join("#")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def identifier
|
39
|
+
"##{id}"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class FakeUser
|
2
|
+
|
3
|
+
def id
|
4
|
+
0
|
5
|
+
end
|
6
|
+
|
7
|
+
def can?(*args)
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def cannot?(*args)
|
12
|
+
!can?(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def is_root?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_not_root?
|
20
|
+
!is_root?
|
21
|
+
end
|
22
|
+
|
23
|
+
def applications
|
24
|
+
Typus.applications
|
25
|
+
end
|
26
|
+
|
27
|
+
def application(name)
|
28
|
+
Typus.application(name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def status
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def owns?(resource)
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def locale
|
40
|
+
::I18n.locale
|
41
|
+
end
|
42
|
+
|
43
|
+
def role
|
44
|
+
Typus.master_role
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/lib/support/hash.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def extract_settings
|
4
|
+
split(",").map(&:strip)
|
5
|
+
end
|
6
|
+
|
7
|
+
def remove_prefix
|
8
|
+
split("/")[1..-1].join("/")
|
9
|
+
end
|
10
|
+
|
11
|
+
def extract_class
|
12
|
+
remove_prefix.classify.constantize
|
13
|
+
end
|
14
|
+
|
15
|
+
def extract_singular_class
|
16
|
+
remove_prefix.camelize.constantize
|
17
|
+
end
|
18
|
+
|
19
|
+
# CRUD: create, read, update, delete
|
20
|
+
# Read more at http://en.wikipedia.org/wiki/Create,_read,_update_and_delete
|
21
|
+
def acl_action_mapper
|
22
|
+
case self
|
23
|
+
when "new", "create"
|
24
|
+
"create"
|
25
|
+
when "index", "show"
|
26
|
+
"read"
|
27
|
+
when "edit", "update", "position", "toggle", "relate", "unrelate"
|
28
|
+
"update"
|
29
|
+
when "destroy", "trash"
|
30
|
+
"delete"
|
31
|
+
else
|
32
|
+
self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_resource
|
37
|
+
self.underscore.pluralize
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Typus
|
2
|
+
module Authentication
|
3
|
+
module Base
|
4
|
+
|
5
|
+
def admin_user
|
6
|
+
@admin_user
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_role
|
10
|
+
admin_user.role.to_sym
|
11
|
+
end
|
12
|
+
|
13
|
+
def authenticate; end
|
14
|
+
def check_if_user_can_perform_action_on_user; end
|
15
|
+
def check_if_user_can_perform_action_on_resources; end
|
16
|
+
def check_if_user_can_perform_action_on_resource; end
|
17
|
+
def check_resource_ownership; end
|
18
|
+
def check_resources_ownership; end
|
19
|
+
def set_attributes_on_create; end
|
20
|
+
def set_attributes_on_update; end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Typus
|
2
|
+
module Authentication
|
3
|
+
module Devise
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
include Base
|
8
|
+
|
9
|
+
def admin_user
|
10
|
+
send("current_#{Typus.user_class_name.underscore}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def authenticate
|
14
|
+
send("authenticate_#{Typus.user_class_name.underscore}!")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Typus
|
2
|
+
module Authentication
|
3
|
+
module HttpBasic
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
include Base
|
8
|
+
|
9
|
+
def authenticate
|
10
|
+
@admin_user = FakeUser.new
|
11
|
+
authenticate_or_request_with_http_basic(Typus.admin_title) do |username, password|
|
12
|
+
username == Typus.username && password == Typus.password
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|