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
@@ -0,0 +1,73 @@
|
|
1
|
+
module Railsthemes
|
2
|
+
class EmailInstaller < Thor
|
3
|
+
no_tasks do
|
4
|
+
include Railsthemes::Logging
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
def install_from_file_system original_source_filepath
|
8
|
+
source_filepath = original_source_filepath.gsub(/\\/, '/')
|
9
|
+
logger.warn 'Installing email theme...'
|
10
|
+
logger.info "Source filepath: #{source_filepath}"
|
11
|
+
|
12
|
+
if File.directory?(source_filepath)
|
13
|
+
install_from_directory source_filepath
|
14
|
+
elsif Utils.archive?(source_filepath + '.tar.gz')
|
15
|
+
install_from_archive source_filepath + '.tar.gz'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def install_from_directory source_filepath
|
20
|
+
Dir["#{source_filepath}/email/**/*"].each do |src|
|
21
|
+
logger.debug "src: #{src}"
|
22
|
+
dest = src.sub("#{source_filepath}/email/", '')
|
23
|
+
logger.debug "dest: #{dest}"
|
24
|
+
if File.directory?(src)
|
25
|
+
unless File.directory?(dest)
|
26
|
+
logger.debug "mkdir -p #{dest}"
|
27
|
+
FileUtils.mkdir_p(dest)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
unless src =~ /\/\./ # remove any pesky hidden files that crept into the archive
|
31
|
+
logger.debug "cp #{src} #{dest}"
|
32
|
+
FileUtils.cp(src, dest)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
inject_into_file File.join('app', 'controllers', 'railsthemes_controller.rb'), :after => 'class RailsthemesController < ApplicationController', :verbose => false do
|
38
|
+
<<-EOS
|
39
|
+
|
40
|
+
def email
|
41
|
+
end
|
42
|
+
|
43
|
+
def send_email
|
44
|
+
RailsthemesMailer.test_email(:to => params[:email]).deliver
|
45
|
+
render :sent_email
|
46
|
+
end
|
47
|
+
EOS
|
48
|
+
end
|
49
|
+
|
50
|
+
Utils.conditionally_insert_routes({
|
51
|
+
'railsthemes/email' => 'railsthemes#email',
|
52
|
+
'railsthemes/send_email' => 'railsthemes#send_email'
|
53
|
+
})
|
54
|
+
|
55
|
+
Utils.conditionally_install_gems 'roadie', 'premailer-rails3'
|
56
|
+
|
57
|
+
create_file File.join('config', 'initializers', 'premailer.rb'), :verbose => false do
|
58
|
+
"PremailerRails.config.merge(:input_encoding => 'UTF-8', :generate_text_part => true)"
|
59
|
+
end
|
60
|
+
|
61
|
+
logger.warn 'Done installing email theme.'
|
62
|
+
end
|
63
|
+
|
64
|
+
def install_from_archive filepath
|
65
|
+
Railsthemes::Utils.with_tempdir do |tempdir|
|
66
|
+
Utils.unarchive filepath, tempdir
|
67
|
+
install_from_file_system tempdir
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
module Railsthemes
|
2
|
+
class Ensurer
|
3
|
+
extend Railsthemes::Logging
|
4
|
+
|
5
|
+
@@already_checked = false
|
6
|
+
|
7
|
+
# checks if we can cleanly install into the current working directory
|
8
|
+
def self.ensure_clean_install_possible force = false
|
9
|
+
return if @@already_checked unless force
|
10
|
+
ensure_in_rails_root
|
11
|
+
ensure_bundle_is_up_to_date
|
12
|
+
ensure_railsthemes_is_not_in_gemfile
|
13
|
+
ensure_vcs_is_clean
|
14
|
+
ensure_rails_version_is_valid
|
15
|
+
ensure_installer_is_up_to_date
|
16
|
+
@@already_checked = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.ensure_in_rails_root
|
20
|
+
unless File.directory?('app') && File.directory?('public')
|
21
|
+
Safe.log_and_abort 'Must be in the Rails root directory to use this gem.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.ensure_vcs_is_clean
|
26
|
+
logger.warn "Checking version control..."
|
27
|
+
result = ''
|
28
|
+
variety = ''
|
29
|
+
if File.directory?('.git')
|
30
|
+
variety = 'Git'
|
31
|
+
result = Safe.system_call('git status -s')
|
32
|
+
elsif File.directory?('.hg')
|
33
|
+
variety = 'Mercurial'
|
34
|
+
result = Safe.system_call('hg status')
|
35
|
+
elsif File.directory?('.svn')
|
36
|
+
variety = 'Subversion'
|
37
|
+
result = Safe.system_call('svn status')
|
38
|
+
end
|
39
|
+
|
40
|
+
unless result.size == 0
|
41
|
+
Safe.log_and_abort <<-EOS
|
42
|
+
|
43
|
+
#{variety} reports that you have the following pending changes:
|
44
|
+
#{result}
|
45
|
+
Please roll back or commit the changes before proceeding to ensure that you can roll back after installing if you want.
|
46
|
+
EOS
|
47
|
+
end
|
48
|
+
logger.warn "Done checking version control."
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.ensure_rails_version_is_valid
|
52
|
+
unless File.exists?('Gemfile.lock') && Gem::Version.new('3.1') <= rails_version
|
53
|
+
ask_to_install_unsupported
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.ensure_installer_is_up_to_date
|
58
|
+
logger.warn "Checking installer version..."
|
59
|
+
url = Railsthemes.server + '/installer/version'
|
60
|
+
logger.debug "installer version url: #{url}"
|
61
|
+
begin
|
62
|
+
response = Utils.get_url url
|
63
|
+
rescue SocketError => e
|
64
|
+
logger.debug e.message
|
65
|
+
logger.debug e.backtrace * "\n"
|
66
|
+
Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
|
67
|
+
rescue Exception => e
|
68
|
+
logger.debug e.message
|
69
|
+
logger.debug e.backtrace * "\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
if response && response.code.to_s == '200'
|
73
|
+
server_recommended_version_string = response.body
|
74
|
+
server_recommended_version = Gem::Version.new(server_recommended_version_string)
|
75
|
+
local_installer_version = Gem::Version.new(Railsthemes::VERSION)
|
76
|
+
|
77
|
+
if server_recommended_version > local_installer_version
|
78
|
+
Safe.log_and_abort <<-EOS
|
79
|
+
Your version is older than the recommended version.
|
80
|
+
Your version: #{Railsthemes::VERSION}
|
81
|
+
Recommended version: #{server_recommended_version_string}
|
82
|
+
EOS
|
83
|
+
else
|
84
|
+
logger.debug "server recommended version: #{server_recommended_version_string}"
|
85
|
+
end
|
86
|
+
else
|
87
|
+
logger.debug 'Got an error'
|
88
|
+
logger.debug response
|
89
|
+
Safe.log_and_abort 'There was an issue checking your installer version.'
|
90
|
+
end
|
91
|
+
logger.warn "Done checking installer version."
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.ask_to_install_unsupported
|
95
|
+
logger.warn "WARNING\n"
|
96
|
+
|
97
|
+
if File.exists?('Gemfile.lock')
|
98
|
+
logger.warn <<-EOS
|
99
|
+
Your Gemfile.lock file indicates that you are using a version of Rails that
|
100
|
+
is not officially supported by RailsThemes.
|
101
|
+
EOS
|
102
|
+
else
|
103
|
+
logger.warn <<-EOS
|
104
|
+
We could not find a Gemfile.lock file in this directory. This could indicate
|
105
|
+
that you are not in a Rails application, or that you are not using Bundler
|
106
|
+
(which probably means that you are using a version of Rails that is not
|
107
|
+
officially supported by RailsThemes.)
|
108
|
+
EOS
|
109
|
+
end
|
110
|
+
logger.warn <<-EOS
|
111
|
+
While Rails applications that are less than version 3.1 are not officially
|
112
|
+
supported, you can try installing anyway, or can stop. If you cancel the
|
113
|
+
install before downloading, we can refund your purchase. If you install,
|
114
|
+
we cannot guarantee that RailsThemes will work for your app. You may have
|
115
|
+
to do some custom changes, which might be as easy as copying files,
|
116
|
+
but which may be more complicated.
|
117
|
+
EOS
|
118
|
+
|
119
|
+
unless Safe.yes? 'Do you still wish to install the theme? [y/N]'
|
120
|
+
Safe.log_and_abort 'Halting.'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.ensure_bundle_is_up_to_date
|
125
|
+
logger.warn "Checking bundle..."
|
126
|
+
result = Safe.system_call('bundle check')
|
127
|
+
if result !~ /The Gemfile's dependencies are satisfied/
|
128
|
+
Safe.log_and_abort <<-EOS
|
129
|
+
Running `bundle check` resulted in the following issues:
|
130
|
+
#{result}
|
131
|
+
Please run `bundle` and try installing again.
|
132
|
+
EOS
|
133
|
+
end
|
134
|
+
logger.warn "Done checking bundle."
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.rails_version gemfile_contents = nil
|
138
|
+
gemfile_contents ||= Utils.read_file('Gemfile.lock')
|
139
|
+
specs = Utils.gemspecs(gemfile_contents)
|
140
|
+
rails = specs.select{ |x| x.name == 'rails' }.first
|
141
|
+
rails.version if rails && rails.version
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.ensure_railsthemes_is_not_in_gemfile gemfile_contents = nil
|
145
|
+
gemfile_contents ||= Utils.read_file('Gemfile.lock')
|
146
|
+
specs = Utils.gemspecs(gemfile_contents)
|
147
|
+
if specs.any? { |x| x.name == 'railsthemes' }
|
148
|
+
Safe.log_and_abort "You should not install the railsthemes installer in your Gemfile.\nPlease remove and try again."
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|