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
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzIyNDY4YWY0ZjFkMGZmNGFjMTAzNDlhMTE2NTM5YjRmNDEwZGEzNw==
5
+ data.tar.gz: !binary |-
6
+ NWJiNjUzZDcyMjMyZjY0NmY4NzllZjMxYTFlMjQ2Yzg4ZGE5MTM4NQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ N2E0NTYzZmMwNGY4NWJkOGE1ZGI5MWRjNzYwZGE0MzlmN2RlZjUyNmJmMDg1
10
+ OTA4MzMxYWNmMTZlZDgyNTRhMGU5MzFhODUxOThiMzBmMGM5NDljNjJlNDY4
11
+ YjQ5ZDIxNzRkZTNkYWNiNjY3MzY5YmVhNDViYjAzY2ViZGRmZDA=
12
+ data.tar.gz: !binary |-
13
+ NTFiYWIwMjM4YjY0MWUxOTc1ZDhjMWYyOWI3MzVjMTJkOWVmZjFlZmQzNjgy
14
+ MTEzNzBkZjQ1Nzc4YTFkYTczMWM0Y2Q3YzJmOWNjNWViYTBiZWFmOWE2N2Ux
15
+ MzFkYzEyYjUyMjg5NGFmZDQ0MWVhMjcyNjUzYzFiNzQyYjcwZmE=
data/.rvmrc CHANGED
@@ -1,4 +1,2 @@
1
- # because "Rails 3.1 requires at least Ruby 1.8.7"
2
- # can upgrade safely when we get past this
3
- # would also be nice to test 1.9.2, 1.9.3 to ensure that they work as well
4
- rvm use ree-1.8.7-head@railsthemes --create
1
+ # because "Rails 4 requires at least Ruby 1.9.3"
2
+ rvm use ruby-1.9.3@railsthemes --create
data/Gemfile CHANGED
@@ -4,14 +4,12 @@ gemspec
4
4
 
5
5
  group :development do
6
6
  gem 'gem-release'
7
- gem 'guard'
8
- gem 'guard-rspec'
9
7
  end
10
8
 
11
9
  group :test do
12
- gem 'rspec'
13
- gem 'rr'
14
- gem 'autotest'
15
- gem 'fakefs', :require => 'fakefs/safe', :git => 'https://github.com/RailsThemes/fakefs.git'
10
+ gem 'aruba', :github => 'cucumber/aruba'
11
+ gem 'fakefs', :require => 'fakefs/safe', :git => 'https://github.com/defunkt/fakefs.git'
16
12
  gem 'fakeweb'
13
+ gem 'rr'
14
+ gem 'rspec'
17
15
  end
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
-
2
+ require 'bundler/gem_tasks'
3
+ require 'cucumber/rake/task'
4
4
  require 'rspec/core/rake_task'
5
5
 
6
- RSpec::Core::RakeTask.new('spec')
6
+ Cucumber::Rake::Task.new do |t|
7
+ t.cucumber_opts = "--format pretty"
8
+ end
9
+ task :cuc => :cucumber
7
10
 
8
- # If you want to make this the default task
9
- task :default => :spec
11
+ RSpec::Core::RakeTask.new(:spec)
12
+ task :default => [:spec, :cucumber]
data/bin/railsthemes CHANGED
@@ -14,8 +14,10 @@ class Installer < Thor
14
14
  puts Railsthemes::VERSION
15
15
  else
16
16
  puts <<-EOS
17
+ Usage:
17
18
  railsthemes -v # Print the version of the installer gem you are using
18
19
  railsthemes install your@email:code # Install from RailsThemes.com using your download code
20
+ railsthemes list # List all themes installed in this app
19
21
  railsthemes help [TASK] # Describe available tasks or one specific task
20
22
  EOS
21
23
  end
@@ -24,36 +26,20 @@ EOS
24
26
 
25
27
  desc "install your@email:code", "Install from RailsThemes.com using your download code"
26
28
  method_option :file,
