jekyll-s3 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -54,18 +54,39 @@ It is easy to deliver your S3-based web site via Cloudfront, the CDN of Amazon.
54
54
  * Run `jekyll-s3` to deploy your site to S3 and invalidate the Cloudfront
55
55
  distribution
56
56
 
57
+ ## The headless mode
58
+
59
+ Jekyll-s3 has a headless mode, in which the interactions with a user are
60
+ disabled.
61
+
62
+ In the headless mode, Jekyll-s3 will automatically delete the files on the S3
63
+ bucket that are not on your local computer. (You can use the delete feature to
64
+ unpublish blog posts.)
65
+
66
+ Enable the headless mode by adding the `--headless` or `-h` argument after
67
+ `jekyll-s3`.
68
+
57
69
  ## Changelog
58
70
 
71
+ ### 0.0.7
72
+
73
+ * Headless mode
74
+
75
+ ### 0.0.6
76
+
77
+ * Upload only new or changed files
78
+ * Support ERB syntax in `_jekyll_s3.yml`
79
+
59
80
  ### 0.0.5
60
81
 
61
- Invalidate the Cloudfront distribution of the Jekyll S3 bucket.
82
+ * Invalidate the Cloudfront distribution of the Jekyll S3 bucket.
62
83
 
63
84
  ## Known issues
64
85
 
65
86
  ### Only S3 buckets in the US Standard region work
66
87
 
67
- Jekyll-s3 supports only S3 buckets that are in the US Standard region. If your
68
- bucket is currently on some other region, you can set a non-existing
88
+ Jekyll-s3 supports only S3 buckets that are in the US Standard region. If your
89
+ bucket is currently on some other region, you can set a non-existing
69
90
  bucket in *_jekyll_s3.yml* and then run `jekyll-s3`. Jekyll-s3 will then create
70
91
  the bucket in the US Standard region.
71
92
 
data/bin/jekyll-s3 CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/jekyll-s3'
4
4
 
