railsthemes 1.1.pre → 1.1.pre.2
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.
- data/Gemfile +2 -2
- data/bin/railsthemes +27 -12
- data/cacert.pem +3331 -0
- data/lib/railsthemes/email_installer.rb +73 -0
- data/lib/railsthemes/ensurer.rb +152 -0
- data/lib/railsthemes/installer.rb +116 -345
- data/lib/railsthemes/logging.rb +35 -0
- data/lib/railsthemes/theme_installer.rb +126 -0
- data/lib/railsthemes/utils.rb +116 -24
- data/lib/railsthemes/version.rb +1 -1
- data/lib/railsthemes.rb +22 -1
- data/railsthemes.gemspec +2 -0
- data/spec/fixtures/blank-assets/{base/app/assets/images/bg/sprite.png → email/app/assets/stylesheets/email.css} +0 -0
- data/spec/fixtures/blank-assets/{base/app/assets/images/image1.png → erb-css/base/app/assets/images/bg/sprite.png} +0 -0
- data/spec/fixtures/blank-assets/{base/app/assets/javascripts/jquery.dataTables.js → erb-css/base/app/assets/images/image1.png} +0 -0
- data/spec/fixtures/blank-assets/{base/app/assets/javascripts/scripts.js.erb → erb-css/base/app/assets/javascripts/jquery.dataTables.js} +0 -0
- data/spec/fixtures/blank-assets/{base/app/views/layouts/_interior_sidebar.html.erb → erb-css/base/app/assets/javascripts/scripts.js.erb} +0 -0
- data/spec/fixtures/blank-assets/{base → erb-css/base}/app/assets/stylesheets/style.css.erb +0 -0
- data/spec/fixtures/blank-assets/{base/app/views/layouts/application.html.erb → erb-css/base/app/views/layouts/_interior_sidebar.html.erb} +0 -0
- data/spec/fixtures/blank-assets/{base/app/views/layouts/homepage.html.erb → erb-css/base/app/views/layouts/application.html.erb} +0 -0
- data/spec/fixtures/blank-assets/{gems/formtastic/app/assets/stylesheets/formtastic.css.scss → erb-css/base/app/views/layouts/homepage.html.erb} +0 -0
- data/spec/fixtures/blank-assets/{gems/simple_form/app/assets/stylesheets/simple_form.css.scss → erb-css/gems/formtastic/app/assets/stylesheets/formtastic.css.scss} +0 -0
- data/spec/fixtures/blank-assets/erb-css/gems/simple_form/app/assets/stylesheets/simple_form.css.scss +0 -0
- data/spec/fixtures/{blank-assets.tar.gz → blank-assets-archived/email.tar.gz} +0 -0
- data/spec/fixtures/blank-assets-archived/erb-css.tar.gz +0 -0
- data/spec/lib/railsthemes/email_installer_spec.rb +8 -0
- data/spec/lib/railsthemes/ensurer_spec.rb +215 -0
- data/spec/lib/railsthemes/installer_spec.rb +100 -456
- data/spec/lib/railsthemes/theme_installer_spec.rb +206 -0
- data/spec/lib/railsthemes/utils_spec.rb +62 -0
- data/spec/spec_helper.rb +49 -0
- metadata +71 -26
- data/lib/railsthemes/win_cacerts.rb +0 -26
@@ -1,372 +1,136 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'date'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'logger'
|
5
|
-
require 'tmpdir'
|
6
|
-
require 'bundler'
|
7
|
-
require 'net/http'
|
8
|
-
require 'rest-client'
|
9
|
-
require 'launchy'
|
10
|
-
|
11
1
|
module Railsthemes
|
12
|
-
class Installer
|
13
|
-
|
14
|
-
|
15
|
-
|
2
|
+
class Installer < Thor
|
3
|
+
no_tasks do
|
4
|
+
include Railsthemes::Logging
|
5
|
+
include Thor::Actions
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
def initialize
|
8
|
+
@doc_popup = true
|
9
|
+
@installed_email = false
|
20
10
|
end
|
21
11
|
|
22
|
-
|
23
|
-
|
24
|
-
@server = File.read('railsthemes_server').gsub("\n", '')
|
12
|
+
def doc_popup= doc_popup
|
13
|
+
@doc_popup = doc_popup
|
25
14
|
end
|
26
15
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@doc_popup = doc_popup
|
32
|
-
end
|
33
|
-
|
34
|
-
def verbose
|
35
|
-
@logger.level = Logger::INFO
|
36
|
-
@logger.info 'In verbose mode.'
|
37
|
-
end
|
38
|
-
|
39
|
-
def debug
|
40
|
-
@logger.level = Logger::DEBUG
|
41
|
-
@logger.debug 'In debug mode.'
|
42
|
-
end
|
43
|
-
|
44
|
-
def ensure_in_rails_root
|
45
|
-
unless File.directory?('app') && File.directory?('public')
|
46
|
-
Safe.log_and_abort 'Must be in the Rails root directory to use this gem.'
|
16
|
+
# can probably just make static
|
17
|
+
def theme_installer
|
18
|
+
@theme_installer ||= ThemeInstaller.new
|
19
|
+
@theme_installer
|
47
20
|
end
|
48
|
-
end
|
49
21
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
22
|
+
# can probably just make static
|
23
|
+
def email_installer
|
24
|
+
@email_installer ||= EmailInstaller.new
|
25
|
+
@email_installer
|
26
|
+
end
|
54
27
|
|
55
|
-
|
28
|
+
def popup_documentation
|
29
|
+
style_guide = Dir['doc/*Usage_And_Style_Guide.html'].first
|
30
|
+
logger.debug("style_guide: #{style_guide}")
|
31
|
+
Launchy.open(style_guide) if style_guide
|
32
|
+
end
|
56
33
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
Utils.remove_file('app/views/layouts/application.html.erb')
|
34
|
+
# primary method
|
35
|
+
def install_from_file_system original_source_filepath
|
36
|
+
Ensurer.ensure_clean_install_possible
|
61
37
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
FileUtils.mkdir_p(dest)
|
70
|
-
else
|
71
|
-
unless (dest =~ /railsthemes_.*_overrides\.*/ && File.exists?(dest)) ||
|
72
|
-
src =~ /\/\./ # remove any pesky hidden files that crept into the archive
|
73
|
-
@logger.debug "cp #{src} #{dest}"
|
74
|
-
FileUtils.cp(src, dest)
|
75
|
-
end
|
76
|
-
end
|
38
|
+
# install main theme
|
39
|
+
config = Utils.get_primary_configuration
|
40
|
+
filepath = File.join(original_source_filepath, config.join('-'))
|
41
|
+
if File.directory?(filepath) || Utils.archive?(filepath + '.tar.gz')
|
42
|
+
theme_installer.install_from_file_system filepath
|
43
|
+
else
|
44
|
+
Safe.log_and_abort "Could not find the file you need: #{filepath}"
|
77
45
|
end
|
78
46
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
47
|
+
# install email theme if present
|
48
|
+
filepath = File.join(original_source_filepath, 'email')
|
49
|
+
if File.directory?(filepath) || Utils.archive?(filepath + '.tar.gz')
|
50
|
+
email_installer.install_from_file_system filepath
|
51
|
+
@installed_email = true
|
52
|
+
else
|
53
|
+
# no email to install... moving along
|
54
|
+
end
|
83
55
|
|
84
|
-
post_copying_changes
|
85
56
|
print_post_installation_instructions
|
86
57
|
popup_documentation if @doc_popup
|
87
|
-
elsif archive?(source_filepath)
|
88
|
-
if File.exists?(source_filepath)
|
89
|
-
install_from_archive source_filepath
|
90
|
-
# no need for post_installation, because we will do this in the
|
91
|
-
# install_from_archive method
|
92
|
-
else
|
93
|
-
Safe.log_and_abort 'Cannot find the file you specified.'
|
94
|
-
end
|
95
|
-
else
|
96
|
-
print_usage_and_abort 'Need to specify either a directory or an archive file when --file is used.'
|
97
58
|
end
|
98
|
-
end
|
99
59
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
Launchy.open(style_guide) if style_guide
|
104
|
-
end
|
60
|
+
# primary method
|
61
|
+
def install_from_code code
|
62
|
+
Ensurer.ensure_clean_install_possible
|
105
63
|
|
106
|
-
|
107
|
-
|
108
|
-
@logger.debug "gem_names: #{gem_names * ' '}"
|
109
|
-
gems_that_we_can_install = Dir.entries("#{source_filepath}/gems").reject{|x| x == '.' || x == '..'}
|
110
|
-
@logger.debug "gems_that_we_can_install: #{gems_that_we_can_install * ' '}"
|
111
|
-
(gem_names & gems_that_we_can_install).each do |gem_name|
|
112
|
-
src = File.join(source_filepath, 'gems', gem_name, '.')
|
113
|
-
@logger.debug("copying gems from #{src}")
|
114
|
-
FileUtils.cp_r(src, '.')
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def install_from_archive filepath
|
119
|
-
@logger.warn "Extracting..."
|
120
|
-
with_tempdir do |tempdir|
|
121
|
-
io = Tar.ungzip(File.open(filepath, 'rb'))
|
122
|
-
Tar.untar(io, tempdir)
|
64
|
+
logger.warn "Figuring out what to download..."
|
65
|
+
send_gemfile code
|
123
66
|
|
124
|
-
|
125
|
-
install_from_file_system tempdir
|
126
|
-
end
|
127
|
-
end
|
67
|
+
dl_hash = get_download_hash code
|
128
68
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
else
|
134
|
-
version_is_bad_message = check_installer_version
|
135
|
-
if version_is_bad_message
|
136
|
-
Safe.log_and_abort version_is_bad_message
|
137
|
-
else
|
138
|
-
if File.exists?('Gemfile.lock') && Gem::Version.new('3.1') <= rails_version
|
139
|
-
install_from_server code
|
140
|
-
else
|
141
|
-
ask_to_install_unsupported code
|
69
|
+
if dl_hash
|
70
|
+
Utils.with_tempdir do |tempdir|
|
71
|
+
download_from_hash dl_hash, tempdir
|
72
|
+
install_from_file_system tempdir
|
142
73
|
end
|
74
|
+
else
|
75
|
+
Safe.log_and_abort("We didn't recognize the code you gave to download the theme (#{code}). It should look something like your@email.com:ABCDEF.")
|
143
76
|
end
|
144
77
|
end
|
145
|
-
end
|
146
78
|
|
147
|
-
def check_installer_version
|
148
|
-
begin
|
149
|
-
response = Utils.get_url(@server + '/installer/version')
|
150
|
-
rescue SocketError => e
|
151
|
-
Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
|
152
|
-
rescue Exception => e
|
153
|
-
@logger.info e.message
|
154
|
-
@logger.info e.backtrace * "\n"
|
155
|
-
end
|
156
79
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
80
|
+
def get_download_hash code
|
81
|
+
config = Utils.get_primary_configuration
|
82
|
+
server_request_url = "#{Railsthemes.server}/download?code=#{code}&config=#{config * ','}&v=2"
|
83
|
+
response = nil
|
84
|
+
begin
|
85
|
+
response = Utils.get_url server_request_url
|
86
|
+
rescue SocketError => e
|
87
|
+
Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
|
88
|
+
rescue Exception => e
|
89
|
+
logger.debug e.message
|
90
|
+
logger.debug e.backtrace
|
91
|
+
end
|
161
92
|
|
162
|
-
if
|
163
|
-
|
164
|
-
Your version is older than the recommended version.
|
165
|
-
Your version: #{Railsthemes::VERSION}
|
166
|
-
Recommended version: #{server_recommended_version_string}
|
167
|
-
EOS
|
93
|
+
if response && response.code.to_s == '200'
|
94
|
+
JSON.parse(response.body)
|
168
95
|
else
|
169
|
-
@logger.debug "server recommended version: #{server_recommended_version_string}"
|
170
96
|
nil
|
171
97
|
end
|
172
|
-
else
|
173
|
-
'There was an issue checking your installer version.'
|
174
98
|
end
|
175
|
-
end
|
176
99
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
100
|
+
def download_from_hash dl_hash, download_to
|
101
|
+
url = dl_hash['theme']
|
102
|
+
if url
|
103
|
+
logger.warn "Downloading main theme..."
|
104
|
+
config = Utils.get_primary_configuration
|
105
|
+
archive = File.join(download_to, "#{config.join('-')}.tar.gz")
|
106
|
+
Utils.download :url => url, :save_to => archive
|
107
|
+
logger.warn "Done downloading main theme."
|
183
108
|
end
|
184
|
-
config = get_primary_configuration(Utils.read_file('Gemfile.lock'))
|
185
|
-
dl_url = get_download_url "#{@server}/download?code=#{code}&config=#{config}"
|
186
|
-
if dl_url
|
187
|
-
Utils.download_file_to dl_url, archive
|
188
|
-
@logger.warn "Finished downloading."
|
189
|
-
install_from_archive archive
|
190
|
-
else
|
191
|
-
Safe.log_and_abort("We didn't recognize the code you gave to download the theme (#{code}). It should look something like your@email.com:ABCDEF.")
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
def ask_to_install_unsupported code
|
197
|
-
@logger.warn "WARNING\n"
|
198
|
-
|
199
|
-
if File.exists?('Gemfile.lock')
|
200
|
-
@logger.warn <<-EOS
|
201
|
-
Your Gemfile.lock file indicates that you are using a version of Rails that
|
202
|
-
is not officially supported by RailsThemes.
|
203
|
-
EOS
|
204
|
-
else
|
205
|
-
@logger.warn <<-EOS
|
206
|
-
We could not find a Gemfile.lock file in this directory. This could indicate
|
207
|
-
that you are not in a Rails application, or that you are not using Bundler
|
208
|
-
(which probably means that you are using a version of Rails that is not
|
209
|
-
officially supported by RailsThemes.)
|
210
|
-
EOS
|
211
|
-
end
|
212
|
-
@logger.warn <<-EOS
|
213
|
-
While Rails applications that are less than version 3.1 are not officially
|
214
|
-
supported, you can try installing anyway, or can stop. If you cancel the
|
215
|
-
install before downloading, we can refund your purchase. If you install,
|
216
|
-
we cannot guarantee that RailsThemes will work for your app. You may have
|
217
|
-
to do some custom changes, which might be as easy as copying files,
|
218
|
-
but which may be more complicated.
|
219
|
-
EOS
|
220
|
-
|
221
|
-
if Safe.yes? 'Do you still wish to install the theme? [y/N]'
|
222
|
-
install_from_server code
|
223
|
-
else
|
224
|
-
Safe.log_and_abort 'Halting.'
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
def get_download_url server_request_url
|
229
|
-
response = nil
|
230
|
-
begin
|
231
|
-
response = Utils.get_url server_request_url
|
232
|
-
rescue SocketError => e
|
233
|
-
Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
|
234
|
-
rescue Exception => e
|
235
|
-
@logger.info e.message
|
236
|
-
@logger.info e.backtrace
|
237
|
-
end
|
238
|
-
|
239
|
-
if response && response.code.to_s == '200'
|
240
|
-
response.body
|
241
|
-
else
|
242
|
-
nil
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
def gemspecs gemfile_contents = nil
|
247
|
-
gemfile_contents ||= Utils.read_file('Gemfile.lock')
|
248
|
-
return [] if gemfile_contents.strip == ''
|
249
|
-
lockfile = Bundler::LockfileParser.new(gemfile_contents)
|
250
|
-
lockfile.specs
|
251
|
-
end
|
252
|
-
|
253
|
-
def get_primary_configuration gemfile_contents
|
254
|
-
gem_names = gemspecs(gemfile_contents).map(&:name)
|
255
|
-
(gem_names.include?('haml') ? 'haml' : 'erb') + ',' +
|
256
|
-
(gem_names.include?('sass') ? 'scss' : 'css')
|
257
|
-
end
|
258
|
-
|
259
|
-
def rails_version gemfile_contents = nil
|
260
|
-
gemfile_contents ||= Utils.read_file('Gemfile.lock')
|
261
|
-
specs = gemspecs(gemfile_contents)
|
262
|
-
rails = specs.select{ |x| x.name == 'rails' }.first
|
263
|
-
rails.version if rails && rails.version
|
264
|
-
end
|
265
|
-
|
266
|
-
def send_gemfile code
|
267
|
-
begin
|
268
|
-
response = RestClient.post("#{@server}/gemfiles/parse",
|
269
|
-
:code => code, :gemfile_lock => File.new('Gemfile.lock', 'rb'))
|
270
|
-
rescue SocketError => e
|
271
|
-
Safe.log_and_abort 'We could not reach the RailsThemes server to start your download. Please check your internet connection and try again.'
|
272
|
-
rescue Exception => e
|
273
|
-
@logger.info e.message
|
274
|
-
@logger.info e.backtrace
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
def with_tempdir &block
|
279
|
-
tempdir = generate_tempdir_name
|
280
|
-
FileUtils.mkdir_p tempdir
|
281
|
-
yield tempdir
|
282
|
-
FileUtils.rm_rf tempdir
|
283
|
-
end
|
284
109
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
def archive? filepath
|
292
|
-
filepath =~ /\.tar\.gz$/
|
293
|
-
end
|
294
|
-
|
295
|
-
# this happens after a successful copy so that we set up the environment correctly
|
296
|
-
# for people to view the theme correctly
|
297
|
-
def post_copying_changes
|
298
|
-
@logger.info "Removing public/index.html"
|
299
|
-
Utils.remove_file File.join('public', 'index.html')
|
300
|
-
create_railsthemes_demo_pages
|
301
|
-
end
|
302
|
-
|
303
|
-
def create_railsthemes_demo_pages
|
304
|
-
@logger.warn 'Creating RailsThemes demo pages...'
|
305
|
-
|
306
|
-
@logger.debug "mkdir -p app/controllers"
|
307
|
-
FileUtils.mkdir_p(File.join('app', 'controllers'))
|
308
|
-
@logger.debug "writing to app/controllers/railsthemes_controller.rb"
|
309
|
-
File.open(File.join('app', 'controllers', 'railsthemes_controller.rb'), 'w') do |f|
|
310
|
-
f.write <<-EOS
|
311
|
-
class RailsthemesController < ApplicationController
|
312
|
-
# normally every view will use your application layout
|
313
|
-
def inner
|
314
|
-
render :layout => 'application'
|
315
|
-
end
|
316
|
-
|
317
|
-
# this is a special layout for landing and home pages
|
318
|
-
def landing
|
319
|
-
render :layout => 'landing'
|
320
|
-
end
|
321
|
-
end
|
322
|
-
EOS
|
323
|
-
end
|
324
|
-
|
325
|
-
lines = []
|
326
|
-
if File.exists?(File.join('config', 'routes.rb'))
|
327
|
-
lines = Utils.read_file('config/routes.rb').split("\n")
|
328
|
-
last = lines.pop
|
329
|
-
if lines.grep(/railsthemes#landing/).empty?
|
330
|
-
lines << " match 'railsthemes/landing' => 'railsthemes#landing'"
|
331
|
-
end
|
332
|
-
if lines.grep(/railsthemes#inner/).empty?
|
333
|
-
lines << " match 'railsthemes/inner' => 'railsthemes#inner'"
|
334
|
-
end
|
335
|
-
if lines.grep(/railsthemes#jquery_ui/).empty?
|
336
|
-
lines << " match 'railsthemes/jquery_ui' => 'railsthemes#jquery_ui'"
|
337
|
-
end
|
338
|
-
lines << last
|
339
|
-
File.open(File.join('config', 'routes.rb'), 'w') do |f|
|
340
|
-
lines.each do |line|
|
341
|
-
f.puts line
|
342
|
-
end
|
110
|
+
url = dl_hash['email']
|
111
|
+
if url
|
112
|
+
logger.warn "Downloading email theme..."
|
113
|
+
archive = File.join(download_to, 'email.tar.gz')
|
114
|
+
Utils.download :url => url, :save_to => archive
|
115
|
+
logger.warn "Done downloading email theme."
|
343
116
|
end
|
344
117
|
end
|
345
118
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
result = Safe.system_call('hg status')
|
358
|
-
elsif File.directory?('.svn')
|
359
|
-
variety = 'Subversion'
|
360
|
-
result = Safe.system_call('svn status')
|
361
|
-
end
|
362
|
-
unless result.size == 0
|
363
|
-
return "\n#{variety} reports that you have the following pending changes:\n#{result}\nPlease roll back or commit the changes before proceeding to ensure that you can roll back after installing if you want."
|
119
|
+
def send_gemfile code
|
120
|
+
return nil unless File.exists?('Gemfile.lock')
|
121
|
+
begin
|
122
|
+
RestClient.post("#{Railsthemes.server}/gemfiles/parse",
|
123
|
+
:code => code, :gemfile_lock => File.new('Gemfile.lock', 'rb'))
|
124
|
+
rescue SocketError => e
|
125
|
+
Safe.log_and_abort 'We could not reach the RailsThemes server to start your download. Please check your internet connection and try again.'
|
126
|
+
rescue Exception => e
|
127
|
+
logger.info e.message
|
128
|
+
logger.info e.backtrace
|
129
|
+
end
|
364
130
|
end
|
365
|
-
end
|
366
131
|
|
367
|
-
|
368
|
-
|
369
|
-
@logger.warn <<-EOS
|
132
|
+
def print_post_installation_instructions
|
133
|
+
logger.warn <<-EOS
|
370
134
|
|
371
135
|
Yay! Your theme is installed!
|
372
136
|
|
@@ -380,21 +144,28 @@ There are some help articles for your perusal at http://support.railsthemes.com.
|
|
380
144
|
|
381
145
|
|
382
146
|
What now?
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
147
|
+
EOS
|
148
|
+
with_number("Make sure that you have the jquery-rails gem installed. All of the current",
|
149
|
+
"themes require this in your Gemfile so we can use jQuery UI.")
|
150
|
+
with_number "Start or restart your development server."
|
151
|
+
with_number("Check out the local theme samples at:",
|
152
|
+
"http://localhost:3000/railsthemes/landing",
|
153
|
+
"http://localhost:3000/railsthemes/inner",
|
154
|
+
"http://localhost:3000/railsthemes/jquery_ui")
|
155
|
+
with_number("Ensure your new application layout file contains everything that you wanted",
|
156
|
+
"from the old one.")
|
157
|
+
with_number("For instructions on how to send RailsThemes-styled emails in your app,",
|
158
|
+
"check out the documentation in the docs folder.") if @installed_email
|
159
|
+
with_number "Let us know how it went: @railsthemes or support@railsthemes.com."
|
160
|
+
end
|
161
|
+
|
162
|
+
def with_number *lines
|
163
|
+
@number ||= 0
|
164
|
+
logger.warn "#{@number += 1}) #{lines[0]}"
|
165
|
+
lines[1..-1].each do |line|
|
166
|
+
logger.warn " #{line}"
|
167
|
+
end
|
168
|
+
end
|
398
169
|
end
|
399
170
|
end
|
400
171
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Railsthemes
|
2
|
+
module Logging
|
3
|
+
# Method to mix into classes
|
4
|
+
def logger
|
5
|
+
Logging.logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.logger
|
9
|
+
if @logger
|
10
|
+
@logger
|
11
|
+
else
|
12
|
+
@logger = Logger.new(STDOUT)
|
13
|
+
@logger.level = Logger::WARN
|
14
|
+
|
15
|
+
# just print out basic information, not all of the extra logger stuff
|
16
|
+
@logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
|
17
|
+
@logger
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.logger= logger
|
22
|
+
@logger = logger
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.verbose
|
26
|
+
logger.level = Logger::INFO
|
27
|
+
logger.info 'In verbose mode.'
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.debug
|
31
|
+
logger.level = Logger::DEBUG
|
32
|
+
logger.debug 'In debug mode.'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module Railsthemes
|
2
|
+
class ThemeInstaller < Thor
|
3
|
+
no_tasks do
|
4
|
+
include Railsthemes::Logging
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
def install_from_archive filepath
|
8
|
+
Railsthemes::Utils.with_tempdir do |tempdir|
|
9
|
+
Utils.unarchive filepath, tempdir
|
10
|
+
install_from_file_system tempdir
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def install_from_file_system original_source_filepath
|
15
|
+
source_filepath = original_source_filepath.gsub(/\\/, '/')
|
16
|
+
logger.warn 'Installing main theme...'
|
17
|
+
logger.info "Source filepath: #{source_filepath}"
|
18
|
+
|
19
|
+
if File.directory?(source_filepath)
|
20
|
+
install_from_directory source_filepath
|
21
|
+
elsif Utils.archive?(source_filepath + '.tar.gz')
|
22
|
+
install_from_archive(source_filepath + '.tar.gz')
|
23
|
+
else
|
24
|
+
Safe.log_and_abort 'Expected either a directory or archive.'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def install_from_directory source_filepath
|
29
|
+
# this file causes issues when HAML is also present, and we overwrite
|
30
|
+
# it in the ERB case, so safe to delete here
|
31
|
+
logger.debug 'removing file app/views/layouts/application.html.erb'
|
32
|
+
Utils.remove_file('app/views/layouts/application.html.erb')
|
33
|
+
|
34
|
+
Dir["#{source_filepath}/base/**/*"].each do |src|
|
35
|
+
logger.debug "src: #{src}"
|
36
|
+
dest = src.sub("#{source_filepath}/base/", '')
|
37
|
+
logger.debug "dest: #{dest}"
|
38
|
+
if File.directory?(src)
|
39
|
+
unless File.directory?(dest)
|
40
|
+
logger.debug "mkdir -p #{dest}"
|
41
|
+
FileUtils.mkdir_p(dest)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
unless (dest =~ /railsthemes_.*_overrides\.*/ && File.exists?(dest)) ||
|
45
|
+
src =~ /\/\./ # remove any pesky hidden files that crept into the archive
|
46
|
+
logger.debug "cp #{src} #{dest}"
|
47
|
+
FileUtils.cp(src, dest)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
gem_names = Utils.gemspecs(Utils.read_file('Gemfile.lock')).map(&:name) - ['haml', 'sass']
|
53
|
+
install_gems_from(source_filepath, gem_names)
|
54
|
+
|
55
|
+
logger.warn 'Done installing.'
|
56
|
+
|
57
|
+
post_copying_changes
|
58
|
+
end
|
59
|
+
|
60
|
+
def install_gems_from source_filepath, gem_names
|
61
|
+
return unless File.directory?("#{source_filepath}/gems")
|
62
|
+
logger.debug "gem_names: #{gem_names * ' '}"
|
63
|
+
gems_that_we_can_install = Dir.entries("#{source_filepath}/gems").reject{|x| x == '.' || x == '..'}
|
64
|
+
logger.debug "gems_that_we_can_install: #{gems_that_we_can_install * ' '}"
|
65
|
+
(gem_names & gems_that_we_can_install).each do |gem_name|
|
66
|
+
gem_src = File.join(source_filepath, 'gems', gem_name)
|
67
|
+
logger.debug("copying gems from #{gem_src}")
|
68
|
+
Dir["#{gem_src}/**/*"].each do |src|
|
69
|
+
logger.debug "src: #{src}"
|
70
|
+
dest = src.sub("#{source_filepath}/gems/#{gem_name}/", '')
|
71
|
+
logger.debug "dest: #{dest}"
|
72
|
+
if File.directory?(src)
|
73
|
+
logger.debug "mkdir -p #{dest}"
|
74
|
+
FileUtils.mkdir_p(dest)
|
75
|
+
else
|
76
|
+
unless src =~ /\/\./ # remove any pesky hidden files that crept into the archive
|
77
|
+
logger.debug "cp #{src} #{dest}"
|
78
|
+
FileUtils.cp(src, dest)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# this happens after a successful copy so that we set up the environment correctly
|
86
|
+
# for people to view the theme correctly
|
87
|
+
def post_copying_changes
|
88
|
+
logger.info "Removing public/index.html"
|
89
|
+
Utils.remove_file File.join('public', 'index.html')
|
90
|
+
create_railsthemes_demo_pages
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_railsthemes_demo_pages
|
94
|
+
logger.warn 'Creating RailsThemes demo pages...'
|
95
|
+
|
96
|
+
logger.debug "mkdir -p app/controllers"
|
97
|
+
FileUtils.mkdir_p(File.join('app', 'controllers'))
|
98
|
+
logger.debug "writing to app/controllers/railsthemes_controller.rb"
|
99
|
+
File.open(File.join('app', 'controllers', 'railsthemes_controller.rb'), 'w') do |f|
|
100
|
+
f.write <<-EOS
|
101
|
+
class RailsthemesController < ApplicationController
|
102
|
+
# normally every view will use your application layout
|
103
|
+
def inner
|
104
|
+
render :layout => 'application'
|
105
|
+
end
|
106
|
+
|
107
|
+
# this is a special layout for landing and home pages
|
108
|
+
def landing
|
109
|
+
render :layout => 'landing'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
EOS
|
113
|
+
end
|
114
|
+
|
115
|
+
Utils.conditionally_insert_routes({
|
116
|
+
'railsthemes/landing' => 'railsthemes#landing',
|
117
|
+
'railsthemes/inner' => 'railsthemes#inner',
|
118
|
+
'railsthemes/jquery_ui' => 'railsthemes#jquery_ui'
|
119
|
+
})
|
120
|
+
|
121
|
+
logger.warn 'Done creating RailsThemes demo pages.'
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|