27
- :desc => "Use local relative pathname instead of a code, and install from there.",
28
- :type => :boolean
29
+ :desc => "Install using local relative pathname instead of a code.", :type => :boolean
29
30
  method_option :staging,
30
- :desc => "Hit the staging server instead of https://railsthemes.com.",
31
- :type => :boolean
31
+ :desc => "Hit the staging server instead of https://railsthemes.com.", :type => :boolean
32
32
  method_option :server,
33
- :desc => "Hit an arbitrary server instead of https://railsthemes.com.",
34
- :type => :string
33
+ :desc => "Hit an arbitrary server instead of https://railsthemes.com.", :type => :string
35
34
  method_option :no_doc_popup,
36
- :desc => "Do not pop up documentation on successful install.",
37
- :type => :boolean
35
+ :desc => "Do not pop up documentation on successful install.", :type => :boolean
38
36
  method_option :verbose,
39
- :desc => "Print more output on installation.",
40
- :type => :boolean
37
+ :desc => "Print more output on installation.", :type => :boolean
41
38
  # do not rename to :debug, conflicts with Thor built-in functionality
42
39
  method_option :debugging,
43
- :desc => "Print gratuitous output on installation (for debugging).",
44
- :type => :boolean
40
+ :desc => "Print gratuitous output on installation (for debugging).", :type => :boolean
45
41
  def install code_or_file
46
- # might be better to pass in the options directly if we get more options
47
- installer = Railsthemes::Installer.new
48
-
49
- if options[:email]
50
- end
51
-
52
- installer.doc_popup = !options[:no_doc_popup]
53
- Railsthemes::Logging.verbose if options[:verbose]
54
- Railsthemes::Logging.debug if options[:debugging]
55
- Railsthemes.server = 'http://staging.railsthemes.com' if options[:staging]
56
- Railsthemes.server = options[:server] if options[:server]
42
+ installer = Railsthemes::Installer.new options
57
43
 
58
44
  if options[:file]
59
45
  file = code_or_file
@@ -66,7 +52,17 @@ EOS
66
52
  end
67
53
  end
68
54
 
69
- # AP: other options could include list, remove, help, etc.
55
+ desc "list", "List all themes installed in this app"
56
+ def list
57
+ switcher = Railsthemes::Switcher.new
58
+ switcher.list
59
+ end
60
+
61
+ desc "use", "Use a RailsTheme Theme installed in this app"
62
+ def use theme
63
+ switcher = Railsthemes::Switcher.new
64
+ switcher.switch_to theme
65
+ end
70
66
  end
71
67
 
72
68
  Installer.start ARGV
@@ -0,0 +1,11 @@
1
+ Feature: Running railsthemes on the command-line
2
+ As a RailsThemes customer
3
+ In order to install my theme on the command-line
4
+ I want to run the installer
5
+
6
+ Scenario: Running without any parameters
7
+ When I run `railsthemes`
8
+ Then the output should contain:
9
+ """
10
+ Usage:
11
+ """
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -1,87 +1,26 @@
1
1
  module Railsthemes
2
- class EmailInstaller < Thor
3
- no_tasks do
4
- include Railsthemes::Logging
5
- include Thor::Actions
2
+ class EmailInstaller
3
+ include Railsthemes::Logging
6
4
 
7
- def install_from_file_system original_source_filepath
8
- logger.warn 'Installing email theme...'
9
- source_filepath = original_source_filepath.gsub(/\\/, '/')
10
- logger.info "Source filepath: #{source_filepath}"
5
+ def install
6
+ logger.warn 'Installing email...'
11
7
 
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
8
+ install_mail_gems_if_necessary
49
9
 