5
- Jekyll::S3::CLI.run
5
+ is_headless = ARGV.length == 1 and ARGV[0] == '--headless' or ARGV[0] == '-h'
6
+
7
+ Jekyll::S3::CLI.run is_headless
@@ -0,0 +1,341 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://s3.amazonaws.com/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - ''
12
+ User-Agent:
13
+ - aws-sdk-ruby/1.5.8 ruby/1.9.3 x86_64-darwin11.4.0
14
+ Date:
15
+ - Mon, 12 Nov 2012 18:04:05 +0200
16
+ Authorization:
17
+ - AWS foo
18
+ Accept:
19
+ - ! '*/*'
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ X-Amz-Id-2:
26
+ - UtUBSslAwcVq5q0QwmXNFmbWhUMJTO6RzFFpVqdplXFMUAB/EV1i8y8Nl6wWB9mK
27
+ X-Amz-Request-Id:
28
+ - C418CD7D3B1A94A0
29
+ Date:
30
+ - Mon, 12 Nov 2012 16:04:06 GMT
31
+ Content-Type:
32
+ - application/xml
33
+ Transfer-Encoding:
34
+ - chunked
35
+ Server:
36
+ - AmazonS3
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ! '<?xml version="1.0" encoding="UTF-8"?>
40
+
41
+ <ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>3855ebae0f370c3dd0c8d8031863792112bd2a2cb18fa310d3f463ae0dea62f1</ID><DisplayName>foo</DisplayName></Owner><Buckets><Bucket><Name>jekyll-s3-test.net</Name><CreationDate>2012-10-14T12:58:37.000Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>'
42
+ http_version:
43
+ recorded_at: Mon, 12 Nov 2012 16:04:06 GMT
44
+ - request:
45
+ method: get
46
+ uri: https://s3.amazonaws.com/jekyll-s3-test.net?max-keys=1000
47
+ body:
48
+ encoding: US-ASCII
49
+ string: ''
50
+ headers:
51
+ Content-Type:
52
+ - ''
53
+ User-Agent:
54
+ - aws-sdk-ruby/1.5.8 ruby/1.9.3 x86_64-darwin11.4.0
55
+ Date:
56
+ - Mon, 12 Nov 2012 18:04:06 +0200
57
+ Authorization:
58
+ - AWS
59
+ Accept:
60
+ - ! '*/*'
61
+ response:
62
+ status:
63
+ code: 200
64
+ message: OK
65
+ headers:
66
+ X-Amz-Id-2:
67
+ - fdsRJtd8iQjs86DoPoDH7oN4DatGZD68MeX2z3DK9js8zFODEewFsBsPc0Qk9ahv
68
+ X-Amz-Request-Id:
69
+ - 41A328772547F5CE
70
+ Date:
71
+ - Mon, 12 Nov 2012 16:04:07 GMT
72
+ Content-Type:
73
+ - application/xml
74
+ Transfer-Encoding:
75
+ - chunked
76
+ Server:
77
+ - AmazonS3
78
+ body:
79
+ encoding: US-ASCII
80
+ string: ! '<?xml version="1.0" encoding="UTF-8"?>
81
+
82
+ <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>jekyll-s3-test.net</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>css/styles.css</Key><LastModified>2012-10-14T14:20:04.000Z</LastModified><ETag>&quot;8fcf43a38cbf0c502f029a50645f2374&quot;</ETag><Size>10</Size><Owner><ID>3855ebae0f370c3dd0c8d8031863792112bd2a2cb18fa310d3f463ae0dea62f1</ID><DisplayName>fluid83</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>index.html</Key><LastModified>2012-11-12T16:03:45.000Z</LastModified><ETag>&quot;8a8892a2b0fad281f26c0dedbff7011a&quot;</ETag><Size>60</Size><Owner><ID>3855ebae0f370c3dd0c8d8031863792112bd2a2cb18fa310d3f463ae0dea62f1</ID><DisplayName>fluid83</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>'
83
+ http_version:
84
+ recorded_at: Mon, 12 Nov 2012 16:04:06 GMT
85
+ - request:
86
+ method: head
87
+ uri: https://s3.amazonaws.com/jekyll-s3-test.net/css/styles.css
88
+ body:
89
+ encoding: US-ASCII
90
+ string: ''
91
+ headers:
92
+ Content-Type:
93
+ - ''
94
+ User-Agent:
95
+ - aws-sdk-ruby/1.5.8 ruby/1.9.3 x86_64-darwin11.4.0
96
+ Date:
97
+ - Mon, 12 Nov 2012 18:04:06 +0200
98
+ Authorization:
99
+ - AWS
100
+ Accept:
101
+ - ! '*/*'
102
+ response:
103
+ status:
104
+ code: 200
105
+ message: OK
106
+ headers:
107
+ X-Amz-Id-2:
108
+ - VVKukQx/SJjzviiFnW+vR+AY6hPDh0UcGZ4vTgxUu5xuzTo/sfLZ3fv/i2uMTt8y
109
+ X-Amz-Request-Id:
110
+ - C6FD6AB27A3AB708
111
+ Date:
112
+ - Mon, 12 Nov 2012 16:04:07 GMT
113
+ Last-Modified:
114
+ - Sun, 14 Oct 2012 14:20:04 GMT
115
+ Etag:
116
+ - ! '"8fcf43a38cbf0c502f029a50645f2374"'
117
+ Accept-Ranges:
118
+ - bytes
119
+ Content-Type:
120
+ - ''
121
+ Content-Length:
122
+ - '10'
123
+ Server:
124
+ - AmazonS3
125
+ body:
126
+ encoding: US-ASCII
127
+ string: ''
128
+ http_version:
129
+ recorded_at: Mon, 12 Nov 2012 16:04:07 GMT
130
+ - request:
131
+ method: head
132
+ uri: https://s3.amazonaws.com/jekyll-s3-test.net/css/styles.css
133
+ body:
134
+ encoding: US-ASCII
135
+ string: ''
136
+ headers:
137
+ Content-Type:
138
+ - ''
139
+ User-Agent:
140
+ - aws-sdk-ruby/1.5.8 ruby/1.9.3 x86_64-darwin11.4.0
141
+ Date:
142
+ - Mon, 12 Nov 2012 18:04:07 +0200
143
+ Authorization:
144
+ - AWS
145
+ Accept:
146
+ - ! '*/*'
147
+ response:
148
+ status:
149
+ code: 200
150
+ message: OK
151
+ headers:
152
+ X-Amz-Id-2:
153
+ - lJ05yU2+Hpmjr75Ailh685mfkhRivsIrH0eRjfUN25lfg0kEOETv85tUNcjuAM/g
154
+ X-Amz-Request-Id:
155
+ - 93363578095BC286
156
+ Date:
157
+ - Mon, 12 Nov 2012 16:04:08 GMT
158
+ Last-Modified:
159
+ - Sun, 14 Oct 2012 14:20:04 GMT
160
+ Etag:
161
+ - ! '"8fcf43a38cbf0c502f029a50645f2374"'
162
+ Accept-Ranges:
163
+ - bytes
164
+ Content-Type:
165
+ - ''
166
+ Content-Length:
167
+ - '10'
168
+ Server:
169
+ - AmazonS3
170
+ body:
171
+ encoding: US-ASCII
172
+ string: ''
173
+ http_version:
174
+ recorded_at: Mon, 12 Nov 2012 16:04:07 GMT
175
+ - request:
176
+ method: head
177
+ uri: https://s3.amazonaws.com/jekyll-s3-test.net/index.html
178
+ body:
179
+ encoding: US-ASCII
180
+ string: ''
181
+ headers:
182
+ Content-Type:
183
+ - ''
184
+ User-Agent:
185
+ - aws-sdk-ruby/1.5.8 ruby/1.9.3 x86_64-darwin11.4.0
186
+ Date:
187
+ - Mon, 12 Nov 2012 18:04:07 +0200
188
+ Authorization:
189
+ - AWS
190
+ Accept:
191
+ - ! '*/*'
192
+ response:
193
+ status:
194
+ code: 200
195
+ message: OK
196
+ headers:
197
+ X-Amz-Id-2:
198
+ - xnoD03ghUvW6Lms7N0Pai0sEhh4ulWhuswYghePx/PU7ep9wr18nfS02oTyNJIic
199
+ X-Amz-Request-Id:
200
+ - 93C1F004A5E9FC7C
201
+ Date:
202
+ - Mon, 12 Nov 2012 16:04:09 GMT
203
+ Last-Modified:
204
+ - Mon, 12 Nov 2012 16:03:45 GMT
205
+ Etag:
206
+ - ! '"8a8892a2b0fad281f26c0dedbff7011a"'
207
+ Accept-Ranges:
208
+ - bytes
209
+ Content-Type:
210
+ - text/html
211
+ Content-Length:
212
+ - '60'
213
+ Server:
214
+ - AmazonS3
215
+ body:
216
+ encoding: US-ASCII
217
+ string: ''
218
+ http_version:
219
+ recorded_at: Mon, 12 Nov 2012 16:04:08 GMT
220
+ - request:
221
+ method: head
222
+ uri: https://s3.amazonaws.com/jekyll-s3-test.net/index.html
223
+ body:
224
+ encoding: US-ASCII
225
+ string: ''
226
+ headers:
227
+ Content-Type:
228
+ - ''
229
+ User-Agent:
230
+ - aws-sdk-ruby/1.5.8 ruby/1.9.3 x86_64-darwin11.4.0
231
+ Date:
232
+ - Mon, 12 Nov 2012 18:04:08 +0200
233
+ Authorization:
234
+ - AWS
235
+ Accept:
236
+ - ! '*/*'
237
+ response:
238
+ status:
239
+ code: 200
240
+ message: OK
241
+ headers:
242
+ X-Amz-Id-2:
243
+ - YSTZ/ljVpRfsE8esm1vzqipkScBP40LUOwo1QU3/9Vx1YaR7suE0OY7mUfPuqVV2
244
+ X-Amz-Request-Id:
245
+ - FB412B911EB2705E
246
+ Date:
247
+ - Mon, 12 Nov 2012 16:04:09 GMT
248
+ Last-Modified:
249
+ - Mon, 12 Nov 2012 16:03:45 GMT
250
+ Etag:
251
+ - ! '"8a8892a2b0fad281f26c0dedbff7011a"'
252
+ Accept-Ranges:
253
+ - bytes
254
+ Content-Type:
255
+ - text/html
256
+ Content-Length:
257
+ - '60'
258
+ Server:
259
+ - AmazonS3
260
+ body:
261
+ encoding: US-ASCII
262
+ string: ''
263
+ http_version:
264
+ recorded_at: Mon, 12 Nov 2012 16:04:09 GMT
265
+ - request:
266
+ method: get
267
+ uri: https://s3.amazonaws.com/jekyll-s3-test.net?max-keys=1000
268
+ body:
269
+ encoding: US-ASCII
270
+ string: ''
271
+ headers:
272
+ Content-Type:
273
+ - ''
274
+ User-Agent:
275
+ - aws-sdk-ruby/1.5.8 ruby/1.9.3 x86_64-darwin11.4.0
276
+ Date:
277
+ - Mon, 12 Nov 2012 18:04:09 +0200
278
+ Authorization:
279
+ - AWS
280
+ Accept:
281
+ - ! '*/*'
282
+ response:
283
+ status:
284
+ code: 200
285
+ message: OK
286
+ headers:
287
+ X-Amz-Id-2:
288
+ - W3AqIHSMcW0OZcNHeSvGh4WOjDv0TAmwI8zZlAgh0qhYeJ1cnDTuOBaEKlrKVF17
289
+ X-Amz-Request-Id:
290
+ - C5E23FFE6D568DFC
291
+ Date:
292
+ - Mon, 12 Nov 2012 16:04:10 GMT
293
+ Content-Type:
294
+ - application/xml
295
+ Transfer-Encoding:
296
+ - chunked
297
+ Server:
298
+ - AmazonS3
299
+ body:
300
+ encoding: US-ASCII
301
+ string: ! '<?xml version="1.0" encoding="UTF-8"?>
302
+
303
+ <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>jekyll-s3-test.net</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>css/styles.css</Key><LastModified>2012-10-14T14:20:04.000Z</LastModified><ETag>&quot;8fcf43a38cbf0c502f029a50645f2374&quot;</ETag><Size>10</Size><Owner><ID>3855ebae0f370c3dd0c8d8031863792112bd2a2cb18fa310d3f463ae0dea62f1</ID><DisplayName>fluid83</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>index.html</Key><LastModified>2012-11-12T16:03:45.000Z</LastModified><ETag>&quot;8a8892a2b0fad281f26c0dedbff7011a&quot;</ETag><Size>60</Size><Owner><ID>3855ebae0f370c3dd0c8d8031863792112bd2a2cb18fa310d3f463ae0dea62f1</ID><DisplayName>fluid83</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>'
304
+ http_version:
305
+ recorded_at: Mon, 12 Nov 2012 16:04:09 GMT
306
+ - request:
307
+ method: delete
308
+ uri: https://s3.amazonaws.com/jekyll-s3-test.net/index.html
309
+ body:
310
+ encoding: US-ASCII
311
+ string: ''
312
+ headers:
313
+ Content-Type:
314
+ - ''
315
+ User-Agent:
316
+ - aws-sdk-ruby/1.5.8 ruby/1.9.3 x86_64-darwin11.4.0
317
+ Date:
318
+ - Mon, 12 Nov 2012 18:04:09 +0200
319
+ Authorization:
320
+ - AWS AKIAIFB7KCPAR6YNNZLA:ail6+cNPu7thlzkBPkMQsA9G8QA=
321
+ Accept:
322
+ - ! '*/*'
323
+ response:
324
+ status:
325
+ code: 204
326
+ message: No Content
327
+ headers:
328
+ X-Amz-Id-2:
329
+ - qHi5ypZ5LlelraO05VBE2I8lQtvPhyV4FdSZBWLyQ0xWwNq9eo1RKqrTyhoo3G5u
330
+ X-Amz-Request-Id:
331
+ - A25BE3288715EE97
332
+ Date:
333
+ - Mon, 12 Nov 2012 16:04:10 GMT
334
+ Server:
335
+ - AmazonS3
336
+ body:
337
+ encoding: US-ASCII
338
+ string: ''
339
+ http_version:
340
+ recorded_at: Mon, 12 Nov 2012 16:04:10 GMT
341
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,12 @@
1
+ Feature: remove a Jekyll blog post from S3
2
+
3
+ In order to remove a blog post from S3
4
+ As a blogger
5
+ I want to run jekyll-s3 and see that my post was deleted from S3
6
+
7
+ @one-file-to-delete
8
+ Scenario: The user deletes a blog post
9
+ When my Jekyll site is in "features/support/test_site_dirs/unpublish-a-post.com"
10
+ Then jekyll-s3 will push my blog to S3
11
+ And report that it uploaded 0 new and 0 changed files into S3
12
+ And report that it deleted 1 file from S3
@@ -1,4 +1,4 @@
1
- Feature: jekyll-s3
1
+ Feature: upload Jekyll site to S3
2
2
 
