Move off-by-default extensions into middleman-more, make middleman-more itself an extension
This commit is contained in:
parent
182ad87ad3
commit
1cad726c81
|
@ -16,19 +16,6 @@ Feature: Build Clean
|
||||||
| build/should_be_ignored3.html |
|
| build/should_be_ignored3.html |
|
||||||
And the file "build/index.html" should contain "Comment in layout"
|
And the file "build/index.html" should contain "Comment in layout"
|
||||||
|
|
||||||
Scenario: Clean an app with directory indexes
|
|
||||||
Given a successfully built app at "clean-dir-app"
|
|
||||||
Then the following files should exist:
|
|
||||||
| build/about/index.html |
|
|
||||||
Given a successfully built app at "clean-dir-app" with flags "--clean"
|
|
||||||
Then the following files should exist:
|
|
||||||
| build/about/index.html |
|
|
||||||
|
|
||||||
Scenario: Clean build an app that's never been built
|
|
||||||
Given a successfully built app at "clean-dir-app" with flags "--clean"
|
|
||||||
Then the following files should exist:
|
|
||||||
| build/about/index.html |
|
|
||||||
|
|
||||||
Scenario: Clean build an app with newly ignored files and a nested output directory
|
Scenario: Clean build an app with newly ignored files and a nested output directory
|
||||||
Given a built app at "clean-nested-app"
|
Given a built app at "clean-nested-app"
|
||||||
Then a directory named "sub/dir" should exist
|
Then a directory named "sub/dir" should exist
|
||||||
|
|
|
@ -1,46 +1,14 @@
|
||||||
Feature: Text Files Without Extensions Should Build and Preview
|
Feature: Text Files Without Extensions Should Build and Preview
|
||||||
|
|
||||||
Scenario: Building Text Files without directory indexes
|
Scenario: Building Text Files without directory indexes
|
||||||
Given a fixture app "extensionless-text-files-app"
|
Given a successfully built app at "extensionless-text-files-app"
|
||||||
And a file named "config.rb" with:
|
|
||||||
"""
|
|
||||||
"""
|
|
||||||
And a successfully built app at "extensionless-text-files-app"
|
|
||||||
When I cd to "build"
|
When I cd to "build"
|
||||||
Then the following files should exist:
|
Then the following files should exist:
|
||||||
| CNAME |
|
| CNAME |
|
||||||
| LICENSE |
|
| LICENSE |
|
||||||
| README |
|
| README |
|
||||||
|
|
||||||
Scenario: Building Text Files with directory indexes
|
Scenario: Previewing Text Files
|
||||||
Given a fixture app "extensionless-text-files-app"
|
|
||||||
And a file named "config.rb" with:
|
|
||||||
"""
|
|
||||||
activate :directory_indexes
|
|
||||||
"""
|
|
||||||
And a successfully built app at "extensionless-text-files-app"
|
|
||||||
When I cd to "build"
|
|
||||||
Then the following files should exist:
|
|
||||||
| CNAME |
|
|
||||||
| LICENSE |
|
|
||||||
| README |
|
|
||||||
Then the following files should not exist:
|
|
||||||
| CNAME/index.html |
|
|
||||||
| LICENSE/index.html |
|
|
||||||
| README/index.html |
|
|
||||||
|
|
||||||
Scenario: Previewing Text Files without directory indexes
|
|
||||||
Given "directory_indexes" feature is "disabled"
|
|
||||||
Given the Server is running at "extensionless-text-files-app"
|
|
||||||
When I go to "/CNAME"
|
|
||||||
Then I should see "test.github.com"
|
|
||||||
When I go to "/LICENSE"
|
|
||||||
Then I should see "You have the right to remain classy."
|
|
||||||
When I go to "/README"
|
|
||||||
Then I should see "Bork bork bork"
|
|
||||||
|
|
||||||
Scenario: Previewing Text Files with directory indexes
|
|
||||||
Given "directory_indexes" feature is "enabled"
|
|
||||||
Given the Server is running at "extensionless-text-files-app"
|
Given the Server is running at "extensionless-text-files-app"
|
||||||
When I go to "/CNAME"
|
When I go to "/CNAME"
|
||||||
Then I should see "test.github.com"
|
Then I should see "test.github.com"
|
||||||
|
|
|
@ -2,33 +2,24 @@ Feature: Setting page settings through frontmatter
|
||||||
Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (build)
|
Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (build)
|
||||||
Given a successfully built app at "frontmatter-settings-app"
|
Given a successfully built app at "frontmatter-settings-app"
|
||||||
Then the following files should exist:
|
Then the following files should exist:
|
||||||
| build/proxied/index.html |
|
| build/proxied.html |
|
||||||
| build/no_index.html |
|
And the file "build/alternate_layout.html" should contain "Alternate layout"
|
||||||
And the file "build/alternate_layout/index.html" should contain "Alternate layout"
|
|
||||||
And the following files should not exist:
|
And the following files should not exist:
|
||||||
| build/ignored/index.html |
|
| build/ignored.html |
|
||||||
| build/no_index/index.html |
|
|
||||||
|
|
||||||
|
|
||||||
Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (preview)
|
Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (preview)
|
||||||
Given the Server is running at "frontmatter-settings-app"
|
Given the Server is running at "frontmatter-settings-app"
|
||||||
# When I go to "/proxied/"
|
When I go to "/alternate_layout.html"
|
||||||
# Then I should not see "File Not Found"
|
|
||||||
When I go to "/no_index.html"
|
|
||||||
Then I should not see "File Not Found"
|
|
||||||
When I go to "/alternate_layout/"
|
|
||||||
Then I should not see "File Not Found"
|
Then I should not see "File Not Found"
|
||||||
And I should see "Alternate layout"
|
And I should see "Alternate layout"
|
||||||
When I go to "/ignored.html"
|
When I go to "/ignored.html"
|
||||||
Then I should see "File Not Found"
|
Then I should see "File Not Found"
|
||||||
When I go to "/ignored/index.html"
|
When I go to "/ignored/index.html"
|
||||||
Then I should see "File Not Found"
|
Then I should see "File Not Found"
|
||||||
When I go to "/no_index/index.html"
|
|
||||||
Then I should see "File Not Found"
|
|
||||||
|
|
||||||
Scenario: Changing frontmatter in preview server
|
Scenario: Changing frontmatter in preview server
|
||||||
Given the Server is running at "frontmatter-settings-app"
|
Given the Server is running at "frontmatter-settings-app"
|
||||||
When I go to "/ignored/index.html"
|
When I go to "/ignored.html"
|
||||||
Then I should see "File Not Found"
|
Then I should see "File Not Found"
|
||||||
And the file "source/ignored.html.erb" has the contents
|
And the file "source/ignored.html.erb" has the contents
|
||||||
"""
|
"""
|
||||||
|
@ -38,5 +29,5 @@ Feature: Setting page settings through frontmatter
|
||||||
|
|
||||||
This file is no longer ignored.
|
This file is no longer ignored.
|
||||||
"""
|
"""
|
||||||
When I go to "/ignored/index.html"
|
When I go to "/ignored.html"
|
||||||
Then I should see "This file is no longer ignored."
|
Then I should see "This file is no longer ignored."
|
||||||
|
|
|
@ -46,23 +46,3 @@ Feature: relative_link_to helper
|
||||||
When I go to "/link_to/sub.html"
|
When I go to "/link_to/sub.html"
|
||||||
Then I should see 'absolute: <a href="../needs_index.html">Needs Index</a>'
|
Then I should see 'absolute: <a href="../needs_index.html">Needs Index</a>'
|
||||||
Then I should see 'relative: <a href="../needs_index.html">Relative</a>'
|
Then I should see 'relative: <a href="../needs_index.html">Relative</a>'
|
||||||
|
|
||||||
Scenario: relative_link_to knows about directory indexes
|
|
||||||
Given a fixture app "indexable-app"
|
|
||||||
And a file named "source/link_to.html.erb" with:
|
|
||||||
"""
|
|
||||||
absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %>
|
|
||||||
relative: <%= link_to "Relative", "needs_index.html", :relative => true %>
|
|
||||||
"""
|
|
||||||
And a file named "source/link_to/sub.html.erb" with:
|
|
||||||
"""
|
|
||||||
absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %>
|
|
||||||
relative: <%= link_to "Relative", "../needs_index.html", :relative => true %>
|
|
||||||
"""
|
|
||||||
And the Server is running at "indexable-app"
|
|
||||||
When I go to "/link_to/"
|
|
||||||
Then I should see 'absolute: <a href="needs_index/">Needs Index</a>'
|
|
||||||
Then I should see 'relative: <a href="needs_index/">Relative</a>'
|
|
||||||
When I go to "/link_to/sub/"
|
|
||||||
Then I should see 'absolute: <a href="../needs_index/">Needs Index</a>'
|
|
||||||
Then I should see 'relative: <a href="../needs_index/">Relative</a>'
|
|
|
@ -119,80 +119,3 @@ Feature: Ignoring paths
|
||||||
Then I should see "File Not Found"
|
Then I should see "File Not Found"
|
||||||
When I go to "/images/icons/messages.png"
|
When I go to "/images/icons/messages.png"
|
||||||
Then I should see "File Not Found"
|
Then I should see "File Not Found"
|
||||||
|
|
||||||
Scenario: Ignore with directory indexes (source file, build)
|
|
||||||
Given a fixture app "ignore-app"
|
|
||||||
And a file named "config.rb" with:
|
|
||||||
"""
|
|
||||||
activate :directory_indexes
|
|
||||||
ignore 'about.html.erb'
|
|
||||||
ignore 'plain.html'
|
|
||||||
"""
|
|
||||||
And a successfully built app at "ignore-app"
|
|
||||||
Then the following files should exist:
|
|
||||||
| build/index.html |
|
|
||||||
And the following files should not exist:
|
|
||||||
| build/about/index.html |
|
|
||||||
| build/plain/index.html |
|
|
||||||
|
|
||||||
Scenario: Ignore with directory indexes (source file, server)
|
|
||||||
Given a fixture app "ignore-app"
|
|
||||||
And a file named "config.rb" with:
|
|
||||||
"""
|
|
||||||
activate :directory_indexes
|
|
||||||
ignore 'about.html.erb'
|
|
||||||
ignore 'plain.html'
|
|
||||||
"""
|
|
||||||
And the Server is running
|
|
||||||
When I go to "/index.html"
|
|
||||||
Then I should not see "File Not Found"
|
|
||||||
When I go to "/about/index.html"
|
|
||||||
Then I should see "File Not Found"
|
|
||||||
When I go to "/plain/index.html"
|
|
||||||
Then I should see "File Not Found"
|
|
||||||
|
|
||||||
Scenario: Ignore with directory indexes (output path splat, build)
|
|
||||||
Given a fixture app "ignore-app"
|
|
||||||
And a file named "config.rb" with:
|
|
||||||
"""
|
|
||||||
activate :directory_indexes
|
|
||||||
ignore 'about*'
|
|
||||||
ignore 'plain*'
|
|
||||||
"""
|
|
||||||
And a successfully built app at "ignore-app"
|
|
||||||
Then the following files should exist:
|
|
||||||
| build/index.html |
|
|
||||||
And the following files should not exist:
|
|
||||||
| build/about/index.html |
|
|
||||||
| build/plain/index.html |
|
|
||||||
|
|
||||||
Scenario: Ignore with directory indexes (output path splat, server)
|
|
||||||
Given a fixture app "ignore-app"
|
|
||||||
And a file named "config.rb" with:
|
|
||||||
"""
|
|
||||||
activate :directory_indexes
|
|
||||||
ignore 'about*'
|
|
||||||
ignore 'plain*'
|
|
||||||
"""
|
|
||||||
And the Server is running
|
|
||||||
When I go to "/index.html"
|
|
||||||
Then I should not see "File Not Found"
|
|
||||||
When I go to "/about/index.html"
|
|
||||||
Then I should see "File Not Found"
|
|
||||||
When I go to "/plain/index.html"
|
|
||||||
Then I should see "File Not Found"
|
|
||||||
|
|
||||||
# Scenario: Ignore with directory indexes (output path index)
|
|
||||||
# Given a fixture app "ignore-app"
|
|
||||||
# And a file named "config.rb" with:
|
|
||||||
# """
|
|
||||||
# activate :directory_indexes
|
|
||||||
# ignore 'about/index.html'
|
|
||||||
# ignore 'plain/index.html'
|
|
||||||
# """
|
|
||||||
# And a successfully built app at "ignore-app"
|
|
||||||
# Then the following files should exist:
|
|
||||||
# | build/index.html |
|
|
||||||
# And the following files should not exist:
|
|
||||||
# | build/about/index.html |
|
|
||||||
# | build/plain/index.html |
|
|
|
@ -35,7 +35,7 @@ Feature: Step through sitemap as a tree
|
||||||
|
|
||||||
Scenario: Page has siblings, parent, and source file
|
Scenario: Page has siblings, parent, and source file
|
||||||
Given the Server is running at "traversal-app"
|
Given the Server is running at "traversal-app"
|
||||||
When I go to "/sub/sibling/"
|
When I go to "/sub/sibling.html"
|
||||||
Then I should see "Parent: sub/index.html"
|
Then I should see "Parent: sub/index.html"
|
||||||
Then I should see "Sibling: sub/fake.html"
|
Then I should see "Sibling: sub/fake.html"
|
||||||
Then I should see "Sibling: sub/fake2.html"
|
Then I should see "Sibling: sub/fake2.html"
|
||||||
|
@ -45,7 +45,7 @@ Feature: Step through sitemap as a tree
|
||||||
|
|
||||||
Scenario: Proxied page has siblings, parent, and source file
|
Scenario: Proxied page has siblings, parent, and source file
|
||||||
Given the Server is running at "traversal-app"
|
Given the Server is running at "traversal-app"
|
||||||
When I go to "/sub/fake/"
|
When I go to "/sub/fake.html"
|
||||||
Then I should see "Path: sub/fake.html"
|
Then I should see "Path: sub/fake.html"
|
||||||
Then I should see "Parent: sub/index.html"
|
Then I should see "Parent: sub/index.html"
|
||||||
Then I should see "Sibling: sub/fake2.html"
|
Then I should see "Sibling: sub/fake2.html"
|
||||||
|
@ -56,13 +56,13 @@ Feature: Step through sitemap as a tree
|
||||||
|
|
||||||
Scenario: Child pages have data
|
Scenario: Child pages have data
|
||||||
Given the Server is running at "traversal-app"
|
Given the Server is running at "traversal-app"
|
||||||
When I go to "/directory-indexed"
|
When I go to "/directory-indexed.html"
|
||||||
Then I should see "Title of Sibling One"
|
Then I should see "Title of Sibling One"
|
||||||
Then I should see "Title of Sibling Two"
|
Then I should see "Title of Sibling Two"
|
||||||
|
|
||||||
Scenario: When directory_index extension is active, child pages are found in named directory
|
Scenario: When directory_index extension is inactive, child pages are found in named directory
|
||||||
Given the Server is running at "traversal-app"
|
Given the Server is running at "traversal-app"
|
||||||
When I go to "/directory-indexed"
|
When I go to "/directory-indexed.html"
|
||||||
Then I should see "Path: directory-indexed.html"
|
Then I should see "Path: directory-indexed.html"
|
||||||
Then I should see "Parent: index.html"
|
Then I should see "Parent: index.html"
|
||||||
Then I should see "Child: directory-indexed/fake.html"
|
Then I should see "Child: directory-indexed/fake.html"
|
||||||
|
|
|
@ -8,12 +8,3 @@ Feature: Wildcards in Page helper
|
||||||
Then I should see "Admin Layout"
|
Then I should see "Admin Layout"
|
||||||
When I go to "/admin/page.html"
|
When I go to "/admin/page.html"
|
||||||
Then I should see "Admin Layout"
|
Then I should see "Admin Layout"
|
||||||
|
|
||||||
Scenario: Setting the layout for a folder
|
|
||||||
Given the Server is running at "wildcard-directory-index-app"
|
|
||||||
When I go to "/"
|
|
||||||
Then I should see "Normal Layout"
|
|
||||||
When I go to "/admin/"
|
|
||||||
Then I should see "Admin Layout"
|
|
||||||
When I go to "/admin/page/"
|
|
||||||
Then I should see "Admin Layout"
|
|
|
@ -1,6 +0,0 @@
|
||||||
set :layout, false
|
|
||||||
|
|
||||||
activate :asset_host
|
|
||||||
set :asset_host do |asset|
|
|
||||||
"http://assets%d.example.com" % (asset.hash % 4)
|
|
||||||
end
|
|
Binary file not shown.
Before Width: | Height: | Size: 43 B |
|
@ -1,4 +1,2 @@
|
||||||
activate :directory_indexes
|
|
||||||
|
|
||||||
# Proxy ignored.html, which should ignore itself through a frontmatter
|
# Proxy ignored.html, which should ignore itself through a frontmatter
|
||||||
page 'proxied.html', :proxy => 'ignored.html'
|
page 'proxied.html', :proxy => 'ignored.html'
|
|
@ -1,4 +0,0 @@
|
||||||
activate :directory_indexes
|
|
||||||
page "/leave_me_alone.html", :directory_index => false
|
|
||||||
|
|
||||||
page "/wildcard*", :directory_index => false
|
|
|
@ -1,5 +1,3 @@
|
||||||
activate :directory_indexes
|
|
||||||
|
|
||||||
page "/sub/fake.html", :proxy => "/proxied.html", :ignore => true
|
page "/sub/fake.html", :proxy => "/proxied.html", :ignore => true
|
||||||
page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true
|
page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true
|
||||||
|
|
||||||
|
|
|
@ -111,10 +111,6 @@ module Middleman
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
set :show_exceptions, true
|
set :show_exceptions, true
|
||||||
|
|
||||||
# Automatically loaded extensions
|
|
||||||
# @return [Array<Symbol>]
|
|
||||||
set :default_extensions, [ :lorem ]
|
|
||||||
|
|
||||||
# Default layout name
|
# Default layout name
|
||||||
# @return [String, Symbold]
|
# @return [String, Symbold]
|
||||||
set :layout, :_auto_layout
|
set :layout, :_auto_layout
|
||||||
|
@ -162,37 +158,6 @@ module Middleman
|
||||||
# i18n
|
# i18n
|
||||||
register Middleman::CoreExtensions::I18n
|
register Middleman::CoreExtensions::I18n
|
||||||
|
|
||||||
# Built-in Extensions
|
|
||||||
|
|
||||||
# Provide Apache-style index.html files for directories
|
|
||||||
Middleman::Extensions.register(:directory_indexes) do
|
|
||||||
require "middleman-core/extensions/directory_indexes"
|
|
||||||
Middleman::Extensions::DirectoryIndexes
|
|
||||||
end
|
|
||||||
|
|
||||||
# Lorem provides a handful of helpful prototyping methods to generate
|
|
||||||
# words, paragraphs, fake images, names and email addresses.
|
|
||||||
Middleman::Extensions.register(:lorem) do
|
|
||||||
require "middleman-core/extensions/lorem"
|
|
||||||
Middleman::Extensions::Lorem
|
|
||||||
end
|
|
||||||
|
|
||||||
# AutomaticImageSizes inspects the images used in your dynamic templates
|
|
||||||
# and automatically adds width and height attributes to their HTML
|
|
||||||
# elements.
|
|
||||||
Middleman::Extensions.register(:automatic_image_sizes) do
|
|
||||||
require "middleman-core/extensions/automatic_image_sizes"
|
|
||||||
Middleman::Extensions::AutomaticImageSizes
|
|
||||||
end
|
|
||||||
|
|
||||||
# AssetHost allows you to setup multiple domains to host your static
|
|
||||||
# assets. Calls to asset paths in dynamic templates will then rotate
|
|
||||||
# through each of the asset servers to better spread the load.
|
|
||||||
Middleman::Extensions.register(:asset_host) do
|
|
||||||
require "middleman-core/extensions/asset_host"
|
|
||||||
Middleman::Extensions::AssetHost
|
|
||||||
end
|
|
||||||
|
|
||||||
# Initialize the Middleman project
|
# Initialize the Middleman project
|
||||||
def initialize(&block)
|
def initialize(&block)
|
||||||
# Current path defaults to nil, used in views.
|
# Current path defaults to nil, used in views.
|
||||||
|
|
|
@ -40,7 +40,6 @@ module Middleman
|
||||||
# Using for version parsing
|
# Using for version parsing
|
||||||
require "rubygems"
|
require "rubygems"
|
||||||
|
|
||||||
# app.set :default_extensions, []
|
|
||||||
app.define_hook :after_configuration
|
app.define_hook :after_configuration
|
||||||
app.define_hook :before_configuration
|
app.define_hook :before_configuration
|
||||||
app.define_hook :build_config
|
app.define_hook :build_config
|
||||||
|
@ -140,11 +139,6 @@ module Middleman
|
||||||
|
|
||||||
run_hook :after_configuration
|
run_hook :after_configuration
|
||||||
|
|
||||||
# Add in defaults
|
|
||||||
default_extensions.each do |ext|
|
|
||||||
activate ext
|
|
||||||
end
|
|
||||||
|
|
||||||
if logging?
|
if logging?
|
||||||
self.class.extensions.each do |ext|
|
self.class.extensions.each do |ext|
|
||||||
puts "== Extension: #{ext}"
|
puts "== Extension: #{ext}"
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
# Extensions namespace
|
|
||||||
module Middleman::Extensions
|
|
||||||
|
|
||||||
# Asset Host module
|
|
||||||
module AssetHost
|
|
||||||
|
|
||||||
# Setup extension
|
|
||||||
class << self
|
|
||||||
|
|
||||||
# Once registered
|
|
||||||
def registered(app)
|
|
||||||
# Default to no host
|
|
||||||
app.set :asset_host, false
|
|
||||||
|
|
||||||
# Include methods
|
|
||||||
app.send :include, InstanceMethods
|
|
||||||
end
|
|
||||||
|
|
||||||
alias :included :registered
|
|
||||||
end
|
|
||||||
|
|
||||||
# Asset Host Instance Methods
|
|
||||||
module InstanceMethods
|
|
||||||
|
|
||||||
# Override default asset url helper to include asset hosts
|
|
||||||
#
|
|
||||||
# @param [String] path
|
|
||||||
# @param [String] prefix
|
|
||||||
# @return [String]
|
|
||||||
def asset_url(path, prefix="")
|
|
||||||
original_output = super
|
|
||||||
return original_output unless asset_host
|
|
||||||
|
|
||||||
asset_prefix = if asset_host.is_a?(Proc)
|
|
||||||
asset_host.call(original_output)
|
|
||||||
elsif asset_host.is_a?(String)
|
|
||||||
asset_host
|
|
||||||
end
|
|
||||||
|
|
||||||
File.join(asset_prefix, original_output)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Register the extension
|
|
||||||
register :asset_host, AssetHost
|
|
||||||
end
|
|
|
@ -1,57 +0,0 @@
|
||||||
# Extensions namespace
|
|
||||||
module Middleman::Extensions
|
|
||||||
|
|
||||||
# Automatic Image Sizes extension
|
|
||||||
module AutomaticImageSizes
|
|
||||||
|
|
||||||
# Setup extension
|
|
||||||
class << self
|
|
||||||
|
|
||||||
# Once registered
|
|
||||||
def registered(app)
|
|
||||||
# Include 3rd-party fastimage library
|
|
||||||
require "middleman-core/extensions/automatic_image_sizes/fastimage"
|
|
||||||
|
|
||||||
# Include methods
|
|
||||||
app.send :include, InstanceMethods
|
|
||||||
end
|
|
||||||
|
|
||||||
alias :included :registered
|
|
||||||
end
|
|
||||||
|
|
||||||
# Automatic Image Sizes Instance Methods
|
|
||||||
module InstanceMethods
|
|
||||||
|
|
||||||
# Override default image_tag helper to automatically calculate and include
|
|
||||||
# image dimensions.
|
|
||||||
#
|
|
||||||
# @param [String] path
|
|
||||||
# @param [Hash] params
|
|
||||||
# @return [String]
|
|
||||||
def image_tag(path, params={})
|
|
||||||
if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://")
|
|
||||||
params[:alt] ||= ""
|
|
||||||
http_prefix = http_images_path rescue images_dir
|
|
||||||
|
|
||||||
begin
|
|
||||||
real_path = File.join(source, images_dir, path)
|
|
||||||
full_path = File.expand_path(real_path, root)
|
|
||||||
http_prefix = http_images_path rescue images_dir
|
|
||||||
if File.exists? full_path
|
|
||||||
dimensions = ::FastImage.size(full_path, :raise_on_failure => true)
|
|
||||||
params[:width] = dimensions[0]
|
|
||||||
params[:height] = dimensions[1]
|
|
||||||
end
|
|
||||||
rescue
|
|
||||||
# $stderr.puts params.inspect
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
super(path, params)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Register the extension
|
|
||||||
register :automatic_image_sizes, AutomaticImageSizes
|
|
||||||
end
|
|
|
@ -1,54 +0,0 @@
|
||||||
# Extensions namespace
|
|
||||||
module Middleman::Extensions
|
|
||||||
|
|
||||||
# Directory Indexes extension
|
|
||||||
module DirectoryIndexes
|
|
||||||
|
|
||||||
# Setup extension
|
|
||||||
class << self
|
|
||||||
|
|
||||||
# Once registered
|
|
||||||
def registered(app)
|
|
||||||
app.ready do
|
|
||||||
sitemap.register_resource_list_manipulator(
|
|
||||||
:directory_indexes,
|
|
||||||
DirectoryIndexManager.new(self)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
alias :included :registered
|
|
||||||
end
|
|
||||||
|
|
||||||
class DirectoryIndexManager
|
|
||||||
def initialize(app)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
# Update the main sitemap resource list
|
|
||||||
# @return [void]
|
|
||||||
def manipulate_resource_list(resources)
|
|
||||||
index_file = @app.index_file
|
|
||||||
new_index_path = "/#{index_file}"
|
|
||||||
|
|
||||||
resources.each do |resource|
|
|
||||||
# Check if it would be pointless to reroute
|
|
||||||
next if resource.path == index_file ||
|
|
||||||
resource.path.end_with?(new_index_path) ||
|
|
||||||
File.extname(index_file) != resource.ext
|
|
||||||
|
|
||||||
# Check if frontmatter turns directory_index off
|
|
||||||
d = resource.data
|
|
||||||
next if d && d["directory_index"] == false
|
|
||||||
|
|
||||||
# Check if file metadata (options set by "page" in config.rb) turns directory_index off
|
|
||||||
if resource.metadata[:options] && resource.metadata[:options][:directory_index] == false
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
resource.destination_path = resource.destination_path.chomp(File.extname(index_file)) + new_index_path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,195 +0,0 @@
|
||||||
# Extension namespace
|
|
||||||
module Middleman::Extensions
|
|
||||||
|
|
||||||
# Lorem helper
|
|
||||||
module Lorem
|
|
||||||
|
|
||||||
# Setup extension
|
|
||||||
class << self
|
|
||||||
|
|
||||||
# Once registered
|
|
||||||
def registered(app)
|
|
||||||
# Include methods
|
|
||||||
app.send :include, InstanceMethods
|
|
||||||
end
|
|
||||||
|
|
||||||
alias :included :registered
|
|
||||||
end
|
|
||||||
|
|
||||||
# Lorem extension instance methods
|
|
||||||
module InstanceMethods
|
|
||||||
# Access to the Lorem object
|
|
||||||
# @return [Middleman::Extensions::Lorem::LoremObject]
|
|
||||||
def lorem
|
|
||||||
@_lorem ||= LoremObject.new
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return a placeholder image using placekitten.com
|
|
||||||
#
|
|
||||||
# @param [String] size
|
|
||||||
# @param [Hash] options
|
|
||||||
# @return [String]
|
|
||||||
def placekitten(size, options={})
|
|
||||||
options[:domain] = "http://placekitten.com"
|
|
||||||
lorem.image(size, options)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Adapted from Frank:
|
|
||||||
# https://github.com/blahed/frank/
|
|
||||||
# Copyright (c) 2010 Travis Dunn
|
|
||||||
#
|
|
||||||
# Permission is hereby granted, free of charge, to any person
|
|
||||||
# obtaining a copy of this software and associated documentation
|
|
||||||
# files (the "Software"), to deal in the Software without
|
|
||||||
# restriction, including without limitation the rights to use,
|
|
||||||
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
# copies of the Software, and to permit persons to whom the
|
|
||||||
# Software is furnished to do so, subject to the following
|
|
||||||
# conditions:
|
|
||||||
#
|
|
||||||
# The above copyright notice and this permission notice shall be
|
|
||||||
# included in all copies or substantial portions of the Software.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
||||||
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
||||||
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||||
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
||||||
# OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
class LoremObject
|
|
||||||
# Words for use in lorem text
|
|
||||||
WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat)
|
|
||||||
|
|
||||||
# Get one placeholder word
|
|
||||||
# @return [String]
|
|
||||||
def word
|
|
||||||
words(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get some number of placeholder words
|
|
||||||
# @param [Fixnum] total
|
|
||||||
# @return [String]
|
|
||||||
def words(total)
|
|
||||||
(1..total).map do
|
|
||||||
randm(WORDS)
|
|
||||||
end.join(' ')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get one placeholder sentence
|
|
||||||
# @return [String]
|
|
||||||
def sentence
|
|
||||||
sentences(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get some number of placeholder sentences
|
|
||||||
# @param [Fixnum] total
|
|
||||||
# @return [String]
|
|
||||||
def sentences(total)
|
|
||||||
(1..total).map do
|
|
||||||
words(randm(4..15)).capitalize
|
|
||||||
end.join('. ')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get one placeholder paragraph
|
|
||||||
# @return [String]
|
|
||||||
def paragraph
|
|
||||||
paragraphs(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get some number of placeholder paragraphs
|
|
||||||
# @param [Fixnum] total
|
|
||||||
# @return [String]
|
|
||||||
def paragraphs(total)
|
|
||||||
(1..total).map do
|
|
||||||
sentences(randm(3..7)).capitalize
|
|
||||||
end.join("\n\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get a placeholder date
|
|
||||||
# @param [String] fmt
|
|
||||||
# @return [String]
|
|
||||||
def date(fmt = '%a %b %d, %Y')
|
|
||||||
y = rand(20) + 1990
|
|
||||||
m = rand(12) + 1
|
|
||||||
d = rand(31) + 1
|
|
||||||
Time.local(y,m,d).strftime(fmt)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get a placeholder name
|
|
||||||
# @return [String]
|
|
||||||
def name
|
|
||||||
"#{first_name} #{last_name}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get a placeholder first name
|
|
||||||
# @return [String]
|
|
||||||
def first_name
|
|
||||||
names = "Judith Angelo Margarita Kerry Elaine Lorenzo Justice Doris Raul Liliana Kerry Elise Ciaran Johnny Moses Davion Penny Mohammed Harvey Sheryl Hudson Brendan Brooklynn Denis Sadie Trisha Jacquelyn Virgil Cindy Alexa Marianne Giselle Casey Alondra Angela Katherine Skyler Kyleigh Carly Abel Adrianna Luis Dominick Eoin Noel Ciara Roberto Skylar Brock Earl Dwayne Jackie Hamish Sienna Nolan Daren Jean Shirley Connor Geraldine Niall Kristi Monty Yvonne Tammie Zachariah Fatima Ruby Nadia Anahi Calum Peggy Alfredo Marybeth Bonnie Gordon Cara John Staci Samuel Carmen Rylee Yehudi Colm Beth Dulce Darius inley Javon Jason Perla Wayne Laila Kaleigh Maggie Don Quinn Collin Aniya Zoe Isabel Clint Leland Esmeralda Emma Madeline Byron Courtney Vanessa Terry Antoinette George Constance Preston Rolando Caleb Kenneth Lynette Carley Francesca Johnnie Jordyn Arturo Camila Skye Guy Ana Kaylin Nia Colton Bart Brendon Alvin Daryl Dirk Mya Pete Joann Uriel Alonzo Agnes Chris Alyson Paola Dora Elias Allen Jackie Eric Bonita Kelvin Emiliano Ashton Kyra Kailey Sonja Alberto Ty Summer Brayden Lori Kelly Tomas Joey Billie Katie Stephanie Danielle Alexis Jamal Kieran Lucinda Eliza Allyson Melinda Alma Piper Deana Harriet Bryce Eli Jadyn Rogelio Orlaith Janet Randal Toby Carla Lorie Caitlyn Annika Isabelle inn Ewan Maisie Michelle Grady Ida Reid Emely Tricia Beau Reese Vance Dalton Lexi Rafael Makenzie Mitzi Clinton Xena Angelina Kendrick Leslie Teddy Jerald Noelle Neil Marsha Gayle Omar Abigail Alexandra Phil Andre Billy Brenden Bianca Jared Gretchen Patrick Antonio Josephine Kyla Manuel Freya Kellie Tonia Jamie Sydney Andres Ruben Harrison Hector Clyde Wendell Kaden Ian Tracy Cathleen Shawn".split(" ")
|
|
||||||
names[rand(names.size)]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get a placeholder last name
|
|
||||||
# @return [String]
|
|
||||||
def last_name
|
|
||||||
names = "Chung Chen Melton Hill Puckett Song Hamilton Bender Wagner McLaughlin McNamara Raynor Moon Woodard Desai Wallace Lawrence Griffin Dougherty Powers May Steele Teague Vick Gallagher Solomon Walsh Monroe Connolly Hawkins Middleton Goldstein Watts Johnston Weeks Wilkerson Barton Walton Hall Ross Chung Bender Woods Mangum Joseph Rosenthal Bowden Barton Underwood Jones Baker Merritt Cross Cooper Holmes Sharpe Morgan Hoyle Allen Rich Rich Grant Proctor Diaz Graham Watkins Hinton Marsh Hewitt Branch Walton O'Brien Case Watts Christensen Parks Hardin Lucas Eason Davidson Whitehead Rose Sparks Moore Pearson Rodgers Graves Scarborough Sutton Sinclair Bowman Olsen Love McLean Christian Lamb James Chandler Stout Cowan Golden Bowling Beasley Clapp Abrams Tilley Morse Boykin Sumner Cassidy Davidson Heath Blanchard McAllister McKenzie Byrne Schroeder Griffin Gross Perkins Robertson Palmer Brady Rowe Zhang Hodge Li Bowling Justice Glass Willis Hester Floyd Graves Fischer Norman Chan Hunt Byrd Lane Kaplan Heller May Jennings Hanna Locklear Holloway Jones Glover Vick O'Donnell Goldman McKenna Starr Stone McClure Watson Monroe Abbott Singer Hall Farrell Lucas Norman Atkins Monroe Robertson Sykes Reid Chandler Finch Hobbs Adkins Kinney Whitaker Alexander Conner Waters Becker Rollins Love Adkins Black Fox Hatcher Wu Lloyd Joyce Welch Matthews Chappell MacDonald Kane Butler Pickett Bowman Barton Kennedy Branch Thornton McNeill Weinstein Middleton Moss Lucas Rich Carlton Brady Schultz Nichols Harvey Stevenson Houston Dunn West O'Brien Barr Snyder Cain Heath Boswell Olsen Pittman Weiner Petersen Davis Coleman Terrell Norman Burch Weiner Parrott Henry Gray Chang McLean Eason Weeks Siegel Puckett Heath Hoyle Garrett Neal Baker Goldman Shaffer Choi Carver".split(" ")
|
|
||||||
names[rand(names.size)]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get a placeholder 140 character tweet about Philip the Purple Otter
|
|
||||||
# Via http://www.kevadamson.com/talking-of-design/article/140-alternative-characters-to-lorem-ipsum
|
|
||||||
# @return [String]
|
|
||||||
def tweet
|
|
||||||
tweets = [ 'Far away, in a forest next to a river beneath the mountains, there lived a small purple otter called Philip. Philip likes sausages. The End.',
|
|
||||||
'He liked the quality sausages from Marks & Spencer but due to the recession he had been forced to shop in a less desirable supermarket. End.',
|
|
||||||
'He awoke one day to find his pile of sausages missing. Roger the greedy boar with human eyes, had skateboarded into the forest & eaten them!']
|
|
||||||
tweets[rand(tweets.size)]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get a placeholder email address
|
|
||||||
# @return [String]
|
|
||||||
def email
|
|
||||||
delimiters = [ '_', '-', '' ]
|
|
||||||
domains = %w(gmail.com yahoo.com hotmail.com email.com live.com me.com mac.com aol.com fastmail.com mail.com)
|
|
||||||
username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)])
|
|
||||||
"#{username}@#{domains[rand(domains.size)]}".downcase
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get a placeholder image, using placehold.it by default
|
|
||||||
# @param [String] size
|
|
||||||
# @param [Hash] options
|
|
||||||
# @return [String]
|
|
||||||
def image(size, options={})
|
|
||||||
domain = options[:domain] || "http://placehold.it"
|
|
||||||
src = "#{domain}/#{size}"
|
|
||||||
hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9]
|
|
||||||
background_color = options[:background_color]
|
|
||||||
color = options[:color]
|
|
||||||
|
|
||||||
if options[:random_color]
|
|
||||||
background_color = hex.shuffle[0...6].join
|
|
||||||
color = hex.shuffle[0...6].join
|
|
||||||
end
|
|
||||||
|
|
||||||
src << "/#{background_color.sub(/^#/, '')}" if background_color
|
|
||||||
src << "/ccc" if background_color.nil? && color
|
|
||||||
src << "/#{color.sub(/^#/, '')}" if color
|
|
||||||
src << "&text=#{Rack::Utils::escape(options[:text])}" if options[:text]
|
|
||||||
|
|
||||||
src
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# Pick a random item from a given range
|
|
||||||
# @param [Range] range
|
|
||||||
# @return [Object]
|
|
||||||
def randm(range)
|
|
||||||
a = range.to_a
|
|
||||||
a[rand(a.length)]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
14
middleman-more/features/clean_build.feature
Normal file
14
middleman-more/features/clean_build.feature
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
Feature: Build Clean
|
||||||
|
|
||||||
|
Scenario: Clean an app with directory indexes
|
||||||
|
Given a successfully built app at "clean-dir-app"
|
||||||
|
Then the following files should exist:
|
||||||
|
| build/about/index.html |
|
||||||
|
Given a successfully built app at "clean-dir-app" with flags "--clean"
|
||||||
|
Then the following files should exist:
|
||||||
|
| build/about/index.html |
|
||||||
|
|
||||||
|
Scenario: Clean build an app that's never been built
|
||||||
|
Given a successfully built app at "clean-dir-app" with flags "--clean"
|
||||||
|
Then the following files should exist:
|
||||||
|
| build/about/index.html |
|
28
middleman-more/features/extensionless_text_files.feature
Normal file
28
middleman-more/features/extensionless_text_files.feature
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
Feature: Text Files Without Extensions Should Build and Preview
|
||||||
|
|
||||||
|
Scenario: Building Text Files with directory indexes
|
||||||
|
Given a successfully built app at "extensionless-text-files-app"
|
||||||
|
When I cd to "build"
|
||||||
|
Then the following files should exist:
|
||||||
|
| CNAME |
|
||||||
|
| LICENSE |
|
||||||
|
| README |
|
||||||
|
Then the following files should not exist:
|
||||||
|
| CNAME/index.html |
|
||||||
|
| LICENSE/index.html |
|
||||||
|
| README/index.html |
|
||||||
|
|
||||||
|
Scenario: Previewing Text Files
|
||||||
|
Given the Server is running at "extensionless-text-files-app"
|
||||||
|
When I go to "/CNAME"
|
||||||
|
Then I should see "test.github.com"
|
||||||
|
When I go to "/LICENSE"
|
||||||
|
Then I should see "You have the right to remain classy."
|
||||||
|
When I go to "/README"
|
||||||
|
Then I should see "Bork bork bork"
|
||||||
|
# When I go to "/CNAME/index.html"
|
||||||
|
# Then I should see "File Not Found"
|
||||||
|
# When I go to "/LICENSE/index.html"
|
||||||
|
# Then I should see "File Not Found"
|
||||||
|
# When I go to "/README/index.html"
|
||||||
|
# Then I should see "File Not Found"
|
42
middleman-more/features/frontmatter_page_settings.feature
Normal file
42
middleman-more/features/frontmatter_page_settings.feature
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
Feature: Setting page settings through frontmatter
|
||||||
|
Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (build)
|
||||||
|
Given a successfully built app at "frontmatter-settings-app"
|
||||||
|
Then the following files should exist:
|
||||||
|
| build/proxied/index.html |
|
||||||
|
| build/no_index.html |
|
||||||
|
And the file "build/alternate_layout/index.html" should contain "Alternate layout"
|
||||||
|
And the following files should not exist:
|
||||||
|
| build/ignored/index.html |
|
||||||
|
| build/no_index/index.html |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (preview)
|
||||||
|
Given the Server is running at "frontmatter-settings-app"
|
||||||
|
# When I go to "/proxied/"
|
||||||
|
# Then I should not see "File Not Found"
|
||||||
|
When I go to "/no_index.html"
|
||||||
|
Then I should not see "File Not Found"
|
||||||
|
When I go to "/alternate_layout/"
|
||||||
|
Then I should not see "File Not Found"
|
||||||
|
And I should see "Alternate layout"
|
||||||
|
When I go to "/ignored.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/ignored/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/no_index/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
|
||||||
|
Scenario: Changing frontmatter in preview server
|
||||||
|
Given the Server is running at "frontmatter-settings-app"
|
||||||
|
When I go to "/ignored/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
And the file "source/ignored.html.erb" has the contents
|
||||||
|
"""
|
||||||
|
---
|
||||||
|
ignored: false
|
||||||
|
---
|
||||||
|
|
||||||
|
This file is no longer ignored.
|
||||||
|
"""
|
||||||
|
When I go to "/ignored/index.html"
|
||||||
|
Then I should see "This file is no longer ignored."
|
21
middleman-more/features/helpers_relative_link_to.feature
Normal file
21
middleman-more/features/helpers_relative_link_to.feature
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
Feature: relative_link_to helper
|
||||||
|
|
||||||
|
Scenario: relative_link_to knows about directory indexes
|
||||||
|
Given a fixture app "indexable-app"
|
||||||
|
And a file named "source/link_to.html.erb" with:
|
||||||
|
"""
|
||||||
|
absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %>
|
||||||
|
relative: <%= link_to "Relative", "needs_index.html", :relative => true %>
|
||||||
|
"""
|
||||||
|
And a file named "source/link_to/sub.html.erb" with:
|
||||||
|
"""
|
||||||
|
absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %>
|
||||||
|
relative: <%= link_to "Relative", "../needs_index.html", :relative => true %>
|
||||||
|
"""
|
||||||
|
And the Server is running at "indexable-app"
|
||||||
|
When I go to "/link_to/"
|
||||||
|
Then I should see 'absolute: <a href="needs_index/">Needs Index</a>'
|
||||||
|
Then I should see 'relative: <a href="needs_index/">Relative</a>'
|
||||||
|
When I go to "/link_to/sub/"
|
||||||
|
Then I should see 'absolute: <a href="../needs_index/">Needs Index</a>'
|
||||||
|
Then I should see 'relative: <a href="../needs_index/">Relative</a>'
|
62
middleman-more/features/ignore.feature
Normal file
62
middleman-more/features/ignore.feature
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
Feature: Ignoring paths
|
||||||
|
Scenario: Ignore with directory indexes (source file, build)
|
||||||
|
Given a fixture app "ignore-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
activate :directory_indexes
|
||||||
|
ignore 'about.html.erb'
|
||||||
|
ignore 'plain.html'
|
||||||
|
"""
|
||||||
|
And a successfully built app at "ignore-app"
|
||||||
|
Then the following files should exist:
|
||||||
|
| build/index.html |
|
||||||
|
And the following files should not exist:
|
||||||
|
| build/about/index.html |
|
||||||
|
| build/plain/index.html |
|
||||||
|
|
||||||
|
Scenario: Ignore with directory indexes (source file, server)
|
||||||
|
Given a fixture app "ignore-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
activate :directory_indexes
|
||||||
|
ignore 'about.html.erb'
|
||||||
|
ignore 'plain.html'
|
||||||
|
"""
|
||||||
|
And the Server is running
|
||||||
|
When I go to "/index.html"
|
||||||
|
Then I should not see "File Not Found"
|
||||||
|
When I go to "/about/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/plain/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
|
||||||
|
Scenario: Ignore with directory indexes (output path splat, build)
|
||||||
|
Given a fixture app "ignore-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
activate :directory_indexes
|
||||||
|
ignore 'about*'
|
||||||
|
ignore 'plain*'
|
||||||
|
"""
|
||||||
|
And a successfully built app at "ignore-app"
|
||||||
|
Then the following files should exist:
|
||||||
|
| build/index.html |
|
||||||
|
And the following files should not exist:
|
||||||
|
| build/about/index.html |
|
||||||
|
| build/plain/index.html |
|
||||||
|
|
||||||
|
Scenario: Ignore with directory indexes (output path splat, server)
|
||||||
|
Given a fixture app "ignore-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
activate :directory_indexes
|
||||||
|
ignore 'about*'
|
||||||
|
ignore 'plain*'
|
||||||
|
"""
|
||||||
|
And the Server is running
|
||||||
|
When I go to "/index.html"
|
||||||
|
Then I should not see "File Not Found"
|
||||||
|
When I go to "/about/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/plain/index.html"
|
||||||
|
Then I should see "File Not Found"
|
73
middleman-more/features/sitemap_traversal.feature
Normal file
73
middleman-more/features/sitemap_traversal.feature
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
Feature: Step through sitemap as a tree
|
||||||
|
|
||||||
|
Scenario: Root
|
||||||
|
Given the Server is running at "traversal-app"
|
||||||
|
When I go to "/index.html"
|
||||||
|
Then I should see "Path: index.html"
|
||||||
|
Then I should not see "Parent: index.html"
|
||||||
|
Then I should see "Child: sub/index.html"
|
||||||
|
Then I should see "Child: root.html"
|
||||||
|
Then I should not see "Child: proxied.html"
|
||||||
|
|
||||||
|
Scenario: Directories have children and a parent
|
||||||
|
Given the Server is running at "traversal-app"
|
||||||
|
When I go to "/sub/index.html"
|
||||||
|
Then I should see "Path: sub/index.html"
|
||||||
|
Then I should see "Parent: index.html"
|
||||||
|
Then I should see "Child: sub/fake.html"
|
||||||
|
Then I should see "Child: sub/fake2.html"
|
||||||
|
Then I should see "Child: sub/sibling.html"
|
||||||
|
Then I should see "Child: sub/sibling2.html"
|
||||||
|
Then I should see "Child: sub/sub2/index.html"
|
||||||
|
Then I should see "Sibling: root.html"
|
||||||
|
|
||||||
|
Scenario: Directory accessed without index.html
|
||||||
|
Given the Server is running at "traversal-app"
|
||||||
|
When I go to "/sub/"
|
||||||
|
Then I should see "Path: sub/index.html"
|
||||||
|
Then I should see "Parent: index.html"
|
||||||
|
Then I should see "Child: sub/fake.html"
|
||||||
|
Then I should see "Child: sub/fake2.html"
|
||||||
|
Then I should see "Child: sub/sibling.html"
|
||||||
|
Then I should see "Child: sub/sibling2.html"
|
||||||
|
Then I should see "Child: sub/sub2/index.html"
|
||||||
|
Then I should see "Sibling: root.html"
|
||||||
|
|
||||||
|
Scenario: Page has siblings, parent, and source file
|
||||||
|
Given the Server is running at "traversal-app"
|
||||||
|
When I go to "/sub/sibling/"
|
||||||
|
Then I should see "Parent: sub/index.html"
|
||||||
|
Then I should see "Sibling: sub/fake.html"
|
||||||
|
Then I should see "Sibling: sub/fake2.html"
|
||||||
|
Then I should see "Sibling: sub/sibling2.html"
|
||||||
|
Then I should see "Sibling: sub/sub2/index.html"
|
||||||
|
Then I should see "Source: source/sub/sibling.html.erb"
|
||||||
|
|
||||||
|
Scenario: Proxied page has siblings, parent, and source file
|
||||||
|
Given the Server is running at "traversal-app"
|
||||||
|
When I go to "/sub/fake/"
|
||||||
|
Then I should see "Path: sub/fake.html"
|
||||||
|
Then I should see "Parent: sub/index.html"
|
||||||
|
Then I should see "Sibling: sub/fake2.html"
|
||||||
|
Then I should see "Sibling: sub/sibling.html"
|
||||||
|
Then I should see "Sibling: sub/sibling2.html"
|
||||||
|
Then I should see "Sibling: sub/sub2/index.html"
|
||||||
|
Then I should see "Source: source/proxied.html.erb"
|
||||||
|
|
||||||
|
Scenario: Child pages have data
|
||||||
|
Given the Server is running at "traversal-app"
|
||||||
|
When I go to "/directory-indexed"
|
||||||
|
Then I should see "Title of Sibling One"
|
||||||
|
Then I should see "Title of Sibling Two"
|
||||||
|
|
||||||
|
Scenario: When directory_index extension is active, child pages are found in named directory
|
||||||
|
Given the Server is running at "traversal-app"
|
||||||
|
When I go to "/directory-indexed"
|
||||||
|
Then I should see "Path: directory-indexed.html"
|
||||||
|
Then I should see "Parent: index.html"
|
||||||
|
Then I should see "Child: directory-indexed/fake.html"
|
||||||
|
Then I should see "Child: directory-indexed/fake2.html"
|
||||||
|
Then I should see "Child: directory-indexed/sibling.html"
|
||||||
|
Then I should see "Child: directory-indexed/sibling2.html"
|
||||||
|
Then I should see "Child: directory-indexed/sub2/index.html"
|
||||||
|
Then I should see "Sibling: root.html"
|
10
middleman-more/features/wildcard_page_helper.feature
Normal file
10
middleman-more/features/wildcard_page_helper.feature
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
Feature: Wildcards in Page helper
|
||||||
|
|
||||||
|
Scenario: Setting the layout for a folder
|
||||||
|
Given the Server is running at "wildcard-directory-index-app"
|
||||||
|
When I go to "/"
|
||||||
|
Then I should see "Normal Layout"
|
||||||
|
When I go to "/admin/"
|
||||||
|
Then I should see "Admin Layout"
|
||||||
|
When I go to "/admin/page/"
|
||||||
|
Then I should see "Admin Layout"
|
Before Width: | Height: | Size: 43 B After Width: | Height: | Size: 43 B |
|
@ -0,0 +1 @@
|
||||||
|
activate :directory_indexes
|
|
@ -0,0 +1 @@
|
||||||
|
test.github.com
|
|
@ -0,0 +1 @@
|
||||||
|
You have the right to remain classy.
|
|
@ -0,0 +1 @@
|
||||||
|
Bork bork bork
|
|
@ -0,0 +1 @@
|
||||||
|
sup
|
|
@ -0,0 +1,4 @@
|
||||||
|
activate :directory_indexes
|
||||||
|
|
||||||
|
# Proxy ignored.html, which should ignore itself through a frontmatter
|
||||||
|
page 'proxied.html', :proxy => 'ignored.html'
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
layout: alternate
|
||||||
|
---
|
||||||
|
|
||||||
|
This uses an alternate layout
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
ignored: true
|
||||||
|
---
|
||||||
|
|
||||||
|
This file ignores itself! But it can still be proxied.
|
|
@ -0,0 +1,3 @@
|
||||||
|
Alternate layout!
|
||||||
|
|
||||||
|
<%= yield %>
|
1
middleman-more/fixtures/ignore-app/source/about.html.erb
Normal file
1
middleman-more/fixtures/ignore-app/source/about.html.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
About
|
1
middleman-more/fixtures/ignore-app/source/plain.html
Normal file
1
middleman-more/fixtures/ignore-app/source/plain.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Plain
|
4
middleman-more/fixtures/indexable-app/config.rb
Normal file
4
middleman-more/fixtures/indexable-app/config.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
activate :directory_indexes
|
||||||
|
page "/leave_me_alone.html", :directory_index => false
|
||||||
|
|
||||||
|
page "/wildcard*", :directory_index => false
|
|
@ -0,0 +1 @@
|
||||||
|
Indexable
|
|
@ -0,0 +1 @@
|
||||||
|
Stay away
|
|
@ -0,0 +1 @@
|
||||||
|
Indexable
|
|
@ -0,0 +1 @@
|
||||||
|
Regular
|
|
@ -0,0 +1 @@
|
||||||
|
Stay away, wildcards!
|
7
middleman-more/fixtures/traversal-app/config.rb
Normal file
7
middleman-more/fixtures/traversal-app/config.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
activate :directory_indexes
|
||||||
|
|
||||||
|
page "/sub/fake.html", :proxy => "/proxied.html", :ignore => true
|
||||||
|
page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true
|
||||||
|
|
||||||
|
page "/directory-indexed/fake.html", :proxy => "/proxied.html", :ignore => true
|
||||||
|
page "/directory-indexed/fake2.html", :proxy => "/proxied.html", :ignore => true
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
title: Title of Sibling One
|
||||||
|
---
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
title: Title of Sibling Two
|
||||||
|
---
|
21
middleman-more/fixtures/traversal-app/source/layout.erb
Normal file
21
middleman-more/fixtures/traversal-app/source/layout.erb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
Path: <%= current_page.path %>
|
||||||
|
|
||||||
|
Source: <%= current_page.source_file.sub(root + "/", "") %>
|
||||||
|
|
||||||
|
<% if current_page.parent %>
|
||||||
|
Parent: <%= current_page.parent.path %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% current_page.children.each do |p| %>
|
||||||
|
Child: <%= p.path %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% current_page.siblings.each do |p| %>
|
||||||
|
Sibling: <%= p.path %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% current_page.children.each do |p| %>
|
||||||
|
<% if p.data %>
|
||||||
|
Data: <%= p.data %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
|
@ -1,6 +1,127 @@
|
||||||
|
require "middleman-core"
|
||||||
|
|
||||||
# Setup our load paths
|
# Setup our load paths
|
||||||
libdir = File.expand_path(File.dirname(__FILE__))
|
libdir = File.expand_path(File.dirname(__FILE__))
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
require "middleman-core"
|
module Middleman::More
|
||||||
require "middleman-more/register_extensions"
|
|
||||||
|
# Setup extension
|
||||||
|
class << self
|
||||||
|
|
||||||
|
# Once registered
|
||||||
|
def registered(app, options={})
|
||||||
|
###
|
||||||
|
# Setup renderers
|
||||||
|
###
|
||||||
|
|
||||||
|
# CoffeeScript Support
|
||||||
|
require "middleman-more/renderers/coffee_script"
|
||||||
|
Middleman::Application.register Middleman::Renderers::CoffeeScript
|
||||||
|
|
||||||
|
# Haml Support
|
||||||
|
require "middleman-more/renderers/haml"
|
||||||
|
Middleman::Application.register Middleman::Renderers::Haml
|
||||||
|
|
||||||
|
# Sass Support
|
||||||
|
require "middleman-more/renderers/sass"
|
||||||
|
Middleman::Application.register Middleman::Renderers::Sass
|
||||||
|
|
||||||
|
# Markdown Support
|
||||||
|
require "middleman-more/renderers/markdown"
|
||||||
|
Middleman::Application.register Middleman::Renderers::Markdown
|
||||||
|
|
||||||
|
# Liquid Support
|
||||||
|
require "middleman-more/renderers/liquid"
|
||||||
|
Middleman::Application.register Middleman::Renderers::Liquid
|
||||||
|
|
||||||
|
# Slim Support
|
||||||
|
require "middleman-more/renderers/slim"
|
||||||
|
Middleman::Application.register Middleman::Renderers::Slim
|
||||||
|
|
||||||
|
###
|
||||||
|
# Setup Core Extensions
|
||||||
|
###
|
||||||
|
|
||||||
|
# Compass framework
|
||||||
|
require "middleman-more/core_extensions/compass"
|
||||||
|
Middleman::Application.register Middleman::CoreExtensions::Compass
|
||||||
|
|
||||||
|
# Sprockets asset handling
|
||||||
|
require "middleman-more/core_extensions/sprockets"
|
||||||
|
Middleman::Application.register Middleman::CoreExtensions::Sprockets
|
||||||
|
|
||||||
|
###
|
||||||
|
# Setup Optional Extensions
|
||||||
|
###
|
||||||
|
|
||||||
|
# CacheBuster adds a query string to assets in dynamic templates to avoid
|
||||||
|
# browser caches failing to update to your new content.
|
||||||
|
Middleman::Extensions.register(:cache_buster) do
|
||||||
|
require "middleman-more/extensions/cache_buster"
|
||||||
|
Middleman::Extensions::CacheBuster
|
||||||
|
end
|
||||||
|
|
||||||
|
# MinifyCss compresses CSS
|
||||||
|
Middleman::Extensions.register(:minify_css) do
|
||||||
|
require "middleman-more/extensions/minify_css"
|
||||||
|
Middleman::Extensions::MinifyCss
|
||||||
|
end
|
||||||
|
|
||||||
|
# MinifyJavascript compresses JS
|
||||||
|
Middleman::Extensions.register(:minify_javascript) do
|
||||||
|
require "middleman-more/extensions/minify_javascript"
|
||||||
|
Middleman::Extensions::MinifyJavascript
|
||||||
|
end
|
||||||
|
|
||||||
|
# RelativeAssets allow any asset path in dynamic templates to be either
|
||||||
|
# relative to the root of the project or use an absolute URL.
|
||||||
|
Middleman::Extensions.register(:relative_assets) do
|
||||||
|
require "middleman-more/extensions/relative_assets"
|
||||||
|
Middleman::Extensions::RelativeAssets
|
||||||
|
end
|
||||||
|
|
||||||
|
# GZIP assets and pages during build
|
||||||
|
Middleman::Extensions.register(:gzip) do
|
||||||
|
require "middleman-more/extensions/gzip"
|
||||||
|
Middleman::Extensions::Gzip
|
||||||
|
end
|
||||||
|
|
||||||
|
# AssetHash appends a hash of the file contents to the assets filename
|
||||||
|
# to avoid browser caches failing to update to your new content.
|
||||||
|
Middleman::Extensions.register(:asset_hash) do
|
||||||
|
require "middleman-more/extensions/asset_hash"
|
||||||
|
Middleman::Extensions::AssetHash
|
||||||
|
end
|
||||||
|
|
||||||
|
# AssetHost allows you to setup multiple domains to host your static
|
||||||
|
# assets. Calls to asset paths in dynamic templates will then rotate
|
||||||
|
# through each of the asset servers to better spread the load.
|
||||||
|
Middleman::Extensions.register(:asset_host) do
|
||||||
|
require "middleman-more/extensions/asset_host"
|
||||||
|
Middleman::Extensions::AssetHost
|
||||||
|
end
|
||||||
|
|
||||||
|
# Provide Apache-style index.html files for directories
|
||||||
|
Middleman::Extensions.register(:directory_indexes) do
|
||||||
|
require "middleman-more/extensions/directory_indexes"
|
||||||
|
Middleman::Extensions::DirectoryIndexes
|
||||||
|
end
|
||||||
|
|
||||||
|
# Lorem provides a handful of helpful prototyping methods to generate
|
||||||
|
# words, paragraphs, fake images, names and email addresses.
|
||||||
|
require "middleman-more/extensions/lorem"
|
||||||
|
Middleman::Application.register Middleman::Extensions::Lorem
|
||||||
|
|
||||||
|
# AutomaticImageSizes inspects the images used in your dynamic templates
|
||||||
|
# and automatically adds width and height attributes to their HTML
|
||||||
|
# elements.
|
||||||
|
Middleman::Extensions.register(:automatic_image_sizes) do
|
||||||
|
require "middleman-more/extensions/automatic_image_sizes"
|
||||||
|
Middleman::Extensions::AutomaticImageSizes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Middleman::Application.register Middleman::More
|
|
@ -1,106 +1,106 @@
|
||||||
require 'digest/sha1'
|
module Middleman
|
||||||
module Middleman::Extensions
|
module Extensions
|
||||||
module AssetHash
|
module AssetHash
|
||||||
class << self
|
class << self
|
||||||
def registered(app, options)
|
def registered(app, options)
|
||||||
exts = options[:exts] || %w(.jpg .jpeg .png .gif .js .css)
|
require 'digest/sha1'
|
||||||
|
exts = options[:exts] || %w(.jpg .jpeg .png .gif .js .css)
|
||||||
|
|
||||||
# Allow specifying regexes to ignore, plus always ignore apple touch icons
|
# Allow specifying regexes to ignore, plus always ignore apple touch icons
|
||||||
ignore = Array(options[:ignore]) << /^apple-touch-icon/
|
ignore = Array(options[:ignore]) << /^apple-touch-icon/
|
||||||
|
|
||||||
app.ready do
|
app.ready do
|
||||||
sitemap.register_resource_list_manipulator(
|
sitemap.register_resource_list_manipulator(
|
||||||
:asset_hash,
|
:asset_hash,
|
||||||
AssetHashManager.new(self, exts, ignore)
|
AssetHashManager.new(self, exts, ignore)
|
||||||
)
|
)
|
||||||
use Middleware, :exts => exts, :middleman_app => self
|
use Middleware, :exts => exts, :middleman_app => self
|
||||||
end
|
|
||||||
end
|
|
||||||
alias :included :registered
|
|
||||||
end
|
|
||||||
|
|
||||||
class AssetHashManager
|
|
||||||
def initialize(app, exts, ignore)
|
|
||||||
@app = app
|
|
||||||
@exts = exts
|
|
||||||
@ignore = ignore
|
|
||||||
end
|
|
||||||
|
|
||||||
# Update the main sitemap resource list
|
|
||||||
# @return [void]
|
|
||||||
def manipulate_resource_list(resources)
|
|
||||||
resources.each do |resource|
|
|
||||||
if @exts.include?(resource.ext) && @ignore.none? {|ignore| resource.path =~ ignore }
|
|
||||||
# figure out the path Sprockets would use for this asset
|
|
||||||
if resource.ext == '.js'
|
|
||||||
sprockets_path = resource.path.sub(@app.js_dir,'').sub(/^\//,'')
|
|
||||||
elsif resource.ext == '.css'
|
|
||||||
sprockets_path = resource.path.sub(@app.css_dir,'').sub(/^\//,'')
|
|
||||||
end
|
|
||||||
|
|
||||||
# See if Sprockets knows about the file
|
|
||||||
asset = @app.sprockets.find_asset(sprockets_path) if sprockets_path
|
|
||||||
|
|
||||||
if asset # if it's a Sprockets asset, ask sprockets for its digest
|
|
||||||
digest = asset.digest[0..7]
|
|
||||||
elsif resource.template? # if it's a template, render it out
|
|
||||||
digest = Digest::SHA1.hexdigest(resource.render)[0..7]
|
|
||||||
else # if it's a static file, just hash it
|
|
||||||
digest = Digest::SHA1.file(resource.source_file).hexdigest[0..7]
|
|
||||||
end
|
|
||||||
|
|
||||||
resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
alias :included :registered
|
||||||
end
|
|
||||||
|
|
||||||
# The asset hash middleware is responsible for rewriting references to
|
|
||||||
# assets to include their new, hashed name.
|
|
||||||
class Middleware
|
|
||||||
def initialize(app, options={})
|
|
||||||
@rack_app = app
|
|
||||||
@exts = options[:exts]
|
|
||||||
@exts_regex_text = @exts.map {|e| Regexp.escape(e) }.join('|')
|
|
||||||
@middleman_app = options[:middleman_app]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
class AssetHashManager
|
||||||
status, headers, response = @rack_app.call(env)
|
def initialize(app, exts, ignore)
|
||||||
|
@app = app
|
||||||
|
@exts = exts
|
||||||
|
@ignore = ignore
|
||||||
|
end
|
||||||
|
|
||||||
path = @middleman_app.full_path(env["PATH_INFO"])
|
# Update the main sitemap resource list
|
||||||
dirpath = Pathname.new(File.dirname(path))
|
# @return [void]
|
||||||
|
def manipulate_resource_list(resources)
|
||||||
if path =~ /(^\/$)|(\.(htm|html|php|css|js)$)/
|
resources.each do |resource|
|
||||||
body = ::Middleman::Util.extract_response_text(response)
|
if @exts.include?(resource.ext) && @ignore.none? {|ignore| resource.path =~ ignore }
|
||||||
|
# figure out the path Sprockets would use for this asset
|
||||||
if body
|
if resource.ext == '.js'
|
||||||
# TODO: This regex will change some paths in plan HTML (not in a tag) - is that OK?
|
sprockets_path = resource.path.sub(@app.js_dir,'').sub(/^\//,'')
|
||||||
body.gsub! /([=\'\"\(]\s*)([^\s\'\"\)]+(#{@exts_regex_text}))/ do |match|
|
elsif resource.ext == '.css'
|
||||||
asset_path = $2
|
sprockets_path = resource.path.sub(@app.css_dir,'').sub(/^\//,'')
|
||||||
relative_path = Pathname.new(asset_path).relative?
|
|
||||||
|
|
||||||
asset_path = dirpath.join(asset_path).to_s if relative_path
|
|
||||||
|
|
||||||
if asset_page = @middleman_app.sitemap.find_resource_by_path(asset_path)
|
|
||||||
replacement_path = "/#{asset_page.destination_path}"
|
|
||||||
replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path
|
|
||||||
|
|
||||||
"#{$1}#{replacement_path}"
|
|
||||||
else
|
|
||||||
match
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
status, headers, response = Rack::Response.new(body, status, headers).finish
|
# See if Sprockets knows about the file
|
||||||
|
asset = @app.sprockets.find_asset(sprockets_path) if sprockets_path
|
||||||
|
|
||||||
|
if asset # if it's a Sprockets asset, ask sprockets for its digest
|
||||||
|
digest = asset.digest[0..7]
|
||||||
|
elsif resource.template? # if it's a template, render it out
|
||||||
|
digest = Digest::SHA1.hexdigest(resource.render)[0..7]
|
||||||
|
else # if it's a static file, just hash it
|
||||||
|
digest = Digest::SHA1.file(resource.source_file).hexdigest[0..7]
|
||||||
|
end
|
||||||
|
|
||||||
|
resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
[status, headers, response]
|
end
|
||||||
|
|
||||||
|
# The asset hash middleware is responsible for rewriting references to
|
||||||
|
# assets to include their new, hashed name.
|
||||||
|
class Middleware
|
||||||
|
def initialize(app, options={})
|
||||||
|
@rack_app = app
|
||||||
|
@exts = options[:exts]
|
||||||
|
@exts_regex_text = @exts.map {|e| Regexp.escape(e) }.join('|')
|
||||||
|
@middleman_app = options[:middleman_app]
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
status, headers, response = @rack_app.call(env)
|
||||||
|
|
||||||
|
path = @middleman_app.full_path(env["PATH_INFO"])
|
||||||
|
dirpath = Pathname.new(File.dirname(path))
|
||||||
|
|
||||||
|
if path =~ /(^\/$)|(\.(htm|html|php|css|js)$)/
|
||||||
|
body = ::Middleman::Util.extract_response_text(response)
|
||||||
|
|
||||||
|
if body
|
||||||
|
# TODO: This regex will change some paths in plan HTML (not in a tag) - is that OK?
|
||||||
|
body.gsub! /([=\'\"\(]\s*)([^\s\'\"\)]+(#{@exts_regex_text}))/ do |match|
|
||||||
|
asset_path = $2
|
||||||
|
relative_path = Pathname.new(asset_path).relative?
|
||||||
|
|
||||||
|
asset_path = dirpath.join(asset_path).to_s if relative_path
|
||||||
|
|
||||||
|
if asset_page = @middleman_app.sitemap.find_resource_by_path(asset_path)
|
||||||
|
replacement_path = "/#{asset_page.destination_path}"
|
||||||
|
replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path
|
||||||
|
|
||||||
|
"#{$1}#{replacement_path}"
|
||||||
|
else
|
||||||
|
match
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
status, headers, response = Rack::Response.new(body, status, headers).finish
|
||||||
|
end
|
||||||
|
end
|
||||||
|
[status, headers, response]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
register :asset_hash, AssetHash
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
46
middleman-more/lib/middleman-more/extensions/asset_host.rb
Normal file
46
middleman-more/lib/middleman-more/extensions/asset_host.rb
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# Extensions namespace
|
||||||
|
module Middleman
|
||||||
|
module Extensions
|
||||||
|
|
||||||
|
# Asset Host module
|
||||||
|
module AssetHost
|
||||||
|
|
||||||
|
# Setup extension
|
||||||
|
class << self
|
||||||
|
|
||||||
|
# Once registered
|
||||||
|
def registered(app)
|
||||||
|
# Default to no host
|
||||||
|
app.set :asset_host, false
|
||||||
|
|
||||||
|
# Include methods
|
||||||
|
app.send :include, InstanceMethods
|
||||||
|
end
|
||||||
|
|
||||||
|
alias :included :registered
|
||||||
|
end
|
||||||
|
|
||||||
|
# Asset Host Instance Methods
|
||||||
|
module InstanceMethods
|
||||||
|
|
||||||
|
# Override default asset url helper to include asset hosts
|
||||||
|
#
|
||||||
|
# @param [String] path
|
||||||
|
# @param [String] prefix
|
||||||
|
# @return [String]
|
||||||
|
def asset_url(path, prefix="")
|
||||||
|
original_output = super
|
||||||
|
return original_output unless asset_host
|
||||||
|
|
||||||
|
asset_prefix = if asset_host.is_a?(Proc)
|
||||||
|
asset_host.call(original_output)
|
||||||
|
elsif asset_host.is_a?(String)
|
||||||
|
asset_host
|
||||||
|
end
|
||||||
|
|
||||||
|
File.join(asset_prefix, original_output)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
56
middleman-more/lib/middleman-more/extensions/automatic_image_sizes.rb
Executable file
56
middleman-more/lib/middleman-more/extensions/automatic_image_sizes.rb
Executable file
|
@ -0,0 +1,56 @@
|
||||||
|
# Extensions namespace
|
||||||
|
module Middleman
|
||||||
|
module Extensions
|
||||||
|
|
||||||
|
# Automatic Image Sizes extension
|
||||||
|
module AutomaticImageSizes
|
||||||
|
|
||||||
|
# Setup extension
|
||||||
|
class << self
|
||||||
|
|
||||||
|
# Once registered
|
||||||
|
def registered(app)
|
||||||
|
# Include 3rd-party fastimage library
|
||||||
|
require "middleman-more/extensions/automatic_image_sizes/fastimage"
|
||||||
|
|
||||||
|
# Include methods
|
||||||
|
app.send :include, InstanceMethods
|
||||||
|
end
|
||||||
|
|
||||||
|
alias :included :registered
|
||||||
|
end
|
||||||
|
|
||||||
|
# Automatic Image Sizes Instance Methods
|
||||||
|
module InstanceMethods
|
||||||
|
|
||||||
|
# Override default image_tag helper to automatically calculate and include
|
||||||
|
# image dimensions.
|
||||||
|
#
|
||||||
|
# @param [String] path
|
||||||
|
# @param [Hash] params
|
||||||
|
# @return [String]
|
||||||
|
def image_tag(path, params={})
|
||||||
|
if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://")
|
||||||
|
params[:alt] ||= ""
|
||||||
|
http_prefix = http_images_path rescue images_dir
|
||||||
|
|
||||||
|
begin
|
||||||
|
real_path = File.join(source, images_dir, path)
|
||||||
|
full_path = File.expand_path(real_path, root)
|
||||||
|
http_prefix = http_images_path rescue images_dir
|
||||||
|
if File.exists? full_path
|
||||||
|
dimensions = ::FastImage.size(full_path, :raise_on_failure => true)
|
||||||
|
params[:width] = dimensions[0]
|
||||||
|
params[:height] = dimensions[1]
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
# $stderr.puts params.inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
super(path, params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,56 @@
|
||||||
|
# Extensions namespace
|
||||||
|
module Middleman
|
||||||
|
module Extensions
|
||||||
|
|
||||||
|
# Directory Indexes extension
|
||||||
|
module DirectoryIndexes
|
||||||
|
|
||||||
|
# Setup extension
|
||||||
|
class << self
|
||||||
|
|
||||||
|
# Once registered
|
||||||
|
def registered(app)
|
||||||
|
app.ready do
|
||||||
|
sitemap.register_resource_list_manipulator(
|
||||||
|
:directory_indexes,
|
||||||
|
DirectoryIndexManager.new(self)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
alias :included :registered
|
||||||
|
end
|
||||||
|
|
||||||
|
class DirectoryIndexManager
|
||||||
|
def initialize(app)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
# Update the main sitemap resource list
|
||||||
|
# @return [void]
|
||||||
|
def manipulate_resource_list(resources)
|
||||||
|
index_file = @app.index_file
|
||||||
|
new_index_path = "/#{index_file}"
|
||||||
|
|
||||||
|
resources.each do |resource|
|
||||||
|
# Check if it would be pointless to reroute
|
||||||
|
next if resource.path == index_file ||
|
||||||
|
resource.path.end_with?(new_index_path) ||
|
||||||
|
File.extname(index_file) != resource.ext
|
||||||
|
|
||||||
|
# Check if frontmatter turns directory_index off
|
||||||
|
d = resource.data
|
||||||
|
next if d && d["directory_index"] == false
|
||||||
|
|
||||||
|
# Check if file metadata (options set by "page" in config.rb) turns directory_index off
|
||||||
|
if resource.metadata[:options] && resource.metadata[:options][:directory_index] == false
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
resource.destination_path = resource.destination_path.chomp(File.extname(index_file)) + new_index_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
197
middleman-more/lib/middleman-more/extensions/lorem.rb
Normal file
197
middleman-more/lib/middleman-more/extensions/lorem.rb
Normal file
|
@ -0,0 +1,197 @@
|
||||||
|
# Extension namespace
|
||||||
|
module Middleman
|
||||||
|
module Extensions
|
||||||
|
|
||||||
|
# Lorem helper
|
||||||
|
module Lorem
|
||||||
|
|
||||||
|
# Setup extension
|
||||||
|
class << self
|
||||||
|
|
||||||
|
# Once registered
|
||||||
|
def registered(app)
|
||||||
|
# Include methods
|
||||||
|
app.send :include, InstanceMethods
|
||||||
|
end
|
||||||
|
|
||||||
|
alias :included :registered
|
||||||
|
end
|
||||||
|
|
||||||
|
# Lorem extension instance methods
|
||||||
|
module InstanceMethods
|
||||||
|
# Access to the Lorem object
|
||||||
|
# @return [Middleman::Extensions::Lorem::LoremObject]
|
||||||
|
def lorem
|
||||||
|
@_lorem ||= LoremObject.new
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return a placeholder image using placekitten.com
|
||||||
|
#
|
||||||
|
# @param [String] size
|
||||||
|
# @param [Hash] options
|
||||||
|
# @return [String]
|
||||||
|
def placekitten(size, options={})
|
||||||
|
options[:domain] = "http://placekitten.com"
|
||||||
|
lorem.image(size, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Adapted from Frank:
|
||||||
|
# https://github.com/blahed/frank/
|
||||||
|
# Copyright (c) 2010 Travis Dunn
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person
|
||||||
|
# obtaining a copy of this software and associated documentation
|
||||||
|
# files (the "Software"), to deal in the Software without
|
||||||
|
# restriction, including without limitation the rights to use,
|
||||||
|
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the
|
||||||
|
# Software is furnished to do so, subject to the following
|
||||||
|
# conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
# OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
class LoremObject
|
||||||
|
# Words for use in lorem text
|
||||||
|
WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat)
|
||||||
|
|
||||||
|
# Get one placeholder word
|
||||||
|
# @return [String]
|
||||||
|
def word
|
||||||
|
words(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get some number of placeholder words
|
||||||
|
# @param [Fixnum] total
|
||||||
|
# @return [String]
|
||||||
|
def words(total)
|
||||||
|
(1..total).map do
|
||||||
|
randm(WORDS)
|
||||||
|
end.join(' ')
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get one placeholder sentence
|
||||||
|
# @return [String]
|
||||||
|
def sentence
|
||||||
|
sentences(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get some number of placeholder sentences
|
||||||
|
# @param [Fixnum] total
|
||||||
|
# @return [String]
|
||||||
|
def sentences(total)
|
||||||
|
(1..total).map do
|
||||||
|
words(randm(4..15)).capitalize
|
||||||
|
end.join('. ')
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get one placeholder paragraph
|
||||||
|
# @return [String]
|
||||||
|
def paragraph
|
||||||
|
paragraphs(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get some number of placeholder paragraphs
|
||||||
|
# @param [Fixnum] total
|
||||||
|
# @return [String]
|
||||||
|
def paragraphs(total)
|
||||||
|
(1..total).map do
|
||||||
|
sentences(randm(3..7)).capitalize
|
||||||
|
end.join("\n\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get a placeholder date
|
||||||
|
# @param [String] fmt
|
||||||
|
# @return [String]
|
||||||
|
def date(fmt = '%a %b %d, %Y')
|
||||||
|
y = rand(20) + 1990
|
||||||
|
m = rand(12) + 1
|
||||||
|
d = rand(31) + 1
|
||||||
|
Time.local(y,m,d).strftime(fmt)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get a placeholder name
|
||||||
|
# @return [String]
|
||||||
|
def name
|
||||||
|
"#{first_name} #{last_name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get a placeholder first name
|
||||||
|
# @return [String]
|
||||||
|
def first_name
|
||||||
|
names = "Judith Angelo Margarita Kerry Elaine Lorenzo Justice Doris Raul Liliana Kerry Elise Ciaran Johnny Moses Davion Penny Mohammed Harvey Sheryl Hudson Brendan Brooklynn Denis Sadie Trisha Jacquelyn Virgil Cindy Alexa Marianne Giselle Casey Alondra Angela Katherine Skyler Kyleigh Carly Abel Adrianna Luis Dominick Eoin Noel Ciara Roberto Skylar Brock Earl Dwayne Jackie Hamish Sienna Nolan Daren Jean Shirley Connor Geraldine Niall Kristi Monty Yvonne Tammie Zachariah Fatima Ruby Nadia Anahi Calum Peggy Alfredo Marybeth Bonnie Gordon Cara John Staci Samuel Carmen Rylee Yehudi Colm Beth Dulce Darius inley Javon Jason Perla Wayne Laila Kaleigh Maggie Don Quinn Collin Aniya Zoe Isabel Clint Leland Esmeralda Emma Madeline Byron Courtney Vanessa Terry Antoinette George Constance Preston Rolando Caleb Kenneth Lynette Carley Francesca Johnnie Jordyn Arturo Camila Skye Guy Ana Kaylin Nia Colton Bart Brendon Alvin Daryl Dirk Mya Pete Joann Uriel Alonzo Agnes Chris Alyson Paola Dora Elias Allen Jackie Eric Bonita Kelvin Emiliano Ashton Kyra Kailey Sonja Alberto Ty Summer Brayden Lori Kelly Tomas Joey Billie Katie Stephanie Danielle Alexis Jamal Kieran Lucinda Eliza Allyson Melinda Alma Piper Deana Harriet Bryce Eli Jadyn Rogelio Orlaith Janet Randal Toby Carla Lorie Caitlyn Annika Isabelle inn Ewan Maisie Michelle Grady Ida Reid Emely Tricia Beau Reese Vance Dalton Lexi Rafael Makenzie Mitzi Clinton Xena Angelina Kendrick Leslie Teddy Jerald Noelle Neil Marsha Gayle Omar Abigail Alexandra Phil Andre Billy Brenden Bianca Jared Gretchen Patrick Antonio Josephine Kyla Manuel Freya Kellie Tonia Jamie Sydney Andres Ruben Harrison Hector Clyde Wendell Kaden Ian Tracy Cathleen Shawn".split(" ")
|
||||||
|
names[rand(names.size)]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get a placeholder last name
|
||||||
|
# @return [String]
|
||||||
|
def last_name
|
||||||
|
names = "Chung Chen Melton Hill Puckett Song Hamilton Bender Wagner McLaughlin McNamara Raynor Moon Woodard Desai Wallace Lawrence Griffin Dougherty Powers May Steele Teague Vick Gallagher Solomon Walsh Monroe Connolly Hawkins Middleton Goldstein Watts Johnston Weeks Wilkerson Barton Walton Hall Ross Chung Bender Woods Mangum Joseph Rosenthal Bowden Barton Underwood Jones Baker Merritt Cross Cooper Holmes Sharpe Morgan Hoyle Allen Rich Rich Grant Proctor Diaz Graham Watkins Hinton Marsh Hewitt Branch Walton O'Brien Case Watts Christensen Parks Hardin Lucas Eason Davidson Whitehead Rose Sparks Moore Pearson Rodgers Graves Scarborough Sutton Sinclair Bowman Olsen Love McLean Christian Lamb James Chandler Stout Cowan Golden Bowling Beasley Clapp Abrams Tilley Morse Boykin Sumner Cassidy Davidson Heath Blanchard McAllister McKenzie Byrne Schroeder Griffin Gross Perkins Robertson Palmer Brady Rowe Zhang Hodge Li Bowling Justice Glass Willis Hester Floyd Graves Fischer Norman Chan Hunt Byrd Lane Kaplan Heller May Jennings Hanna Locklear Holloway Jones Glover Vick O'Donnell Goldman McKenna Starr Stone McClure Watson Monroe Abbott Singer Hall Farrell Lucas Norman Atkins Monroe Robertson Sykes Reid Chandler Finch Hobbs Adkins Kinney Whitaker Alexander Conner Waters Becker Rollins Love Adkins Black Fox Hatcher Wu Lloyd Joyce Welch Matthews Chappell MacDonald Kane Butler Pickett Bowman Barton Kennedy Branch Thornton McNeill Weinstein Middleton Moss Lucas Rich Carlton Brady Schultz Nichols Harvey Stevenson Houston Dunn West O'Brien Barr Snyder Cain Heath Boswell Olsen Pittman Weiner Petersen Davis Coleman Terrell Norman Burch Weiner Parrott Henry Gray Chang McLean Eason Weeks Siegel Puckett Heath Hoyle Garrett Neal Baker Goldman Shaffer Choi Carver".split(" ")
|
||||||
|
names[rand(names.size)]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get a placeholder 140 character tweet about Philip the Purple Otter
|
||||||
|
# Via http://www.kevadamson.com/talking-of-design/article/140-alternative-characters-to-lorem-ipsum
|
||||||
|
# @return [String]
|
||||||
|
def tweet
|
||||||
|
tweets = [ 'Far away, in a forest next to a river beneath the mountains, there lived a small purple otter called Philip. Philip likes sausages. The End.',
|
||||||
|
'He liked the quality sausages from Marks & Spencer but due to the recession he had been forced to shop in a less desirable supermarket. End.',
|
||||||
|
'He awoke one day to find his pile of sausages missing. Roger the greedy boar with human eyes, had skateboarded into the forest & eaten them!']
|
||||||
|
tweets[rand(tweets.size)]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get a placeholder email address
|
||||||
|
# @return [String]
|
||||||
|
def email
|
||||||
|
delimiters = [ '_', '-', '' ]
|
||||||
|
domains = %w(gmail.com yahoo.com hotmail.com email.com live.com me.com mac.com aol.com fastmail.com mail.com)
|
||||||
|
username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)])
|
||||||
|
"#{username}@#{domains[rand(domains.size)]}".downcase
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get a placeholder image, using placehold.it by default
|
||||||
|
# @param [String] size
|
||||||
|
# @param [Hash] options
|
||||||
|
# @return [String]
|
||||||
|
def image(size, options={})
|
||||||
|
domain = options[:domain] || "http://placehold.it"
|
||||||
|
src = "#{domain}/#{size}"
|
||||||
|
hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9]
|
||||||
|
background_color = options[:background_color]
|
||||||
|
color = options[:color]
|
||||||
|
|
||||||
|
if options[:random_color]
|
||||||
|
background_color = hex.shuffle[0...6].join
|
||||||
|
color = hex.shuffle[0...6].join
|
||||||
|
end
|
||||||
|
|
||||||
|
src << "/#{background_color.sub(/^#/, '')}" if background_color
|
||||||
|
src << "/ccc" if background_color.nil? && color
|
||||||
|
src << "/#{color.sub(/^#/, '')}" if color
|
||||||
|
src << "&text=#{Rack::Utils::escape(options[:text])}" if options[:text]
|
||||||
|
|
||||||
|
src
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Pick a random item from a given range
|
||||||
|
# @param [Range] range
|
||||||
|
# @return [Object]
|
||||||
|
def randm(range)
|
||||||
|
a = range.to_a
|
||||||
|
a[rand(a.length)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,82 +0,0 @@
|
||||||
###
|
|
||||||
# Setup renderers
|
|
||||||
###
|
|
||||||
|
|
||||||
# CoffeeScript Support
|
|
||||||
require "middleman-more/renderers/coffee_script"
|
|
||||||
Middleman::Application.register Middleman::Renderers::CoffeeScript
|
|
||||||
|
|
||||||
# Haml Support
|
|
||||||
require "middleman-more/renderers/haml"
|
|
||||||
Middleman::Application.register Middleman::Renderers::Haml
|
|
||||||
|
|
||||||
# Sass Support
|
|
||||||
require "middleman-more/renderers/sass"
|
|
||||||
Middleman::Application.register Middleman::Renderers::Sass
|
|
||||||
|
|
||||||
# Markdown Support
|
|
||||||
require "middleman-more/renderers/markdown"
|
|
||||||
Middleman::Application.register Middleman::Renderers::Markdown
|
|
||||||
|
|
||||||
# Liquid Support
|
|
||||||
require "middleman-more/renderers/liquid"
|
|
||||||
Middleman::Application.register Middleman::Renderers::Liquid
|
|
||||||
|
|
||||||
# Slim Support
|
|
||||||
require "middleman-more/renderers/slim"
|
|
||||||
Middleman::Application.register Middleman::Renderers::Slim
|
|
||||||
|
|
||||||
###
|
|
||||||
# Setup Core Extensions
|
|
||||||
###
|
|
||||||
|
|
||||||
# Compass framework
|
|
||||||
require "middleman-more/core_extensions/compass"
|
|
||||||
Middleman::Application.register Middleman::CoreExtensions::Compass
|
|
||||||
|
|
||||||
# Sprockets asset handling
|
|
||||||
require "middleman-more/core_extensions/sprockets"
|
|
||||||
Middleman::Application.register Middleman::CoreExtensions::Sprockets
|
|
||||||
|
|
||||||
###
|
|
||||||
# Setup Optional Extensions
|
|
||||||
###
|
|
||||||
|
|
||||||
# CacheBuster adds a query string to assets in dynamic templates to avoid
|
|
||||||
# browser caches failing to update to your new content.
|
|
||||||
Middleman::Extensions.register(:cache_buster) do
|
|
||||||
require "middleman-more/extensions/cache_buster"
|
|
||||||
Middleman::Extensions::CacheBuster
|
|
||||||
end
|
|
||||||
|
|
||||||
# MinifyCss compresses CSS
|
|
||||||
Middleman::Extensions.register(:minify_css) do
|
|
||||||
require "middleman-more/extensions/minify_css"
|
|
||||||
Middleman::Extensions::MinifyCss
|
|
||||||
end
|
|
||||||
|
|
||||||
# MinifyJavascript compresses JS
|
|
||||||
Middleman::Extensions.register(:minify_javascript) do
|
|
||||||
require "middleman-more/extensions/minify_javascript"
|
|
||||||
Middleman::Extensions::MinifyJavascript
|
|
||||||
end
|
|
||||||
|
|
||||||
# RelativeAssets allow any asset path in dynamic templates to be either
|
|
||||||
# relative to the root of the project or use an absolute URL.
|
|
||||||
Middleman::Extensions.register(:relative_assets) do
|
|
||||||
require "middleman-more/extensions/relative_assets"
|
|
||||||
Middleman::Extensions::RelativeAssets
|
|
||||||
end
|
|
||||||
|
|
||||||
# GZIP assets and pages during build
|
|
||||||
Middleman::Extensions.register(:gzip) do
|
|
||||||
require "middleman-more/extensions/gzip"
|
|
||||||
Middleman::Extensions::Gzip
|
|
||||||
end
|
|
||||||
|
|
||||||
# AssetHash appends a hash of the file contents to the assets filename
|
|
||||||
# to avoid browser caches failing to update to your new content.
|
|
||||||
Middleman::Extensions.register(:asset_hash) do
|
|
||||||
require "middleman-more/extensions/asset_hash"
|
|
||||||
Middleman::Extensions::AssetHash
|
|
||||||
end
|
|
1
middleman-more/lib/middleman_extension.rb
Normal file
1
middleman-more/lib/middleman_extension.rb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
require "middleman-more"
|
Loading…
Reference in a new issue