50
- Utils.conditionally_insert_routes({
51
- 'railsthemes/email' => 'railsthemes#email',
52
- 'railsthemes/send_email' => 'railsthemes#send_email'
53
- })
54
-
55
- install_mail_gems_if_necessary
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_mail_gems_if_necessary
65
- gem_names = Utils.gemspecs.map(&:name)
66
- logger.debug "gem_names: #{gem_names}"
67
- unless gem_names.include?('premailer-rails3')
68
- if (gem_names & ['hpricot', 'nokogiri']).empty?
69
- Utils.add_gem_to_gemfile 'hpricot'
70
- end
71
- Utils.add_gem_to_gemfile 'premailer-rails3'
72
- logger.warn 'Installing assistant mail gems...'
73
- Safe.system_call 'bundle'
74
- logger.warn 'Done installing assistant mail gems.'
75
- end
76
- end
10
+ logger.warn 'Done installing email.'
11
+ end
77
12
 
78
- def install_from_archive filepath
79
- Railsthemes::Utils.with_tempdir do |tempdir|
80
- Utils.unarchive filepath, tempdir
81
- install_from_file_system tempdir
13
+ def install_mail_gems_if_necessary
14
+ gem_names = Utils.gemspecs.map(&:name)
15
+ logger.debug "gem_names: #{gem_names}"
16
+ unless gem_names.include?('premailer-rails')
17
+ if (gem_names & ['hpricot', 'nokogiri']).empty?
18
+ Utils.add_gem_to_gemfile 'hpricot'
82
19
  end
20
+ logger.warn 'Installing assistant mail gems...'
21
+ Utils.add_gem_to_gemfile 'premailer-rails'
22
+ logger.warn 'Done installing assistant mail gems.'
83
23
  end
84
-
85
24
  end
86
25
  end
87
26
  end
@@ -12,7 +12,7 @@ module Railsthemes
12
12
  ensure_railsthemes_is_not_in_gemfile
13
13
  ensure_vcs_is_clean
14
14
  ensure_rails_version_is_valid
15
- ensure_installer_is_up_to_date unless options[:hit_server] == false
15
+ ensure_installer_is_up_to_date(options[:server]) if options[:server]
16
16
  @@already_checked = true
17
17
  end
18
18
 
@@ -54,9 +54,9 @@ Please roll back or commit the changes before proceeding to ensure that you can
54
54
  end
55
55
  end
56
56
 
57
- def self.ensure_installer_is_up_to_date
57
+ def self.ensure_installer_is_up_to_date server
58
58
  logger.warn "Checking installer version..."
59
- url = Railsthemes.server + '/installer/version'
59
+ url = server + '/installer/version'
60
60
  logger.debug "installer version url: #{url}"
61
61
  begin
62
62
  response = Utils.get_url url
@@ -1,160 +1,142 @@
1
1
  module Railsthemes
2
- class Installer < Thor
3
- no_tasks do
4
- include Railsthemes::Logging
5
- include Thor::Actions
6
-
7
- def initialize
8
- @doc_popup = true
9
- @installed_email = false
10
- end
2
+ class Installer
3
+ include Railsthemes::Logging
11
4
 
12
- def doc_popup= doc_popup
13
- @doc_popup = doc_popup
14
- end
5
+ def initialize options = {}
6
+ @installed_email = false
15
7
 
16
- # can probably just make static
17
- def theme_installer
18
- @theme_installer ||= ThemeInstaller.new
19
- end
8
+ @doc_popup = !options[:no_doc_popup]
9
+ server = 'http://staging.railsthemes.com' if options[:staging]
10
+ server = options[:server] if options[:server]
11
+ server ||= 'https://railsthemes.com'
12
+ server = nil if options[:file]
13
+ @server = server
20
14
 
21
- # can probably just make static
22
- def email_installer
23
- @email_installer ||= EmailInstaller.new
24
- end
15
+ Railsthemes::Logging.verbose if options[:verbose]
16
+ Railsthemes::Logging.debug if options[:debugging]
17
+ end
25
18
 
26
- # can probably just make static
27
- def asset_installer
28
- @asset_installer ||= AssetInstaller.new
29
- end
19
+ attr_accessor :doc_popup, :server
30
20
 