3
3
  In order to push my jekyll site to s3
4
4
  As a blogger
@@ -21,7 +21,12 @@ Then /^report that it uploaded (\d+) new and (\d+) changed files into S3$/ do
21
21
  raise unless @amount_of_changed_files == changed_count.to_i
22
22
  end
23
23
 
24
+ Then /^report that it deleted (\d+) file from S3$/ do |amount_of_deleted_files|
25
+ raise unless @amount_of_deleted_files == amount_of_deleted_files.to_i
26
+ end
27
+
24
28
  def do_run
25
- @amount_of_new_files, @amount_of_changed_files =
26
- Jekyll::S3::CLI.new.run("#{@blog_dir}/_site")
29
+ in_headless_mode = true
30
+ @amount_of_new_files, @amount_of_changed_files, @amount_of_deleted_files =
31
+ Jekyll::S3::CLI.new.run("#{@blog_dir}/_site", in_headless_mode)
27
32
  end
@@ -0,0 +1,3 @@
1
+ s3_id: foo
2
+ s3_secret: foo
3
+ s3_bucket: jekyll-s3-test.net
@@ -11,4 +11,5 @@ VCR.cucumber_tags do |t|
11
11
  t.tag '@only-changed-files'
12
12
  t.tag '@no-new-or-changed-files'
