middleman-s3_redirect 3.0.0
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/lib/middleman-s3_redirect/commands.rb +29 -0
- data/lib/middleman-s3_redirect/extension.rb +104 -0
- data/lib/middleman-s3_redirect/version.rb +5 -0
- data/lib/middleman-s3_redirect.rb +10 -0
- data/middleman-s3_redirect.gemspec +23 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Frederic Jean
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Middleman::S3Redirect
|
2
|
+
|
3
|
+
AWS S3 allows redirects to occur directly from an S3 object. This gem
|
4
|
+
automates configuring AWS S3 to redirect from one path to another.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'middleman-s3_redirect'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install middleman-s3_sync
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
You need to add the following code to your ```config.rb``` file:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
activate :s3_redirect do |config|
|
26
|
+
config.bucket = 'my.bucket.com' # The name of the S3 bucket you are targetting. This is globally unique.
|
27
|
+
config.region = 'us-west-1' # The AWS region for your bucket.
|
28
|
+
config.aws_access_key_id = 'AWS KEY ID'
|
29
|
+
config.aws_secret_access_key = 'AWS SECRET KEY'
|
30
|
+
config.after_build = false # We chain after the build step by default. This may not be your desired behavior...
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
The ```redirect``` method register a redirect:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
redirect '/old/path', '/new/path'
|
38
|
+
```
|
39
|
+
|
40
|
+
You can then configure S3 to redirect these path by running ```middleman s3_redirect```.
|
41
|
+
|
42
|
+
## A Debt of Gratitude
|
43
|
+
|
44
|
+
I used Middleman Sync as a template for building a Middleman extension.
|
45
|
+
The code is well structured and easy to understand and it was easy to
|
46
|
+
extend it to add my synchronization code. My gratitude goes to @karlfreeman
|
47
|
+
and is work on Middleman sync.
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'middleman-core/cli'
|
2
|
+
require 'middleman-s3_redirect/extension'
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module Cli
|
6
|
+
class S3Redirect < Thor
|
7
|
+
include Thor::Actions
|
8
|
+
|
9
|
+
check_unknown_options!
|
10
|
+
|
11
|
+
namespace :s3_redirect
|
12
|
+
|
13
|
+
def self.exit_on_failure?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "s3_redirect", "Creates redirect objects directly in S3."
|
18
|
+
def s3_redirect
|
19
|
+
shared_inst = ::Middleman::Application.server.inst
|
20
|
+
bucket = shared_inst.options.bucket
|
21
|
+
if (!bucket)
|
22
|
+
raise Thor::Error.new "You need to activate this extension."
|
23
|
+
end
|
24
|
+
|
25
|
+
::Middleman::S3Redirect.generate
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'middleman-core'
|
2
|
+
|
3
|
+
module Middleman
|
4
|
+
module S3Redirect
|
5
|
+
class Options < Struct.new(
|
6
|
+
:prefix,
|
7
|
+
:public_path,
|
8
|
+
:bucket,
|
9
|
+
:region,
|
10
|
+
:aws_access_key_id,
|
11
|
+
:aws_secret_access_key,
|
12
|
+
:after_build
|
13
|
+
)
|
14
|
+
|
15
|
+
def redirect(from, to)
|
16
|
+
redirects << RedirectEntry.new(from, to)
|
17
|
+
end
|
18
|
+
|
19
|
+
def redirects
|
20
|
+
@redirects ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
class RedirectEntry
|
25
|
+
attr_reader :from, :to
|
26
|
+
def initialize(from, to)
|
27
|
+
@from = normalize(from)
|
28
|
+
@to = to
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def normalize(path)
|
33
|
+
unless path =~ /\.html$/
|
34
|
+
path << '/' unless path =~ /\/$/
|
35
|
+
path << 'index.html'
|
36
|
+
end
|
37
|
+
path = path[1..path.length] if path[0] = '/'
|
38
|
+
path
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
class << self
|
45
|
+
def options
|
46
|
+
@@options
|
47
|
+
end
|
48
|
+
|
49
|
+
def registered(app, options_hash = {}, &block)
|
50
|
+
options = Options.new(options.hash)
|
51
|
+
yield options if block_given?
|
52
|
+
|
53
|
+
@@options = options
|
54
|
+
|
55
|
+
app.send :include, Helpers
|
56
|
+
|
57
|
+
options.public_path ||= "build"
|
58
|
+
|
59
|
+
app.after_configuration do |config|
|
60
|
+
after_build do |builder|
|
61
|
+
::Middleman::S3Redirect.generate if options.after_build
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
alias :included :registered
|
66
|
+
|
67
|
+
def generate
|
68
|
+
options.redirects.each do |redirect|
|
69
|
+
puts "Redirecting /#{redirect.from} to #{redirect.to}"
|
70
|
+
bucket.files.create({
|
71
|
+
:key => redirect.from,
|
72
|
+
:public => true,
|
73
|
+
:acl => 'public-read',
|
74
|
+
:body => '',
|
75
|
+
'x-amz-website-redirect-location' => "#{redirect.to}"
|
76
|
+
})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def connection
|
81
|
+
@connection ||= Fog::Storage.new({
|
82
|
+
:provider => 'AWS',
|
83
|
+
:aws_access_key_id => options.aws_access_key_id,
|
84
|
+
:aws_secret_access_key => options.aws_secret_access_key,
|
85
|
+
:region => options.region
|
86
|
+
})
|
87
|
+
end
|
88
|
+
|
89
|
+
def bucket
|
90
|
+
@bucket ||= connection.directories.get(options.bucket)
|
91
|
+
end
|
92
|
+
|
93
|
+
def s3_files
|
94
|
+
@s3_files ||= bucket.files
|
95
|
+
end
|
96
|
+
|
97
|
+
module Helpers
|
98
|
+
def redirect(from, to)
|
99
|
+
::Middleman::S3Redirect.options.redirect(from, to)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'middleman-core'
|
2
|
+
require 'fog'
|
3
|
+
require 'parallel'
|
4
|
+
require 'middleman-s3_redirect/version'
|
5
|
+
require 'middleman-s3_redirect/commands'
|
6
|
+
|
7
|
+
::Middleman::Extensions.register(:s3_redirect, '>= 3.0.0') do
|
8
|
+
require 'middleman-s3_redirect/extension'
|
9
|
+
::Middleman::S3Redirect
|
10
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'middleman-s3_redirect/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "middleman-s3_redirect"
|
8
|
+
gem.version = Middleman::S3Redirect::VERSION
|
9
|
+
gem.authors = ["Frederic Jean"]
|
10
|
+
gem.email = ["fred@fredjean.net"]
|
11
|
+
gem.description = %q{Generates redirects via S3 API.}
|
12
|
+
gem.summary = %q{Nothing to see here... Move along.}
|
13
|
+
gem.homepage = "https://github.com/fredjean/middleman-s3_redirect"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
|
21
|
+
gem.add_runtime_dependency 'middleman-core', '>= 3.0.0'
|
22
|
+
gem.add_runtime_dependency 'fog'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-s3_redirect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 3.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Frederic Jean
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
type: :runtime
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
name: middleman-core
|
23
|
+
prerelease: false
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
name: fog
|
39
|
+
prerelease: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Generates redirects via S3 API.
|
47
|
+
email:
|
48
|
+
- fred@fredjean.net
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/middleman-s3_redirect.rb
|
59
|
+
- lib/middleman-s3_redirect/commands.rb
|
60
|
+
- lib/middleman-s3_redirect/extension.rb
|
61
|
+
- lib/middleman-s3_redirect/version.rb
|
62
|
+
- middleman-s3_redirect.gemspec
|
63
|
+
homepage: https://github.com/fredjean/middleman-s3_redirect
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
hash: -3985194922976205752
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
hash: -3985194922976205752
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.8.23
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Nothing to see here... Move along.
|
93
|
+
test_files: []
|