railsthemes 2.0.0.pre → 2.0.0.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzIyNDY4YWY0ZjFkMGZmNGFjMTAzNDlhMTE2NTM5YjRmNDEwZGEzNw==
4
+ OGY2YTAwYzNjMzMyMWUxMGMwNWNhM2Y1ZDQwMWZlYjU4NGUyYzg4YQ==
5
5
  data.tar.gz: !binary |-
6
- NWJiNjUzZDcyMjMyZjY0NmY4NzllZjMxYTFlMjQ2Yzg4ZGE5MTM4NQ==
6
+ NjU1NmJkMGM4MGMxZjQyZTBhZGIyM2M5MjlmOTFlZmNmMjc2Njk3YQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- N2E0NTYzZmMwNGY4NWJkOGE1ZGI5MWRjNzYwZGE0MzlmN2RlZjUyNmJmMDg1
10
- OTA4MzMxYWNmMTZlZDgyNTRhMGU5MzFhODUxOThiMzBmMGM5NDljNjJlNDY4
11
- YjQ5ZDIxNzRkZTNkYWNiNjY3MzY5YmVhNDViYjAzY2ViZGRmZDA=
9
+ ZTJkMzY4MWVmNTA0MzkyYzdiZTMwMTkyMDAxNTc5NjUwZTEwNjYzYmY0MWQ3
10
+ OTE1NTQ0MDA3NDQwOGFjYTIxZGNjYzI1YzQwY2ZkMDZlMDljODQ4MTliZjMz
11
+ YTFiZjljZWEwYzE2YmZhZDZjM2FmODIyNzE2YjUzOTc2NGJhNzQ=
12
12
  data.tar.gz: !binary |-
13
- NTFiYWIwMjM4YjY0MWUxOTc1ZDhjMWYyOWI3MzVjMTJkOWVmZjFlZmQzNjgy
14
- MTEzNzBkZjQ1Nzc4YTFkYTczMWM0Y2Q3YzJmOWNjNWViYTBiZWFmOWE2N2Ux
15
- MzFkYzEyYjUyMjg5NGFmZDQ0MWVhMjcyNjUzYzFiNzQyYjcwZmE=
13
+ ZjNmNTY0OWFkNmNjMmM4ZGVmNGIzMzNlYTU5MDcxMjNhOGY4NThjMzg0ZGQ0
14
+ N2YyNGM2NTU4NzZhNGZlMDMyZGJkMjhjY2M5MzEzM2UzYTcxODZmNzliZWJj
15
+ YmIyMjA1MjhiY2NmMjE1ZDU1NjM0MGFmYjAyYTMzYjk5Y2UzYmI=
@@ -2,12 +2,61 @@ module Railsthemes
2
2
  class EmailInstaller
3
3
  include Railsthemes::Logging
4
4
 
5
- def install
6
- logger.warn 'Installing email...'
5
+ def email_stylesheet_filenames theme_name
6
+ Dir["app/assets/stylesheets/railsthemes_#{theme_name}/*_email.css.*"]
7
+ end
8
+
9
+ def install_from_file_system source_filepath
10
+ theme_name = Utils.read_file(File.join(source_filepath, 'theme_name')).chomp
11
+ if email_stylesheet_filenames(theme_name).count > 0
12
+ logger.warn 'Installing email...'
13
+ logger.info "Source filepath: #{source_filepath}"
14
+
15
+ unless File.directory?(source_filepath)
16
+ Safe.log_and_abort 'Expected a directory to install email theme from, but found none.'
17
+ end
18
+
19
+ add_to_asset_precompilation_list theme_name
20
+ install_mail_gems_if_necessary
21
+
22
+ logger.warn 'Done installing email.'
23
+ true
24
+ else
25
+ false
26
+ end
27
+ end
7
28
 
