middleman-alias 0.0.1

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: 2ecd02c745ef27ba02d7fcdfc20362fcc0ba2f5d
4
+ data.tar.gz: c703d3d75754481b339f8aeb47048d596eff3529
5
+ SHA512:
6
+ metadata.gz: 24d174defd0c85ef813cf3d77008b1be2412cf4aab79142e6536fead7694f53ee4bf9f15649a49b4287176ea4cc1e56a7b0f20f9b859e3bc7d04247f8135f669
7
+ data.tar.gz: 5d7c9cc77e980586246cd5aac02811ba1b7734441b72c89895f9ce9bf285f230d34bd1d58ba0073b6efb02452b0757e3256749259439c1380372c85ef8865403
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in middleman-alias.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jeremy Green
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,56 @@
1
+ # Middleman::Alias
2
+
3
+ Add alias/redirect information to your middleman pages and posts.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'middleman-alias'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install middleman-alias
18
+
19
+ ## Usage
20
+
21
+ First you need to activate the module in your `config.rb`.
22
+
23
+ ```
24
+ activate :alias
25
+ ```
26
+
27
+ Then you need to generate the template that will handle the aliases.
28
+ You only need to do this one time.
29
+
30
+ ```
31
+ middleman alias_template
32
+ ```
33
+
34
+ Then you can add an `alias` to the frontmatter for a page or post and
35
+ middleman-alias will generate a SEO friendly redirect page at that
36
+ location.
37
+
38
+ Say that you have a page at `/foo.html`, but that the page used to live
39
+ at `/old-foo.html`. In the frontmatter for `foo.html` you can alias it
40
+ to the old address.
41
+
42
+ ```
43
+ title : "A post about foo"
44
+ alias : /old-foo.html
45
+ ```
46
+
47
+ Now someone can visit your middleman site at `/old-foo.html` and they'll
48
+ be redirected to `/foo.html`.
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( http://github.com/<my-github-username>/middleman-alias/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ Feature: Aliases
2
+ Scenario: Aliases should generate redirect pages
3
+ Given the Server is running at "alias-app"
4
+ When I go to "/foo.html"
5
+ Then I should see "You are being redirected"
@@ -0,0 +1,7 @@
1
+ Feature: Template generator CLI command
2
+ Scenario: Create a new alias template with the command line
3
+ Given a fixture app "empty-alias-app"
4
+ And I run `middleman alias_template`
5
+ Then the exit status should be 0
6
+ Then the following files should exist:
7
+ | source/alias.html.erb |
@@ -0,0 +1,7 @@
1
+ ENV["TEST"] = "true"
2
+ ENV["AUTOLOAD_SPROCKETS"] = "false"
3
+
4
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
5
+ require "middleman-core"
6
+ require "middleman-core/step_definitions"
7
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-alias')
@@ -0,0 +1,2 @@
1
+ activate :alias
2
+ #redirect "foo.html", :to => "bar.html"
@@ -0,0 +1,3 @@
1
+ <meta http-equiv="refresh" content="0; url=<%= destination %>">
2
+ <link rel="canonical" href="<%= destination %>" />
3
+ <%= link_to "You are being redirected.", destination %>
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Bar"
3
+ alias: foo.html
4
+ ---
5
+
6
+ This is the bar page.
@@ -0,0 +1,8 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <%= yield %>
7
+ </body>
8
+ </html>
@@ -0,0 +1 @@
1
+ activate :alias
File without changes
@@ -0,0 +1,33 @@
1
+ require 'middleman-core/cli'
2
+
3
+ module Middleman
4
+ module Cli
5
+ # This class provides an "article" command for the middleman CLI.
6
+ class AliasGenerator < Thor
7
+ include Thor::Actions
8
+
9
+ check_unknown_options!
10
+
11
+ namespace :alias_template
12
+
13
+ def self.source_root
14
+ ENV['MM_ROOT']
15
+ end
16
+
17
+ # Tell Thor to exit with a nonzero exit code on failure
18
+ def self.exit_on_failure?
19
+ true
20
+ end
21
+
22
+ desc "alias_template", "Create a new template to handle alias redirects"
23
+
24
+ def alias_template
25
+ source_root = ENV['MM_ROOT']
26
+ template_sub_path = "source/alias.html.erb"
27
+ template_filename = "#{source_root}/#{template_sub_path}"
28
+ FileUtils.cp "#{File.dirname(__FILE__)}/template/source/alias.html.erb", template_filename
29
+ puts "Alias template generated in #{template_sub_path}"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'middleman-core'
2
+
3
+ module Middleman
4
+ class AliasExtension < Middleman::Extension
5
+ def initialize(app, options_hash={}, &block)
6
+ super
7
+ end
8
+
9
+ def manipulate_resource_list(resources)
10
+ resources.each do |resource|
11
+ if resource.data["alias"]
12
+ redirect = Sitemap::Resource.new(@app.sitemap, resource.data["alias"]).tap do |p|
13
+ p.proxy_to("alias.html")
14
+ p.add_metadata locals: {
15
+ destination: resource.destination_path
16
+ }
17
+ end
18
+ resources.push redirect
19
+ end
20
+ end
21
+ resources
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ <meta http-equiv="refresh" content="0; url=<%= destination %>">
2
+ <link rel="canonical" href="<%= destination %>" />
3
+ <%= link_to "You are being redirected.", destination %>
4
+
@@ -0,0 +1,3 @@
1
+ module MiddlemanAlias
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'middleman-core'
2
+ require "middleman-alias/version"
3
+ require "middleman-alias/commands"
4
+
5
+ ::Middleman::Extensions.register(:alias) do
6
+ require 'middleman-alias/extension'
7
+ ::Middleman::AliasExtension
8
+ end
9
+
10
+ #module Middleman
11
+ #module Alias
12
+ ## Your code goes here...
13
+ #end
14
+ #end
@@ -0,0 +1 @@
1
+ require "middleman-alias"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middleman-alias/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "middleman-alias"
8
+ spec.version = MiddlemanAlias::VERSION
9
+ spec.authors = ["Jeremy Green"]
10
+ spec.email = ["jeremy@octolabs.com"]
11
+ spec.summary = %q{Redirects for Middleman that are friendly to the Googles.}
12
+ spec.description = %q{Redirects for Middleman that are friendly to the Googles.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "middleman-core", "~> 3.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "cucumber", "~> 1.3.10"
26
+ spec.add_development_dependency "aruba", "~> 0.5.1"
27
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-alias
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Green
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cucumber
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.10
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.10
69
+ - !ruby/object:Gem::Dependency
70
+ name: aruba
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.5.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.5.1
83
+ description: Redirects for Middleman that are friendly to the Googles.
84
+ email:
85
+ - jeremy@octolabs.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - features/alias.feature
96
+ - features/generator_cli.feature
97
+ - features/support/env.rb
98
+ - fixtures/alias-app/config.rb
99
+ - fixtures/alias-app/source/alias.html.erb
100
+ - fixtures/alias-app/source/bar.html.erb
101
+ - fixtures/alias-app/source/layout.html.erb
102
+ - fixtures/empty-alias-app/config.rb
103
+ - fixtures/empty-alias-app/source/.gitkeep
104
+ - lib/middleman-alias.rb
105
+ - lib/middleman-alias/commands.rb
106
+ - lib/middleman-alias/extension.rb
107
+ - lib/middleman-alias/template/source/alias.html.erb
108
+ - lib/middleman-alias/version.rb
109
+ - lib/middleman_extension.rb
110
+ - middleman-alias.gemspec
111
+ homepage: ''
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.2.0.rc.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Redirects for Middleman that are friendly to the Googles.
135
+ test_files:
136
+ - features/alias.feature
137
+ - features/generator_cli.feature
138
+ - features/support/env.rb