13
13
  t.tag '@s3-and-cloudfront'
14
+ t.tag '@one-file-to-delete'
14
15
  end
@@ -1,8 +1,11 @@
1
1
  module Jekyll
2
2
  module Cloudfront
3
3
  class Invalidator
4
- def self.invalidate(
5
- aws_key, aws_secret, s3_bucket_name, cloudfront_distribution_id)
4
+ def self.invalidate(config)
5
+ aws_key = config['s3_id']
6
+ aws_secret = config['s3_secret']
7
+ s3_bucket_name = config['s3_bucket']
8
+ cloudfront_distribution_id = config['cloudfront_distribution_id']
6
9
  s3 = AWS::S3.new(
7
10
  :access_key_id => aws_key,
8
11
  :secret_access_key => aws_secret)
data/lib/jekyll-s3/cli.rb CHANGED
@@ -3,18 +3,17 @@ module Jekyll
3
3
  class CLI
4
4
  SITE_DIR = '_site'
5
5
 
6
- def self.run
7
- CLI.new.run SITE_DIR
6
+ def self.run(in_headless_mode)
7
+ CLI.new.run SITE_DIR, in_headless_mode
8
8
  end
9
9
 
10
- def run(site_dir)
10
+ def run(site_dir, in_headless_mode = false)
11
11
  CLI.check_configuration site_dir
12
- s3_id, s3_secret, s3_bucket, cloudfront_distribution_id =
13
- Jekyll::S3::ConfigLoader.load_configuration site_dir
14
- amount_of_uploaded_files =
15
- Uploader.run(site_dir, s3_id, s3_secret, s3_bucket)
16
- CLI.invalidate_cf_dist_if_configured s3_id, s3_secret, s3_bucket, cloudfront_distribution_id
17
- amount_of_uploaded_files
12
+ config = Jekyll::S3::ConfigLoader.load_configuration site_dir
13
+ new_files_count, changed_files_count, deleted_files_count =
14
+ Uploader.run(site_dir, config, in_headless_mode)
15
+ CLI.invalidate_cf_dist_if_configured config
16
+ [new_files_count, changed_files_count, deleted_files_count]
18
17
  rescue JekyllS3Error => e
19
18
  puts e.message
20
19
  exit 1
@@ -22,12 +21,10 @@ module Jekyll
22
21
 
23
22
  private
24
23
 
25
- def self.invalidate_cf_dist_if_configured(s3_id, s3_secret, s3_bucket, cloudfront_distribution_id)
26
- cloudfront_configured = cloudfront_distribution_id != nil &&
27
- cloudfront_distribution_id != ''
28
- Jekyll::Cloudfront::Invalidator.invalidate(
29
- s3_id, s3_secret, s3_bucket, cloudfront_distribution_id
30
- ) if cloudfront_configured
24
+ def self.invalidate_cf_dist_if_configured(config)
25
+ cloudfront_configured = config['cloudfront_distribution_id'] &&
26
+ (not config['cloudfront_distribution_id'].empty?)
27
+ Jekyll::Cloudfront::Invalidator.invalidate(config) if cloudfront_configured
31
28
  end
