express_admin 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +37 -0
- data/Rakefile +32 -0
- data/app/assets/fonts/app_express.eot +0 -0
- data/app/assets/fonts/app_express.svg +21 -0
- data/app/assets/fonts/app_express.ttf +0 -0
- data/app/assets/fonts/app_express.woff +0 -0
- data/app/assets/fonts/ionicons.eot +0 -0
- data/app/assets/fonts/ionicons.svg +1899 -0
- data/app/assets/fonts/ionicons.ttf +0 -0
- data/app/assets/fonts/ionicons.woff +0 -0
- data/app/assets/javascripts/express_admin/admin.js +30 -0
- data/app/assets/javascripts/express_admin/dataTables/dataTables.foundation.js +183 -0
- data/app/assets/javascripts/express_admin/dataTables/jquery.dataTables.js +14382 -0
- data/app/assets/javascripts/express_admin/utility.js +30 -0
- data/app/assets/javascripts/express_admin.js +7 -0
- data/app/assets/stylesheets/dataTables/dataTables.foundation.css.erb +217 -0
- data/app/assets/stylesheets/express_admin/components/_empty_state.sass +10 -0
- data/app/assets/stylesheets/express_admin/components/_megadropdown.sass +71 -0
- data/app/assets/stylesheets/express_admin/express_icons.sass +56 -0
- data/app/assets/stylesheets/express_admin/foundation_and_overrides.scss +1443 -0
- data/app/assets/stylesheets/express_admin/globals/_mixins.sass +9 -0
- data/app/assets/stylesheets/express_admin/globals/_typography.sass +30 -0
- data/app/assets/stylesheets/express_admin/globals/_variables.sass +16 -0
- data/app/assets/stylesheets/express_admin/plugins/_dataTables.sass +118 -0
- data/app/assets/stylesheets/express_admin/plugins/_select2.sass +91 -0
- data/app/assets/stylesheets/express_admin/screen.sass +47 -0
- data/app/assets/stylesheets/express_admin/sections/_devise.sass +42 -0
- data/app/assets/stylesheets/express_admin/sections/_header.sass +98 -0
- data/app/assets/stylesheets/express_admin/sections/_main_content.sass +63 -0
- data/app/assets/stylesheets/express_admin/sections/_sidebar.sass +42 -0
- data/app/assets/stylesheets/express_admin/shared/_alerts.sass +45 -0
- data/app/assets/stylesheets/express_admin/shared/_breadcrumbs.sass +3 -0
- data/app/assets/stylesheets/express_admin/shared/_buttons.sass +33 -0
- data/app/assets/stylesheets/express_admin/shared/_forms.sass +99 -0
- data/app/assets/stylesheets/express_admin/shared/_labels.sass +16 -0
- data/app/assets/stylesheets/express_admin/shared/_loading.sass +2 -0
- data/app/assets/stylesheets/express_admin/shared/_media_object.sass +23 -0
- data/app/assets/stylesheets/express_admin/shared/_messages.sass +12 -0
- data/app/assets/stylesheets/express_admin/shared/_navigation.sass +20 -0
- data/app/assets/stylesheets/express_admin/shared/_progress.sass +3 -0
- data/app/assets/stylesheets/express_admin/shared/_reveal.sass +20 -0
- data/app/assets/stylesheets/express_admin/shared/_tables.sass +75 -0
- data/app/assets/stylesheets/express_admin/shared/_tabs.sass +25 -0
- data/app/assets/stylesheets/express_admin/shared/_widgets.sass +57 -0
- data/app/assets/stylesheets/express_admin.css +9 -0
- data/app/assets/stylesheets/ionicons/ionicons.css.sass +1873 -0
- data/app/components/express_admin/addon_sidebar_component.rb +47 -0
- data/app/components/express_admin/flash_message_component.rb +19 -0
- data/app/components/express_admin/main_region.rb +9 -0
- data/app/components/express_admin/mega_menu_component.rb +68 -0
- data/app/components/express_admin/page_header_component.rb +39 -0
- data/app/components/express_admin/setting_form.rb +45 -0
- data/app/components/express_admin/sidebar_region.rb +11 -0
- data/app/components/express_admin/smart_form.rb +70 -0
- data/app/components/express_admin/smart_table.rb +97 -0
- data/app/components/express_admin/widget_box.rb +22 -0
- data/app/helpers/express_admin/admin_helper.rb +104 -0
- data/app/helpers/express_admin/module_settings_helper.rb +53 -0
- data/app/views/express_admin/dashboard/show.html.et +6 -0
- data/app/views/layouts/express_admin/admin.html.et +31 -0
- data/app/views/layouts/express_admin/external.html.et +15 -0
- data/app/views/shared/express_admin/_messages.html.et +1 -0
- data/app/views/shared/express_admin/_navigation_bar.html.et +20 -0
- data/app/views/shared/express_admin/_navigation_bar_profile.html.et +8 -0
- data/app/views/shared/express_admin/_title.html.et +8 -0
- data/config/initializers/gravatar_image_tag.rb +4 -0
- data/lib/express_admin/engine.rb +52 -0
- data/lib/express_admin/menu.rb +62 -0
- data/lib/express_admin/version.rb +3 -0
- data/lib/express_admin.rb +4 -0
- data/lib/generators/express_admin/install/USAGE +23 -0
- data/lib/generators/express_admin/install/install_generator.rb +97 -0
- data/lib/generators/express_admin/install/templates/assets/javascripts/application.js +1 -0
- data/lib/generators/express_admin/install/templates/assets/stylesheets/application.css +5 -0
- data/lib/generators/express_admin/install/templates/config/menu.yml.erb +3 -0
- data/lib/generators/express_admin/install/templates/controllers/admin_controller.rb.erb +34 -0
- data/lib/generators/express_admin/install/templates/install/USAGE +8 -0
- data/lib/generators/express_admin/install/templates/install/installer.rb.erb +10 -0
- data/lib/generators/express_admin/install/templates/install/installer_test.rb.erb +16 -0
- data/lib/generators/express_admin/install/templates/views/layouts/admin.html.et +1 -0
- data/lib/generators/express_admin/scaffold/scaffold_generator.rb +135 -0
- data/lib/generators/express_admin/scaffold/templates/controller/controller.rb +14 -0
- data/lib/generators/express_admin/scaffold/templates/index.html.et.erb +10 -0
- data/lib/generators/express_admin/scaffold/templates/model/model.rb +4 -0
- data/lib/generators/express_admin/scaffold/templates/show.html.et.erb +10 -0
- data/lib/tasks/express_admin_tasks.rake +4 -0
- data/test/bin/run +1 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/javascripts/demo.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/assets/stylesheets/demo.css.scss +3 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/demo_controller.rb +8 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/demo_helper.rb +2 -0
- data/test/dummy/app/views/demo/show.html.et +2 -0
- data/test/dummy/app/views/demo/sign_in.html.et +30 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/schema.rb +22 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +3847 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/controllers/demo_controller_test.rb +9 -0
- data/test/dummy/test/helpers/demo_helper_test.rb +4 -0
- data/test/fixtures/engine.rb +5 -0
- data/test/fixtures/express_admin/test_menu.yml +12 -0
- data/test/fixtures/routes.rb +2 -0
- data/test/generators_test_helper.rb +32 -0
- data/test/lib/express_admin/menu_test.rb +18 -0
- data/test/lib/generators/express_admin/install_generator_test.rb +72 -0
- data/test/lib/generators/express_admin/scaffold_generator_test.rb +67 -0
- data/test/test_helper.rb +18 -0
- data/vendor/assets/images/dataTables/Sorting icons.psd +0 -0
- data/vendor/assets/images/dataTables/back_disabled.png +0 -0
- data/vendor/assets/images/dataTables/back_enabled.png +0 -0
- data/vendor/assets/images/dataTables/back_enabled_hover.png +0 -0
- data/vendor/assets/images/dataTables/favicon.ico +0 -0
- data/vendor/assets/images/dataTables/forward_disabled.png +0 -0
- data/vendor/assets/images/dataTables/forward_enabled.png +0 -0
- data/vendor/assets/images/dataTables/forward_enabled_hover.png +0 -0
- data/vendor/assets/images/dataTables/sort_asc.png +0 -0
- data/vendor/assets/images/dataTables/sort_asc_disabled.png +0 -0
- data/vendor/assets/images/dataTables/sort_both.png +0 -0
- data/vendor/assets/images/dataTables/sort_desc.png +0 -0
- data/vendor/assets/images/dataTables/sort_desc_disabled.png +0 -0
- data/vendor/assets/javascripts/jquery.loadingdotdotdot.js +82 -0
- metadata +432 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require "express_admin/menu"
|
2
|
+
require "express_admin/version"
|
3
|
+
require "express_templates"
|
4
|
+
require "jquery-rails"
|
5
|
+
require "foundation-rails"
|
6
|
+
require "bourbon"
|
7
|
+
require "gravatar_image_tag"
|
8
|
+
require "kaminari"
|
9
|
+
require "responders"
|
10
|
+
require 'inherited_resources'
|
11
|
+
|
12
|
+
# should be a way to add this folder to rails' autoload paths
|
13
|
+
components = Dir.glob(File.join(File.dirname(__FILE__), '..', '..', 'app', 'components', '**', '*.rb'))
|
14
|
+
components.each {|component| require component }
|
15
|
+
|
16
|
+
module ExpressAdmin
|
17
|
+
class Engine < ::Rails::Engine
|
18
|
+
|
19
|
+
initializer :assets do |config|
|
20
|
+
engine_assets_path = File.join(File.dirname(__FILE__), '..', '..', 'app', 'assets')
|
21
|
+
all_assets = Dir.glob File.join(engine_assets_path, 'stylesheets', '**', '*.css*')
|
22
|
+
all_assets += Dir.glob File.join(engine_assets_path, 'javascripts', '**', '*.js*')
|
23
|
+
all_assets.each {|path| path.gsub!("#{engine_assets_path}/stylesheets/", '')}
|
24
|
+
all_assets.each {|path| path.gsub!("#{engine_assets_path}/javascripts/", '')}
|
25
|
+
all_assets.each {|path| path.gsub!("#{engine_assets_path}/fonts/", '')}
|
26
|
+
all_assets.each {|path| path.gsub!(/.(scss|coffee)$/, '')}
|
27
|
+
Rails.application.config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
|
28
|
+
Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/
|
29
|
+
Rails.application.config.assets.precompile << /\.(?:png)$/
|
30
|
+
Rails.application.config.assets.precompile += all_assets
|
31
|
+
end
|
32
|
+
|
33
|
+
def all_rails_engines
|
34
|
+
Rails.application.eager_load!
|
35
|
+
@all_engines ||= ::Rails::Engine.descendants
|
36
|
+
end
|
37
|
+
|
38
|
+
# Find all the rails engines that have
|
39
|
+
# :addon_name presumably from including
|
40
|
+
# ExpressAdmin::Menu::Loader
|
41
|
+
def all_addons
|
42
|
+
@all_addons ||= all_rails_engines.select do |engine|
|
43
|
+
engine.methods.include?(:addon_name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class Railtie < ::Rails::Railtie
|
50
|
+
config.app_generators.template_engine :et
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module ExpressAdmin
|
2
|
+
# Provide menus for Express Admin addon engines.
|
3
|
+
#
|
4
|
+
# To use:
|
5
|
+
#
|
6
|
+
# 1) include ExpressAdmin::Menu::Loader in your engine.rb
|
7
|
+
# 2) add a config/menu.yml defining the menu structure
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
#
|
11
|
+
# title: 'Blog'
|
12
|
+
# path: 'express_blog.admin_blog_posts_path'
|
13
|
+
# items:
|
14
|
+
# -
|
15
|
+
# title: 'Posts'
|
16
|
+
# path: 'express_blog.admin_blog_posts_path'
|
17
|
+
# -
|
18
|
+
# title: 'Categories'
|
19
|
+
# path: 'express_blog.admin_blog_categories_path'
|
20
|
+
module Menu
|
21
|
+
|
22
|
+
# Return the top level MenuItem for the addon or defined in the supplied path.
|
23
|
+
#
|
24
|
+
# Accepts an addon_name such as :express_admin or a path to a yaml file
|
25
|
+
# containing a menu definition.
|
26
|
+
def self.[](addon_name)
|
27
|
+
@menus ||= {}
|
28
|
+
@menus[addon_name.to_sym] ||= begin
|
29
|
+
addon_path = Gem.loaded_specs[addon_name].full_gem_path if addon_name.to_s.match(/^\w+$/)
|
30
|
+
menu_yml_path = File.join(addon_path, 'config', 'menu.yml')
|
31
|
+
from(menu_yml_path)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.from(yaml_path)
|
36
|
+
raise "unable to locate #{yaml_path}" unless File.exists?(yaml_path)
|
37
|
+
MenuItem.new YAML.load_file(yaml_path).with_indifferent_access
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
class MenuItem
|
42
|
+
attr :title, :path, :position, :items
|
43
|
+
def initialize(hash)
|
44
|
+
@title = hash[:title]
|
45
|
+
@path = hash[:path]
|
46
|
+
@position = hash[:position] || 99
|
47
|
+
@items = (hash[:items]||[]).map {|item| MenuItem.new(item)}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Loader
|
52
|
+
def self.included(base)
|
53
|
+
class << base
|
54
|
+
def addon_name
|
55
|
+
self.to_s.split('::')[-2].underscore.to_sym
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Description:
|
2
|
+
Installs a new AppExpress module.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
`rails generate express_admin:install`
|
6
|
+
|
7
|
+
Creates a standard AppExpress module:
|
8
|
+
app/assets/javascripts/express_awesome/admin/ajax_forms.js
|
9
|
+
app/controllers/express_awesome/admin_controller.rb
|
10
|
+
app/views/layouts/express_awesome/admin.html.et
|
11
|
+
config/menu.yml
|
12
|
+
lib/generators/express_awesome/install/install_generator.rb
|
13
|
+
lib/generators/express_awesome/install/USAGE
|
14
|
+
test/lib/generators/express_awesome/install/install_generator_test.rb
|
15
|
+
|
16
|
+
Adds an entry to config/routes.rb:
|
17
|
+
`mount ExpressAwesome::Engine, at: ExpressAwesome::Engine.config.express_awesome_mount_point`
|
18
|
+
|
19
|
+
Adds a line to app/assets/javascripts/express_awesome/admin/application.js:
|
20
|
+
`//= require express_admin`
|
21
|
+
|
22
|
+
Adds a line to app/assets/stylesheets/express_awesome/admin/application.css:
|
23
|
+
`*= require express_admin`
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module ExpressAdmin
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
attr_reader :project_name, :project_class
|
6
|
+
|
7
|
+
def create_common_files
|
8
|
+
@project_name = destination_root.split('/').last
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_installer
|
12
|
+
@project_class = @project_name.camelize
|
13
|
+
|
14
|
+
template 'install/installer.rb.erb',
|
15
|
+
File.join('lib/generators', @project_name, 'install', 'install_generator.rb')
|
16
|
+
template 'install/USAGE', File.join('lib/generators', @project_name, 'install', 'USAGE')
|
17
|
+
empty_directory File.join('lib/generators', @project_name, 'install', 'templates')
|
18
|
+
template 'install/installer_test.rb.erb',
|
19
|
+
File.join('test/lib/generators', @project_name, 'install', 'install_generator_test.rb')
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_admin_controller
|
23
|
+
template 'controllers/admin_controller.rb.erb',
|
24
|
+
File.join('app/controllers', @project_name, 'admin', 'admin_controller.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_admin_layout
|
28
|
+
template 'views/layouts/admin.html.et',
|
29
|
+
File.join('app/views/layouts', @project_name, 'admin.html.et')
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_application_js
|
33
|
+
empty_directory("app/assets/javascripts/#{@project_name}/admin")
|
34
|
+
template 'assets/javascripts/application.js',
|
35
|
+
File.join('app/assets/javascripts', @project_name, 'admin', 'application.js')
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_application_css
|
39
|
+
empty_directory("app/assets/stylesheets/#{@project_name}/admin")
|
40
|
+
template 'assets/stylesheets/application.css',
|
41
|
+
File.join('app/assets/stylesheets', @project_name, 'admin', 'application.css')
|
42
|
+
end
|
43
|
+
|
44
|
+
def insert_mount_point
|
45
|
+
@project_class = @project_name.camelize
|
46
|
+
|
47
|
+
if open(engine_path).any?
|
48
|
+
inject_into_file engine_path,
|
49
|
+
" #{@project_class}::Engine.config.#{@project_name}_mount_point = '/'\n",
|
50
|
+
after: "class Engine < ::Rails::Engine\n"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def require_express_admin
|
55
|
+
@project_class = @project_name.camelize
|
56
|
+
|
57
|
+
if open(engine_path).any?
|
58
|
+
inject_into_file engine_path, "require 'express_admin'\n",
|
59
|
+
before: "module #{@project_class}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_menu
|
64
|
+
template 'config/menu.yml.erb', File.join('config/menu.yml')
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_express_admin_menu
|
68
|
+
if open(engine_path).any?
|
69
|
+
inject_into_file engine_path, " include ::ExpressAdmin::Menu::Loader\n",
|
70
|
+
after: "class Engine < ::Rails::Engine\n"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def precompile_assets
|
75
|
+
assets = <<-'EOD'
|
76
|
+
initializer :assets do |config|
|
77
|
+
engine_assets_path = File.join(File.dirname(__FILE__), '..', '..', 'app', 'assets')
|
78
|
+
all_assets = Dir.glob File.join(engine_assets_path, 'stylesheets', '**', '*.css*')
|
79
|
+
all_assets += Dir.glob File.join(engine_assets_path, 'javascripts', '**', '*.js*')
|
80
|
+
all_assets.each {|path| path.gsub!("#{engine_assets_path}/stylesheets/", '')}
|
81
|
+
all_assets.each {|path| path.gsub!("#{engine_assets_path}/javascripts/", '')}
|
82
|
+
Rails.application.config.assets.precompile += all_assets
|
83
|
+
end
|
84
|
+
EOD
|
85
|
+
if open(engine_path).any?
|
86
|
+
inject_into_file engine_path, assets, after: "class Engine < ::Rails::Engine\n"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def engine_path
|
93
|
+
Rails.root ? "#{Rails.root}/lib/#{@project_name}/engine.rb" : "lib/#{@project_name}/engine.rb"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require_tree .
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_dependency "<%= project_name %>/application_controller"
|
2
|
+
|
3
|
+
module <%= project_class %>
|
4
|
+
module Admin
|
5
|
+
class AdminController < ApplicationController
|
6
|
+
inherit_resources # Use inherited_resources
|
7
|
+
|
8
|
+
helper ::ExpressAdmin::AdminHelper
|
9
|
+
before_filter :authenticate_user! if defined?(Devise)
|
10
|
+
layout "<%= project_name %>/admin"
|
11
|
+
|
12
|
+
before_filter :load_collection, only: [:show]
|
13
|
+
before_filter :build_new_resource, only: [:index]
|
14
|
+
|
15
|
+
def show
|
16
|
+
show! do |format|
|
17
|
+
format.html { render :index }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def load_collection
|
24
|
+
collection # from InheritedResources
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_new_resource
|
28
|
+
@resource_params = {}
|
29
|
+
build_resource
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class <%= project_class %>::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
desc "mount <%= project_name %> engine"
|
5
|
+
def install
|
6
|
+
route "mount <%= project_class %>::Engine, at: <%= project_class %>::Engine.config.<%= project_name %>_mount_point"
|
7
|
+
rake "<%= project_name %>:install:migrations"
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/<%= project_name %>/install/install_generator'
|
3
|
+
|
4
|
+
module <%= project_class %>
|
5
|
+
class <%= project_class %>::InstallGeneratorTest < Rails::Generators::TestCase
|
6
|
+
tests <%= project_class %>::InstallGenerator
|
7
|
+
destination Rails.root.join('tmp/generators')
|
8
|
+
setup :prepare_destination
|
9
|
+
|
10
|
+
# test "generator runs without errors" do
|
11
|
+
# assert_nothing_raised do
|
12
|
+
# run_generator ["arguments"]
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
render(template: 'layouts/express_admin/admin')
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'rails/generators/rails/scaffold/scaffold_generator'
|
2
|
+
|
3
|
+
module ExpressAdmin
|
4
|
+
module Generators
|
5
|
+
class ScaffoldGenerator < ::Rails::Generators::ScaffoldGenerator
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
attr_reader :view_path, :resource_class
|
8
|
+
|
9
|
+
remove_hook_for :scaffold_controller
|
10
|
+
|
11
|
+
def create_root_folder
|
12
|
+
empty_directory admin_view_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_view_files
|
16
|
+
available_views.each do |view|
|
17
|
+
template "#{view}.html.et.erb", File.join(admin_view_path, "#{view}.html.et")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_controller
|
22
|
+
controller_file_path = File.join(["app/controllers", project_name, admin_controller_path, "#{controller_file_name}_controller.rb"].compact)
|
23
|
+
template "controller/controller.rb", controller_file_path
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_route
|
27
|
+
route_path = Rails.root ? "#{Rails.root}/config/routes.rb": "config/routes.rb"
|
28
|
+
if open(route_path).grep("scope '#{project_path}'").any?
|
29
|
+
inject_into_file 'config/routes.rb', " resources :#{controller_file_name}\n",
|
30
|
+
after: "scope '#{project_path}' do\n"
|
31
|
+
else
|
32
|
+
if module_name
|
33
|
+
admin_route = <<-EOD
|
34
|
+
namespace :admin do
|
35
|
+
scope '#{module_name}' do
|
36
|
+
resources :#{controller_file_name}, except: [:edit]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
EOD
|
40
|
+
else
|
41
|
+
admin_route = <<-EOD
|
42
|
+
namespace :admin do
|
43
|
+
resources :#{controller_file_name}, except: [:edit]
|
44
|
+
end
|
45
|
+
EOD
|
46
|
+
end
|
47
|
+
inject_into_file 'config/routes.rb', admin_route,
|
48
|
+
after: "#{namespaced?}::Engine.routes.draw do\n"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_menu_item
|
53
|
+
menu_entry = %Q(
|
54
|
+
-
|
55
|
+
title: '#{controller_file_name.titleize}'
|
56
|
+
path: '#{namespaced?.to_s.underscore}.#{project_name}_admin_#{controller_file_name}_path'
|
57
|
+
)
|
58
|
+
menu_path = Rails.root ? "#{Rails.root}/config/menu.yml": "config/menu.yml"
|
59
|
+
if File.exists?(menu_path)
|
60
|
+
inject_into_file menu_path, menu_entry, after: 'items:'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
protected
|
66
|
+
def available_views
|
67
|
+
%w(index)
|
68
|
+
end
|
69
|
+
|
70
|
+
def available_actions
|
71
|
+
%w(index show update destroy)
|
72
|
+
end
|
73
|
+
|
74
|
+
def handler
|
75
|
+
:et
|
76
|
+
end
|
77
|
+
|
78
|
+
def project_path
|
79
|
+
project_name || Rails.application.class.parent_name
|
80
|
+
end
|
81
|
+
|
82
|
+
def project_name
|
83
|
+
namespaced_path rescue nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def module_name
|
87
|
+
controller_class_path.last if controller_class_path.size.eql?(2)
|
88
|
+
end
|
89
|
+
|
90
|
+
def admin_controller_path
|
91
|
+
# place the generated controller into an Admin module
|
92
|
+
acp = controller_class_path.dup
|
93
|
+
if acp.empty?
|
94
|
+
acp.push 'admin'
|
95
|
+
else
|
96
|
+
acp.insert(1,'admin').compact.slice(1..-1)
|
97
|
+
end
|
98
|
+
File.join acp
|
99
|
+
end
|
100
|
+
|
101
|
+
def model_class_name
|
102
|
+
class_path_parts = class_name.split("::")
|
103
|
+
class_path_parts.unshift namespace.to_s if namespaced?
|
104
|
+
class_path_parts.join("::")
|
105
|
+
end
|
106
|
+
|
107
|
+
def admin_view_path
|
108
|
+
path_parts = ["app/views", project_name, admin_controller_path, controller_file_name]
|
109
|
+
File.join path_parts.compact
|
110
|
+
end
|
111
|
+
|
112
|
+
def model_path
|
113
|
+
if Rails.application
|
114
|
+
class_name.underscore
|
115
|
+
else
|
116
|
+
# drop the module name for the engine as the generators
|
117
|
+
# we invoke will automatically add it back again
|
118
|
+
class_name.split("::").slice(1..-1).join("::").underscore
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def destroy(what, *args)
|
125
|
+
log :destroy, what
|
126
|
+
argument = args.flat_map(&:to_s).join(" ")
|
127
|
+
# in_root { run_ruby_script("bin/rails destroy #{what} #{argument}", verbose: true) }
|
128
|
+
system("bin/rails destroy #{what} #{argument}")
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
module Admin
|
3
|
+
class <%= controller_class_name %>Controller < AdminController
|
4
|
+
|
5
|
+
defaults resource_class: <%= model_class_name %>
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def <%= singular_table_name %>_params
|
10
|
+
params.require(:<%= singular_table_name %>).permit!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
<% end -%>
|
data/test/bin/run
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rake test
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|