8
- install_mail_gems_if_necessary
29
+ def add_to_asset_precompilation_list theme_name
30
+ filenames = email_stylesheet_filenames(theme_name).map do |filename|
31
+ "railsthemes_#{theme_name}/#{File.basename(filename.gsub(/\.erb$/, ''))}"
32
+ end
33
+ updated_or_new_line = " config.assets.precompile += %w( #{filenames.join(' ')} )"
9
34
 
10
- logger.warn 'Done installing email.'
35
+ config_lines = Utils.lines('config/environments/production.rb')
36
+ email_regex = /^\s*config.assets.precompile\s*\+=\s*%w\(\s*railsthemes_#{theme_name}\/\w*email\.css.*\)$/
37
+ count = config_lines.grep(email_regex).count
38
+ if count == 0 # precompile line we want not found, add it
39
+ added = false # only want to add the new line once
40
+ Utils.safe_write('config/environments/production.rb') do |f|
41
+ config_lines.each do |line|
42
+ f.puts line
43
+ if !added && (line =~ /Precompile additional assets/ || line =~ /config\.assets\.precompile/)
44
+ f.puts updated_or_new_line
45
+ added = true
46
+ end
47
+ end
48
+ end
49
+ else
50
+ Utils.safe_write('config/environments/production.rb') do |f|
51
+ config_lines.each do |line|
52
+ if line =~ email_regex
53
+ f.puts updated_or_new_line
54
+ else
55
+ f.puts line
56
+ end
57
+ end
58
+ end
59
+ end
11
60
  end
12
61
 
13
62
  def install_mail_gems_if_necessary
@@ -46,21 +46,30 @@ module Railsthemes
46
46
  Ensurer.ensure_clean_install_possible :server => false
47
47
 
48
48
  # install main theme
49
- if File.directory?(filepath) || Utils.archive?(filepath + '.tar.gz')
49
+ filepath = filepath.gsub(/\\/, '/')
50
+ filepath += '.tar.gz' if Utils.archive?(filepath + '.tar.gz')
51
+ if Utils.archive?(filepath)
52
+ install_from_archive filepath
53
+ elsif File.directory?(filepath)
50
54
  theme_installer.install_from_file_system filepath
51
- if Dir['app/mailers/railsthemes*'].count > 0
52
- email_installer.install
53
- end
55
+ @installed_email = email_installer.install_from_file_system filepath
56
+
57
+ logger.warn 'Bundling to install new gems...'
58
+ Safe.system_call 'bundle'
59
+ logger.warn 'Done bundling.'
60
+
61
+ print_post_installation_instructions
62
+ popup_documentation if @doc_popup
54
63
  else
55
64
  Safe.log_and_abort "Could not find the file you need: #{filepath}"
56
65
  end
66
+ end
57
67
 
58
- logger.warn 'Bundling to install new gems...'
59
- Safe.system_call 'bundle'
60
- logger.warn 'Done bundling.'
61
-
62
- print_post_installation_instructions
63
- popup_documentation if @doc_popup
68
+ def install_from_archive filepath
69
+ Railsthemes::Utils.with_tempdir do |tempdir|
70
+ Utils.unarchive filepath, tempdir
71
+ install_from_file_system tempdir
72
+ end
64
73
  end
65
74
 
66
75
  def install_from_code code
@@ -2,27 +2,16 @@ module Railsthemes
2
2
  class ThemeInstaller
3
3
  include Railsthemes::Logging
4
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
9
- end
10
- end
11
-
12
- def install_from_file_system original_source_filepath
13
- source_filepath = original_source_filepath.gsub(/\\/, '/')
5
+ def install_from_file_system source_filepath
14
6
  logger.warn 'Installing main theme...'
15
7
  logger.info "Source filepath: #{source_filepath}"
16
8
 
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.'
9
+ unless File.directory?(source_filepath)
10
+ Safe.log_and_abort 'Expected a directory to install theme from, but found none.'
25
11
  end
12
+
13
+ theme_name = install_from_directory source_filepath
14
+ post_copying_changes(theme_name)
26
15
  end
27
16
 
28
17
  def copy_theme_portions source_filepath, file_mappings
@@ -158,7 +147,7 @@ module Railsthemes
158
147
  private
159
148
 
160
149
  def override? dest
161
- dest =~ /overrides/ && File.exists?(dest)
150
+ (dest =~ /overrides/ || dest =~ /_header_navigation/) && File.exists?(dest)
162
151
  end
163
152
 
164
153
  def system_file? src
@@ -1,5 +1,5 @@
1
1
  module Railsthemes
2
2
  unless defined?(Railsthemes::VERSION)
3
- VERSION = "2.0.0.pre"
3
+ VERSION = "2.0.0.pre.2"
4
4
  end
5
5
  end
@@ -8,6 +8,16 @@ describe Railsthemes::EmailInstaller do
8
8
  @tempdir = stub_tempdir
9
9
  end
10
10
 
11
+ describe '#install_from_file_system' do
12
+ it 'should not install and return false if the theme does not have any mailers' do
13
+ pending
14
+ end
15
+
16
+ it 'should install and return true if the theme does not have any mailers' do
17
+ pending
18
+ end
19
+ end
20
+
11
21
  describe '#install_mail_gems_if_necessary' do
12
22
  it 'should install no new gems if premailer-rails gem already installed' do
13
23
  write_gemfiles_using_gems 'premailer-rails', 'hpricot'
@@ -34,4 +44,54 @@ describe Railsthemes::EmailInstaller do
34
44
  @installer.install_mail_gems_if_necessary
35
45
  end
36
46
  end
47
+
48
+ describe '#add_to_asset_precompilation_list' do
49
+ before do
50
+ create_file 'app/assets/stylesheets/railsthemes_magenta/1_email.css.erb'
51
+ create_file 'app/assets/stylesheets/railsthemes_magenta/2_email.css.erb'
52
+ end
53
+
54
+ it 'should add it to the list if the line is not there yet' do
55
+ create_file 'config/environments/production.rb', :content => <<-EOS
56
+ BaseApp::Application.configure do
57
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
58
+ end
59
+ EOS
60
+ @installer.add_to_asset_precompilation_list 'magenta'
61
+ File.read('config/environments/production.rb').should == <<-EOS
62
+ BaseApp::Application.configure do
63
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
64
+ config.assets.precompile += %w( railsthemes_magenta/1_email.css railsthemes_magenta/2_email.css )
65
+ end
66
+ EOS
67
+ end
68
+
69
+ it 'should update the line if the line is there already' do
70
+ create_file 'config/environments/production.rb', :content => <<-EOS
71
+ BaseApp::Application.configure do
72
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
73
+ config.assets.precompile += %w( railsthemes_magenta.js railsthemes_magenta.css )
74
+ config.assets.precompile += %w( railsthemes_magenta/1_email.css )
75
+ end
76
+ EOS
77
+ @installer.add_to_asset_precompilation_list 'magenta'
78
+ File.read('config/environments/production.rb').should == <<-EOS
79
+ BaseApp::Application.configure do
80
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
81
+ config.assets.precompile += %w( railsthemes_magenta.js railsthemes_magenta.css )
82
+ config.assets.precompile += %w( railsthemes_magenta/1_email.css railsthemes_magenta/2_email.css )
83
+ end
84
+ EOS
85
+ end
86
+
87
+ it 'should add it to the list if there is a different theme already installed' do
88
+ create_file 'config/environments/production.rb', :content => <<-EOS
89
+ BaseApp::Application.configure do
90
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
91
+ config.assets.precompile += %w( railsthemes_orange/email1.css )
92
+ end
93
+ EOS
94
+ @installer.add_to_asset_precompilation_list 'magenta'
95
+ end
96
+ end
37
97
  end
@@ -48,39 +48,96 @@ describe Railsthemes::Installer do
48
48
  end
49
49
  end
50
50
 
51
+ # this should arguably be an integration test, but I'm not sure how
52
+ # fakefs + running arbitrary binaries will work out
53
+ describe 'end to end behavior' do
54
+ before do
55
+ stub(@installer).post_copying_changes
56
+ FakeFS::FileSystem.clone('spec/fixtures')
57
+ end
58
+
59
+ def verify_end_to_end_operation
60
+ [
61
+ 'app/controllers/controller1.rb',
62
+ 'doc/some_doc.md',
63
+ 'app/helpers/helper1.rb',
64
+ 'app/assets/images/image1.jpg',
65
+ 'app/assets/javascripts/file1.js',
66
+ 'app/views/layouts/layout1.html.haml',
67
+ 'app/mailers/mailer.rb',
68
+ 'app/assets/stylesheets/stylesheet1.css.scss',
69
+ ].each do |filename|
70
+ File.should exist(filename), "#{filename} was expected but not present"
71
+ end
72
+ end
73
+
74
+ it 'should extract correctly from directory' do
75
+ filename = 'spec/fixtures/blank-assets/tier1-erb-scss'
76
+ @installer.install_from_file_system filename
77
+ verify_end_to_end_operation
78
+ end
79
+
80
+ # this spec does not work on Windows, NotImplementedError in tar module
81
+ it 'should extract correctly from archive' do
82
+ filename = 'spec/fixtures/blank-assets-archived/tier1-erb-scss'
83
+ @installer.install_from_file_system filename
84
+ verify_end_to_end_operation
85
+ end
86
+ end
87
+
51
88
  describe :install_from_file_system do
52
89
  before do
53
90
  FakeFS::FileSystem.clone('spec/fixtures')
54
91
  @theme_installer = @installer.theme_installer
92
+ @email_installer = @installer.email_installer
93
+ end
94
+
95
+ context 'when the filepath represents an archive file' do
96
+ let(:archive) { 'tarfile.tar.gz' }
97
+
98
+ it 'should extract the archive file to a temp directory if the archive exists' do
99
+ FileUtils.touch archive
100
+ mock(@installer).install_from_archive archive
101
+ @installer.install_from_file_system 'tarfile'
102
+ end
103
+
104
+ it 'should extract the archive file to a temp directory if the archive exists' do
105
+ FileUtils.touch archive
106
+ mock(@installer).install_from_archive archive
107
+ @installer.install_from_file_system 'tarfile.tar.gz'
108
+ end
109
+ end
110
+
111
+ context 'when the filepath has Windows directory separators' do
112
+ it 'should handle windows style paths' do
113
+ create_file 'subdir/theme/text.txt'
114
+ mock(@theme_installer).install_from_file_system('subdir/theme')
115
+ @installer.install_from_file_system('subdir\theme')
116
+ end
55
117
  end
56
118
 
57
119
  describe 'installing theme' do
58
120
  it 'should install the right theme version' do
59
121
  mock(@theme_installer).install_from_file_system('spec/fixtures/blank-assets/tier1-erb-scss')
122
+ mock(@email_installer).install_from_file_system('spec/fixtures/blank-assets/tier1-erb-scss')
60
123
  @installer.install_from_file_system 'spec/fixtures/blank-assets/tier1-erb-scss'
61
124
  end
62
125
 
63
126
  it 'should install the right theme version if it is an archive in that directory' do
64
- mock(@theme_installer).install_from_file_system('spec/fixtures/blank-assets-archived/tier1-erb-scss')
127
+ mock(@theme_installer).install_from_file_system('tmp')
128
+ mock(@email_installer).install_from_file_system('tmp')
65
129
  @installer.install_from_file_system 'spec/fixtures/blank-assets-archived/tier1-erb-scss'
66
130
  end
67
131
  end
132
+ end
68
133
 
69
- describe 'installing email' do
70
- before do
71
- create_file 'theme/views/test.txt'
72
- end
73
-
74
- it 'should install email if it is present' do
75
- create_file 'theme/mailers/railsthemes_mailer/test.txt'
76
- mock(@installer.email_installer).install
77
- @installer.install_from_file_system('theme')
78
- end
79
-
80
- it 'should not install email if it is not present' do
81
- dont_allow(@installer.email_installer).install
82
- @installer.install_from_file_system('theme')
83
- end
134
+ describe :install_from_archive do
135
+ # this spec does not work on Windows, NotImplementedError in tar module
136
+ it 'should extract and then install from that extracted directory' do
137
+ filename = 'spec/fixtures/blank-assets-archived/tier1-erb-scss.tar.gz'
138
+ FakeFS::FileSystem.clone(filename)
139
+ mock(@installer).install_from_file_system @tempdir
140
+ @installer.install_from_archive filename
84
141
  end
85
142
  end
86
143
 
@@ -12,16 +12,6 @@ describe Railsthemes::ThemeInstaller do
12
12
  FileUtils.touch('Gemfile.lock')
13
13
  end
14
14
 
15
- describe :install_from_archive do
16
- # this spec does not work on Windows, NotImplementedError in tar module
17
- it 'should extract and then install from that extracted directory' do
18
- filename = 'spec/fixtures/blank-assets-archived/tier1-erb-scss.tar.gz'
19
- FakeFS::FileSystem.clone(filename)
20
- mock(@installer).install_from_file_system @tempdir
21
- @installer.install_from_archive filename
22
- end
23
- end
24
-
25
15
  describe :install_from_file_system do
26
16
  context 'when the filepath is a directory' do
27
17
  context 'copying files' do
@@ -98,12 +88,6 @@ describe Railsthemes::ThemeInstaller do
98
88
  filesystem_should_match ['app/assets/images/image with spaces.png']
99
89
  end
100
90
 
101
- it 'should handle windows style paths' do
102
- create_file 'subdir/theme/images/image.png'
103
- @installer.install_from_file_system('subdir\theme')
104
- filesystem_should_match ['app/assets/images/image.png']
105
- end
106
-
107
91
  it 'should not copy system files' do
108
92
  create_file 'theme/controllers/.DS_Store'
109
93
  @installer.install_from_file_system('theme')
@@ -117,9 +101,9 @@ describe Railsthemes::ThemeInstaller do
117
101
  end
118
102
  end
119
103
 
120
- describe 'override file behavior' do
104
+ describe 'override stylesheet file behavior' do
121
105
  before do
122
- create_file 'theme/stylesheets/overrides.css.scss', :content => 'the override'
106
+ create_file 'theme/stylesheets/overrides.css.scss', :content => 'overridden'
123
107
  @filename = 'app/assets/stylesheets/overrides.css.scss'
124
108
  end
125
109
 
@@ -133,61 +117,59 @@ describe Railsthemes::ThemeInstaller do
133
117
  it 'should create override files when they do not already exist' do
134
118
  @installer.install_from_file_system('theme')
135
119
  File.should exist(@filename)
136
- File.read(@filename).should == 'the override'
120
+ File.read(@filename).should == 'overridden'
137
121
  end
138
122
  end
139
123
 
140
- context 'when the filepath is an archive file' do
141
- it 'should extract the archive file to a temp directory if the archive exists' do
142
- archive = 'tarfile.tar.gz'
143
- FileUtils.touch archive
144
- mock(@installer).install_from_archive archive
145
- @installer.install_from_file_system 'tarfile'
146
- end
147
- end
124
+ describe 'keep header navigation if it exists' do
125
+ context 'erb' do
126
+ before do
127
+ basename = '_header_navigation.html.erb'
128
+ create_file "theme/layouts/#{basename}", :content => 'overridden'
129
+ @filename = "app/views/layouts/#{basename}"
130
+ end
148
131
 
149
- context 'otherwise' do
150
- it 'should report an error reading the file' do
151
- mock(Railsthemes::Safe).log_and_abort(/either/)
152
- @installer.install_from_file_system("does not exist")
132
+ it 'should not overwrite override files when they already exist' do
133
+ create_file @filename, :content => 'do not replace'
134
+ @installer.install_from_file_system('theme')
135
+ File.should exist(@filename)
136
+ File.read(@filename).should =~ /do not replace/
137
+ end
138
+
139
+ it 'should create override files when they do not already exist' do
140
+ @installer.install_from_file_system('theme')
141
+ File.should exist(@filename)
142
+ File.read(@filename).should == 'overridden'
143
+ end
153
144
  end
154
- end
155
- end
156
145
 
157
- # this should arguably be an integration test, but I'm not sure how
158
- # fakefs + running arbitrary binaries will work out
159
- describe 'end to end behavior' do
160
- before do
161
- stub(@installer).post_copying_changes
162
- FakeFS::FileSystem.clone('spec/fixtures')
163
- end
146
+ context 'haml' do
147
+ before do
148
+ basename = '_header_navigation.html.haml'
149
+ create_file "theme/layouts/#{basename}", :content => 'overridden'
150
+ @filename = "app/views/layouts/#{basename}"
151
+ end
164
152
 
165
- def verify_end_to_end_operation
166
- [
167
- 'app/controllers/controller1.rb',
168
- 'doc/some_doc.md',
169
- 'app/helpers/helper1.rb',
170
- 'app/assets/images/image1.jpg',
171
- 'app/assets/javascripts/file1.js',
172
- 'app/views/layouts/layout1.html.haml',
173
- 'app/mailers/mailer.rb',
174
- 'app/assets/stylesheets/stylesheet1.css.scss',
175
- ].each do |filename|
176
- File.should exist(filename), "#{filename} was expected but not present"
177
- end
178
- end
153
+ it 'should not overwrite override files when they already exist' do
154
+ create_file @filename, :content => 'do not replace'
155
+ @installer.install_from_file_system('theme')
156
+ File.should exist(@filename)
157
+ File.read(@filename).should =~ /do not replace/
158
+ end
179
159
 
180
- it 'should extract correctly from directory' do
181
- filename = 'spec/fixtures/blank-assets/tier1-erb-scss'
182
- @installer.install_from_file_system filename
183
- verify_end_to_end_operation
160
+ it 'should create override files when they do not already exist' do
161
+ @installer.install_from_file_system('theme')
162
+ File.should exist(@filename)
163
+ File.read(@filename).should == 'overridden'
164
+ end
165
+ end
184
166
  end
185
167
 
186
- # this spec does not work on Windows, NotImplementedError in tar module
187
- it 'should extract correctly from archive' do
188
- filename = 'spec/fixtures/blank-assets-archived/tier1-erb-scss'
189
- @installer.install_from_file_system filename
190
- verify_end_to_end_operation
168
+ context 'otherwise' do
169
+ it 'should report an error reading the file' do
170
+ mock(Railsthemes::Safe).log_and_abort(/Expected a directory/)
171
+ @installer.install_from_file_system("does not exist")
172
+ end
191
173
  end
192
174
  end
193
175
 
@@ -385,6 +367,9 @@ end
385
367
  count = File.read('config/environments/production.rb').split("\n").grep(
386
368
  /^\s*config.assets.precompile \+= %w\( railsthemes_magenta\.js railsthemes_magenta\.css \)$/).count
387
369
  count.should == 1
370
+ count = File.read('config/environments/production.rb').split("\n").grep(
371
+ /^\s*config.assets.precompile \+= %w\( railsthemes_orange\.js railsthemes_orange\.css \)$/).count
372
+ count.should == 1
388
373
  end
389
374
  end
390
375
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railsthemes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre
4
+ version: 2.0.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Railsthemes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-04 00:00:00.000000000 Z
11
+ date: 2013-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor