middleman-s3_sync 3.0.13 → 3.0.14
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.
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/README.md +22 -2
- data/Rakefile +5 -0
- data/lib/middleman-s3_sync.rb +1 -125
- data/lib/middleman-s3_sync/extension.rb +5 -70
- data/lib/middleman/s3_sync.rb +138 -0
- data/lib/middleman/s3_sync/options.rb +91 -0
- data/lib/middleman/s3_sync/resource.rb +15 -1
- data/lib/{middleman-s3_sync → middleman/s3_sync}/version.rb +1 -1
- data/middleman-s3_sync.gemspec +5 -1
- data/spec/options_spec.rb +104 -0
- data/spec/resource_spec.rb +5 -0
- data/spec/spec_helper.rb +25 -0
- metadata +80 -6
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
env:
|
7
|
+
global:
|
8
|
+
- secure: ! 'dQ/vYDmUZEW9LD8IyTRFoRFo24w2yJTYQHuAS24vfKToDZ0BO2/Tpq5lh0vb
|
9
|
+
|
10
|
+
EJ25M7+IwJgo0PC++c1cbssurpNvNeMmDMKuBd6IjnSoJSzK6AszK5wA8dRs
|
11
|
+
|
12
|
+
gd3RC+G5lJ2sKPip28t6bIf5K6KFPD/3d45rE+qY9rXZxCwMJHw='
|
13
|
+
- secure: ! 'N26NTcIxZa6kUVMRPe2HONMjcAKTJUAFBMOXu9CC6FAyeIMFbldUMDs2Dk3D
|
14
|
+
|
15
|
+
CWPYiWQmqXywTbqHsnPfv9LwqQ9zntsURlq8I5JPVGNvf7QWqKdojI05cIiS
|
16
|
+
|
17
|
+
kT7C8IqnK3RzVmx4WZ5qFYxG6ypwilYq1px0OKjB4JHbFR5bj18='
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Middleman::S3Sync
|
2
2
|
|
3
|
-
[](https://codeclimate.com/github/fredjean/middleman-s3_sync)
|
3
|
+
[](https://codeclimate.com/github/fredjean/middleman-s3_sync) [](https://travis-ci.org/fredjean/middleman-s3_sync)
|
5
4
|
|
6
5
|
This gem determines which files need to be added, updated and optionally deleted
|
7
6
|
and only transfer these files up. This reduces the impact of an update
|
@@ -47,6 +46,27 @@ end
|
|
47
46
|
|
48
47
|
You can then start synchronizing files with S3 through ```middleman s3_sync```.
|
49
48
|
|
49
|
+
### Configuration Defaults
|
50
|
+
|
51
|
+
The following defaults apply to the configuration items:
|
52
|
+
|
53
|
+
| Setting | Default |
|
54
|
+
| ----------------- | ---------------------------- |
|
55
|
+
| aws_access_key_id | ```ENV['AWS_ACCESS_KEY_ID``` |
|
56
|
+
| aws_secret_access_key | ```ENV['AWS_SECRET_ACCESS_KEY']``` |
|
57
|
+
| delete | ```true``` |
|
58
|
+
| after_build | ```false``` |
|
59
|
+
| prefer_gzip | ```true``` |
|
60
|
+
|
61
|
+
You do not need to specify the settings that match the defaults. This
|
62
|
+
simplify the configuration of the extension:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
activate :s3_sync do |s3_sync|
|
66
|
+
s3_sync.bucket = 'my.bucket.com'
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
50
70
|
## Push All Content to S3
|
51
71
|
|
52
72
|
There are situations where you might need to push the files to S3. In
|
data/Rakefile
CHANGED
data/lib/middleman-s3_sync.rb
CHANGED
@@ -1,131 +1,7 @@
|
|
1
1
|
require 'middleman-core'
|
2
|
-
require '
|
3
|
-
require 'pmap'
|
4
|
-
require 'digest/md5'
|
5
|
-
require 'middleman-s3_sync/version'
|
6
|
-
require 'middleman-s3_sync/commands'
|
7
|
-
require 'middleman/s3_sync/status'
|
8
|
-
require 'middleman/s3_sync/resource'
|
9
|
-
require 'middleman-s3_sync/extension'
|
10
|
-
require 'ruby-progressbar'
|
11
|
-
|
12
|
-
Fog::Logger[:warning] = nil
|
2
|
+
require 'middleman/s3_sync'
|
13
3
|
|
14
4
|
::Middleman::Extensions.register(:s3_sync, '>= 3.0.0') do
|
15
5
|
::Middleman::S3Sync
|
16
6
|
end
|
17
7
|
|
18
|
-
module Middleman
|
19
|
-
module S3Sync
|
20
|
-
class << self
|
21
|
-
include Status
|
22
|
-
|
23
|
-
def sync
|
24
|
-
unless work_to_be_done?
|
25
|
-
say_status "\nAll S3 files are up to date."
|
26
|
-
return
|
27
|
-
end
|
28
|
-
|
29
|
-
say_status "\nReady to apply updates to #{s3_sync_options.bucket}."
|
30
|
-
|
31
|
-
create_resources
|
32
|
-
update_resources
|
33
|
-
delete_resources
|
34
|
-
end
|
35
|
-
|
36
|
-
def bucket
|
37
|
-
@bucket ||= connection.directories.get(s3_sync_options.bucket)
|
38
|
-
end
|
39
|
-
|
40
|
-
protected
|
41
|
-
def connection
|
42
|
-
@connection ||= Fog::Storage.new({
|
43
|
-
:provider => 'AWS',
|
44
|
-
:aws_access_key_id => s3_sync_options.aws_access_key_id,
|
45
|
-
:aws_secret_access_key => s3_sync_options.aws_secret_access_key,
|
46
|
-
:region => s3_sync_options.region
|
47
|
-
})
|
48
|
-
end
|
49
|
-
|
50
|
-
def resources
|
51
|
-
@resources ||= paths.pmap do |p|
|
52
|
-
progress_bar.increment
|
53
|
-
S3Sync::Resource.new(p)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def progress_bar
|
58
|
-
@progress_bar ||= ProgressBar.create(total: paths.length)
|
59
|
-
end
|
60
|
-
|
61
|
-
def paths
|
62
|
-
@paths ||= begin
|
63
|
-
say_status "Gathering the paths to evaluate."
|
64
|
-
(remote_paths + local_paths).uniq.sort
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def local_paths
|
69
|
-
@local_paths ||= begin
|
70
|
-
local_paths = (Dir[build_dir + "/**/*"] + Dir[build_dir + "/**/.*"])
|
71
|
-
.reject { |p| File.directory?(p) }
|
72
|
-
|
73
|
-
if s3_sync_options.prefer_gzip
|
74
|
-
local_paths.reject! { |p| p =~ /\.gz$/ && File.exist?(p.gsub(/\.gz$/, '')) }
|
75
|
-
end
|
76
|
-
|
77
|
-
local_paths.pmap { |p| p.gsub(/#{build_dir}\//, '') }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def remote_paths
|
82
|
-
@remote_paths ||= bucket.files.map{ |f| f.key }.reject { |p| p =~ %r{/$} }
|
83
|
-
end
|
84
|
-
|
85
|
-
def create_resources
|
86
|
-
files_to_create.each do |r|
|
87
|
-
r.create!
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def update_resources
|
92
|
-
files_to_update.each do |r|
|
93
|
-
r.update!
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def delete_resources
|
98
|
-
files_to_delete.each do |r|
|
99
|
-
r.destroy!
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def work_to_be_done?
|
104
|
-
!(files_to_create.empty? && files_to_update.empty? && files_to_delete.empty?)
|
105
|
-
end
|
106
|
-
|
107
|
-
def files_to_delete
|
108
|
-
@files_to_delete ||= if s3_sync_options.delete
|
109
|
-
resources.select { |r| r.to_delete? }
|
110
|
-
else
|
111
|
-
[]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def files_to_create
|
116
|
-
@files_to_create ||= resources.select { |r| r.to_create? }
|
117
|
-
end
|
118
|
-
|
119
|
-
def files_to_update
|
120
|
-
return resources.select { |r| r.local? } if s3_sync_options.force
|
121
|
-
|
122
|
-
@files_to_update ||= resources.select { |r| r.to_update? }
|
123
|
-
end
|
124
|
-
|
125
|
-
def build_dir
|
126
|
-
@build_dir ||= s3_sync_options.build_dir
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
@@ -3,77 +3,9 @@ require 'map'
|
|
3
3
|
|
4
4
|
module Middleman
|
5
5
|
module S3Sync
|
6
|
-
class Options < Struct.new(
|
7
|
-
:prefix,
|
8
|
-
:bucket,
|
9
|
-
:region,
|
10
|
-
:aws_access_key_id,
|
11
|
-
:aws_secret_access_key,
|
12
|
-
:after_build,
|
13
|
-
:delete,
|
14
|
-
:existing_remote_file,
|
15
|
-
:build_dir,
|
16
|
-
:force,
|
17
|
-
:prefer_gzip,
|
18
|
-
:verbose
|
19
|
-
)
|
20
|
-
|
21
|
-
def add_caching_policy(content_type, options)
|
22
|
-
caching_policies[content_type.to_s] = BrowserCachePolicy.new(options)
|
23
|
-
end
|
24
|
-
|
25
|
-
def caching_policy_for(content_type)
|
26
|
-
caching_policies.fetch(content_type.to_s, caching_policies[:default])
|
27
|
-
end
|
28
|
-
|
29
|
-
def default_caching_policy
|
30
|
-
caching_policies[:default]
|
31
|
-
end
|
32
|
-
|
33
|
-
def caching_policies
|
34
|
-
@caching_policies ||= Map.new
|
35
|
-
end
|
36
|
-
|
37
|
-
protected
|
38
|
-
class BrowserCachePolicy
|
39
|
-
attr_accessor :policies
|
40
|
-
|
41
|
-
def initialize(options)
|
42
|
-
@policies = Map.from_hash(options)
|
43
|
-
end
|
44
|
-
|
45
|
-
def cache_control
|
46
|
-
policy = []
|
47
|
-
policy << "max-age=#{policies.max_age}" if policies.has_key?(:max_age)
|
48
|
-
policy << "s-maxage=#{s_maxage}" if policies.has_key?(:s_maxage)
|
49
|
-
policy << "public" if policies.fetch(:public, false)
|
50
|
-
policy << "private" if policies.fetch(:private, false)
|
51
|
-
policy << "no-cache" if policies.fetch(:no_cache, false)
|
52
|
-
policy << "no-store" if policies.fetch(:no_store, false)
|
53
|
-
policy << "must-revalidate" if policies.fetch(:must_revalidate, false)
|
54
|
-
policy << "proxy-revalidate" if policies.fetch(:proxy_revalidate, false)
|
55
|
-
if policy.empty?
|
56
|
-
nil
|
57
|
-
else
|
58
|
-
policy.join(", ")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def expires
|
63
|
-
if expiration = policies.fetch(:expires, nil)
|
64
|
-
CGI.rfc1123_date(expiration)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
6
|
class << self
|
71
|
-
def s3_sync_options
|
72
|
-
@@options
|
73
|
-
end
|
74
|
-
|
75
7
|
def registered(app, options_hash = {}, &block)
|
76
|
-
options = Options.new
|
8
|
+
options = Options.new
|
77
9
|
yield options if block_given?
|
78
10
|
|
79
11
|
@@options = options
|
@@ -88,9 +20,12 @@ module Middleman
|
|
88
20
|
::Middleman::S3Sync.sync if options.after_build
|
89
21
|
end
|
90
22
|
end
|
91
|
-
|
92
23
|
alias :included :registered
|
93
24
|
|
25
|
+
def s3_sync_options
|
26
|
+
@@options
|
27
|
+
end
|
28
|
+
|
94
29
|
module Helpers
|
95
30
|
def s3_sync_options
|
96
31
|
::Middleman::S3Sync.s3_sync_options
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'fog'
|
2
|
+
require 'pmap'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'middleman/s3_sync/version'
|
5
|
+
require 'middleman/s3_sync/options'
|
6
|
+
require 'middleman-s3_sync/commands'
|
7
|
+
require 'middleman/s3_sync/status'
|
8
|
+
require 'middleman/s3_sync/resource'
|
9
|
+
require 'middleman-s3_sync/extension'
|
10
|
+
require 'ruby-progressbar'
|
11
|
+
|
12
|
+
Fog::Logger[:warning] = nil
|
13
|
+
|
14
|
+
module Middleman
|
15
|
+
module S3Sync
|
16
|
+
class << self
|
17
|
+
include Status
|
18
|
+
|
19
|
+
def sync
|
20
|
+
unless work_to_be_done?
|
21
|
+
say_status "\nAll S3 files are up to date."
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
25
|
+
say_status "\nReady to apply updates to #{s3_sync_options.bucket}."
|
26
|
+
|
27
|
+
ignore_resources
|
28
|
+
create_resources
|
29
|
+
update_resources
|
30
|
+
delete_resources
|
31
|
+
end
|
32
|
+
|
33
|
+
def bucket
|
34
|
+
@bucket ||= connection.directories.get(s3_sync_options.bucket)
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
def connection
|
39
|
+
@connection ||= Fog::Storage.new({
|
40
|
+
:provider => 'AWS',
|
41
|
+
:aws_access_key_id => s3_sync_options.aws_access_key_id,
|
42
|
+
:aws_secret_access_key => s3_sync_options.aws_secret_access_key,
|
43
|
+
:region => s3_sync_options.region
|
44
|
+
})
|
45
|
+
end
|
46
|
+
|
47
|
+
def resources
|
48
|
+
@resources ||= paths.pmap do |p|
|
49
|
+
progress_bar.increment
|
50
|
+
S3Sync::Resource.new(p)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def progress_bar
|
55
|
+
@progress_bar ||= ProgressBar.create(total: paths.length)
|
56
|
+
end
|
57
|
+
|
58
|
+
def paths
|
59
|
+
@paths ||= begin
|
60
|
+
say_status "Gathering the paths to evaluate."
|
61
|
+
(remote_paths + local_paths).uniq.sort
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def local_paths
|
66
|
+
@local_paths ||= begin
|
67
|
+
local_paths = (Dir[build_dir + "/**/*"] + Dir[build_dir + "/**/.*"])
|
68
|
+
.reject { |p| File.directory?(p) }
|
69
|
+
|
70
|
+
if s3_sync_options.prefer_gzip
|
71
|
+
local_paths.reject! { |p| p =~ /\.gz$/ && File.exist?(p.gsub(/\.gz$/, '')) }
|
72
|
+
end
|
73
|
+
|
74
|
+
local_paths.pmap { |p| p.gsub(/#{build_dir}\//, '') }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def remote_paths
|
79
|
+
@remote_paths ||= bucket.files.map{ |f| f.key }.reject { |p| p =~ %r{/$} }
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_resources
|
83
|
+
files_to_create.each do |r|
|
84
|
+
r.create!
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def update_resources
|
89
|
+
files_to_update.each do |r|
|
90
|
+
r.update!
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def delete_resources
|
95
|
+
files_to_delete.each do |r|
|
96
|
+
r.destroy!
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def ignore_resources
|
101
|
+
files_to_ignore.each do |r|
|
102
|
+
r.ignore!
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def work_to_be_done?
|
107
|
+
!(files_to_create.empty? && files_to_update.empty? && files_to_delete.empty?)
|
108
|
+
end
|
109
|
+
|
110
|
+
def files_to_delete
|
111
|
+
@files_to_delete ||= if s3_sync_options.delete
|
112
|
+
resources.select { |r| r.to_delete? }
|
113
|
+
else
|
114
|
+
[]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def files_to_create
|
119
|
+
@files_to_create ||= resources.select { |r| r.to_create? }
|
120
|
+
end
|
121
|
+
|
122
|
+
def files_to_update
|
123
|
+
return resources.select { |r| r.local? } if s3_sync_options.force
|
124
|
+
|
125
|
+
@files_to_update ||= resources.select { |r| r.to_update? }
|
126
|
+
end
|
127
|
+
|
128
|
+
def files_to_ignore
|
129
|
+
@files_to_ignore ||= resources.select { |r| r.to_ignore? }
|
130
|
+
end
|
131
|
+
|
132
|
+
def build_dir
|
133
|
+
@build_dir ||= s3_sync_options.build_dir
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Middleman
|
2
|
+
module S3Sync
|
3
|
+
class Options
|
4
|
+
attr_accessor \
|
5
|
+
:prefix,
|
6
|
+
:bucket,
|
7
|
+
:region,
|
8
|
+
:aws_access_key_id,
|
9
|
+
:aws_secret_access_key,
|
10
|
+
:after_build,
|
11
|
+
:delete,
|
12
|
+
:existing_remote_file,
|
13
|
+
:build_dir,
|
14
|
+
:force,
|
15
|
+
:prefer_gzip,
|
16
|
+
:verbose
|
17
|
+
|
18
|
+
def add_caching_policy(content_type, options)
|
19
|
+
caching_policies[content_type.to_s] = BrowserCachePolicy.new(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def caching_policy_for(content_type)
|
23
|
+
caching_policies.fetch(content_type.to_s, caching_policies[:default])
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_caching_policy
|
27
|
+
caching_policies[:default]
|
28
|
+
end
|
29
|
+
|
30
|
+
def caching_policies
|
31
|
+
@caching_policies ||= Map.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def aws_access_key_id
|
35
|
+
@aws_access_key_id || ENV['AWS_ACCESS_KEY_ID']
|
36
|
+
end
|
37
|
+
|
38
|
+
def aws_secret_access_key
|
39
|
+
@aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY']
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete
|
43
|
+
@delete.nil? ? true : @delete
|
44
|
+
end
|
45
|
+
|
46
|
+
def after_build
|
47
|
+
@after_build.nil? ? false : @after_build
|
48
|
+
end
|
49
|
+
|
50
|
+
def prefer_gzip
|
51
|
+
(@prefer_gzip.nil? ? true : @prefer_gzip)
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
class BrowserCachePolicy
|
56
|
+
attr_accessor :policies
|
57
|
+
|
58
|
+
def initialize(options)
|
59
|
+
@policies = Map.from_hash(options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def cache_control
|
63
|
+
policy = []
|
64
|
+
policy << "max-age=#{policies.max_age}" if policies.has_key?(:max_age)
|
65
|
+
policy << "s-maxage=#{policies.s_maxage}" if policies.has_key?(:s_maxage)
|
66
|
+
policy << "public" if policies.fetch(:public, false)
|
67
|
+
policy << "private" if policies.fetch(:private, false)
|
68
|
+
policy << "no-cache" if policies.fetch(:no_cache, false)
|
69
|
+
policy << "no-store" if policies.fetch(:no_store, false)
|
70
|
+
policy << "must-revalidate" if policies.fetch(:must_revalidate, false)
|
71
|
+
policy << "proxy-revalidate" if policies.fetch(:proxy_revalidate, false)
|
72
|
+
if policy.empty?
|
73
|
+
nil
|
74
|
+
else
|
75
|
+
policy.join(", ")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_s
|
80
|
+
cache_control
|
81
|
+
end
|
82
|
+
|
83
|
+
def expires
|
84
|
+
if expiration = policies.fetch(:expires, nil)
|
85
|
+
CGI.rfc1123_date(expiration)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -76,7 +76,7 @@ module Middleman
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def destroy!
|
79
|
-
say_status "Deleting".red + " #{path}"
|
79
|
+
say_status "Deleting".red + " #{path}"
|
80
80
|
s3_resource.destroy
|
81
81
|
end
|
82
82
|
|
@@ -91,6 +91,10 @@ module Middleman
|
|
91
91
|
bucket.files.create(to_h)
|
92
92
|
end
|
93
93
|
|
94
|
+
def ignore!
|
95
|
+
say_status "Ignoring".yellow + " #{path} #{ redirect? ? "(redirect)".white : "" }"
|
96
|
+
end
|
97
|
+
|
94
98
|
def to_delete?
|
95
99
|
status == :deleted
|
96
100
|
end
|
@@ -107,6 +111,10 @@ module Middleman
|
|
107
111
|
status == :updated
|
108
112
|
end
|
109
113
|
|
114
|
+
def to_ignore?
|
115
|
+
status == :ignored
|
116
|
+
end
|
117
|
+
|
110
118
|
def body
|
111
119
|
@body = File.open(local_path)
|
112
120
|
end
|
@@ -120,6 +128,8 @@ module Middleman
|
|
120
128
|
end
|
121
129
|
elsif local?
|
122
130
|
:new
|
131
|
+
elsif redirect?
|
132
|
+
:ignored
|
123
133
|
else
|
124
134
|
:deleted
|
125
135
|
end
|
@@ -133,6 +143,10 @@ module Middleman
|
|
133
143
|
s3_resource
|
134
144
|
end
|
135
145
|
|
146
|
+
def redirect?
|
147
|
+
s3_resource.metadata.has_key? 'x-amz-website-redirect-location'
|
148
|
+
end
|
149
|
+
|
136
150
|
def relative_path
|
137
151
|
@relative_path ||= local_path.gsub(/#{build_dir}/, '')
|
138
152
|
end
|
data/middleman-s3_sync.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'middleman
|
4
|
+
require 'middleman/s3_sync/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "middleman-s3_sync"
|
@@ -27,4 +27,8 @@ Gem::Specification.new do |gem|
|
|
27
27
|
gem.add_development_dependency 'rake'
|
28
28
|
gem.add_development_dependency 'pry'
|
29
29
|
gem.add_development_dependency 'pry-nav'
|
30
|
+
gem.add_development_dependency 'rspec'
|
31
|
+
gem.add_development_dependency 'timerizer'
|
32
|
+
gem.add_development_dependency 'travis'
|
33
|
+
gem.add_development_dependency 'travis-lint'
|
30
34
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'middleman/s3_sync/options'
|
3
|
+
|
4
|
+
describe Middleman::S3Sync::Options do
|
5
|
+
subject(:options) { Middleman::S3Sync::Options.new }
|
6
|
+
|
7
|
+
its(:delete) { should be_true }
|
8
|
+
its(:after_build) { should be_false }
|
9
|
+
its(:prefer_gzip) { should be_true }
|
10
|
+
its(:aws_secret_access_key) { should == ENV['AWS_SECRET_ACCESS_KEY'] }
|
11
|
+
its(:aws_access_key_id) { should == ENV['AWS_ACCESS_KEY_ID'] }
|
12
|
+
its(:caching_policies) { should be_empty }
|
13
|
+
its(:default_caching_policy) { should be_nil }
|
14
|
+
|
15
|
+
context "browser caching policy" do
|
16
|
+
let(:policy) { options.default_caching_policy }
|
17
|
+
|
18
|
+
it "should have a blank default caching policy" do
|
19
|
+
options.add_caching_policy :default, {}
|
20
|
+
|
21
|
+
policy.should_not be_nil
|
22
|
+
|
23
|
+
policy.to_s.should_not =~ /max-age=/
|
24
|
+
policy.to_s.should_not =~ /s-maxage=/
|
25
|
+
policy.to_s.should_not =~ /public/
|
26
|
+
policy.to_s.should_not =~ /private/
|
27
|
+
policy.to_s.should_not =~ /no-cache/
|
28
|
+
policy.to_s.should_not =~ /no-store/
|
29
|
+
policy.to_s.should_not =~ /must-revalidate/
|
30
|
+
policy.to_s.should_not =~ /proxy-revalidate/
|
31
|
+
policy.expires.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set the max-age policy" do
|
35
|
+
options.add_caching_policy :default, :max_age => 300
|
36
|
+
|
37
|
+
policy.to_s.should =~ /max-age=300/
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should set the s-maxage policy" do
|
41
|
+
options.add_caching_policy :default, :s_maxage => 300
|
42
|
+
|
43
|
+
policy.to_s.should =~ /s-maxage=300/
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should set the public flag on the policy if set to true" do
|
47
|
+
options.add_caching_policy :default, :public => true
|
48
|
+
|
49
|
+
policy.to_s.should =~ /public/
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not set the public flag on the policy if it is set to false" do
|
53
|
+
options.add_caching_policy :default, :public => false
|
54
|
+
|
55
|
+
policy.to_s.should_not =~ /public/
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set the private flag on the policy if it is set to true" do
|
59
|
+
options.add_caching_policy :default, :private => true
|
60
|
+
|
61
|
+
policy.to_s.should =~ /private/
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should set the no-cache flag on the policy if it is set to true" do
|
65
|
+
options.add_caching_policy :default, :no_cache => true
|
66
|
+
|
67
|
+
policy.to_s.should =~ /no-cache/
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should set the no-store flag if it is set to true" do
|
71
|
+
options.add_caching_policy :default, :no_store => true
|
72
|
+
|
73
|
+
policy.to_s.should =~ /no-store/
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should set the must-revalidate policy if it is set to true" do
|
77
|
+
options.add_caching_policy :default, :must_revalidate => true
|
78
|
+
|
79
|
+
policy.to_s.should =~ /must-revalidate/
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should set the proxy-revalidate policy if it is set to true" do
|
83
|
+
options.add_caching_policy :default, :proxy_revalidate => true
|
84
|
+
|
85
|
+
policy.to_s.should =~ /proxy-revalidate/
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should divide caching policies with commas and a space" do
|
89
|
+
options.add_caching_policy :default, :max_age => 300, :public => true
|
90
|
+
|
91
|
+
policies = policy.to_s.split(/, /)
|
92
|
+
policies.length.should == 2
|
93
|
+
policies.first.should == 'max-age=300'
|
94
|
+
policies.last.should == 'public'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should set the expiration date" do
|
98
|
+
expiration = 1.years.from_now
|
99
|
+
|
100
|
+
options.add_caching_policy :default, :expires => expiration
|
101
|
+
policy.expires.should == CGI.rfc1123_date(expiration)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'middleman-s3_sync'
|
9
|
+
require 'timerizer'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
|
22
|
+
config.before :all do
|
23
|
+
Fog.mock!
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-s3_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.14
|
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: 2013-
|
13
|
+
date: 2013-08-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: middleman-core
|
@@ -156,6 +156,70 @@ dependencies:
|
|
156
156
|
- - ! '>='
|
157
157
|
- !ruby/object:Gem::Version
|
158
158
|
version: '0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: rspec
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: timerizer
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
179
|
+
requirements:
|
180
|
+
- - ! '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
type: :development
|
184
|
+
prerelease: false
|
185
|
+
version_requirements: !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - ! '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
- !ruby/object:Gem::Dependency
|
192
|
+
name: travis
|
193
|
+
requirement: !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
195
|
+
requirements:
|
196
|
+
- - ! '>='
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
type: :development
|
200
|
+
prerelease: false
|
201
|
+
version_requirements: !ruby/object:Gem::Requirement
|
202
|
+
none: false
|
203
|
+
requirements:
|
204
|
+
- - ! '>='
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
- !ruby/object:Gem::Dependency
|
208
|
+
name: travis-lint
|
209
|
+
requirement: !ruby/object:Gem::Requirement
|
210
|
+
none: false
|
211
|
+
requirements:
|
212
|
+
- - ! '>='
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '0'
|
215
|
+
type: :development
|
216
|
+
prerelease: false
|
217
|
+
version_requirements: !ruby/object:Gem::Requirement
|
218
|
+
none: false
|
219
|
+
requirements:
|
220
|
+
- - ! '>='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
159
223
|
description: Only syncs files that have been updated to S3.
|
160
224
|
email:
|
161
225
|
- fred@fredjean.net
|
@@ -164,6 +228,8 @@ extensions: []
|
|
164
228
|
extra_rdoc_files: []
|
165
229
|
files:
|
166
230
|
- .gitignore
|
231
|
+
- .rspec
|
232
|
+
- .travis.yml
|
167
233
|
- Changelog.md
|
168
234
|
- Gemfile
|
169
235
|
- LICENSE.txt
|
@@ -172,11 +238,16 @@ files:
|
|
172
238
|
- lib/middleman-s3_sync.rb
|
173
239
|
- lib/middleman-s3_sync/commands.rb
|
174
240
|
- lib/middleman-s3_sync/extension.rb
|
175
|
-
- lib/middleman
|
241
|
+
- lib/middleman/s3_sync.rb
|
242
|
+
- lib/middleman/s3_sync/options.rb
|
176
243
|
- lib/middleman/s3_sync/resource.rb
|
177
244
|
- lib/middleman/s3_sync/status.rb
|
245
|
+
- lib/middleman/s3_sync/version.rb
|
178
246
|
- lib/middleman_extension.rb
|
179
247
|
- middleman-s3_sync.gemspec
|
248
|
+
- spec/options_spec.rb
|
249
|
+
- spec/resource_spec.rb
|
250
|
+
- spec/spec_helper.rb
|
180
251
|
homepage: http://github.com/fredjean/middleman-s3_sync
|
181
252
|
licenses: []
|
182
253
|
post_install_message:
|
@@ -191,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
262
|
version: '0'
|
192
263
|
segments:
|
193
264
|
- 0
|
194
|
-
hash: -
|
265
|
+
hash: -2891873384991304950
|
195
266
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
267
|
none: false
|
197
268
|
requirements:
|
@@ -200,11 +271,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
271
|
version: '0'
|
201
272
|
segments:
|
202
273
|
- 0
|
203
|
-
hash: -
|
274
|
+
hash: -2891873384991304950
|
204
275
|
requirements: []
|
205
276
|
rubyforge_project:
|
206
277
|
rubygems_version: 1.8.23
|
207
278
|
signing_key:
|
208
279
|
specification_version: 3
|
209
280
|
summary: Tries really, really hard not to push files to S3.
|
210
|
-
test_files:
|
281
|
+
test_files:
|
282
|
+
- spec/options_spec.rb
|
283
|
+
- spec/resource_spec.rb
|
284
|
+
- spec/spec_helper.rb
|