31
- def popup_documentation
32
- style_guides = Dir['doc/*Usage_And_Style_Guide.html']
33
- # need better tests of popping up multiple docs
34
- style_guides.each do |style_guide|
35
- logger.debug("style_guide: #{style_guide}")
36
- Launchy.open(style_guide) if style_guide
37
- end
38
- end
21
+ def server= server
22
+ @server = server
23
+ Logging.logger.warn "Using server: #{@server}"
24
+ end
25
+
26
+ # can probably just make static
27
+ def theme_installer
28
+ @theme_installer ||= ThemeInstaller.new
29
+ end
39
30
 
40
- def install_from_file_system original_source_filepath
41
- Ensurer.ensure_clean_install_possible :hit_server => false
31
+ def email_installer
32
+ @email_installer ||= EmailInstaller.new
33
+ end
42
34
 
43
- # install main theme
44
- config = Utils.get_primary_configuration
45
- filepath = File.join(original_source_filepath, config.join('-'))
46
- if File.directory?(filepath) || Utils.archive?(filepath + '.tar.gz')
47
- theme_installer.install_from_file_system filepath
48
- else
49
- Safe.log_and_abort "Could not find the file you need: #{filepath}"
35
+ def popup_documentation
36
+ latest_installed_dir = Dir.glob("doc/railsthemes_*").max_by {|f| File.mtime(f)}
37
+ if latest_installed_dir
38
+ Dir[File.join(latest_installed_dir, '*.html')].each do |document|
39
+ logger.debug("document: #{document}")
40
+ Launchy.open(document) if document
50
41
  end
42
+ end
43
+ end
51
44
 
52
- # install email theme if present
53
- filepath = File.join(original_source_filepath, 'email')
54
- if File.directory?(filepath) || Utils.archive?(filepath + '.tar.gz')
55
- email_installer.install_from_file_system filepath
56
- @installed_email = true
57
- end
45
+ def install_from_file_system filepath
46
+ Ensurer.ensure_clean_install_possible :server => false
58
47
 
59
- # install design assets if present
60
- filepath = File.join(original_source_filepath, 'design-assets')
61
- if File.directory?(filepath) || Utils.archive?(filepath + '.tar.gz')
62
- asset_installer.install_from_file_system filepath
63
- @installed_assets = true
48
+ # install main theme
49
+ if File.directory?(filepath) || Utils.archive?(filepath + '.tar.gz')
50
+ theme_installer.install_from_file_system filepath
51
+ if Dir['app/mailers/railsthemes*'].count > 0
52
+ email_installer.install
64
53
  end
65
-
66
- print_post_installation_instructions
67
- popup_documentation if @doc_popup
54
+ else
55
+ Safe.log_and_abort "Could not find the file you need: #{filepath}"
68
56
  end
69
57
 
70
- def install_from_code code
71
- Ensurer.ensure_clean_install_possible :hit_server => true
58
+ logger.warn 'Bundling to install new gems...'
59
+ Safe.system_call 'bundle'
60
+ logger.warn 'Done bundling.'
72
61
 
73
- logger.warn "Figuring out what to download..."
74
- send_gemfile code
75
-
76
- dl_hash = get_download_hash code
62
+ print_post_installation_instructions
63
+ popup_documentation if @doc_popup
64
+ end
77
65
 
78
- if dl_hash
79
- logger.debug "dl_hash: #{dl_hash.inspect}"
80
- Utils.with_tempdir do |tempdir|
81
- download_from_hash dl_hash, tempdir
82
- install_from_file_system tempdir
83
- end
84
- else
85
- 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.")
86
- end
87
- end
66
+ def install_from_code code
67
+ Ensurer.ensure_clean_install_possible :server => @server
88
68
 
69
+ logger.warn "Figuring out what to download..."
70
+ send_gemfile code
89
71
 
90
- def get_download_hash code
91
- config = Utils.get_primary_configuration
92
- server_request_url = "#{Railsthemes.server}/download?code=#{code}&config=#{config * ','}&v=2"
93
- response = nil
94
- begin
95
- response = Utils.get_url server_request_url
96
- rescue SocketError => e
97
- Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
98
- rescue Exception => e
99
- logger.debug e.message
100
- logger.debug e.backtrace
101
- end
72
+ download_url = get_download_url code
102
73
 
