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.
Files changed (41) hide show
  1. checksums.yaml +15 -0
  2. data/.rvmrc +2 -4
  3. data/Gemfile +4 -6
  4. data/Rakefile +8 -5
  5. data/bin/railsthemes +20 -24
  6. data/features/railsthemes.feature +11 -0
  7. data/features/support/env.rb +1 -0
  8. data/lib/railsthemes/email_installer.rb +16 -77
  9. data/lib/railsthemes/ensurer.rb +3 -3
  10. data/lib/railsthemes/installer.rb +118 -142
  11. data/lib/railsthemes/switcher.rb +33 -0
  12. data/lib/railsthemes/tar.rb +4 -5
  13. data/lib/railsthemes/theme_installer.rb +144 -102
  14. data/lib/railsthemes/utils.rb +148 -107
  15. data/lib/railsthemes/version.rb +1 -1
  16. data/lib/railsthemes.rb +2 -9
  17. data/spec/fixtures/blank-assets/{email/app/assets/stylesheets/email.css → tier1-erb-scss/controllers/controller1.rb} +0 -0
  18. data/spec/fixtures/blank-assets/{erb-css/base/app/assets/images/bg/sprite.png → tier1-erb-scss/helpers/helper1.rb} +0 -0
  19. data/spec/fixtures/blank-assets/{erb-css/base/app/assets/images/image1.png → tier1-erb-scss/images/image1.jpg} +0 -0
  20. data/spec/fixtures/blank-assets/{erb-css/base/app/assets/javascripts/jquery.dataTables.js → tier1-erb-scss/javascripts/file1.js} +0 -0
  21. data/spec/fixtures/blank-assets/{erb-css/base/app/assets/javascripts/scripts.js.erb → tier1-erb-scss/layouts/layout1.html.haml} +0 -0
  22. data/spec/fixtures/blank-assets/{erb-css/base/app/views/layouts/_interior_sidebar.html.erb → tier1-erb-scss/mailers/mailer.rb} +0 -0
  23. data/spec/fixtures/blank-assets/{erb-css/base/app/views/layouts/application.html.erb → tier1-erb-scss/stylesheets/stylesheet1.css.scss} +0 -0
  24. data/spec/fixtures/blank-assets-archived/tier1-erb-scss.tar.gz +0 -0
  25. data/spec/lib/railsthemes/email_installer_spec.rb +10 -20
  26. data/spec/lib/railsthemes/ensurer_spec.rb +9 -9
  27. data/spec/lib/railsthemes/installer_spec.rb +90 -75
  28. data/spec/lib/railsthemes/switcher_spec.rb +82 -0
  29. data/spec/lib/railsthemes/theme_installer_spec.rb +323 -109
  30. data/spec/lib/railsthemes/utils_spec.rb +43 -3
  31. data/spec/spec_helper.rb +49 -0
  32. metadata +95 -122
  33. data/lib/railsthemes/asset_installer.rb +0 -48
  34. data/spec/fixtures/blank-assets/erb-css/base/app/assets/stylesheets/style.css.erb +0 -1
  35. data/spec/fixtures/blank-assets/erb-css/base/app/views/layouts/homepage.html.erb +0 -0
  36. data/spec/fixtures/blank-assets/erb-css/gems/formtastic/app/assets/stylesheets/formtastic.css.scss +0 -0
  37. data/spec/fixtures/blank-assets/erb-css/gems/simple_form/app/assets/stylesheets/simple_form.css.scss +0 -0
  38. data/spec/fixtures/blank-assets-archived/design-assets.tar.gz +0 -0
  39. data/spec/fixtures/blank-assets-archived/email.tar.gz +0 -0
  40. data/spec/fixtures/blank-assets-archived/erb-css.tar.gz +0 -0
  41. data/spec/lib/railsthemes/asset_installer_spec.rb +0 -10
@@ -1,126 +1,168 @@
1
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
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
- 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
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
- 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 =~ /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
- gem_names = Utils.gemspecs(Utils.read_file('Gemfile.lock')).map(&:name) - ['haml', 'sass']
53
- install_gems_from(source_filepath, gem_names)
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
- logger.warn 'Done installing.'
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
- post_copying_changes
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
- 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
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
- # 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
101
+ if lines.grep(/^\s*root /).count == 0
102
+ lines_to_insert << ' root :to => "railsthemes#index"'
91
103
  end
