mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
New extension API with on-demand loading, and gem versioning
This commit is contained in:
parent
6de8d5dde5
commit
d1003a23bc
24 changed files with 540 additions and 471 deletions
|
@ -2,6 +2,7 @@
|
|||
====
|
||||
Rewritten to work directly with Rack (Sinatra apps can still be mounted)
|
||||
Sitemap maintains own state
|
||||
New Extension Registration API
|
||||
Remove old 1.x mm- binaries
|
||||
|
||||
2.1.pre
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
# * CSS Minification
|
||||
#
|
||||
#### Robust Extensions:
|
||||
# Add your own runtime and build-time features!
|
||||
# Add your own runtime and build-time extensions!
|
||||
#
|
||||
#### Next Steps:
|
||||
# * [Visit the website]
|
||||
|
@ -89,7 +89,7 @@ module Middleman
|
|||
autoload :Builder, "middleman/core_extensions/builder"
|
||||
|
||||
# Custom Feature API
|
||||
autoload :Features, "middleman/core_extensions/features"
|
||||
autoload :Extensions, "middleman/core_extensions/extensions"
|
||||
|
||||
# Asset Path Pipeline
|
||||
autoload :Assets, "middleman/core_extensions/assets"
|
||||
|
@ -117,43 +117,43 @@ module Middleman
|
|||
autoload :Routing, "middleman/core_extensions/routing"
|
||||
end
|
||||
|
||||
module Features
|
||||
module Extensions
|
||||
# RelativeAssets allow any asset path in dynamic templates to be either
|
||||
# relative to the root of the project or use an absolute URL.
|
||||
autoload :RelativeAssets, "middleman/features/relative_assets"
|
||||
autoload :RelativeAssets, "middleman/extensions/relative_assets"
|
||||
|
||||
# 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.
|
||||
autoload :AssetHost, "middleman/features/asset_host"
|
||||
autoload :AssetHost, "middleman/extensions/asset_host"
|
||||
|
||||
# CacheBuster adds a query string to assets in dynamic templates to avoid
|
||||
# browser caches failing to update to your new content.
|
||||
autoload :CacheBuster, "middleman/features/cache_buster"
|
||||
autoload :CacheBuster, "middleman/extensions/cache_buster"
|
||||
|
||||
# AutomaticImageSizes inspects the images used in your dynamic templates
|
||||
# and automatically adds width and height attributes to their HTML
|
||||
# elements.
|
||||
autoload :AutomaticImageSizes, "middleman/features/automatic_image_sizes"
|
||||
autoload :AutomaticImageSizes, "middleman/extensions/automatic_image_sizes"
|
||||
|
||||
# MinifyCss uses the YUI compressor to shrink CSS files
|
||||
autoload :MinifyCss, "middleman/features/minify_css"
|
||||
autoload :MinifyCss, "middleman/extensions/minify_css"
|
||||
|
||||
# MinifyJavascript uses the YUI compressor to shrink JS files
|
||||
autoload :MinifyJavascript, "middleman/features/minify_javascript"
|
||||
autoload :MinifyJavascript, "middleman/extensions/minify_javascript"
|
||||
|
||||
# Lorem provides a handful of helpful prototyping methods to generate
|
||||
# words, paragraphs, fake images, names and email addresses.
|
||||
autoload :Lorem, "middleman/features/lorem"
|
||||
autoload :Lorem, "middleman/extensions/lorem"
|
||||
|
||||
# Automatically convert filename.html files into filename/index.html
|
||||
autoload :DirectoryIndexes, "middleman/features/directory_indexes"
|
||||
autoload :DirectoryIndexes, "middleman/extensions/directory_indexes"
|
||||
|
||||
# Organize the sitemap as a tree
|
||||
autoload :SitemapTree, "middleman/features/sitemap_tree"
|
||||
autoload :SitemapTree, "middleman/extensions/sitemap_tree"
|
||||
end
|
||||
|
||||
EXTENSION_FILE = File.join("lib", "middleman_init.rb")
|
||||
EXTENSION_FILE = File.join("lib", "middleman_extension.rb")
|
||||
class << self
|
||||
def load_extensions_in_path
|
||||
extensions = rubygems_latest_specs.select do |spec|
|
||||
|
|
|
@ -99,7 +99,7 @@ class Middleman::Base
|
|||
set :layout, :layout
|
||||
|
||||
# Activate custom features and extensions
|
||||
include Middleman::CoreExtensions::Features
|
||||
include Middleman::CoreExtensions::Extensions
|
||||
|
||||
# Add Builder Callbacks
|
||||
register Middleman::CoreExtensions::Builder
|
||||
|
@ -134,6 +134,17 @@ class Middleman::Base
|
|||
# Parse YAML from templates
|
||||
register Middleman::CoreExtensions::FrontMatter
|
||||
|
||||
# Built-in Extensions
|
||||
Middleman::Extensions.register(:asset_host) { Middleman::Extensions::AssetHost }
|
||||
Middleman::Extensions.register(:automatic_image_sizes) { Middleman::Extensions::AutomaticImageSizes }
|
||||
Middleman::Extensions.register(:cache_buster) { Middleman::Extensions::CacheBuster }
|
||||
Middleman::Extensions.register(:directory_indexes) { Middleman::Extensions::DirectoryIndexes }
|
||||
Middleman::Extensions.register(:lorem) { Middleman::Extensions::Lorem }
|
||||
Middleman::Extensions.register(:minify_css) { Middleman::Extensions::MinifyCss }
|
||||
Middleman::Extensions.register(:minify_javascript) { Middleman::Extensions::MinifyJavascript }
|
||||
Middleman::Extensions.register(:relative_assets) { Middleman::Extensions::RelativeAssets }
|
||||
Middleman::Extensions.register(:sitemap_tree) { Middleman::Extensions::SitemapTree }
|
||||
|
||||
def initialize(&block)
|
||||
@current_path = nil
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
# methods to use in your views. Some modify the output on-the-fly. And some
|
||||
# apply computationally-intensive changes to your final build files.
|
||||
|
||||
module Middleman::CoreExtensions::Features
|
||||
module Middleman::CoreExtensions::Extensions
|
||||
|
||||
class << self
|
||||
def included(app)
|
||||
|
@ -39,6 +39,36 @@ module Middleman::CoreExtensions::Features
|
|||
app.define_hook :development_config
|
||||
app.extend ClassMethods
|
||||
app.send :include, InstanceMethods
|
||||
|
||||
# Setup extension API
|
||||
::Middleman::Extensions.extend API
|
||||
end
|
||||
end
|
||||
|
||||
module API
|
||||
def registered
|
||||
@_registered ||= {}
|
||||
end
|
||||
|
||||
def register(name, namespace=nil, &block)
|
||||
registered[name.to_sym] = if block_given?
|
||||
block
|
||||
elsif namespace
|
||||
namespace
|
||||
end
|
||||
end
|
||||
|
||||
def load(name)
|
||||
name = name.to_sym
|
||||
return nil unless registered.has_key?(name)
|
||||
|
||||
extension = registered[name]
|
||||
if extension.is_a?(Proc)
|
||||
extension = extension.call(Middleman::VERSION) || nil
|
||||
registered[name] = extension
|
||||
end
|
||||
|
||||
extension
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -67,22 +97,15 @@ module Middleman::CoreExtensions::Features
|
|||
# feature module and includes it.
|
||||
#
|
||||
# activate :lorem
|
||||
#
|
||||
# Alternatively, you can pass in a Middleman feature module directly.
|
||||
#
|
||||
# activate MyFeatureModule
|
||||
def activate(feature)
|
||||
if feature.is_a? Symbol
|
||||
feature = feature.to_s
|
||||
end
|
||||
|
||||
if feature.is_a? String
|
||||
feature = feature.camelize
|
||||
feature = ::Middleman::Features.const_get(feature)
|
||||
end
|
||||
ext = ::Middleman::Extensions.load(feature.to_sym)
|
||||
|
||||
puts "== Activating: #{feature}" if logging?
|
||||
self.class.register feature
|
||||
if ext.nil?
|
||||
puts "== Unknown Extension: #{feature}"
|
||||
else
|
||||
puts "== Activating: #{feature}" if logging?
|
||||
self.class.register(ext)
|
||||
end
|
||||
end
|
||||
|
||||
def configure(env, &block)
|
34
lib/middleman/extensions/asset_host.rb
Normal file
34
lib/middleman/extensions/asset_host.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Middleman::Extensions
|
||||
module AssetHost
|
||||
class << self
|
||||
def registered(app)
|
||||
app.set :asset_host, false
|
||||
|
||||
app.compass_config do |config|
|
||||
if asset_host.is_a?(Proc)
|
||||
config.asset_host(&asset_host)
|
||||
end
|
||||
end
|
||||
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def asset_url(path, prefix="")
|
||||
original_output = super
|
||||
|
||||
valid_extensions = %w(.png .gif .jpg .jpeg .js .css)
|
||||
|
||||
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
|
38
lib/middleman/extensions/automatic_image_sizes.rb
Executable file
38
lib/middleman/extensions/automatic_image_sizes.rb
Executable file
|
@ -0,0 +1,38 @@
|
|||
module Middleman::Extensions
|
||||
module AutomaticImageSizes
|
||||
class << self
|
||||
def registered(app)
|
||||
require "middleman/extensions/automatic_image_sizes/fastimage"
|
||||
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
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(views, 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 :automatic_image_sizes, AutomaticImageSizes
|
||||
end
|
59
lib/middleman/extensions/cache_buster.rb
Executable file
59
lib/middleman/extensions/cache_buster.rb
Executable file
|
@ -0,0 +1,59 @@
|
|||
module Middleman::Extensions
|
||||
module CacheBuster
|
||||
class << self
|
||||
def registered(app)
|
||||
app.send :include, InstanceMethods
|
||||
|
||||
app.compass_config do |config|
|
||||
config.asset_cache_buster do |path, real_path|
|
||||
real_path = real_path.path if real_path.is_a? File
|
||||
real_path = real_path.gsub(File.join(root, build_dir), views)
|
||||
if File.readable?(real_path)
|
||||
File.mtime(real_path).strftime("%s")
|
||||
else
|
||||
$stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def asset_url(path, prefix="")
|
||||
http_path = super
|
||||
|
||||
if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path))
|
||||
http_path
|
||||
else
|
||||
begin
|
||||
prefix = images_dir if prefix == http_images_path
|
||||
rescue
|
||||
end
|
||||
|
||||
real_path_static = File.join(prefix, path)
|
||||
|
||||
if build?
|
||||
real_path_dynamic = File.join(build_dir, prefix, path)
|
||||
real_path_dynamic = File.expand_path(real_path_dynamic, root)
|
||||
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
||||
elsif sitemap.exists?(real_path_static)
|
||||
page = sitemap.page(real_path_static)
|
||||
if !page.template?
|
||||
http_path << "?" + File.mtime(result[0]).strftime("%s")
|
||||
else
|
||||
# It's a template, possible with partials. We can't really know when
|
||||
# it's updated, so generate fresh cache buster every time durin
|
||||
# developement
|
||||
http_path << "?" + Time.now.strftime("%s")
|
||||
end
|
||||
end
|
||||
|
||||
http_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
register :cache_buster, CacheBuster
|
||||
end
|
62
lib/middleman/extensions/directory_indexes.rb
Normal file
62
lib/middleman/extensions/directory_indexes.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
module Middleman::Extensions
|
||||
module DirectoryIndexes
|
||||
class << self
|
||||
def registered(app)
|
||||
app.send :include, InstanceMethods
|
||||
app.before do
|
||||
prefix = @original_path.sub(/\/$/, "")
|
||||
indexed_path = prefix + "/" + index_file
|
||||
|
||||
extensioned_path = prefix + File.extname(index_file)
|
||||
is_ignored = ignored_directory_indexes.include?(extensioned_path)
|
||||
|
||||
if !sitemap.exists?(indexed_path) && !is_ignored
|
||||
parts = @original_path.split("/")
|
||||
last_part = parts.last
|
||||
last_part_ext = File.extname(last_part)
|
||||
|
||||
if last_part_ext.blank?
|
||||
# This is a folder, redirect to index
|
||||
@request_path = extensioned_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
app.build_reroute do |destination, request_path|
|
||||
index_ext = File.extname(index_file)
|
||||
new_index_path = "/#{index_file}"
|
||||
|
||||
indexed_path = request_path.sub(/\/$/, "") + index_ext
|
||||
|
||||
if ignored_directory_indexes.include?(request_path)
|
||||
false
|
||||
elsif request_path =~ /#{new_index_path}$/
|
||||
false
|
||||
else
|
||||
[
|
||||
destination.sub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
|
||||
request_path
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def ignored_directory_indexes
|
||||
@_ignored_directory_indexes ||= []
|
||||
end
|
||||
|
||||
def page(url, options={}, &block)
|
||||
if options.has_key?(:directory_index) && !options["directory_index"]
|
||||
ignored_directory_indexes << url
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
register :directory_indexes, DirectoryIndexes
|
||||
end
|
130
lib/middleman/extensions/lorem.rb
Normal file
130
lib/middleman/extensions/lorem.rb
Normal file
|
@ -0,0 +1,130 @@
|
|||
module Middleman::Extensions
|
||||
module Lorem
|
||||
class << self
|
||||
def registered(app)
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def lorem
|
||||
@_lorem ||= LoremObject.new
|
||||
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 = %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)
|
||||
|
||||
def word
|
||||
words(1)
|
||||
end
|
||||
|
||||
def words(total)
|
||||
(1..total).map do
|
||||
randm(WORDS)
|
||||
end.join(' ')
|
||||
end
|
||||
|
||||
def sentence
|
||||
sentences(1)
|
||||
end
|
||||
|
||||
def sentences(total)
|
||||
(1..total).map do
|
||||
words(randm(4..15)).capitalize
|
||||
end.join('. ')
|
||||
end
|
||||
|
||||
def paragraph
|
||||
paragraphs(1)
|
||||
end
|
||||
|
||||
def paragraphs(total)
|
||||
(1..total).map do
|
||||
sentences(randm(3..7)).capitalize
|
||||
end.join("\n\n")
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def image(size, options={})
|
||||
src = "http://placehold.it/#{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
|
||||
|
||||
def randm(range)
|
||||
a = range.to_a
|
||||
a[rand(a.length)]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
register :lorem, Lorem
|
||||
end
|
15
lib/middleman/extensions/minify_css.rb
Normal file
15
lib/middleman/extensions/minify_css.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Middleman::Extensions
|
||||
module MinifyCss
|
||||
class << self
|
||||
def registered(app)
|
||||
require "middleman/extensions/minify_css/cssmin"
|
||||
app.after_configuration do
|
||||
set :css_compressor, ::CSSMin
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
||||
|
||||
register :minify_css, MinifyCss
|
||||
end
|
54
lib/middleman/extensions/minify_javascript.rb
Executable file
54
lib/middleman/extensions/minify_javascript.rb
Executable file
|
@ -0,0 +1,54 @@
|
|||
module Middleman::Extensions
|
||||
module MinifyJavascript
|
||||
class << self
|
||||
def registered(app)
|
||||
require 'uglifier'
|
||||
app.after_configuration do
|
||||
set :js_compressor, ::Uglifier.new
|
||||
end
|
||||
app.use InlineJavascriptRack
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
class InlineJavascriptRack
|
||||
def initialize(app, options={})
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
status, headers, response = @app.call(env)
|
||||
|
||||
if env["PATH_INFO"].match(/\.html$/)
|
||||
compressor = ::Uglifier.new
|
||||
|
||||
uncompressed_source = case(response)
|
||||
when String
|
||||
response
|
||||
when Array
|
||||
response.join
|
||||
when Rack::Response
|
||||
response.body.join
|
||||
when Rack::File
|
||||
File.read(response.path)
|
||||
end
|
||||
|
||||
minified = uncompressed_source.gsub(/(<scri.*?\/\/<!\[CDATA\[\n)(.*?)(\/\/\]\].*?<\/script>)/m) do |m|
|
||||
first = $1
|
||||
uncompressed_source = $2
|
||||
last = $3
|
||||
minified_js = compressor.compile(uncompressed_source)
|
||||
|
||||
first << minified_js << "\n" << last
|
||||
end
|
||||
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
|
||||
response = [minified]
|
||||
end
|
||||
|
||||
[status, headers, response]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
register :minify_javascript, MinifyJavascript
|
||||
end
|
46
lib/middleman/extensions/relative_assets.rb
Executable file
46
lib/middleman/extensions/relative_assets.rb
Executable file
|
@ -0,0 +1,46 @@
|
|||
module Middleman::Extensions
|
||||
module RelativeAssets
|
||||
class << self
|
||||
def registered(app)
|
||||
app.compass_config do |config|
|
||||
config.relative_assets = true
|
||||
end
|
||||
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def asset_url(path, prefix="")
|
||||
begin
|
||||
prefix = images_dir if prefix == http_images_path
|
||||
rescue
|
||||
end
|
||||
|
||||
if path.include?("://")
|
||||
super(path, prefix)
|
||||
elsif path[0,1] == "/"
|
||||
path
|
||||
else
|
||||
path = File.join(prefix, path) if prefix.length > 0
|
||||
request_path = @request_path.dup
|
||||
request_path << index_file if path.match(%r{/$})
|
||||
request_path.gsub!(%r{^/}, '')
|
||||
parts = request_path.split('/')
|
||||
|
||||
if parts.length > 1
|
||||
arry = []
|
||||
(parts.length - 1).times { arry << ".." }
|
||||
arry << path
|
||||
File.join(*arry)
|
||||
else
|
||||
path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
register :relative_assets, RelativeAssets
|
||||
end
|
38
lib/middleman/extensions/sitemap_tree.rb
Normal file
38
lib/middleman/extensions/sitemap_tree.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
module Middleman::Extensions
|
||||
module SitemapTree
|
||||
class << self
|
||||
def registered(app)
|
||||
app.helpers Helpers
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module Helpers
|
||||
def sitemap_tree(regex=nil)
|
||||
@sitemap_tree_cache = {}
|
||||
|
||||
key = regex.nil? ? "all" : regex
|
||||
|
||||
if !@sitemap_tree_cache.has_key?(key)
|
||||
auto_hash = Hash.new{ |h,k| h[k] = Hash.new &h.default_proc }
|
||||
|
||||
app.sitemap.all_paths.each do |path|
|
||||
next if !regex.nil? && !path.match(regex)
|
||||
sub = auto_hash
|
||||
path.split( "/" ).each{ |dir| sub[dir]; sub = sub[dir] }
|
||||
end
|
||||
|
||||
@sitemap_tree_cache[key] = auto_hash
|
||||
end
|
||||
|
||||
@sitemap_tree_cache[key]
|
||||
end
|
||||
|
||||
def html_sitemap
|
||||
sitemap_tree(/\.html$/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
register :sitemap_tree, SitemapTree
|
||||
end
|
|
@ -1,32 +0,0 @@
|
|||
module Middleman::Features::AssetHost
|
||||
class << self
|
||||
def registered(app)
|
||||
app.set :asset_host, nil
|
||||
|
||||
app.compass_config do |config|
|
||||
if asset_host.is_a?(Proc)
|
||||
config.asset_host(&asset_host)
|
||||
end
|
||||
end
|
||||
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def asset_url(path, prefix="")
|
||||
original_output = super
|
||||
|
||||
valid_extensions = %w(.png .gif .jpg .jpeg .js .css)
|
||||
|
||||
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
|
|
@ -1,34 +0,0 @@
|
|||
module Middleman::Features::AutomaticImageSizes
|
||||
class << self
|
||||
def registered(app)
|
||||
require "middleman/features/automatic_image_sizes/fastimage"
|
||||
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
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(views, 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
|
|
@ -1,55 +0,0 @@
|
|||
module Middleman::Features::CacheBuster
|
||||
class << self
|
||||
def registered(app)
|
||||
app.send :include, InstanceMethods
|
||||
|
||||
app.compass_config do |config|
|
||||
config.asset_cache_buster do |path, real_path|
|
||||
real_path = real_path.path if real_path.is_a? File
|
||||
real_path = real_path.gsub(File.join(root, build_dir), views)
|
||||
if File.readable?(real_path)
|
||||
File.mtime(real_path).strftime("%s")
|
||||
else
|
||||
$stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def asset_url(path, prefix="")
|
||||
http_path = super
|
||||
|
||||
if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path))
|
||||
http_path
|
||||
else
|
||||
begin
|
||||
prefix = images_dir if prefix == http_images_path
|
||||
rescue
|
||||
end
|
||||
|
||||
real_path_static = File.join(prefix, path)
|
||||
|
||||
if build?
|
||||
real_path_dynamic = File.join(build_dir, prefix, path)
|
||||
real_path_dynamic = File.expand_path(real_path_dynamic, root)
|
||||
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
||||
elsif sitemap.exists?(real_path_static)
|
||||
page = sitemap.page(real_path_static)
|
||||
if !page.template?
|
||||
http_path << "?" + File.mtime(result[0]).strftime("%s")
|
||||
else
|
||||
# It's a template, possible with partials. We can't really know when
|
||||
# it's updated, so generate fresh cache buster every time durin
|
||||
# developement
|
||||
http_path << "?" + Time.now.strftime("%s")
|
||||
end
|
||||
end
|
||||
|
||||
http_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,58 +0,0 @@
|
|||
module Middleman::Features::DirectoryIndexes
|
||||
class << self
|
||||
def registered(app)
|
||||
app.send :include, InstanceMethods
|
||||
app.before do
|
||||
prefix = @original_path.sub(/\/$/, "")
|
||||
indexed_path = prefix + "/" + index_file
|
||||
|
||||
extensioned_path = prefix + File.extname(index_file)
|
||||
is_ignored = ignored_directory_indexes.include?(extensioned_path)
|
||||
|
||||
if !sitemap.exists?(indexed_path) && !is_ignored
|
||||
parts = @original_path.split("/")
|
||||
last_part = parts.last
|
||||
last_part_ext = File.extname(last_part)
|
||||
|
||||
if last_part_ext.blank?
|
||||
# This is a folder, redirect to index
|
||||
@request_path = extensioned_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
app.build_reroute do |destination, request_path|
|
||||
index_ext = File.extname(index_file)
|
||||
new_index_path = "/#{index_file}"
|
||||
|
||||
indexed_path = request_path.sub(/\/$/, "") + index_ext
|
||||
|
||||
if ignored_directory_indexes.include?(request_path)
|
||||
false
|
||||
elsif request_path =~ /#{new_index_path}$/
|
||||
false
|
||||
else
|
||||
[
|
||||
destination.sub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
|
||||
request_path
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def ignored_directory_indexes
|
||||
@_ignored_directory_indexes ||= []
|
||||
end
|
||||
|
||||
def page(url, options={}, &block)
|
||||
if options.has_key?(:directory_index) && !options["directory_index"]
|
||||
ignored_directory_indexes << url
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,126 +0,0 @@
|
|||
module Middleman::Features::Lorem
|
||||
class << self
|
||||
def registered(app)
|
||||
app.helpers Middleman::Features::Lorem::Helpers
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module Helpers
|
||||
def lorem
|
||||
@@lorem ||= Middleman::Features::Lorem::LoremObject.new
|
||||
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 = %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)
|
||||
|
||||
def word
|
||||
words(1)
|
||||
end
|
||||
|
||||
def words(total)
|
||||
(1..total).map do
|
||||
randm(WORDS)
|
||||
end.join(' ')
|
||||
end
|
||||
|
||||
def sentence
|
||||
sentences(1)
|
||||
end
|
||||
|
||||
def sentences(total)
|
||||
(1..total).map do
|
||||
words(randm(4..15)).capitalize
|
||||
end.join('. ')
|
||||
end
|
||||
|
||||
def paragraph
|
||||
paragraphs(1)
|
||||
end
|
||||
|
||||
def paragraphs(total)
|
||||
(1..total).map do
|
||||
sentences(randm(3..7)).capitalize
|
||||
end.join("\n\n")
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def image(size, options={})
|
||||
src = "http://placehold.it/#{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
|
||||
|
||||
def randm(range)
|
||||
a = range.to_a
|
||||
a[rand(a.length)]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,11 +0,0 @@
|
|||
module Middleman::Features::MinifyCss
|
||||
class << self
|
||||
def registered(app)
|
||||
require "middleman/features/minify_css/cssmin"
|
||||
app.after_configuration do
|
||||
set :css_compressor, ::CSSMin
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
|
@ -1,50 +0,0 @@
|
|||
module Middleman::Features::MinifyJavascript
|
||||
class << self
|
||||
def registered(app)
|
||||
require 'uglifier'
|
||||
app.after_configuration do
|
||||
set :js_compressor, ::Uglifier.new
|
||||
end
|
||||
app.use InlineJavascriptRack
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
class InlineJavascriptRack
|
||||
def initialize(app, options={})
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
status, headers, response = @app.call(env)
|
||||
|
||||
if env["PATH_INFO"].match(/\.html$/)
|
||||
compressor = ::Uglifier.new
|
||||
|
||||
uncompressed_source = case(response)
|
||||
when String
|
||||
response
|
||||
when Array
|
||||
response.join
|
||||
when Rack::Response
|
||||
response.body.join
|
||||
when Rack::File
|
||||
File.read(response.path)
|
||||
end
|
||||
|
||||
minified = uncompressed_source.gsub(/(<scri.*?\/\/<!\[CDATA\[\n)(.*?)(\/\/\]\].*?<\/script>)/m) do |m|
|
||||
first = $1
|
||||
uncompressed_source = $2
|
||||
last = $3
|
||||
minified_js = compressor.compile(uncompressed_source)
|
||||
|
||||
first << minified_js << "\n" << last
|
||||
end
|
||||
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
|
||||
response = [minified]
|
||||
end
|
||||
|
||||
[status, headers, response]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
module Middleman::Features::RelativeAssets
|
||||
class << self
|
||||
def registered(app)
|
||||
app.compass_config do |config|
|
||||
config.relative_assets = true
|
||||
end
|
||||
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def asset_url(path, prefix="")
|
||||
begin
|
||||
prefix = images_dir if prefix == http_images_path
|
||||
rescue
|
||||
end
|
||||
|
||||
if path.include?("://")
|
||||
super(path, prefix)
|
||||
elsif path[0,1] == "/"
|
||||
path
|
||||
else
|
||||
path = File.join(prefix, path) if prefix.length > 0
|
||||
request_path = @request_path.dup
|
||||
request_path << index_file if path.match(%r{/$})
|
||||
request_path.gsub!(%r{^/}, '')
|
||||
parts = request_path.split('/')
|
||||
|
||||
if parts.length > 1
|
||||
arry = []
|
||||
(parts.length - 1).times { arry << ".." }
|
||||
arry << path
|
||||
File.join(*arry)
|
||||
else
|
||||
path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
module Middleman::Features::SitemapTree
|
||||
class << self
|
||||
def registered(app)
|
||||
app.helpers Helpers
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module Helpers
|
||||
def sitemap_tree(regex=nil)
|
||||
@sitemap_tree_cache = {}
|
||||
|
||||
key = regex.nil? ? "all" : regex
|
||||
|
||||
if !@sitemap_tree_cache.has_key?(key)
|
||||
auto_hash = Hash.new{ |h,k| h[k] = Hash.new &h.default_proc }
|
||||
|
||||
app.sitemap.all_paths.each do |path|
|
||||
next if !regex.nil? && !path.match(regex)
|
||||
sub = auto_hash
|
||||
path.split( "/" ).each{ |dir| sub[dir]; sub = sub[dir] }
|
||||
end
|
||||
|
||||
@sitemap_tree_cache[key] = auto_hash
|
||||
end
|
||||
|
||||
@sitemap_tree_cache[key]
|
||||
end
|
||||
|
||||
def html_sitemap
|
||||
sitemap_tree(/\.html$/)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue