railsthemes 1.2.0 → 2.0.0.pre
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 +15 -0
- data/.rvmrc +2 -4
- data/Gemfile +4 -6
- data/Rakefile +8 -5
- data/bin/railsthemes +20 -24
- data/features/railsthemes.feature +11 -0
- data/features/support/env.rb +1 -0
- data/lib/railsthemes/email_installer.rb +16 -77
- data/lib/railsthemes/ensurer.rb +3 -3
- data/lib/railsthemes/installer.rb +118 -142
- data/lib/railsthemes/switcher.rb +33 -0
- data/lib/railsthemes/tar.rb +4 -5
- data/lib/railsthemes/theme_installer.rb +144 -102
- data/lib/railsthemes/utils.rb +148 -107
- data/lib/railsthemes/version.rb +1 -1
- data/lib/railsthemes.rb +2 -9
- data/spec/fixtures/blank-assets/{email/app/assets/stylesheets/email.css → tier1-erb-scss/controllers/controller1.rb} +0 -0
- data/spec/fixtures/blank-assets/{erb-css/base/app/assets/images/bg/sprite.png → tier1-erb-scss/helpers/helper1.rb} +0 -0
- data/spec/fixtures/blank-assets/{erb-css/base/app/assets/images/image1.png → tier1-erb-scss/images/image1.jpg} +0 -0
- data/spec/fixtures/blank-assets/{erb-css/base/app/assets/javascripts/jquery.dataTables.js → tier1-erb-scss/javascripts/file1.js} +0 -0
- data/spec/fixtures/blank-assets/{erb-css/base/app/assets/javascripts/scripts.js.erb → tier1-erb-scss/layouts/layout1.html.haml} +0 -0
- data/spec/fixtures/blank-assets/{erb-css/base/app/views/layouts/_interior_sidebar.html.erb → tier1-erb-scss/mailers/mailer.rb} +0 -0
- data/spec/fixtures/blank-assets/{erb-css/base/app/views/layouts/application.html.erb → tier1-erb-scss/stylesheets/stylesheet1.css.scss} +0 -0
- data/spec/fixtures/blank-assets-archived/tier1-erb-scss.tar.gz +0 -0
- data/spec/lib/railsthemes/email_installer_spec.rb +10 -20
- data/spec/lib/railsthemes/ensurer_spec.rb +9 -9
- data/spec/lib/railsthemes/installer_spec.rb +90 -75
- data/spec/lib/railsthemes/switcher_spec.rb +82 -0
- data/spec/lib/railsthemes/theme_installer_spec.rb +323 -109
- data/spec/lib/railsthemes/utils_spec.rb +43 -3
- data/spec/spec_helper.rb +49 -0
- metadata +95 -122
- data/lib/railsthemes/asset_installer.rb +0 -48
- data/spec/fixtures/blank-assets/erb-css/base/app/assets/stylesheets/style.css.erb +0 -1
- data/spec/fixtures/blank-assets/erb-css/base/app/views/layouts/homepage.html.erb +0 -0
- data/spec/fixtures/blank-assets/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-archived/design-assets.tar.gz +0 -0
- data/spec/fixtures/blank-assets-archived/email.tar.gz +0 -0
- data/spec/fixtures/blank-assets-archived/erb-css.tar.gz +0 -0
- data/spec/lib/railsthemes/asset_installer_spec.rb +0 -10
@@ -1,126 +1,168 @@
|
|
1
1
|
module Railsthemes
|
2
|
-
class ThemeInstaller
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Utils.unarchive filepath, tempdir
|
10
|
-
install_from_file_system tempdir
|
11
|
-
end
|
2
|
+
class ThemeInstaller
|
3
|
+
include Railsthemes::Logging
|
4
|
+
|
5
|
+
def install_from_archive filepath
|
6
|
+
Railsthemes::Utils.with_tempdir do |tempdir|
|
7
|
+
Utils.unarchive filepath, tempdir
|
8
|
+
install_from_file_system tempdir
|
12
9
|
end
|
10
|
+
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
def install_from_file_system original_source_filepath
|
13
|
+
source_filepath = original_source_filepath.gsub(/\\/, '/')
|
14
|
+
logger.warn 'Installing main theme...'
|
15
|
+
logger.info "Source filepath: #{source_filepath}"
|
16
|
+
|
17
|
+
theme_name = nil
|
18
|
+
if File.directory?(source_filepath)
|
19
|
+
theme_name = install_from_directory source_filepath
|
20
|
+
post_copying_changes(theme_name)
|
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.'
|
26
25
|
end
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
#
|
31
|
-
|
32
|
-
|
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 =~ /overrides\.css.*/ && 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
|
28
|
+
def copy_theme_portions source_filepath, file_mappings
|
29
|
+
file_mappings.each do |src_dir, dest_prefix|
|
30
|
+
Dir["#{source_filepath}/#{src_dir}/**/*"].each do |src|
|
31
|
+
dest = src.sub("#{source_filepath}", dest_prefix).sub(/^\//, '')
|
32
|
+
if File.file?(src) && !override?(dest) && !system_file?(src)
|
33
|
+
Utils.copy_ensuring_directory_exists(src, dest)
|
49
34
|
end
|
50
35
|
end
|
36
|
+
end
|
37
|
+
end
|
51
38
|
|
52
|
-
|
53
|
-
|
39
|
+
def install_from_directory source_filepath
|
40
|
+
copy_theme_portions source_filepath, [
|
41
|
+
['controllers', 'app'],
|
42
|
+
['helpers', 'app'],
|
43
|
+
['layouts', 'app/views'],
|
44
|
+
['stylesheets', 'app/assets'],
|
45
|
+
['javascripts', 'app/assets'],
|
46
|
+
['doc', ''],
|
47
|
+
['images', 'app/assets'],
|
48
|
+
['mailers', 'app'],
|
49
|
+
['views', 'app'],
|
50
|
+
['fonts', 'app/assets'],
|
51
|
+
]
|
52
|
+
|
53
|
+
logger.warn 'Done installing.'
|
54
|
+
return Utils.read_file(File.join(source_filepath, 'theme_name')).chomp
|
55
|
+
end
|
54
56
|
|
55
|
-
|
57
|
+
def post_copying_changes theme_name
|
58
|
+
remove_unwanted_public_files
|
59
|
+
create_railsthemes_demo_routes
|
60
|
+
add_needed_gems
|
61
|
+
Utils.set_layout_in_application_controller theme_name
|
62
|
+
add_to_asset_precompilation_list theme_name
|
63
|
+
comment_out_formtastic_if_user_does_not_use_formtastic theme_name
|
64
|
+
end
|
56
65
|
|
57
|
-
|
66
|
+
def remove_unwanted_public_files
|
67
|
+
['index', '404', '422', '500'].each do |filename|
|
68
|
+
Utils.remove_file "public/#{filename}.html"
|
58
69
|
end
|
70
|
+
end
|
59
71
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
72
|
+
def basic_route_lines
|
73
|
+
output = <<-EOS
|
74
|
+
|
75
|
+
### Begin RailsThemes basic generated routes ###
|
76
|
+
# Routes to RailsThemes Theme Example markup:
|
77
|
+
unless Rails.env.production?
|
78
|
+
get 'railsthemes', controller: :railsthemes, action: :index
|
79
|
+
match 'railsthemes/:action', controller: :railsthemes, via: [:get, :post]
|
80
|
+
end
|
81
|
+
|
82
|
+
# This is magical routing for errors (instead of using the static markup in
|
83
|
+
# public/*.html)
|
84
|
+
get '/403', to: 'railsthemes_errors#403_forbidden'
|
85
|
+
get '/404', to: 'railsthemes_errors#404_not_found'
|
86
|
+
get '/500', to: 'railsthemes_errors#500_internal_server_error'
|
87
|
+
|
88
|
+
### End RailsThemes basic generated routes ###
|
89
|
+
EOS
|
90
|
+
output.split("\n")
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_railsthemes_demo_routes
|
94
|
+
lines = Utils.lines('config/routes.rb')
|
95
|
+
lines_to_insert = []
|
96
|
+
|
97
|
+
if lines.grep(/Begin RailsThemes basic generated routes/).count == 0
|
98
|
+
lines_to_insert += basic_route_lines
|
83
99
|
end
|
84
100
|
|
85
|
-
|
86
|
-
|
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
|
101
|
+
if lines.grep(/^\s*root /).count == 0
|
102
|
+
lines_to_insert << ' root :to => "railsthemes#index"'
|
91
103
|
end
|
92
104
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
105
|
+
logger.warn 'Creating basic RailsThemes routes...'
|
106
|
+
Utils.insert_into_routes_file! lines_to_insert
|
107
|
+
logger.warn 'Done creating basic RailsThemes routes.'
|
108
|
+
end
|
106
109
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
# General assumption is `bundler check` is always clean prior to installation (via ensurer),
|
111
|
+
# so if the gemspecs are in the Gemfile.lock, then the gem is in the Gemfile
|
112
|
+
def add_needed_gems
|
113
|
+
installed_gems = Utils.gemspecs.map(&:name)
|
114
|
+
['sass', 'jquery-rails', 'jquery-ui-rails'].each do |gemname|
|
115
|
+
Utils.add_gem_to_gemfile gemname unless installed_gems.include?(gemname)
|
116
|
+
end
|
114
117
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
'railsthemes/jquery_ui' => 'railsthemes#jquery_ui'
|
119
|
-
})
|
118
|
+
unless installed_gems.include?('compass-rails')
|
119
|
+
Utils.add_gem_to_gemfile('compass-rails', :group => 'assets')
|
120
|
+
end
|
120
121
|
|
121
|
-
|
122
|
+
unless installed_gems.include?('zurb-foundation')
|
123
|
+
Utils.add_gem_to_gemfile('zurb-foundation', :version => '~> 4.0', :group => 'assets')
|
122
124
|
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def add_to_asset_precompilation_list theme_name
|
128
|
+
config_lines = Utils.lines('config/environments/production.rb')
|
129
|
+
count = config_lines.grep(/^\s*config.assets.precompile\s*\+=\s*%w\(\s*railsthemes_#{theme_name}\.js\s+railsthemes_#{theme_name}\.css\s*\)$/).count
|
130
|
+
if count == 0 # precompile line we want not found, add it
|
131
|
+
added = false # only want to add the new line once
|
132
|
+
Utils.safe_write('config/environments/production.rb') do |f|
|
133
|
+
config_lines.each do |line|
|
134
|
+
f.puts line
|
135
|
+
if !added && (line =~ /Precompile additional assets/ || line =~ /config\.assets\.precompile/)
|
136
|
+
f.puts " config.assets.precompile += %w( railsthemes_#{theme_name}.js railsthemes_#{theme_name}.css )"
|
137
|
+
added = true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def comment_out_formtastic_if_user_does_not_use_formtastic theme_name
|
145
|
+
return if (Utils.gemspecs.map(&:name) & ['formtastic']).count > 0
|
146
|
+
filename = "app/assets/stylesheets/railsthemes_#{theme_name}.css"
|
147
|
+
Utils.safe_read_and_write(filename) do |lines, f|
|
148
|
+
lines.each do |line|
|
149
|
+
if line =~ /\*= require formtastic/
|
150
|
+
f.puts ' * require formtastic'
|
151
|
+
else
|
152
|
+
f.puts line
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
def override? dest
|
161
|
+
dest =~ /overrides/ && File.exists?(dest)
|
162
|
+
end
|
123
163
|
|
164
|
+
def system_file? src
|
165
|
+
File.basename(src)[0,1] == '.' # remove any pesky hidden files that crept into the archive
|
124
166
|
end
|
125
167
|
end
|
126
168
|
end
|
data/lib/railsthemes/utils.rb
CHANGED
@@ -1,136 +1,177 @@
|
|
1
1
|
module Railsthemes
|
2
|
-
class Utils
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def self.remove_file filepath
|
9
|
-
if File.exists?(filepath)
|
10
|
-
File.delete filepath
|
11
|
-
end
|
12
|
-
end
|
2
|
+
class Utils
|
3
|
+
extend Railsthemes::Logging
|
4
|
+
|
5
|
+
def self.remove_file filepath
|
6
|
+
File.delete filepath if File.exists?(filepath)
|
7
|
+
end
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
def self.safe_write filepath, &block
|
10
|
+
create_dir_for(filepath)
|
11
|
+
File.open(filepath, 'w') do |f|
|
12
|
+
yield f
|
18
13
|
end
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
16
|
+
def self.safe_read_and_write filepath, &block
|
17
|
+
create_dir_for(filepath)
|
18
|
+
lines = read_file(filepath).split("\n")
|
19
|
+
File.open(filepath, 'w') do |f|
|
20
|
+
yield lines, f
|
22
21
|
end
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
24
|
+
def self.create_dir_for filepath
|
25
|
+
FileUtils.mkdir_p(File.dirname(filepath))
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.copy_ensuring_directory_exists src, dest
|
29
|
+
create_dir_for(dest)
|
30
|
+
logger.debug "Copying #{src} to #{dest}"
|
31
|
+
FileUtils.cp src, dest
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.read_file filepath
|
35
|
+
File.exists?(filepath) ? File.read(filepath) : ''
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.lines filepath
|
39
|
+
read_file(filepath).split("\n")
|
40
|
+
end
|
41
|
+
|
42
|
+
# would be nice to put download status in the output (speed, progress, etc.)
|
43
|
+
# needs tests
|
44
|
+
def self.download params = {}
|
45
|
+
url = params[:url]
|
46
|
+
save_to = params[:save_to]
|
47
|
+
return unless url && save_to
|
48
|
+
logger.info "Downloading url: #{url}"
|
49
|
+
logger.info "Saving to: #{save_to}"
|
50
|
+
uri = URI(url)
|
51
|
+
http = Net::HTTP.new uri.host, uri.port
|
52
|
+
set_https http if uri.scheme == 'https'
|
53
|
+
path = url.gsub(%r{https?://[^/]+}, '')
|
54
|
+
response = http.get(path)
|
55
|
+
if response.code.to_s == '200'
|
56
|
+
File.open(save_to, 'wb') do |file|
|
57
|
+
file.write(response.body)
|
45
58
|
end
|
59
|
+
else
|
60
|
+
logger.debug "response.code: #{response.code}"
|
61
|
+
logger.debug "response.body: #{response.body}"
|
62
|
+
Safe.log_and_abort 'Had trouble downloading a file and cannot continue.'
|
46
63
|
end
|
64
|
+
end
|
47
65
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
66
|
+
# needs tests I think
|
67
|
+
def self.get_url url
|
68
|
+
uri = URI.parse url
|
69
|
+
http = Net::HTTP.new uri.host, uri.port
|
70
|
+
set_https(http) if uri.scheme == 'https'
|
71
|
+
path = url.gsub(%r{https?://[^/]+}, '')
|
72
|
+
http.request_get(path)
|
73
|
+
end
|
56
74
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
75
|
+
# needs tests
|
76
|
+
def self.set_https http
|
77
|
+
cacert_file = File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'cacert.pem')
|
78
|
+
http.ca_file = cacert_file
|
79
|
+
http.ca_path = cacert_file
|
80
|
+
ENV['SSL_CERT_FILE'] = cacert_file
|
63
81
|
|
64
|
-
|
65
|
-
|
66
|
-
|
82
|
+
http.use_ssl = true
|
83
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
84
|
+
end
|
67
85
|
|
68
|
-
|
69
|
-
|
70
|
-
|
86
|
+
def self.archive? filepath
|
87
|
+
File.exists?(filepath) && filepath =~ /\.tar\.gz$/
|
88
|
+
end
|
71
89
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
90
|
+
# needs tests
|
91
|
+
def self.with_tempdir &block
|
92
|
+
tempdir = generate_tempdir_name
|
93
|
+
FileUtils.mkdir_p tempdir
|
94
|
+
yield tempdir
|
95
|
+
FileUtils.rm_rf tempdir
|
96
|
+
end
|
79
97
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
98
|
+
# needs tests
|
99
|
+
def self.generate_tempdir_name
|
100
|
+
tempdir = File.join(Dir.tmpdir, DateTime.now.strftime("railsthemes-%Y%m%d-%H%M%S-#{rand(100000000)}"))
|
101
|
+
logger.debug "tempdir: #{tempdir}"
|
102
|
+
tempdir
|
103
|
+
end
|
86
104
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
105
|
+
# needs tests
|
106
|
+
def self.gemspecs gemfile_contents = nil
|
107
|
+
gemfile_contents ||= Utils.read_file('Gemfile.lock')
|
108
|
+
return [] if gemfile_contents.strip == ''
|
109
|
+
lockfile = Bundler::LockfileParser.new(gemfile_contents)
|
110
|
+
lockfile.specs
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.unarchive archive, extract_to
|
114
|
+
Safe.log_and_abort "Archive expected at #{archive}, but none exists." unless File.exist?(archive)
|
115
|
+
logger.warn "Extracting..."
|
116
|
+
logger.info "Attempting to extract #{archive}"
|
117
|
+
io = Tar.ungzip(File.open(archive, 'rb'))
|
118
|
+
Tar.untar(io, extract_to)
|
119
|
+
logger.warn "Finished extracting."
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.get_primary_configuration gemfile_contents = read_file('Gemfile.lock')
|
123
|
+
gem_names = gemspecs(gemfile_contents).map(&:name)
|
124
|
+
[(gem_names.include?('haml') ? 'haml' : 'erb'),
|
125
|
+
(gem_names.include?('sass') ? 'scss' : 'css')]
|
126
|
+
end
|
94
127
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
128
|
+
def self.insert_into_routes_file! to_insert
|
129
|
+
lines = lines('config/routes.rb')
|
130
|
+
last = lines.pop
|
131
|
+
lines += to_insert
|
132
|
+
lines << last
|
133
|
+
FileUtils.mkdir_p('config')
|
134
|
+
File.open(File.join('config', 'routes.rb'), 'w') do |f|
|
135
|
+
lines.each do |line|
|
136
|
+
f.puts line
|
137
|
+
end
|
102
138
|
end
|
139
|
+
end
|
103
140
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
141
|
+
def self.add_gem_to_gemfile gem_name, attributes = {}
|
142
|
+
File.open('Gemfile', 'a') do |f|
|
143
|
+
line = "gem '#{gem_name}'"
|
144
|
+
line += ", '#{attributes[:version]}'" if attributes[:version]
|
145
|
+
line += ", :group => '#{attributes[:group]}'" if attributes[:group]
|
146
|
+
line += " # RailsThemes"
|
147
|
+
f.puts line
|
108
148
|
end
|
149
|
+
end
|
109
150
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
151
|
+
def self.set_layout_in_application_controller theme_name
|
152
|
+
ac_lines = Utils.lines('app/controllers/application_controller.rb')
|
153
|
+
count = ac_lines.grep(/^\s*layout 'railsthemes/).count
|
154
|
+
if count == 0 # layout line not found, add it
|
155
|
+
Utils.safe_write('app/controllers/application_controller.rb') do |f|
|
156
|
+
ac_lines.each do |line|
|
157
|
+
f.puts line
|
158
|
+
f.puts " layout 'railsthemes_#{theme_name}'" if line =~ /^class ApplicationController/
|
119
159
|
end
|
120
|
-
|
121
|
-
|
122
|
-
|
160
|
+
end
|
161
|
+
elsif count == 1 # layout line found, change it if necessary
|
162
|
+
Utils.safe_write('app/controllers/application_controller.rb') do |f|
|
163
|
+
ac_lines.each do |line|
|
164
|
+
if line =~ /^\s*layout 'railsthemes_/
|
165
|
+
f.puts " layout 'railsthemes_#{theme_name}'"
|
166
|
+
else
|
123
167
|
f.puts line
|
124
168
|
end
|
125
169
|
end
|
126
170
|
end
|
127
|
-
|
128
|
-
|
129
|
-
def self.add_gem_to_gemfile gem_name
|
130
|
-
File.open('Gemfile', 'a') do |f|
|
131
|
-
f.puts "gem '#{gem_name}'"
|
132
|
-
end
|
171
|
+
else
|
172
|
+
# multiple layout lines, not sure what to do here
|
133
173
|
end
|
134
174
|
end
|
175
|
+
|
135
176
|
end
|
136
177
|
end
|
data/lib/railsthemes/version.rb
CHANGED
data/lib/railsthemes.rb
CHANGED
@@ -15,16 +15,9 @@ require 'railsthemes/tar'
|
|
15
15
|
require 'railsthemes/installer'
|
16
16
|
require 'railsthemes/theme_installer'
|
17
17
|
require 'railsthemes/email_installer'
|
18
|
-
require 'railsthemes/asset_installer'
|
19
18
|
require 'railsthemes/ensurer'
|
19
|
+
require 'railsthemes/os'
|
20
|
+
require 'railsthemes/switcher'
|
20
21
|
|
21
22
|
module Railsthemes
|
22
|
-
def self.server
|
23
|
-
@server ||= 'https://railsthemes.com'
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.server= server
|
27
|
-
Logging.logger.warn "Using server: #{server}"
|
28
|
-
@server = server
|
29
|
-
end
|
30
23
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
Binary file
|