32
29
 
33
30
  def self.check_configuration(site_dir)
@@ -24,17 +24,12 @@ cloudfront_distribution_id: YOUR_CLOUDFRONT_DIST_ID (OPTIONAL)
24
24
  # Load configuration from _jekyll_s3.yml
25
25
  # Raise MalformedConfigurationFileError if the configuration file does not contain the keys we expect
26
26
  def self.load_configuration(site_dir)
27
- config = load_yaml_file site_dir
28
- raise MalformedConfigurationFileError unless config
29
-
27
+ config = load_yaml_file_and_validate site_dir
30
28
  s3_id = config['s3_id']
31
29
  s3_secret = config['s3_secret']
32
30
  s3_bucket = config['s3_bucket']
33
31
  cloudfront_distribution_id = config['cloudfront_distribution_id']
34
-
35
- raise MalformedConfigurationFileError unless
36
- [s3_id, s3_secret, s3_bucket].select { |k| k.nil? || k == '' }.empty?
37
- return s3_id, s3_secret, s3_bucket, cloudfront_distribution_id
32
+ return config
38
33
  end
39
34
 
40
35
  def self.create_template_configuration_file(site_dir)
@@ -44,12 +39,19 @@ cloudfront_distribution_id: YOUR_CLOUDFRONT_DIST_ID (OPTIONAL)
44
39
  }
45
40
  end
46
41
 
47
- def self.load_yaml_file(site_dir)
42
+ def self.load_yaml_file_and_validate(site_dir)
48
43
  begin
49
44
  config = YAML.load(Erubis::Eruby.new(File.read(get_configuration_file(site_dir))).result)
50
45
  rescue Exception
51
46
  raise MalformedConfigurationFileError