92
104
 
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
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
- # 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
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
- Utils.conditionally_insert_routes({
116
- 'railsthemes/landing' => 'railsthemes#landing',
117
- 'railsthemes/inner' => 'railsthemes#inner',
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
- logger.warn 'Done creating RailsThemes demo pages.'
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
@@ -1,136 +1,177 @@
1
1
  module Railsthemes
2
- class Utils < Thor
3
- no_tasks do
4
- extend Railsthemes::Logging
5
- extend Thor::Actions
6
-
7
- # remove file only if it exists
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
- # copy a file, ensuring that the directory is present
15
- def self.copy_ensuring_directory_exists src, dest
16
- FileUtils.mkdir_p(File.dirname(dest)) # create directory if necessary
17
- FileUtils.cp src, dest
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
- def self.read_file filepath
21
- File.exists?(filepath) ? File.read(filepath) : ''
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
- # would be nice to put download status in the output (speed, progress, etc.)
25
- # needs tests
26
- def self.download params = {}
27
- url = params[:url]
28
- save_to = params[:save_to]
29
- return unless url && save_to
30
- logger.info "Downloading url: #{url}"
31
- logger.info "Saving to: #{save_to}"
32
- uri = URI(url)
33
- http = Net::HTTP.new uri.host, uri.port
34
- set_https http if uri.scheme == 'https'
35
- path = url.gsub(%r{https?://[^/]+}, '')
36
- response = http.get(path)
37
- if response.code.to_s == '200'
38
- File.open(save_to, 'wb') do |file|
39
- file.write(response.body)
40
- end
41
- else
42
- logger.debug "response.code: #{response.code}"
43
- logger.debug "response.body: #{response.body}"
44
- Safe.log_and_abort 'Had trouble downloading a file and cannot continue.'
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
- # needs tests I think
49
- def self.get_url url
50
- uri = URI.parse 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
- http.request_get(path)
55
- end
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
- # needs tests
58
- def self.set_https http
59
- cacert_file = File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'cacert.pem')
60
- http.ca_file = cacert_file
61
- http.ca_path = cacert_file
62
- ENV['SSL_CERT_FILE'] = cacert_file
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
- http.use_ssl = true
65
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
66
- end
82
+ http.use_ssl = true
83
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
84
+ end
67
85
 
68
- def self.archive? filepath
69
- File.exists?(filepath) && filepath =~ /\.tar\.gz$/
70
- end
86
+ def self.archive? filepath
87
+ File.exists?(filepath) && filepath =~ /\.tar\.gz$/
88
+ end
71
89
 
72
- # needs tests
73
- def self.with_tempdir &block
74
- tempdir = generate_tempdir_name
75
- FileUtils.mkdir_p tempdir
76
- yield tempdir
77
- FileUtils.rm_rf tempdir
78
- end
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
- # needs tests
81
- def self.generate_tempdir_name
82
- tempdir = File.join(Dir.tmpdir, DateTime.now.strftime("railsthemes-%Y%m%d-%H%M%S-#{rand(100000000)}"))
83
- logger.debug "tempdir: #{tempdir}"
84
- tempdir
85
- end
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
- # needs tests
88
- def self.gemspecs gemfile_contents = nil
89
- gemfile_contents ||= Utils.read_file('Gemfile.lock')
90
- return [] if gemfile_contents.strip == ''
91
- lockfile = Bundler::LockfileParser.new(gemfile_contents)
92
- lockfile.specs
93
- end
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
- def self.unarchive archive, extract_to
96
- Safe.log_and_abort "Archive expected at #{archive}, but none exists." unless File.exist?(archive)
97
- logger.warn "Extracting..."
98
- logger.info "Attempting to extract #{archive}"
99
- io = Tar.ungzip(File.open(archive, 'rb'))
100
- Tar.untar(io, extract_to)
101
- logger.warn "Finished extracting."
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
- def self.get_primary_configuration gemfile_contents = read_file('Gemfile.lock')
105
- gem_names = gemspecs(gemfile_contents).map(&:name)
106
- [(gem_names.include?('haml') ? 'haml' : 'erb'),
107
- (gem_names.include?('sass') ? 'scss' : 'css')]
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
- # needs tests
111
- def self.conditionally_insert_routes routes_hash
112
- if File.exists?(File.join('config', 'routes.rb'))
113
- lines = Utils.read_file('config/routes.rb').split("\n")
114
- last = lines.pop
115
- routes_hash.each do |first, second|
116
- if lines.grep(/#{second}/).empty?
117
- lines << " match '#{first}' => '#{second}'"
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
- lines << last
121
- File.open(File.join('config', 'routes.rb'), 'w') do |f|
122
- lines.each do |line|
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
- end
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
@@ -1,5 +1,5 @@
1
1
  module Railsthemes
2
2
  unless defined?(Railsthemes::VERSION)
3
- VERSION = "1.2.0"
3
+ VERSION = "2.0.0.pre"
4
4
  end
5
5
  end
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