cambium 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/cambium.gemspec +25 -23
- data/lib/cambium/version.rb +1 -1
- data/lib/generators/cambium/helpers/_autoloader.rb +12 -0
- data/lib/generators/cambium/helpers/dependencies_helper.rb +58 -0
- data/lib/generators/cambium/helpers/generators_helper.rb +227 -0
- data/lib/generators/cambium/install/admin_generator.rb +68 -74
- data/lib/generators/cambium/install/app_generator.rb +86 -95
- data/lib/generators/cambium/install/config_generator.rb +98 -108
- data/lib/generators/cambium/install/utilities_generator.rb +2 -50
- data/lib/generators/cambium/model/image_generator.rb +67 -0
- data/lib/generators/cambium/model/page_generator.rb +131 -0
- data/lib/generators/cambium/model/post_generator.rb +71 -0
- data/lib/generators/cambium/model/tag_generator.rb +40 -0
- data/lib/generators/cambium/model/user_generator.rb +78 -0
- data/lib/generators/cambium/templates/Gemfile +43 -0
- data/lib/generators/cambium/templates/_partials/pages/admin_icon.rb +6 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/admin.js.coffee +3 -1
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/image.js.coffee +14 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/tag.js.coffee +14 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/parser_rules/custom.js +552 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/routers/router.js.coffee +21 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/tag.jst.ejs +7 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/image.jst.ejs +3 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/post_tag.jst.ejs +1 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/image_upload.js.coffee +28 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/tags.js.coffee +158 -0
- data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/wysiwyg.js.coffee +77 -0
- data/lib/generators/cambium/templates/app/controllers/admin/images_controller.rb +45 -0
- data/lib/generators/cambium/templates/app/controllers/admin/pages_controller.rb +42 -0
- data/lib/generators/cambium/templates/app/controllers/admin/posts_controller.rb +39 -0
- data/lib/generators/cambium/templates/app/controllers/admin/taggings_controller.rb +69 -0
- data/lib/generators/cambium/templates/app/controllers/admin/tags_controller.rb +11 -0
- data/lib/generators/cambium/templates/app/controllers/admin_controller.rb +11 -2
- data/lib/generators/cambium/templates/app/controllers/application_controller.rb +2 -2
- data/lib/generators/cambium/templates/app/controllers/images_controller.rb +45 -0
- data/lib/generators/cambium/templates/app/controllers/pages_controller.rb +12 -0
- data/lib/generators/cambium/templates/app/controllers/posts_controller.rb +11 -0
- data/lib/generators/cambium/templates/app/helpers/admin/pages_controller.rb +47 -0
- data/lib/generators/cambium/templates/app/helpers/admin_helper.rb +1 -1
- data/lib/generators/cambium/templates/app/models/concerns/image_cropper.rb +24 -0
- data/lib/generators/cambium/templates/app/models/concerns/publishable.rb +32 -4
- data/lib/generators/cambium/templates/app/models/concerns/slug.rb +4 -0
- data/lib/generators/cambium/templates/app/models/concerns/tags.rb +6 -1
- data/lib/generators/cambium/templates/app/models/image.rb +43 -0
- data/lib/generators/cambium/templates/app/models/page.rb +81 -0
- data/lib/generators/cambium/templates/app/models/post.rb +45 -0
- data/lib/generators/cambium/templates/app/models/tag.rb +33 -0
- data/lib/generators/cambium/templates/app/models/tagging.rb +20 -0
- data/lib/generators/cambium/templates/app/uploaders/image_uploader.rb +91 -0
- data/lib/generators/cambium/templates/app/views/admin/images/_image.html.erb +1 -0
- data/lib/generators/cambium/templates/app/views/admin/images/create.js.erb +7 -0
- data/lib/generators/cambium/templates/app/views/admin/images/index.json.jbuilder +4 -0
- data/lib/generators/cambium/templates/app/views/admin/pages/_form.html.erb +26 -0
- data/lib/generators/cambium/templates/app/views/admin/posts/_form.html.erb +40 -0
- data/lib/generators/cambium/templates/app/views/admin/shared/_insert_image.html.erb +12 -0
- data/lib/generators/cambium/templates/app/views/admin/shared/forms/_editor.html.erb +3 -3
- data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_page.html.erb +5 -1
- data/lib/generators/cambium/templates/app/views/home/index.html.erb +7 -0
- data/lib/generators/cambium/templates/app/views/page_templates/default.html.erb +2 -0
- data/lib/generators/cambium/templates/app/views/posts/_post.html.erb +4 -0
- data/lib/generators/cambium/templates/app/views/posts/index.html.erb +1 -0
- data/lib/generators/cambium/templates/app/views/posts/show.html.erb +10 -0
- data/lib/generators/cambium/templates/config/app_routes.rb +77 -0
- data/lib/generators/cambium/templates/config/routes.rb.erb +11 -2
- data/lib/generators/cambium/templates/db/migrate/create_pages.rb.erb +24 -0
- data/lib/generators/cambium/templates/db/migrate/create_posts.rb +19 -0
- data/lib/generators/cambium/templates/gitignore +1 -0
- metadata +52 -256
- data/lib/generators/cambium/install/users_generator.rb +0 -104
- data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_icons.scss +0 -5194
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'rake'
|
|
2
2
|
require 'rails/generators'
|
|
3
|
+
require File.expand_path('../../helpers/_autoloader.rb', __FILE__)
|
|
3
4
|
|
|
4
5
|
module Cambium
|
|
5
6
|
module Install
|
|
@@ -8,27 +9,34 @@ module Cambium
|
|
|
8
9
|
|
|
9
10
|
source_root File.expand_path('../../templates', __FILE__)
|
|
10
11
|
|
|
11
|
-
#
|
|
12
|
-
|
|
12
|
+
# Add a default public controller, so we have a working home page when
|
|
13
|
+
# we're done.
|
|
14
|
+
#
|
|
13
15
|
def add_home_controller
|
|
14
|
-
|
|
16
|
+
generate "controller home index"
|
|
17
|
+
gsub_file("config/routes.rb", /\ \ get\ \'home\/index\'\n\n/, '')
|
|
15
18
|
end
|
|
16
19
|
|
|
17
|
-
#
|
|
18
|
-
|
|
20
|
+
# Add our default routes, ommitting admin routes (which are added via the
|
|
21
|
+
# admin generator)
|
|
22
|
+
#
|
|
19
23
|
def add_default_routes
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
insert_into_file(
|
|
25
|
+
"config/routes.rb",
|
|
26
|
+
file_contents("config/app_routes.rb"),
|
|
27
|
+
:after => "Rails.application.routes.draw do"
|
|
28
|
+
)
|
|
22
29
|
end
|
|
23
30
|
|
|
24
|
-
#
|
|
25
|
-
|
|
31
|
+
# Add our default public views
|
|
32
|
+
#
|
|
26
33
|
def add_public_views
|
|
27
|
-
directory "app/views/application"
|
|
34
|
+
directory "app/views/application"
|
|
35
|
+
directory "app/views/home", :force => true
|
|
28
36
|
end
|
|
29
37
|
|
|
30
|
-
#
|
|
31
|
-
|
|
38
|
+
# Our layouts are templated so we can start with some custom information.
|
|
39
|
+
#
|
|
32
40
|
def add_layouts
|
|
33
41
|
@site_title = Rails.application.class.parent_name.humanize.titleize
|
|
34
42
|
site_title = ask "\n#{set_color('App Title:', :green, :bold)} [default: #{@site_title}]"
|
|
@@ -39,117 +47,100 @@ module Cambium
|
|
|
39
47
|
template app, app
|
|
40
48
|
end
|
|
41
49
|
|
|
42
|
-
#
|
|
43
|
-
|
|
50
|
+
# Backbone.js is our default javascript framework. We don't yet have an
|
|
51
|
+
# option to ignore, so here we automatically install it.
|
|
52
|
+
#
|
|
44
53
|
def install_backbone
|
|
45
54
|
directory "app/assets/javascripts/backbone",
|
|
46
55
|
"app/assets/javascripts"
|
|
47
56
|
end
|
|
48
57
|
|
|
58
|
+
# Next, we need to replace our application.js file to add backbone and its
|
|
59
|
+
# dependencies, along with our default scripts.
|
|
60
|
+
#
|
|
49
61
|
def default_application_js
|
|
50
62
|
app_js = "app/assets/javascripts/application.js"
|
|
51
63
|
remove_file app_js
|
|
52
64
|
template app_js, app_js
|
|
53
65
|
end
|
|
54
66
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# ------------------------------------------ Public Files
|
|
63
|
-
|
|
64
|
-
def add_public_router
|
|
65
|
-
remove_file "app/assets/javascripts/backbone/routers/.gitkeep"
|
|
66
|
-
template "app/assets/javascripts/backbone/routers/router.js.coffee",
|
|
67
|
-
"app/assets/javascripts/backbone/routers/router.js.coffee"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def add_default_view
|
|
71
|
-
remove_file "app/assets/javascripts/backbone/views/.gitkeep"
|
|
72
|
-
template "app/assets/javascripts/backbone/views/default_helpers.js.coffee",
|
|
73
|
-
"app/assets/javascripts/backbone/views/default_helpers.js.coffee"
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# ------------------------------------------ Add Modernizr
|
|
77
|
-
|
|
78
|
-
def add_modernizr
|
|
67
|
+
# Don't forget about modernizr! This is where all the other vendor scripts
|
|
68
|
+
# should be added, although today we only use Modernizr.
|
|
69
|
+
#
|
|
70
|
+
# Modernizr is called from the application layout since it is
|
|
71
|
+
# automatically added.
|
|
72
|
+
#
|
|
73
|
+
def add_other_vendor_javascripts
|
|
79
74
|
modernizr = "vendor/assets/javascripts/modernizr.js"
|
|
80
75
|
copy_file modernizr, modernizr
|
|
81
76
|
end
|
|
82
77
|
|
|
83
|
-
#
|
|
78
|
+
# Now we need to add our styles. We begin here by adding our vendor styles
|
|
79
|
+
# that are not already available via a gem.
|
|
80
|
+
#
|
|
81
|
+
def add_vendor_styles
|
|
82
|
+
normalize = "vendor/assets/stylesheets/normalize.scss"
|
|
83
|
+
template normalize, normalize
|
|
84
|
+
end
|
|
84
85
|
|
|
86
|
+
# Once we have the files and gems we need, we can add our public manifest
|
|
87
|
+
# file. We ask the user if they are ok with us deleting theirs.
|
|
88
|
+
#
|
|
89
|
+
# Note: Injecting seems easier here, and it would be, but we can't predict
|
|
90
|
+
# the name of this file, which is why we don't do it. It could be done
|
|
91
|
+
# with a longer method.
|
|
92
|
+
#
|
|
85
93
|
def add_public_manifest
|
|
86
|
-
|
|
94
|
+
q = "\nWe're going to add our default application.scss file and remove yours. Is that ok?"
|
|
95
|
+
if yes? q
|
|
96
|
+
['css','scss','scss.css'].each { |ext| remove_file "app/assets/stylesheets/application.#{ext}" }
|
|
97
|
+
end
|
|
87
98
|
template "app/assets/stylesheets/application.scss",
|
|
88
99
|
"app/assets/stylesheets/application.scss"
|
|
89
100
|
end
|
|
90
101
|
|
|
91
|
-
#
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
# If we have the user model generated, then we will try to create a
|
|
103
|
+
# default user.
|
|
104
|
+
#
|
|
105
|
+
def add_default_user
|
|
106
|
+
if class_exists?('User')
|
|
107
|
+
create_user
|
|
108
|
+
else
|
|
109
|
+
msg = "\nUser model does not exist yet. If you want to use Cambium "
|
|
110
|
+
msg += "to add a user model, then you can run:\n"
|
|
111
|
+
say set_color(msg, :yellow, :bold)
|
|
112
|
+
say " $ bundle exec rake cambium:model:user\n\n"
|
|
113
|
+
msg = "and Cambium will handle the installation of Devise.\n"
|
|
114
|
+
say set_color(msg, :yellow, :bold)
|
|
115
|
+
end
|
|
96
116
|
end
|
|
97
117
|
|
|
98
|
-
#
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
118
|
+
# Add some gems to the gemfile, but don't install (we've been running into
|
|
119
|
+
# dependency issues)
|
|
120
|
+
#
|
|
121
|
+
def add_application_gems
|
|
122
|
+
gems = [
|
|
123
|
+
'unicorn-rails',
|
|
124
|
+
'jquery-rails',
|
|
125
|
+
'uglifier',
|
|
126
|
+
'sass-rails',
|
|
127
|
+
'bourbon',
|
|
128
|
+
'coffee-rails',
|
|
129
|
+
'backbone-on-rails'
|
|
130
|
+
]
|
|
131
|
+
add_gems_to_gemfile(gems)
|
|
132
|
+
added_gems = []
|
|
133
|
+
gems.each { |g| added_gems << g unless gem_exists?(g) }
|
|
134
|
+
gemfile_update_notification(added_gems)
|
|
102
135
|
end
|
|
103
136
|
|
|
104
137
|
# ------------------------------------------ Private Methods
|
|
105
138
|
|
|
106
139
|
private
|
|
107
140
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
[set_color("run", :green, :bold), cmd]
|
|
112
|
-
],
|
|
113
|
-
:indent => 9
|
|
114
|
-
)
|
|
115
|
-
if options[:quiet] == true
|
|
116
|
-
`#{cmd}`
|
|
117
|
-
else
|
|
118
|
-
system(cmd)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def template_file(name)
|
|
123
|
-
File.expand_path("../../templates/#{name}", __FILE__)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def file_contents(template)
|
|
127
|
-
File.read(template_file(template))
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def be
|
|
131
|
-
"bundle exec"
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def g
|
|
135
|
-
"#{be} rails g"
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def rake
|
|
139
|
-
"#{be} rake"
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def confirm_ask(question)
|
|
143
|
-
answer = ask("\n#{question}")
|
|
144
|
-
match = ask("CONFIRM #{question}")
|
|
145
|
-
if answer == match
|
|
146
|
-
answer
|
|
147
|
-
else
|
|
148
|
-
say set_color("Did not match.", :red)
|
|
149
|
-
confirm_ask(question)
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
141
|
+
# create_user is down here because it can then keep looping until a
|
|
142
|
+
# valid record is created.
|
|
143
|
+
#
|
|
153
144
|
def create_user
|
|
154
145
|
email = confirm_ask "#{set_color('Default User Email', :green, :bold)}:"
|
|
155
146
|
password = confirm_ask "#{set_color('Default User Password', :green, :bold)}:"
|
|
@@ -157,8 +148,8 @@ module Cambium
|
|
|
157
148
|
:email => email,
|
|
158
149
|
:password => password,
|
|
159
150
|
:password_confirmation => password,
|
|
160
|
-
:is_admin => true
|
|
161
151
|
)
|
|
152
|
+
u.is_admin = true if u.respond_to?(:is_admin)
|
|
162
153
|
if u.save
|
|
163
154
|
say "User created successfully!"
|
|
164
155
|
else
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
require 'rake'
|
|
2
2
|
require 'rails/generators'
|
|
3
|
+
require File.expand_path('../../helpers/_autoloader.rb', __FILE__)
|
|
3
4
|
|
|
4
5
|
module Cambium
|
|
5
6
|
module Install
|
|
6
7
|
class ConfigGenerator < Rails::Generators::Base
|
|
7
8
|
desc "Setup config files for new rails project"
|
|
8
9
|
|
|
9
|
-
# ------------------------------------------ Class Methods
|
|
10
|
-
|
|
11
10
|
source_root File.expand_path('../../templates', __FILE__)
|
|
12
11
|
|
|
13
|
-
#
|
|
14
|
-
|
|
12
|
+
# Initialize git repository. If repo was already initialized, repo is
|
|
13
|
+
# reinitialized, but that shouldn't hurt anything.
|
|
14
|
+
#
|
|
15
15
|
def git_init
|
|
16
16
|
run_cmd "git init"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
# Set vars to use throughout this generator
|
|
20
|
+
#
|
|
19
21
|
def cambium_setup
|
|
20
22
|
@config = {
|
|
21
23
|
:db => {},
|
|
@@ -23,11 +25,13 @@ module Cambium
|
|
|
23
25
|
}
|
|
24
26
|
end
|
|
25
27
|
|
|
28
|
+
# Read existing project files to set default config values
|
|
29
|
+
#
|
|
26
30
|
def auto_config
|
|
27
|
-
#
|
|
31
|
+
# read Gemfile
|
|
28
32
|
File.open("#{Rails.root}/Gemfile") do |f|
|
|
29
33
|
f.each_line do |line|
|
|
30
|
-
#
|
|
34
|
+
# find database adapter
|
|
31
35
|
if line.include?("'mysql2'")
|
|
32
36
|
@config[:db][:adapter] = "mysql2"
|
|
33
37
|
elsif line.include?("'pg'")
|
|
@@ -35,157 +39,143 @@ module Cambium
|
|
|
35
39
|
elsif line.include?("'sqlite3'")
|
|
36
40
|
@config[:db][:adapter] = "sqlite3"
|
|
37
41
|
end
|
|
38
|
-
#
|
|
42
|
+
# find rails version
|
|
39
43
|
if line.match(/gem\ \'rails\'/)
|
|
40
44
|
@config[:app][:version] = line.gsub(/gem\ \'rails\'\,/, '').gsub(/\'/, '').strip
|
|
41
45
|
end
|
|
42
46
|
end
|
|
43
47
|
end
|
|
44
|
-
#
|
|
48
|
+
# Find the application class name
|
|
45
49
|
@config[:app][:name] = Rails.application.class.parent_name
|
|
46
50
|
end
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
# These next few methods let the user adjust the default config if they
|
|
53
|
+
# wish. Otherwise, we use default values from the previous method.
|
|
54
|
+
#
|
|
55
|
+
# --------
|
|
56
|
+
#
|
|
57
|
+
# Set correct database adapter.
|
|
58
|
+
#
|
|
59
|
+
# Note: If the user wants to change the adapter, we *could* change the
|
|
60
|
+
# adapter on the fly and install the new one here. Instead, we tell the
|
|
61
|
+
# user what to do and exit. This make absolutely sure we've gotten rid of
|
|
62
|
+
# the original adapter in the Gemfile and added the new one.
|
|
63
|
+
#
|
|
64
|
+
def set_database_adapter
|
|
65
|
+
if @config[:db][:adapter].present?
|
|
66
|
+
if yes?("\nCambium, in all its wisdom, thinks your database adapter as #{set_color(@config[:db][:adapter], :green, :bold)}. Is this correct? [yes, no]")
|
|
67
|
+
say("Oh, goodie! Moving on...")
|
|
68
|
+
else
|
|
69
|
+
new_adapter = ask("What would you prefer?", :limited_to => ['mysql2','pg','sqlite3'])
|
|
70
|
+
unless new_adapter == @config[:db][:adapter]
|
|
71
|
+
say set_color("\nPlease add:", :red, :bold)
|
|
72
|
+
say "\n gem '#{new_adapter}'"
|
|
73
|
+
say set_color("\nto your Gemfile. Then run `bundle install` and `bundle exec cambium setup`.", :red, :bold)
|
|
74
|
+
exit
|
|
75
|
+
end
|
|
59
76
|
end
|
|
60
77
|
end
|
|
78
|
+
end
|
|
61
79
|
|
|
62
|
-
|
|
80
|
+
# Set the database base name (where we append "_#{stage}" to each stage)
|
|
81
|
+
#
|
|
82
|
+
def set_database_name
|
|
63
83
|
@config[:db][:name] = @config[:app][:name].underscore.downcase
|
|
64
84
|
db_name = ask "\n#{set_color('Database Base Name:', :green, :bold)} [default: #{@config[:db][:name]}]"
|
|
65
85
|
@config[:db][:name] = db_name unless db_name.blank?
|
|
86
|
+
end
|
|
66
87
|
|
|
67
|
-
|
|
88
|
+
# Set database credentials
|
|
89
|
+
#
|
|
90
|
+
def set_database_creds
|
|
68
91
|
@config[:db][:user] = confirm_ask("#{set_color('Database User', :green, :bold)}: [leave blank for no user]")
|
|
69
92
|
if @config[:db][:user].present?
|
|
70
93
|
@config[:db][:password] = confirm_ask("#{set_color('Database Password', :green, :bold)}: [leave blank for no password]")
|
|
71
94
|
else
|
|
72
95
|
@config[:db][:password] = ''
|
|
73
96
|
end
|
|
97
|
+
end
|
|
74
98
|
|
|
75
|
-
|
|
99
|
+
# Set root URL (for mailers)
|
|
100
|
+
#
|
|
101
|
+
def set_root_url
|
|
102
|
+
# development
|
|
76
103
|
@config[:app][:dev_url] = ask("\n#{set_color('Development URL', :green, :bold)}: [leave blank for localhost:3000]")
|
|
77
104
|
@config[:app][:dev_url] = 'localhost:3000' if @config[:app][:dev_url].blank?
|
|
105
|
+
environment(
|
|
106
|
+
"config.action_mailer.default_url_options = { :host => '#{@config[:app][:dev_url]}' }",
|
|
107
|
+
:env => "development"
|
|
108
|
+
)
|
|
109
|
+
# production
|
|
78
110
|
@config[:app][:prod_url] = ask("#{set_color('Production URL', :green, :bold)}: [leave blank for localhost:3000]")
|
|
79
111
|
@config[:app][:prod_url] = 'localhost:3000' if @config[:app][:prod_url].blank?
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
run_cmd "bundle clean"
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# ------------------------------------------ Application Settings & Config
|
|
91
|
-
|
|
92
|
-
def add_application_config
|
|
93
|
-
insert_into_file(
|
|
94
|
-
"config/application.rb",
|
|
95
|
-
file_contents("config/application.rb"),
|
|
96
|
-
:after => "class Application < Rails::Application"
|
|
112
|
+
environment(
|
|
113
|
+
"config.action_mailer.default_url_options = { :host => '#{@config[:app][:prod_url]}' }",
|
|
114
|
+
:env => "production"
|
|
115
|
+
)
|
|
116
|
+
environment(
|
|
117
|
+
"config.assets.precompile += %w( admin/admin.css admin/admin.js admin/wysihtml5.css modernizr.js )",
|
|
118
|
+
:env => "production"
|
|
97
119
|
)
|
|
98
120
|
end
|
|
99
121
|
|
|
100
|
-
#
|
|
101
|
-
|
|
102
|
-
def
|
|
103
|
-
|
|
104
|
-
:after => "Rails.application.configure do" do
|
|
105
|
-
"\n\n config.action_mailer.default_url_options = { :host => '#{@config[:app][:dev_url]}' }\n"
|
|
106
|
-
end
|
|
107
|
-
insert_into_file "config/environments/production.rb",
|
|
108
|
-
:after => "Rails.application.configure do" do
|
|
109
|
-
output = ''
|
|
110
|
-
output += "\n\n config.action_mailer.default_url_options = { :host => '#{@config[:app][:prod_url]}' }"
|
|
111
|
-
output += "\n\n config.assets.precompile += %w( admin/admin.css admin/admin.js admin/wysihtml5.css modernizr.js )\n"
|
|
112
|
-
output
|
|
113
|
-
end
|
|
122
|
+
# Add settings to application config file (config/application.rb)
|
|
123
|
+
#
|
|
124
|
+
def add_application_config
|
|
125
|
+
environment { file_contents("config/application.rb") }
|
|
114
126
|
end
|
|
115
127
|
|
|
116
|
-
#
|
|
117
|
-
|
|
128
|
+
# Assets initializer for Rails 4.1+
|
|
129
|
+
#
|
|
118
130
|
def add_assets_initializer
|
|
119
131
|
template "config/initializers/assets.rb",
|
|
120
132
|
"config/initializers/assets.rb"
|
|
121
133
|
end
|
|
122
134
|
|
|
123
|
-
#
|
|
124
|
-
|
|
135
|
+
# Create database based on custom config
|
|
136
|
+
#
|
|
125
137
|
def setup_database
|
|
126
138
|
copy_file "#{Rails.root}/config/database.yml", "config/database.sample.yml"
|
|
127
139
|
remove_file "config/database.yml"
|
|
128
140
|
template "config/database.#{@config[:db][:adapter]}.yml.erb", "config/database.yml"
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
run_cmd "#{rake} db:migrate"
|
|
141
|
+
rake "db:create"
|
|
142
|
+
rake "db:migrate"
|
|
132
143
|
end
|
|
133
144
|
|
|
134
|
-
#
|
|
135
|
-
|
|
145
|
+
# Add custom gitignore file
|
|
146
|
+
#
|
|
136
147
|
def add_gitignore
|
|
137
148
|
remove_file ".gitignore"
|
|
138
149
|
template "gitignore", ".gitignore"
|
|
139
150
|
end
|
|
140
151
|
|
|
141
|
-
#
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
File.expand_path("../../templates/#{name}", __FILE__)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def file_contents(template)
|
|
164
|
-
File.read(template_file(template))
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def be
|
|
168
|
-
"bundle exec"
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def g
|
|
172
|
-
"#{be} rails g"
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def rake
|
|
176
|
-
"#{be} rake"
|
|
152
|
+
# We used to start the user out by installing all the gems we will need
|
|
153
|
+
# throughout the project. Now, we're going to ask the user if they want to
|
|
154
|
+
# replace their Gemfile with our custom file. If they say "no," then we
|
|
155
|
+
# will install the gems we need at a later step.
|
|
156
|
+
#
|
|
157
|
+
def add_recommended_gems
|
|
158
|
+
msg = "\nWe have a set of gems we recommend by default. You can \n"
|
|
159
|
+
msg += "start with this Gemfile if you'd like. Of course, we'll \n"
|
|
160
|
+
msg += "install gems for you when we need them."
|
|
161
|
+
say msg
|
|
162
|
+
if yes? "\nWould you like to replace your existing Gemfile with our default?"
|
|
163
|
+
remove_file "Gemfile"
|
|
164
|
+
template "Gemfile.erb", "Gemfile"
|
|
165
|
+
say "\nYour Gemfile has been updated, but now you need to run:"
|
|
166
|
+
say "\n $ bundle install"
|
|
167
|
+
say "\nto install all your gems. Feel free to any gems you don't want, "
|
|
168
|
+
say "\nsince we will add gems to your project as we need them."
|
|
169
|
+
else
|
|
170
|
+
say "You got it!"
|
|
177
171
|
end
|
|
172
|
+
end
|
|
178
173
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
else
|
|
185
|
-
say set_color("Did not match.", :red)
|
|
186
|
-
confirm_ask(question)
|
|
187
|
-
end
|
|
188
|
-
end
|
|
174
|
+
# Outgoing message
|
|
175
|
+
#
|
|
176
|
+
def tell_user_we_are_done
|
|
177
|
+
say "\n#{set_color('Config completed!', :green, :bold)}"
|
|
178
|
+
end
|
|
189
179
|
|
|
190
180
|
end
|
|
191
181
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
require 'rake'
|
|
2
2
|
require 'rails/generators'
|
|
3
|
+
require "#{Gem::Specification.find_by_name("cambium").gem_dir}/lib/generators/cambium/helpers/generators_helper.rb"
|
|
4
|
+
include Cambium::GeneratorsHelper
|
|
3
5
|
|
|
4
6
|
module Cambium
|
|
5
7
|
module Install
|
|
@@ -18,7 +20,6 @@ module Cambium
|
|
|
18
20
|
'name',
|
|
19
21
|
'publishable',
|
|
20
22
|
'slug',
|
|
21
|
-
'tags',
|
|
22
23
|
'title',
|
|
23
24
|
].each do |concern|
|
|
24
25
|
copy_file "app/models/concerns/#{concern}.rb",
|
|
@@ -51,55 +52,6 @@ module Cambium
|
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
54
|
|
|
54
|
-
# ------------------------------------------ Private Methods
|
|
55
|
-
|
|
56
|
-
private
|
|
57
|
-
|
|
58
|
-
def run_cmd(cmd, options = {})
|
|
59
|
-
print_table(
|
|
60
|
-
[
|
|
61
|
-
[set_color("run", :green, :bold), cmd]
|
|
62
|
-
],
|
|
63
|
-
:indent => 9
|
|
64
|
-
)
|
|
65
|
-
if options[:quiet] == true
|
|
66
|
-
`#{cmd}`
|
|
67
|
-
else
|
|
68
|
-
system(cmd)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def template_file(name)
|
|
73
|
-
File.expand_path("../../templates/#{name}", __FILE__)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def file_contents(template)
|
|
77
|
-
File.read(template_file(template))
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def be
|
|
81
|
-
"bundle exec"
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def g
|
|
85
|
-
"#{be} rails g"
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def rake
|
|
89
|
-
"#{be} rake"
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def confirm_ask(question)
|
|
93
|
-
answer = ask("\n#{question}")
|
|
94
|
-
match = ask("Confirm: #{question}")
|
|
95
|
-
if answer == match
|
|
96
|
-
answer
|
|
97
|
-
else
|
|
98
|
-
say set_color("Did not match.", :red)
|
|
99
|
-
confirm_ask(question)
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
55
|
end
|
|
104
56
|
end
|
|
105
57
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rails/generators'
|
|
3
|
+
require File.expand_path('../../helpers/_autoloader.rb', __FILE__)
|
|
4
|
+
|
|
5
|
+
module Cambium
|
|
6
|
+
module Model
|
|
7
|
+
class ImageGenerator < Rails::Generators::Base
|
|
8
|
+
desc "Create a simple image model"
|
|
9
|
+
|
|
10
|
+
source_root File.expand_path('../../templates', __FILE__)
|
|
11
|
+
|
|
12
|
+
# Let's make sure we have the admin setup already.
|
|
13
|
+
#
|
|
14
|
+
def set_dependencies
|
|
15
|
+
check_dependencies(['cambium:install:admin'])
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Install gems we need for images
|
|
19
|
+
#
|
|
20
|
+
def install_gem_dependencies
|
|
21
|
+
install_gem 'carrierwave'
|
|
22
|
+
install_gem 'rmagick', :require => 'RMagick'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Since the Image model is so simple, we can generate it from the command
|
|
26
|
+
# line instead of copying templates.
|
|
27
|
+
#
|
|
28
|
+
def generate_model
|
|
29
|
+
generate "model Image filename"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Add our pre-built model file
|
|
33
|
+
#
|
|
34
|
+
def add_model_files
|
|
35
|
+
copy_file("app/models/image.rb", "app/models/image.rb", :force => true)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Add our image uploader, which uses CarrierWave
|
|
39
|
+
#
|
|
40
|
+
def add_uploaders
|
|
41
|
+
generate "uploader Image"
|
|
42
|
+
uploader_path = "app/uploaders/image_uploader.rb"
|
|
43
|
+
copy_file uploader_path, uploader_path, :force => true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Add our image cropper model concern. Currently, we don't have the
|
|
47
|
+
# cropping tool functional within the admin.
|
|
48
|
+
#
|
|
49
|
+
def add_model_concerns
|
|
50
|
+
add_model_concern 'image_cropper'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Before we finish up, we need to add our admin files.
|
|
54
|
+
#
|
|
55
|
+
def add_admin_files
|
|
56
|
+
template("app/controllers/admin/images_controller.rb",
|
|
57
|
+
"app/controllers/admin/images_controller.rb")
|
|
58
|
+
directory("app/views/admin/images", "app/views/admin/images")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def finish_up
|
|
62
|
+
migrate_and_annotate
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|