52
47
  end
48
+ raise MalformedConfigurationFileError unless config
49
+ raise MalformedConfigurationFileError if
50
+ ['s3_id', 's3_secret', 's3_bucket'].any? { |key|
51
+ mandatory_config_value = config[key]
52
+ mandatory_config_value.nil? || mandatory_config_value == ''
53
+ }
54
+ config
53
55
  end
54
56
 
55
57
  def self.get_configuration_file(site_dir)
@@ -1,7 +1,10 @@
1
1
  module Jekyll
2
2
  module S3
3
3
  class Uploader
4
- def self.run(site_dir, s3_id, s3_secret, s3_bucket_name)
4
+ def self.run(site_dir, config, in_headless_mode = false)
5
+ s3_id = config['s3_id']
6
+ s3_secret = config['s3_secret']
7
+ s3_bucket_name = config['s3_bucket']
5
8
  puts "Deploying _site/* to #{s3_bucket_name}"
6
9
 
7
10
  s3 = AWS::S3.new(:access_key_id => s3_id,
@@ -9,12 +12,13 @@ module Jekyll
9
12
 
10
13
  create_bucket_if_needed(s3, s3_bucket_name)
11
14
 
12
- amount_of_uploaded_files = upload_files(s3, s3_bucket_name, site_dir)
15
+ new_files_count, changed_files_count = upload_files(s3, s3_bucket_name, site_dir)
13
16
 
14
- remove_superfluous_files(s3, s3_bucket_name, site_dir)
17
+ deleted_files_count = remove_superfluous_files(
18
+ s3, s3_bucket_name, site_dir, in_headless_mode)
15
19
 
16
20
  puts "Done! Go visit: http://#{s3_bucket_name}.s3.amazonaws.com/index.html"
17
- amount_of_uploaded_files
21
+ [new_files_count, changed_files_count, deleted_files_count]
18
22
  end
19
23
 
20
24
  private
@@ -57,21 +61,29 @@ module Jekyll
57
61
  end
58
62
  end
59
63
 
60
- def self.remove_superfluous_files(s3, s3_bucket_name, site_dir)
64
+ def self.remove_superfluous_files(s3, s3_bucket_name, site_dir, in_headless_mode)
61
65
  remote_files = s3.buckets[s3_bucket_name].objects.map { |f| f.key }
62
66
  local_files = load_all_local_files(site_dir)
63
- delete_remote_files_if_user_confirms(
64
- remote_files - local_files, s3, s3_bucket_name)
67
+ files_to_delete = remote_files - local_files
68
+ deleted_files_count = 0
69
+ if in_headless_mode
70
+ files_to_delete.each { |s3_object_key|
71
+ delete_s3_object s3, s3_bucket_name, s3_object_key
72
+ deleted_files_count += 1
73
+ }
74
+ else
75
+ Keyboard.if_user_confirms_delete(files_to_delete) { |s3_object_key|
76
+ delete_s3_object s3, s3_bucket_name, s3_object_key
77
+ deleted_files_count += 1
78
+ }
79
+ end
80
+ deleted_files_count
65
81
  end
66
82
 
67
- def self.delete_remote_files_if_user_confirms(to_delete, s3, s3_bucket_name)
68
- unless to_delete.empty?
69
- Keyboard.if_user_confirms_delete(to_delete) { |s3_object_key|
70
- Retry.run_with_retry do
71
- s3.buckets[s3_bucket_name].objects[s3_object_key].delete
72
- puts("Delete #{s3_object_key}: Success!")
73
- end
74
- }
83
+ def self.delete_s3_object(s3, s3_bucket_name, s3_object_key)
84
+ Retry.run_with_retry do
85
+ s3.buckets[s3_bucket_name].objects[s3_object_key].delete
86
+ puts("Delete #{s3_object_key}: Success!")
75
87
  end
76
88
  end
77
89
 
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module S3
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-20 00:00:00.000000000 Z
13
+ date: 2012-11-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk
@@ -210,11 +210,13 @@ files:
210
210
  - features/cassettes/cucumber_tags/new-and-changed-files.yml
211
211
  - features/cassettes/cucumber_tags/new-files.yml
212
212
  - features/cassettes/cucumber_tags/no-new-or-changed-files.yml
213
+ - features/cassettes/cucumber_tags/one-file-to-delete.yml
213
214
  - features/cassettes/cucumber_tags/only-changed-files.yml
214
215
  - features/cassettes/cucumber_tags/s3-and-cloudfront.yml
215
216
  - features/cli-output.feature
216
217
  - features/jekyll-s3-cloudfront.feature
217
- - features/jekyll-s3.feature
218
+ - features/jekyll-s3-delete.feature
219
+ - features/jekyll-s3-upload.feature
218
220
  - features/step_definitions/steps.rb
219
221
  - features/support/env.rb
220
222
  - features/support/test_site_dirs/cdn-powered.blog.fi/_jekyll_s3.yml
@@ -232,6 +234,8 @@ files:
232
234
  - features/support/test_site_dirs/only-changed-files.com/_jekyll_s3.yml
233
235
  - features/support/test_site_dirs/only-changed-files.com/_site/css/styles.css
234
236
  - features/support/test_site_dirs/only-changed-files.com/_site/index.html
237
+ - features/support/test_site_dirs/unpublish-a-post.com/_jekyll_s3.yml
238
+ - features/support/test_site_dirs/unpublish-a-post.com/_site/css/styles.css
235
239
  - features/support/vcr.rb
236
240
  - jekyll-s3.gemspec
237
241
  - lib/cloudfront/invalidator.rb
@@ -261,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
261
265
  version: '0'
262
266
  segments:
263
267
  - 0
264
- hash: 320836636455003738
268
+ hash: 2702422542857987753
265
269
  required_rubygems_version: !ruby/object:Gem::Requirement
266
270
  none: false
267
271
  requirements:
@@ -270,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
274
  version: '0'
271
275
  segments:
272
276
  - 0
273
- hash: 320836636455003738
277
+ hash: 2702422542857987753
274
278
  requirements: []
275
279
  rubyforge_project:
276
280
  rubygems_version: 1.8.24
@@ -281,11 +285,13 @@ test_files:
281
285
  - features/cassettes/cucumber_tags/new-and-changed-files.yml
282
286
  - features/cassettes/cucumber_tags/new-files.yml
283
287
  - features/cassettes/cucumber_tags/no-new-or-changed-files.yml
288
+ - features/cassettes/cucumber_tags/one-file-to-delete.yml
284
289
  - features/cassettes/cucumber_tags/only-changed-files.yml
285
290
  - features/cassettes/cucumber_tags/s3-and-cloudfront.yml
286
291
  - features/cli-output.feature
287
292
  - features/jekyll-s3-cloudfront.feature
288
- - features/jekyll-s3.feature
293
+ - features/jekyll-s3-delete.feature
294
+ - features/jekyll-s3-upload.feature
289
295
  - features/step_definitions/steps.rb
290
296
  - features/support/env.rb
291
297
  - features/support/test_site_dirs/cdn-powered.blog.fi/_jekyll_s3.yml
@@ -303,6 +309,8 @@ test_files:
303
309
  - features/support/test_site_dirs/only-changed-files.com/_jekyll_s3.yml
304
310
  - features/support/test_site_dirs/only-changed-files.com/_site/css/styles.css
305
311
  - features/support/test_site_dirs/only-changed-files.com/_site/index.html
312
+ - features/support/test_site_dirs/unpublish-a-post.com/_jekyll_s3.yml
313
+ - features/support/test_site_dirs/unpublish-a-post.com/_site/css/styles.css
306
314
  - features/support/vcr.rb
307
315
  - spec/lib/keyboard_spec.rb
308
316
  - spec/lib/retry_spec.rb