103
- if response && response.code.to_s == '200'
104
- JSON.parse(response.body)
105
- else
106
- nil
74
+ if download_url
75
+ logger.debug "download_url: #{download_url}"
76
+ Utils.with_tempdir do |tempdir|
77
+ download_from_url download_url, tempdir
78
+ install_from_file_system File.join(tempdir, 'rt-archive')
107
79
  end
80
+ else
81
+ Safe.log_and_abort "We didn't recognize the code you gave to download the theme (#{code}). " +
82
+ "It should look something like your@email.com:ABCDEF."
108
83
  end
84
+ end
109
85
 
110
- def download_from_hash dl_hash, download_to
111
- url = dl_hash['theme']
112
- if url
113
- logger.warn "Downloading main theme..."
114
- config = Utils.get_primary_configuration
115
- archive = File.join(download_to, "#{config.join('-')}.tar.gz")
116
- Utils.download :url => url, :save_to => archive
117
- logger.warn "Done downloading main theme."
118
- end
86
+ def get_download_url code
87
+ config = Utils.get_primary_configuration
88
+ server_request_url = "#{@server}/download?code=#{code}&config=#{config * ','}&v=2"
89
+ response = nil
90
+
91
+ begin
92
+ response = Utils.get_url server_request_url
93
+ rescue SocketError => e
94
+ Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
95
+ rescue Exception => e
96
+ logger.debug e.message
97
+ logger.debug e.backtrace
98
+ end
119
99
 
120
- url = dl_hash['email']
121
- if url
122
- logger.warn "Downloading email theme..."
123
- archive = File.join(download_to, 'email.tar.gz')
124
- Utils.download :url => url, :save_to => archive
125
- logger.warn "Done downloading email theme."
100
+ if response
101
+ if response.code.to_s == '200'
102
+ response.body
103
+ else
104
+ logger.debug "download_url response code: #{response(:code)}"
126
105
  end
106
+ end
107
+ end
127
108
 
128
- url = dl_hash['design_assets']
129
- if url
130
- logger.warn "Downloading design assets..."
131
- archive = File.join(download_to, 'design-assets.tar.gz')
132
- Utils.download :url => url, :save_to => archive
133
- logger.warn "Done downloading design assets."
134
- end
109
+ def download_from_url url, download_to
110
+ if url
111
+ logger.warn "Downloading theme..."
112
+ config = Utils.get_primary_configuration
113
+ archive = File.join(download_to, "rt-archive.tar.gz")
114
+ Utils.download :url => url, :save_to => archive
115
+ logger.warn "Done downloading theme."
135
116
  end
117
+ end
136
118
 
