cambium 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +339 -15
- data/{lib/generators/cambium/templates/app/assets/javascripts/admin/admin.js.coffee → app/assets/javascripts/cambium/admin/application.js.coffee} +4 -10
- data/app/assets/javascripts/cambium/admin/routers/router.js.coffee +25 -0
- data/app/assets/javascripts/cambium/admin/users.js +2 -0
- data/app/assets/javascripts/cambium/admin/views/dropdown_menu.js.coffee +24 -0
- data/app/assets/javascripts/cambium/admin/views/pickadate.js.coffee +15 -0
- data/app/assets/stylesheets/cambium/admin/application.scss +27 -0
- data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_colors.scss +7 -7
- data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones.scss +18 -18
- data/app/assets/stylesheets/cambium/admin/partials/_globals.scss +21 -0
- data/app/assets/stylesheets/cambium/admin/partials/activity.scss +52 -0
- data/app/assets/stylesheets/cambium/admin/partials/components.scss +64 -0
- data/app/assets/stylesheets/cambium/admin/partials/dashboard.scss +48 -0
- data/app/assets/stylesheets/cambium/admin/partials/forms.scss +107 -0
- data/app/assets/stylesheets/cambium/admin/partials/header.scss +113 -0
- data/app/assets/stylesheets/cambium/admin/partials/page_title.scss +42 -0
- data/app/assets/stylesheets/cambium/admin/partials/sidebar.scss +41 -0
- data/app/assets/stylesheets/cambium/admin/partials/tables.scss +80 -0
- data/app/assets/stylesheets/cambium/admin/partials/typography.scss +5 -0
- data/app/assets/stylesheets/cambium/admin/partials/wireframe.scss +52 -0
- data/app/assets/stylesheets/cambium/admin/users.css +4 -0
- data/app/controllers/cambium/admin/dashboard_controller.rb +12 -0
- data/app/controllers/cambium/admin/search_controller.rb +9 -0
- data/app/controllers/cambium/admin/users_controller.rb +30 -0
- data/app/controllers/cambium/admin_controller.rb +90 -0
- data/app/helpers/cambium/cambium_helper.rb +205 -0
- data/app/presenters/cambium/admin_presenter.rb +127 -0
- data/app/views/cambium/admin/_activity.html.erb +6 -0
- data/app/views/cambium/admin/_header.html.erb +41 -0
- data/app/views/cambium/admin/_sidebar.html.erb +19 -0
- data/app/views/cambium/admin/_status.html.erb +5 -0
- data/app/views/cambium/admin/dashboard/show.html.erb +5 -0
- data/app/views/cambium/admin/edit.html.erb +7 -0
- data/app/views/cambium/admin/index.html.erb +7 -0
- data/app/views/cambium/admin/new.html.erb +7 -0
- data/app/views/cambium/admin/paper_trail/versions/_version.html.erb +20 -0
- data/app/views/cambium/admin/search/index.html.erb +38 -0
- data/app/views/layouts/admin.html.erb +25 -0
- data/bin/rails +12 -0
- data/cambium.gemspec +19 -15
- data/config/routes.rb +10 -0
- data/lib/cambium/configuration.rb +28 -0
- data/lib/cambium/engine.rb +2 -1
- data/lib/cambium/version.rb +1 -1
- data/lib/cambium.rb +12 -1
- data/lib/generators/cambium/admin_generator.rb +104 -0
- data/lib/generators/cambium/app_generator.rb +205 -0
- data/lib/generators/cambium/controller_generator.rb +81 -0
- data/lib/generators/cambium/gemfile_generator.rb +36 -0
- data/lib/generators/cambium/install_generator.rb +19 -0
- data/lib/generators/cambium/user_generator.rb +40 -0
- data/lib/generators/{cambium/helpers → helpers}/generators_helper.rb +32 -24
- data/lib/generators/templates/Gemfile.erb +79 -0
- data/lib/generators/{cambium/templates/app/assets/javascripts/backbone/app.js.coffee → templates/app/assets/javascripts/application.js.coffee} +9 -1
- data/lib/generators/templates/app/assets/javascripts/views/default_helpers.js.coffee +16 -0
- data/lib/generators/templates/app/assets/stylesheets/admin/admin.scss +3 -0
- data/lib/generators/templates/app/controllers/admin/controller.rb.erb +2 -0
- data/lib/generators/{cambium/templates → templates}/app/controllers/application_controller.rb +1 -5
- data/lib/generators/{cambium/templates → templates}/app/models/user.rb +4 -4
- data/lib/generators/templates/app/views/application/_status.html.erb +3 -0
- data/lib/generators/{cambium/templates → templates}/app/views/layouts/application.html.erb +1 -1
- data/lib/generators/templates/config/admin/controller.yml.erb +24 -0
- data/lib/generators/templates/config/admin/sidebar.yml +9 -0
- data/lib/generators/templates/config/admin/users.yml +31 -0
- data/lib/generators/{cambium/templates → templates}/config/application.rb +6 -4
- data/lib/generators/templates/config/initializers/_hash.rb +23 -0
- data/lib/generators/templates/config/initializers/_settings.rb +18 -0
- data/lib/generators/templates/config/initializers/assets.rb +1 -0
- data/lib/generators/templates/config/initializers/cambium.rb +16 -0
- data/lib/generators/templates/config/private.yml +16 -0
- data/lib/generators/templates/config/routes.rb +54 -0
- data/lib/generators/templates/config/settings.yml +16 -0
- data/lib/generators/{cambium/templates → templates}/gitignore +1 -1
- data/lib/help/cambium_prereqs.txt +13 -0
- data/lib/help/pg_search_post_install.txt +13 -0
- data/lib/{generators/cambium/templates/lib/tasks → tasks}/db.rake +2 -2
- data/lib/{generators/cambium/templates/lib/tasks → tasks}/rename.rake +1 -1
- data/test/controllers/cambium/admin/dashboard_controller_test.rb +9 -0
- data/test/controllers/cambium/admin/users_controller_test.rb +9 -0
- data/test/controllers/cambium/admin_controller_test.rb +9 -0
- metadata +192 -152
- data/bin/cambium +0 -16
- data/lib/generators/cambium/helpers/dependencies_helper.rb +0 -58
- data/lib/generators/cambium/install/admin_generator.rb +0 -110
- data/lib/generators/cambium/install/app_generator.rb +0 -162
- data/lib/generators/cambium/install/config_generator.rb +0 -182
- data/lib/generators/cambium/install/utilities_generator.rb +0 -57
- data/lib/generators/cambium/model/image_generator.rb +0 -67
- data/lib/generators/cambium/model/page_generator.rb +0 -131
- data/lib/generators/cambium/model/post_generator.rb +0 -71
- data/lib/generators/cambium/model/tag_generator.rb +0 -40
- data/lib/generators/cambium/model/user_generator.rb +0 -78
- data/lib/generators/cambium/templates/Gemfile +0 -43
- data/lib/generators/cambium/templates/Gemfile.erb +0 -40
- data/lib/generators/cambium/templates/_partials/pages/admin_icon.rb +0 -6
- data/lib/generators/cambium/templates/app/assets/javascripts/.DS_Store +0 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/collections/.gitkeep +0 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/.gitkeep +0 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/image.js.coffee +0 -14
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/tag.js.coffee +0 -14
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/parser_rules/custom.js +0 -552
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/routers/router.js.coffee +0 -37
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/tag.jst.ejs +0 -7
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/image.jst.ejs +0 -3
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/paginator_controls.jst.ejs +0 -8
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/paginator_nav.jst.ejs +0 -11
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/post_tag.jst.ejs +0 -1
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/accordion.js.coffee +0 -33
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/counter.js.coffee +0 -25
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/dropdown_toggle.js.coffee +0 -16
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/image_upload.js.coffee +0 -28
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/init_counter.js.coffee +0 -13
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/paginator.js.coffee +0 -86
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/publishable.js.coffee +0 -12
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/tags.js.coffee +0 -158
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/wysiwyg.js.coffee +0 -87
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/wysihtml5.js +0 -9521
- data/lib/generators/cambium/templates/app/assets/javascripts/application.js +0 -10
- data/lib/generators/cambium/templates/app/assets/javascripts/backbone/templates/.keep +0 -0
- data/lib/generators/cambium/templates/app/assets/stylesheets/admin/admin.scss +0 -14
- data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_content.scss +0 -88
- data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_form.scss +0 -470
- data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_globals.scss +0 -39
- data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_header.scss +0 -121
- data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_nav.scss +0 -45
- data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_wireframe.scss +0 -24
- data/lib/generators/cambium/templates/app/assets/stylesheets/admin/wysihtml5.css +0 -7
- data/lib/generators/cambium/templates/app/controllers/admin/images_controller.rb +0 -45
- data/lib/generators/cambium/templates/app/controllers/admin/pages_controller.rb +0 -42
- data/lib/generators/cambium/templates/app/controllers/admin/posts_controller.rb +0 -39
- data/lib/generators/cambium/templates/app/controllers/admin/taggings_controller.rb +0 -69
- data/lib/generators/cambium/templates/app/controllers/admin/tags_controller.rb +0 -11
- data/lib/generators/cambium/templates/app/controllers/admin/users_controller.rb +0 -13
- data/lib/generators/cambium/templates/app/controllers/admin_controller.rb +0 -97
- data/lib/generators/cambium/templates/app/controllers/images_controller.rb +0 -45
- data/lib/generators/cambium/templates/app/controllers/pages_controller.rb +0 -12
- data/lib/generators/cambium/templates/app/controllers/posts_controller.rb +0 -11
- data/lib/generators/cambium/templates/app/helpers/admin/pages_controller.rb +0 -47
- data/lib/generators/cambium/templates/app/helpers/admin_helper.rb +0 -121
- data/lib/generators/cambium/templates/app/models/concerns/name.rb +0 -7
- data/lib/generators/cambium/templates/app/models/concerns/title.rb +0 -7
- data/lib/generators/cambium/templates/app/models/image.rb +0 -43
- data/lib/generators/cambium/templates/app/models/page.rb +0 -81
- data/lib/generators/cambium/templates/app/models/post.rb +0 -45
- data/lib/generators/cambium/templates/app/models/tag.rb +0 -33
- data/lib/generators/cambium/templates/app/models/tagging.rb +0 -20
- data/lib/generators/cambium/templates/app/uploaders/image_uploader.rb +0 -91
- data/lib/generators/cambium/templates/app/views/admin/_buttons.html.erb +0 -5
- data/lib/generators/cambium/templates/app/views/admin/_form.html.erb +0 -11
- data/lib/generators/cambium/templates/app/views/admin/_title.html.erb +0 -1
- data/lib/generators/cambium/templates/app/views/admin/edit.html.erb +0 -2
- data/lib/generators/cambium/templates/app/views/admin/images/_image.html.erb +0 -1
- data/lib/generators/cambium/templates/app/views/admin/images/create.js.erb +0 -7
- data/lib/generators/cambium/templates/app/views/admin/images/index.json.jbuilder +0 -4
- data/lib/generators/cambium/templates/app/views/admin/index.html.erb +0 -50
- data/lib/generators/cambium/templates/app/views/admin/new.html.erb +0 -2
- data/lib/generators/cambium/templates/app/views/admin/pages/_form.html.erb +0 -26
- data/lib/generators/cambium/templates/app/views/admin/posts/_form.html.erb +0 -40
- data/lib/generators/cambium/templates/app/views/admin/shared/_footer.html.erb +0 -2
- data/lib/generators/cambium/templates/app/views/admin/shared/_header.html.erb +0 -2
- data/lib/generators/cambium/templates/app/views/admin/shared/_insert_image.html.erb +0 -12
- data/lib/generators/cambium/templates/app/views/admin/shared/_nav.html.erb +0 -12
- data/lib/generators/cambium/templates/app/views/admin/shared/_status.html.erb +0 -3
- data/lib/generators/cambium/templates/app/views/admin/shared/forms/_editor.html.erb +0 -54
- data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_column_left.html.erb +0 -9
- data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_column_right.html.erb +0 -9
- data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_page.html.erb +0 -22
- data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_section.html.erb +0 -8
- data/lib/generators/cambium/templates/app/views/admin/shared/forms/_publishable.html.erb +0 -33
- data/lib/generators/cambium/templates/app/views/admin/users/_form.html.erb +0 -11
- data/lib/generators/cambium/templates/app/views/application/_status.html.erb +0 -3
- data/lib/generators/cambium/templates/app/views/layouts/.DS_Store +0 -0
- data/lib/generators/cambium/templates/app/views/layouts/admin.html.erb +0 -44
- data/lib/generators/cambium/templates/app/views/page_templates/default.html.erb +0 -2
- data/lib/generators/cambium/templates/app/views/posts/_post.html.erb +0 -4
- data/lib/generators/cambium/templates/app/views/posts/index.html.erb +0 -1
- data/lib/generators/cambium/templates/app/views/posts/show.html.erb +0 -10
- data/lib/generators/cambium/templates/config/app_routes.rb +0 -77
- data/lib/generators/cambium/templates/config/database.mysql2.yml.erb +0 -15
- data/lib/generators/cambium/templates/config/database.pg.yml.erb +0 -14
- data/lib/generators/cambium/templates/config/database.sqlite3.yml.erb +0 -18
- data/lib/generators/cambium/templates/config/initializers/_settings.rb +0 -11
- data/lib/generators/cambium/templates/config/initializers/assets.rb +0 -1
- data/lib/generators/cambium/templates/config/routes.rb.erb +0 -42
- data/lib/generators/cambium/templates/config/settings.yml +0 -15
- data/lib/generators/cambium/templates/config/settings_private.sample.yml +0 -15
- data/lib/generators/cambium/templates/config/settings_private.yml +0 -13
- data/lib/generators/cambium/templates/db/migrate/create_pages.rb.erb +0 -24
- data/lib/generators/cambium/templates/db/migrate/create_posts.rb +0 -19
- data/lib/generators/cambium/templates/lib/.DS_Store +0 -0
- data/lib/help/cambium +0 -7
- /data/{lib/generators/cambium/templates/app/assets/javascripts/backbone/collections → app/assets/javascripts/cambium/admin/templates}/.keep +0 -0
- /data/{lib/generators/cambium/templates/app/assets/javascripts/backbone → app/assets/javascripts/cambium/admin}/views/default_helpers.js.coffee +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/__default.scss +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_buttons.scss +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_components.scss +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_forms.scss +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_helpers.scss +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_images.scss +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_nav.scss +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_tables.scss +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_typography.scss +0 -0
- /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_wireframe.scss +0 -0
- /data/{lib/generators/cambium/templates/app → app}/models/concerns/idx.rb +0 -0
- /data/{lib/generators/cambium/templates/app → app}/models/concerns/image_cropper.rb +0 -0
- /data/{lib/generators/cambium/templates/app → app}/models/concerns/publishable.rb +0 -0
- /data/{lib/generators/cambium/templates/app → app}/models/concerns/slug.rb +0 -0
- /data/{lib/generators/cambium/templates/app → app}/models/concerns/tags.rb +0 -0
- /data/lib/generators/{cambium/helpers → helpers}/_autoloader.rb +0 -0
- /data/lib/generators/{cambium/templates/app/assets/javascripts/backbone → templates/app/assets/javascripts}/routers/router.js.coffee +0 -0
- /data/lib/generators/{cambium/templates/app/assets/javascripts/backbone/models → templates/app/assets/javascripts/templates}/.keep +0 -0
- /data/lib/generators/{cambium/templates → templates}/app/assets/stylesheets/application.scss +0 -0
- /data/lib/generators/{cambium/templates → templates}/app/views/home/index.html.erb +0 -0
- /data/lib/generators/{cambium/templates → templates}/db/seeds.rb +0 -0
- /data/{lib/generators/cambium/templates/vendor → vendor}/assets/javascripts/modernizr.js +0 -0
- /data/{lib/generators/cambium/templates/vendor → vendor}/assets/stylesheets/normalize.scss +0 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'fileutils'
|
4
|
+
require File.expand_path('../../helpers/_autoloader.rb', __FILE__)
|
5
|
+
|
6
|
+
module Cambium
|
7
|
+
class AdminGenerator < Rails::Generators::Base
|
8
|
+
|
9
|
+
desc "Installs the base for a CMS within your rails application."
|
10
|
+
|
11
|
+
source_root File.expand_path('../../templates', __FILE__)
|
12
|
+
|
13
|
+
class_option(
|
14
|
+
:config_check,
|
15
|
+
:type => :boolean,
|
16
|
+
:default => true,
|
17
|
+
:description => "Verify config at config/initializers/cambium.rb"
|
18
|
+
)
|
19
|
+
|
20
|
+
# If there is no configuration file tell the user to run
|
21
|
+
# that generator first (unless user has manually
|
22
|
+
# overridden).
|
23
|
+
#
|
24
|
+
def verify_configuration
|
25
|
+
if options.config_check?
|
26
|
+
unless File.exists?("#{Rails.root}/config/initializers/cambium.rb")
|
27
|
+
help_message('cambium_prereqs')
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Generate a migration so we can keep users from
|
34
|
+
# accessing the admin if they don't have permission
|
35
|
+
#
|
36
|
+
def add_admin_migration
|
37
|
+
generate "migration add_is_admin_to_users" # is_admin:boolean"
|
38
|
+
Dir.glob("#{Rails.root.join('db','migrate')}/*.rb").each do |file|
|
39
|
+
filename = file.split('/').last
|
40
|
+
if filename =~ /is\_admin/
|
41
|
+
insert_into_file(
|
42
|
+
"db/migrate/#{filename}",
|
43
|
+
"\n add_column :users, :is_admin, :boolean, :default => false",
|
44
|
+
:after => "def change"
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add another migration for user profile fields
|
51
|
+
#
|
52
|
+
def add_user_profile
|
53
|
+
generate "migration add_user_profile_fields_to_users name:string"
|
54
|
+
end
|
55
|
+
|
56
|
+
# Add admin sidebar file to the project
|
57
|
+
#
|
58
|
+
def add_admin_routes
|
59
|
+
['sidebar','users'].each do |file|
|
60
|
+
template "config/admin/#{file}.yml", "config/admin/#{file}.yml"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Add migration for paper_trail versions
|
65
|
+
#
|
66
|
+
def add_paper_trail
|
67
|
+
generate 'paper_trail:install'
|
68
|
+
Dir.glob("#{Rails.root}/app/models/*.rb").each do |f|
|
69
|
+
insert_into_file f.to_s, :after => "ActiveRecord::Base\n" do
|
70
|
+
" # ------------------------------------------ Plugins\n" +
|
71
|
+
" has_paper_trail\n"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Add migration for pg_search
|
77
|
+
#
|
78
|
+
def add_pg_search
|
79
|
+
generate 'pg_search:migration:multisearch'
|
80
|
+
help_message('pg_search_post_install')
|
81
|
+
end
|
82
|
+
|
83
|
+
# Add pg_search to users
|
84
|
+
#
|
85
|
+
def add_user_search
|
86
|
+
insert_into_file(
|
87
|
+
"#{Rails.root}/app/models/user.rb", :after => "---- Plugins\n"
|
88
|
+
) do
|
89
|
+
" include PgSearch\n" +
|
90
|
+
" multisearchable :against => [:name, :email]\n"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Adds a manifest SCSS file to the project, so the
|
95
|
+
# developer can override any admin styles with creating
|
96
|
+
# a new layout
|
97
|
+
#
|
98
|
+
def add_css_override
|
99
|
+
file = "app/assets/stylesheets/admin/admin.scss"
|
100
|
+
template(file, file)
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rails/generators'
|
3
|
+
require File.expand_path('../../helpers/_autoloader.rb', __FILE__)
|
4
|
+
|
5
|
+
module Cambium
|
6
|
+
class AppGenerator < Rails::Generators::Base
|
7
|
+
|
8
|
+
desc "Add all the pieces to your application per your configuration."
|
9
|
+
|
10
|
+
source_root File.expand_path('../../templates', __FILE__)
|
11
|
+
|
12
|
+
class_option(
|
13
|
+
:config_check,
|
14
|
+
:type => :boolean,
|
15
|
+
:default => true,
|
16
|
+
:description => "Verify config at config/initializers/cambium.rb"
|
17
|
+
)
|
18
|
+
|
19
|
+
# If there is no configuration file tell the user to run
|
20
|
+
# that generator first (unless user has manually
|
21
|
+
# overridden).
|
22
|
+
#
|
23
|
+
def verify_configuration
|
24
|
+
if options.config_check?
|
25
|
+
unless File.exists?("#{Rails.root}/config/initializers/cambium.rb")
|
26
|
+
help_message('cambium_prereqs')
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Wrap our config values up in an easier-to-type
|
33
|
+
# variable
|
34
|
+
#
|
35
|
+
def set_config
|
36
|
+
@config = Cambium.configuration
|
37
|
+
end
|
38
|
+
|
39
|
+
# Set root url for mailer in development and production
|
40
|
+
#
|
41
|
+
def set_url_config
|
42
|
+
environment(
|
43
|
+
"config.action_mailer.default_url_options = { :host => '#{@config.development_url}' }",
|
44
|
+
:env => "development"
|
45
|
+
)
|
46
|
+
environment(
|
47
|
+
"config.action_mailer.default_url_options = { :host => '#{@config.production_url}' }",
|
48
|
+
:env => "production"
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Add modernizr to our list of assets to precompile when
|
53
|
+
# we're ready to deploy
|
54
|
+
#
|
55
|
+
def set_precompiled_assets
|
56
|
+
environment(
|
57
|
+
"config.assets.precompile += %w( modernizr.js )",
|
58
|
+
:env => "production"
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Add settings to application config file
|
63
|
+
# (config/application.rb)
|
64
|
+
#
|
65
|
+
def add_application_config
|
66
|
+
environment { file_contents("config/application.rb") }
|
67
|
+
end
|
68
|
+
|
69
|
+
# Assets initializer for Rails 4.1+
|
70
|
+
#
|
71
|
+
def add_assets_initializer
|
72
|
+
file = "config/initializers/assets.rb"
|
73
|
+
template(file, file)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Add custom gitignore file
|
77
|
+
#
|
78
|
+
def add_gitignore
|
79
|
+
remove_file ".gitignore"
|
80
|
+
template "gitignore", ".gitignore"
|
81
|
+
end
|
82
|
+
|
83
|
+
# Add a default public controller, so we have a working
|
84
|
+
# home page when we're done.
|
85
|
+
#
|
86
|
+
def add_home_controller
|
87
|
+
generate "controller home index"
|
88
|
+
end
|
89
|
+
|
90
|
+
# Add our default public views
|
91
|
+
#
|
92
|
+
def add_public_views
|
93
|
+
directory "app/views/application"
|
94
|
+
directory "app/views/home", :force => true
|
95
|
+
end
|
96
|
+
|
97
|
+
# Our layouts are templated so we can start with
|
98
|
+
# some custom information.
|
99
|
+
#
|
100
|
+
def add_layouts
|
101
|
+
app = "app/views/layouts/application.html.erb"
|
102
|
+
template app, app, :force => true
|
103
|
+
end
|
104
|
+
|
105
|
+
# We're going to automatically install backbone unless
|
106
|
+
# the user has disabled it
|
107
|
+
#
|
108
|
+
def add_js_framework
|
109
|
+
directory("app/assets/javascripts", "app/assets/javascripts")
|
110
|
+
end
|
111
|
+
|
112
|
+
# Next, we need to replace our application.js file to add
|
113
|
+
# backbone and its dependencies, along with our default
|
114
|
+
# scripts.
|
115
|
+
#
|
116
|
+
def add_js_manifest
|
117
|
+
app_js = "app/assets/javascripts/application.js"
|
118
|
+
remove_file app_js
|
119
|
+
app_js += ".coffee"
|
120
|
+
template app_js, app_js
|
121
|
+
end
|
122
|
+
|
123
|
+
# Add our application.scss file. Since we don't know what
|
124
|
+
# file exists, we look for and delete all and replace with
|
125
|
+
# ours.
|
126
|
+
#
|
127
|
+
def add_public_manifest
|
128
|
+
['css','scss','scss.css'].each do |ext|
|
129
|
+
file = "app/assets/stylesheets/application.#{ext}"
|
130
|
+
remove_file(file) if File.exists?(file)
|
131
|
+
end
|
132
|
+
manifest_file = "app/assets/stylesheets/application.scss"
|
133
|
+
template manifest_file, manifest_file
|
134
|
+
end
|
135
|
+
|
136
|
+
# Go through standard Devise installation
|
137
|
+
#
|
138
|
+
def install_devise
|
139
|
+
generate "devise:install"
|
140
|
+
end
|
141
|
+
|
142
|
+
# Add a User model
|
143
|
+
#
|
144
|
+
def add_devise_user_model
|
145
|
+
generate "devise User"
|
146
|
+
end
|
147
|
+
|
148
|
+
# Copy our custom user model template into the app
|
149
|
+
#
|
150
|
+
def add_user_model_file
|
151
|
+
copy_file "app/models/user.rb", "app/models/user.rb", :force => true
|
152
|
+
end
|
153
|
+
|
154
|
+
# Override Devise's default redirects and sign in/out
|
155
|
+
#
|
156
|
+
def add_application_controller_redirects
|
157
|
+
insert_into_file(
|
158
|
+
"app/controllers/application_controller.rb",
|
159
|
+
template_snippet("app/controllers/application_controller.rb"),
|
160
|
+
:after => ":exception"
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
# Install Simple Form automatically
|
165
|
+
#
|
166
|
+
def install_simple_form
|
167
|
+
generate "simple_form:install"
|
168
|
+
end
|
169
|
+
|
170
|
+
# Add ruby class overrides and additions
|
171
|
+
#
|
172
|
+
def add_ruby_class_overrides
|
173
|
+
template "config/initializers/_hash.rb", "config/initializers/_hash.rb"
|
174
|
+
end
|
175
|
+
|
176
|
+
# Add our settings and private settings files
|
177
|
+
#
|
178
|
+
def add_settings_files
|
179
|
+
template "config/initializers/_settings.rb",
|
180
|
+
"config/initializers/_settings.rb"
|
181
|
+
['settings','private'].each do |s|
|
182
|
+
template "config/#{s}.yml", "config/#{s}.yml"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Add the custom seed generator, which loads content
|
187
|
+
# from CSV into the database.
|
188
|
+
#
|
189
|
+
def add_seed_generator
|
190
|
+
remove_file "db/seeds.rb"
|
191
|
+
template "db/seeds.rb", "db/seeds.rb"
|
192
|
+
end
|
193
|
+
|
194
|
+
# Add our default routes file, which is commented out
|
195
|
+
# except for the root path to the home controller.
|
196
|
+
#
|
197
|
+
# We don't override routes here in case the user started
|
198
|
+
# to edit their routes file before running this generator.
|
199
|
+
#
|
200
|
+
def add_default_routes
|
201
|
+
template "config/routes.rb", "config/routes.rb", :force => true
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rails/generators'
|
3
|
+
require File.expand_path('../../helpers/_autoloader.rb', __FILE__)
|
4
|
+
|
5
|
+
module Cambium
|
6
|
+
class ControllerGenerator < Rails::Generators::Base
|
7
|
+
|
8
|
+
desc "Installs a controller to use in Cambium's CMS."
|
9
|
+
|
10
|
+
source_root File.expand_path('../../templates', __FILE__)
|
11
|
+
|
12
|
+
argument :model, :type => :string
|
13
|
+
|
14
|
+
# class_option(
|
15
|
+
# :config_check,
|
16
|
+
# :type => :boolean,
|
17
|
+
# :default => true,
|
18
|
+
# :description => "Verify config at config/initializers/cambium.rb"
|
19
|
+
# )
|
20
|
+
|
21
|
+
# If there is no configuration file tell the user to run
|
22
|
+
# that generator first (unless user has manually
|
23
|
+
# overridden).
|
24
|
+
#
|
25
|
+
# def verify_configuration
|
26
|
+
# if options.config_check?
|
27
|
+
# unless File.exists?("#{Rails.root}/config/initializers/cambium.rb")
|
28
|
+
# help_message('cambium_prereqs')
|
29
|
+
# exit
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
|
34
|
+
def confirm_model
|
35
|
+
@model = model.constantize
|
36
|
+
rescue
|
37
|
+
puts "Can't find the model: #{model}"
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_model_attrs
|
42
|
+
@model_pl = @model.to_s.humanize.downcase.pluralize
|
43
|
+
@columns = @model.columns.reject { |col|
|
44
|
+
['id','created_at','updated_at'].include?(col.name) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def generate_controller
|
48
|
+
generate "controller admin/#{@model_pl}"
|
49
|
+
template(
|
50
|
+
"app/controllers/admin/controller.rb.erb",
|
51
|
+
"app/controllers/admin/#{@model_pl}_controller.rb",
|
52
|
+
:force => true
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_routes
|
57
|
+
route = " namespace :admin do\n"
|
58
|
+
route += " resources :#{@model_pl}\n"
|
59
|
+
route += " end\n"
|
60
|
+
insert_into_file(
|
61
|
+
"config/routes.rb",
|
62
|
+
route,
|
63
|
+
:after => /mount\ Cambium\:(.*)\n/
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_config_file
|
68
|
+
template "config/admin/controller.yml.erb", "config/admin/#{@model_pl}.yml"
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_sidebar_item
|
72
|
+
config = "#{@model_pl}:\n"
|
73
|
+
config += " label: #{@model_pl.titleize}\n"
|
74
|
+
config += " route: main_app.admin_#{@model_pl}\n"
|
75
|
+
config += " icon: cog\n"
|
76
|
+
config += " controllers: ['#{@model_pl}']\n"
|
77
|
+
append_to_file("config/admin/sidebar.yml", config)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module Cambium
|
5
|
+
class GemfileGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
desc "Replace your existing Gemfile with Cambium's default Gemfile."
|
8
|
+
|
9
|
+
source_root File.expand_path('../../templates', __FILE__)
|
10
|
+
|
11
|
+
# Here we figure out some of the more complicated logic
|
12
|
+
# before rendering the Gemfile template
|
13
|
+
#
|
14
|
+
def resolve_options
|
15
|
+
@rails_version = `bundle exec rails -v`.to_s.split(' ').last
|
16
|
+
end
|
17
|
+
|
18
|
+
# Move our default Gemfile to the project's Gemfile.
|
19
|
+
#
|
20
|
+
def add_config_file
|
21
|
+
template "Gemfile.erb", "Gemfile", :force => true
|
22
|
+
gsub_file "Gemfile", /\n\n\n+?/, "\n\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def gem_root
|
28
|
+
Gem::Specification.find_by_name("cambium").gem_dir
|
29
|
+
end
|
30
|
+
|
31
|
+
def help_message(file)
|
32
|
+
puts File.read("#{gem_root}/lib/help/#{file}.txt")
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module Cambium
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Add Cambium config file to your initializers."
|
7
|
+
|
8
|
+
source_root File.expand_path('../../templates', __FILE__)
|
9
|
+
|
10
|
+
# Copy our Cambium config file into the project's
|
11
|
+
# config/initializers directory.
|
12
|
+
#
|
13
|
+
def add_config_file
|
14
|
+
config_file = "config/initializers/cambium.rb"
|
15
|
+
copy_file config_file, config_file
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module Cambium
|
5
|
+
class UserGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
desc "Create a new user for your app."
|
8
|
+
|
9
|
+
source_root File.expand_path('../../templates', __FILE__)
|
10
|
+
|
11
|
+
class_option(
|
12
|
+
:admin,
|
13
|
+
:type => :boolean,
|
14
|
+
:default => false,
|
15
|
+
:description => "Make the user an admin"
|
16
|
+
)
|
17
|
+
|
18
|
+
argument :email, :type => :string
|
19
|
+
argument :password, :type => :string
|
20
|
+
|
21
|
+
# Create a user with the provided credentials
|
22
|
+
def create_user
|
23
|
+
if options.admin == true
|
24
|
+
User.create!(
|
25
|
+
:email => email,
|
26
|
+
:password => password,
|
27
|
+
:password_confirmation => password,
|
28
|
+
:is_admin => options.admin
|
29
|
+
)
|
30
|
+
else
|
31
|
+
User.create!(
|
32
|
+
:email => email,
|
33
|
+
:password => password,
|
34
|
+
:password_confirmation => password
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -4,13 +4,13 @@ module Cambium
|
|
4
4
|
# ------------------------------------------ System Commands / Aliases
|
5
5
|
|
6
6
|
# Shorthand for `bundle exec`
|
7
|
-
#
|
7
|
+
#
|
8
8
|
def be
|
9
9
|
"bundle exec"
|
10
10
|
end
|
11
11
|
|
12
12
|
# Runs a system command, but with pretty output
|
13
|
-
#
|
13
|
+
#
|
14
14
|
def run_cmd(cmd, options = {})
|
15
15
|
print_table(
|
16
16
|
[
|
@@ -27,7 +27,7 @@ module Cambium
|
|
27
27
|
|
28
28
|
# Make sure we get a matching answer before moving on. Useful for usernames,
|
29
29
|
# passwords, and other items where user error is harmful (or painful)
|
30
|
-
#
|
30
|
+
#
|
31
31
|
def confirm_ask(question)
|
32
32
|
answer = ask("\n#{question}")
|
33
33
|
match = ask("CONFIRM #{question}")
|
@@ -40,13 +40,13 @@ module Cambium
|
|
40
40
|
end
|
41
41
|
|
42
42
|
# Run rake db:migrate
|
43
|
-
#
|
43
|
+
#
|
44
44
|
def migrate
|
45
45
|
rake "db:migrate"
|
46
46
|
end
|
47
47
|
|
48
48
|
# Annotate our models and tests
|
49
|
-
#
|
49
|
+
#
|
50
50
|
def annotate
|
51
51
|
# need to make sure we have the annotate gem to avoid errors
|
52
52
|
install_gem('annotate')
|
@@ -54,7 +54,7 @@ module Cambium
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# Run migrate and annotate
|
57
|
-
#
|
57
|
+
#
|
58
58
|
def migrate_and_annotate
|
59
59
|
migrate
|
60
60
|
annotate
|
@@ -63,7 +63,7 @@ module Cambium
|
|
63
63
|
# ------------------------------------------ Templating
|
64
64
|
|
65
65
|
# Copy template file to project unless it's already there
|
66
|
-
#
|
66
|
+
#
|
67
67
|
def copy_unless_exists(path, new_path = path)
|
68
68
|
copy_file(path, new_path) unless File.exists?("#{Rails.root}/#{new_path}")
|
69
69
|
end
|
@@ -73,20 +73,20 @@ module Cambium
|
|
73
73
|
end
|
74
74
|
|
75
75
|
# Get the path to a particular template
|
76
|
-
#
|
76
|
+
#
|
77
77
|
def template_file(name)
|
78
78
|
File.expand_path("../../templates/#{name}", __FILE__)
|
79
79
|
end
|
80
80
|
|
81
81
|
# Partial template path are for templates that aren't the entire file to be
|
82
82
|
# copied.
|
83
|
-
#
|
83
|
+
#
|
84
84
|
def template_partial_path(name)
|
85
85
|
File.expand_path("../../templates/_partials/#{name}", __FILE__)
|
86
86
|
end
|
87
87
|
|
88
88
|
# Read a template and return its contents
|
89
|
-
#
|
89
|
+
#
|
90
90
|
def file_contents(template)
|
91
91
|
File.read(template_file(template))
|
92
92
|
end
|
@@ -97,25 +97,25 @@ module Cambium
|
|
97
97
|
end
|
98
98
|
|
99
99
|
# Copies model concern templates to the project
|
100
|
-
#
|
100
|
+
#
|
101
101
|
def add_model_concern(name)
|
102
102
|
copy_unless_exists "app/models/concerns/#{name}.rb"
|
103
103
|
end
|
104
104
|
|
105
105
|
# Alias for previous method
|
106
|
-
#
|
106
|
+
#
|
107
107
|
def model_concern(name)
|
108
108
|
add_model_concern(name)
|
109
109
|
end
|
110
110
|
|
111
111
|
# Add multiple concerns
|
112
|
-
#
|
112
|
+
#
|
113
113
|
def add_model_concerns(concerns)
|
114
114
|
concerns.each { |c| add_model_concern(c) }
|
115
115
|
end
|
116
116
|
|
117
117
|
# Copy multiple directories
|
118
|
-
#
|
118
|
+
#
|
119
119
|
def directories(dir_arr, container)
|
120
120
|
dir_arr.each do |dir|
|
121
121
|
directory "#{container}/#{dir}", "#{container}/#{dir}"
|
@@ -125,14 +125,14 @@ module Cambium
|
|
125
125
|
# ------------------------------------------ Gems
|
126
126
|
|
127
127
|
# Run `bundle install`
|
128
|
-
#
|
128
|
+
#
|
129
129
|
def bundle
|
130
130
|
run_cmd "bundle install"
|
131
131
|
run_cmd "bundle clean"
|
132
132
|
end
|
133
133
|
|
134
134
|
# Get the local path where the gems are installed
|
135
|
-
#
|
135
|
+
#
|
136
136
|
def gem_dir
|
137
137
|
gem_dir = `bundle show rails`
|
138
138
|
gem_dir = gem_dir.split('/')
|
@@ -140,7 +140,7 @@ module Cambium
|
|
140
140
|
end
|
141
141
|
|
142
142
|
# Add gem to Gemfile
|
143
|
-
#
|
143
|
+
#
|
144
144
|
def add_to_gemfile(name, options = {})
|
145
145
|
unless gem_exists?(name)
|
146
146
|
if options[:require].present?
|
@@ -158,17 +158,17 @@ module Cambium
|
|
158
158
|
end
|
159
159
|
|
160
160
|
# Find if a gem exists
|
161
|
-
#
|
161
|
+
#
|
162
162
|
def gem_exists?(name)
|
163
163
|
Gem::Specification::find_all_by_name(name).any?
|
164
164
|
end
|
165
165
|
|
166
166
|
# First, install the gem in the local gem directory, then add it to the
|
167
167
|
# Gemfile (if it doesn't already exist).
|
168
|
-
#
|
168
|
+
#
|
169
169
|
# Note: This will run bundle install after adding the gem, unless specified
|
170
170
|
# otherwise.
|
171
|
-
#
|
171
|
+
#
|
172
172
|
def install_gem(name, options = {})
|
173
173
|
if gem_exists?(name)
|
174
174
|
say "Found existing gem: #{name}"
|
@@ -181,7 +181,7 @@ module Cambium
|
|
181
181
|
|
182
182
|
# Install an array of gems -- useful if needing to install more than one
|
183
183
|
# gem.
|
184
|
-
#
|
184
|
+
#
|
185
185
|
def install_gems(gem_arr)
|
186
186
|
gem_arr.each { |gem_name| install_gem(gem_name, :bundle => false) }
|
187
187
|
bundle
|
@@ -189,7 +189,7 @@ module Cambium
|
|
189
189
|
|
190
190
|
# Notifies the user of the gems that were installed and how desperately
|
191
191
|
# important they are.
|
192
|
-
#
|
192
|
+
#
|
193
193
|
def gem_installation_notification(gems)
|
194
194
|
say "\nThis generator installed the following gems (and added them to "
|
195
195
|
say "your Gemfile):\n\n"
|
@@ -199,7 +199,7 @@ module Cambium
|
|
199
199
|
|
200
200
|
# Similar to gem_installation_notification, except here we just tell the
|
201
201
|
# user we added gems to the gemfile and they will have to bundle
|
202
|
-
#
|
202
|
+
#
|
203
203
|
def gemfile_update_notification(gems)
|
204
204
|
say "\nThis generator added some gems to your Gemfile. You will want to "
|
205
205
|
say "run:\n\n $ bundle install"
|
@@ -210,7 +210,7 @@ module Cambium
|
|
210
210
|
# ------------------------------------------ Miscellaneous
|
211
211
|
|
212
212
|
# Return current time in migration timestamp format
|
213
|
-
#
|
213
|
+
#
|
214
214
|
def timestamp
|
215
215
|
Time.now.gmtime.strftime('%Y%m%d%H%M%S')
|
216
216
|
end
|
@@ -223,5 +223,13 @@ module Cambium
|
|
223
223
|
klass.is_a?(Class)
|
224
224
|
end
|
225
225
|
|
226
|
+
def gem_root
|
227
|
+
Gem::Specification.find_by_name("cambium").gem_dir
|
228
|
+
end
|
229
|
+
|
230
|
+
def help_message(file)
|
231
|
+
puts File.read("#{gem_root}/lib/help/#{file}.txt")
|
232
|
+
end
|
233
|
+
|
226
234
|
end
|
227
235
|
end
|