middleman-redirects 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d6c42d9e534315b7b2d89ee6e616aad23caa29f
4
+ data.tar.gz: dfa43bb0c08a14141c9570902e28c659d5c062f8
5
+ SHA512:
6
+ metadata.gz: d6fa0b135e6cd6286b03ab3f257db52f4f234264652f719918af613902339a538b87285de7846a44c370025871f512aa26052077177e9eb1fd562c86798824bb
7
+ data.tar.gz: 91927a80a94973361bbbe01b68eeeb737f04d01403c7fcded253cd77340af0f89ebc3fadd842393a6c4a075fcfdddd33243ec9ecec3db13f09c100da74503951
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in middleman-redirects.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Middleman::Redirects
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/middleman/redirects`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'middleman-redirects'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install middleman-redirects
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/middleman-redirects/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "middleman/redirects"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module Redirects
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,66 @@
1
+ require 'middleman-core'
2
+ require 'pathname'
3
+
4
+ module Middleman
5
+ module Redirects
6
+ class Extension < Middleman::Extension
7
+ def initialize(app, options_hash={}, &block)
8
+ app.use ::Middleman::Redirects::Middleware
9
+ ::Middleman::Redirects.redirects_file_path = Pathname.new(app.root).join("REDIRECTS").freeze
10
+ super
11
+ end
12
+ end
13
+
14
+ class Middleware
15
+ def initialize(app)
16
+ @app = app
17
+ end
18
+
19
+ def call(env)
20
+ source = env['PATH_INFO']
21
+ if destination = ::Middleman::Redirects.redirects[source]
22
+ [302, {"Location" => destination}, []]
23
+ else
24
+ @app.call(env)
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.redirects_file_path=(v)
30
+ @redirects_file_path = v
31
+ end
32
+
33
+ def self.redirects_file_path
34
+ @redirects_file_path
35
+ end
36
+
37
+ def self.redirects
38
+ if self.redirects_file_path.mtime != @mtime
39
+ read_redirects
40
+ else
41
+ @redirects
42
+ end
43
+ end
44
+
45
+ def self.read_redirects
46
+ @mtime = self.redirects_file_path.mtime
47
+ @redirects = Hash[self.redirects_file_path.each_line.map do |line|
48
+ next if line =~ /^#/ # ignore comments
49
+
50
+ source, destination = line.split.map { |s| URI.parse(s) }
51
+
52
+ # don't allow a single / or * as source
53
+ next if source.path == '/'
54
+ next if source.path == '.*'
55
+ next if source.path == '*' # invalid
56
+
57
+ [source.to_s, destination.to_s]
58
+ end.compact]
59
+ p @redirects
60
+ end
61
+ end
62
+ end
63
+
64
+ ::Middleman::Extensions.register(:redirects, ::Middleman::Redirects::Extension)
65
+
66
+ require "middleman/redirects/version"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middleman/redirects/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "middleman-redirects"
8
+ spec.version = Middleman::Redirects::VERSION
9
+ spec.authors = ["Martin Schurrer"]
10
+ spec.email = ["martin@schuerrer.org"]
11
+
12
+ spec.summary = %q{Makes middleman support REDIRECT files in development}
13
+ spec.homepage = "https://github.com/PSPDFKit-labs/middleman-redirects"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-redirects
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Schurrer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - martin@schuerrer.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/middleman/redirects.rb
57
+ - lib/middleman/redirects/version.rb
58
+ - middleman-redirects.gemspec
59
+ homepage: https://github.com/PSPDFKit-labs/middleman-redirects
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.3
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Makes middleman support REDIRECT files in development
83
+ test_files: []