137
- def send_gemfile code
138
- return nil unless File.exists?('Gemfile.lock')
139
- begin
140
- RestClient.post("#{Railsthemes.server}/gemfiles/parse",
141
- :code => code, :gemfile_lock => File.new('Gemfile.lock', 'rb'))
142
- rescue SocketError => e
143
- Safe.log_and_abort 'We could not reach the RailsThemes server to start your download. Please check your internet connection and try again.'
144
- rescue Exception => e
145
- logger.info e.message
146
- logger.info e.backtrace
147
- end
119
+ def send_gemfile code
120
+ return nil unless File.exists?('Gemfile.lock')
121
+ begin
122
+ RestClient.post("#{@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
148
129
  end
130
+ end
149
131
 
150
- def print_post_installation_instructions
151
- logger.warn <<-EOS
132
+ def print_post_installation_instructions
133
+ logger.warn <<-EOS
152
134
 
153
135
  Yay! Your theme is installed!
154
136
 
155
- =============================
156
137
 
157
138
  Documentation and help
139
+ ======================
158
140
 
159
141
  Theme documentation is located in the doc folder.
160
142
 
@@ -163,26 +145,20 @@ There are some help articles for your perusal at http://support.railsthemes.com.
163
145
 
164
146
  What now?
165
147
  EOS
166
- with_number("Make sure that you have the jquery-rails gem installed. All of the current",
167
- "themes require this in your Gemfile so we can use jQuery UI.")
168
- with_number "Start or restart your development server."
169
- with_number("Check out the local theme samples at:",
170
- "http://localhost:3000/railsthemes/landing",
171
- "http://localhost:3000/railsthemes/inner",
172
- "http://localhost:3000/railsthemes/jquery_ui")
173
- with_number("Ensure your new application layout file contains everything that you wanted",
174
- "from the old one.")
175
- with_number("For instructions on how to send RailsThemes-styled emails in your app,",
176
- "check out the documentation in the docs folder.") if @installed_email
177
- with_number "Let us know how it went: @railsthemes or support@railsthemes.com."
178
- end
148
+ with_number "Start or restart your development server."
149
+ with_number("Check out the local theme samples at: http://localhost:3000/railsthemes")
150
+ with_number("Ensure your new application layout file contains everything that you wanted",
151
+ "from the old one.")
152
+ with_number("For instructions on how to send RailsThemes-styled emails in your app,",
153
+ "check out the documentation in the docs folder.") if @installed_email
154
+ with_number "Let us know how it went: @railsthemes or support@railsthemes.com."
155
+ end
179
156
 
180
- def with_number *lines
181
- @number ||= 0
182
- logger.warn "#{@number += 1}) #{lines[0]}"
183
- lines[1..-1].each do |line|
184
- logger.warn " #{line}"
185
- end
157
+ def with_number *lines
158
+ @number ||= 0
159
+ logger.warn "#{@number += 1}) #{lines[0]}"
160
+ lines[1..-1].each do |line|
161
+ logger.warn " #{line}"
186
162
  end
187
163
  end
188
164
  end
@@ -0,0 +1,33 @@
1
+ module Railsthemes
2
+ class Switcher
3
+ include Railsthemes::Logging
4
+
5
+ def list
6
+ themes = installed_themes
7
+ if themes.empty?
8
+ logger.warn 'There are currently no RailsThemes themes installed.'
9
+ else
10
+ logger.warn 'RailsThemes themes currently installed:'
11
+ themes.each do |theme|
12
+ logger.warn " - #{theme}"
13
+ end
14
+ end
15
+ end
16
+
17
+ def switch_to theme_name
18
+ themes = installed_themes
19
+ if themes.include? theme_name
20
+ Utils.set_layout_in_application_controller theme_name
21
+ else
22
+ logger.warn "'#{theme_name}' is not a locally installed RailsThemes theme."
23
+ end
24
+ end
25
+
26
+ def installed_themes
27
+ Dir['app/assets/stylesheets/railsthemes_*'].inject([]) do |accum, filepath|
28
+ accum << File.basename(filepath).gsub(/^railsthemes_/, '') if File.directory?(filepath)
29
+ accum
30
+ end
31
+ end
32
+ end
33
+ end
@@ -33,7 +33,7 @@ module Railsthemes
33
33
  end
34
34
 
35
35
  # gzips the underlying string in the given StringIO,
36
- # returning a new StringIO representing the
36
+ # returning a new StringIO representing the
37
37
  # compressed file.
38
38
  def self.gzip(tarfile)
39
39
  gz = StringIO.new("")
@@ -49,10 +49,9 @@ module Railsthemes
49
49
  # un-gzips the given IO, returning the
50
50
  # decompressed version as a StringIO
51
51
  def self.ungzip(tarfile)
52
- z = Zlib::GzipReader.new(tarfile)
53
- unzipped = StringIO.new(z.read)
54
- z.close
55
- unzipped
52
+ Zlib::GzipReader.open(tarfile) do |f|
53
+ StringIO.new(f.read)
54
+ end
56
55
  end
57
56
 
58
57
  # untars the given IO into the specified