2011-02-11 08:14:33 +01:00
|
|
|
# Middleman is a static site renderer that provides all the conveniences of
|
|
|
|
# a modern web stack, like Ruby on Rails, while remaining focused on building
|
|
|
|
# the fastest, most-professional sites possible
|
|
|
|
#
|
|
|
|
# Install Middleman:
|
|
|
|
#
|
|
|
|
# gem install middleman
|
|
|
|
#
|
|
|
|
# To accomplish its goals, Middleman supports provides access to:
|
|
|
|
#
|
2011-07-27 08:19:43 +02:00
|
|
|
#### Command-line tool:
|
2011-07-27 10:45:57 +02:00
|
|
|
# * **middleman init**: A tool for creating to new static sites.
|
|
|
|
# * **middleman server**: A tool for rapidly developing your static site.
|
|
|
|
# * **middleman build**: A tool for exporting your site into optimized HTML, CSS & JS.
|
2011-02-11 08:14:33 +01:00
|
|
|
#
|
|
|
|
#### Tons of templating languages including:
|
|
|
|
# * ERB (.erb)
|
|
|
|
# * Interpolated String (.str)
|
|
|
|
# * Sass (.sass)
|
|
|
|
# * Scss (.scss)
|
|
|
|
# * Haml (.haml)
|
2011-06-24 03:05:25 +02:00
|
|
|
# * Slim (.slim)
|
2011-02-11 08:14:33 +01:00
|
|
|
# * Less CSS (.less)
|
|
|
|
# * Builder (.builder)
|
|
|
|
# * Liquid (.liquid)
|
|
|
|
# * RDiscount (.markdown)
|
|
|
|
# * RedCloth (.textile)
|
|
|
|
# * RDoc (.rdoc)
|
|
|
|
# * Radius (.radius)
|
|
|
|
# * Markaby (.mab)
|
|
|
|
# * Nokogiri (.nokogiri)
|
|
|
|
# * Mustache (.mustache)
|
|
|
|
# * CoffeeScript (.coffee)
|
|
|
|
#
|
|
|
|
#### Compile-time Optimiztions
|
|
|
|
# * Javascript Minifiers: YUI, Google Closure & UglifyJS
|
|
|
|
# * Smush.it Image Compression
|
|
|
|
# * CSS Minification
|
|
|
|
#
|
|
|
|
#### Robust Extensions:
|
|
|
|
# Add your own runtime and build-time features!
|
|
|
|
#
|
|
|
|
#### Next Steps:
|
|
|
|
# * [Visit the website]
|
|
|
|
# * [Read the wiki]
|
|
|
|
# * [Email the users group]
|
|
|
|
# * [Submit bug reports]
|
|
|
|
#
|
|
|
|
# [Visit the website]: http://middlemanapp.com
|
|
|
|
# [Read the wiki]: https://github.com/tdreyno/middleman/wiki
|
2011-10-25 06:59:24 +02:00
|
|
|
# [Email the users group]: https://convore.com/middleman/
|
2011-02-11 08:14:33 +01:00
|
|
|
# [Submit bug reports]: https://github.com/tdreyno/middleman/issues
|
|
|
|
|
2011-07-27 06:05:13 +02:00
|
|
|
# Setup our load paths
|
2009-10-23 02:25:15 +02:00
|
|
|
libdir = File.dirname(__FILE__)
|
|
|
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|
|
|
|
2011-11-11 00:09:52 +01:00
|
|
|
# Quiet down Thin
|
|
|
|
require "thin"
|
|
|
|
::Thin::Logging.silent = true
|
|
|
|
|
2011-07-13 09:38:04 +02:00
|
|
|
# We're riding on Sinatra, so let's include it.
|
|
|
|
require "sinatra/base"
|
|
|
|
|
2011-02-11 08:14:33 +01:00
|
|
|
# Top-level Middleman object
|
2010-03-03 07:00:46 +01:00
|
|
|
module Middleman
|
2011-02-11 08:14:33 +01:00
|
|
|
# Auto-load modules on-demand
|
2011-11-08 07:34:02 +01:00
|
|
|
autoload :Base, "middleman/base"
|
|
|
|
autoload :Builder, "middleman/builder"
|
|
|
|
autoload :CLI, "middleman/cli"
|
|
|
|
autoload :Templates, "middleman/templates"
|
|
|
|
autoload :Guard, "middleman/guard"
|
2010-09-07 03:48:25 +02:00
|
|
|
|
2011-02-11 08:14:33 +01:00
|
|
|
# Custom Renderers
|
2010-09-07 03:48:25 +02:00
|
|
|
module Renderers
|
2011-09-09 08:06:22 +02:00
|
|
|
autoload :Sass, "middleman/renderers/sass"
|
|
|
|
autoload :Markdown, "middleman/renderers/markdown"
|
2011-10-27 18:24:48 +02:00
|
|
|
autoload :ERb, "middleman/renderers/erb"
|
2011-06-27 22:10:09 +02:00
|
|
|
autoload :CoffeeScript, "middleman/renderers/coffee_script"
|
2011-09-09 08:06:22 +02:00
|
|
|
autoload :Liquid, "middleman/renderers/liquid"
|
2010-09-07 03:48:25 +02:00
|
|
|
end
|
2011-07-06 18:50:34 +02:00
|
|
|
|
|
|
|
module CoreExtensions
|
2011-11-09 00:38:15 +01:00
|
|
|
# File Change Notifier
|
2011-11-08 07:34:02 +01:00
|
|
|
autoload :FileWatcher, "middleman/core_extensions/file_watcher"
|
|
|
|
|
2011-11-09 00:38:15 +01:00
|
|
|
# In-memory Sitemap
|
2011-11-08 07:34:02 +01:00
|
|
|
autoload :Sitemap, "middleman/core_extensions/sitemap"
|
|
|
|
|
2011-08-05 04:43:42 +02:00
|
|
|
# Add Builder callbacks
|
|
|
|
autoload :Builder, "middleman/core_extensions/builder"
|
|
|
|
|
2011-07-11 00:10:49 +02:00
|
|
|
# Add Rack::Builder.map support
|
|
|
|
autoload :RackMap, "middleman/core_extensions/rack_map"
|
|
|
|
|
2011-07-06 19:15:31 +02:00
|
|
|
# Custom Feature API
|
|
|
|
autoload :Features, "middleman/core_extensions/features"
|
|
|
|
|
2011-07-06 19:40:17 +02:00
|
|
|
# Asset Path Pipeline
|
|
|
|
autoload :Assets, "middleman/core_extensions/assets"
|
|
|
|
|
2011-07-06 18:50:34 +02:00
|
|
|
# DefaultHelpers are the built-in dynamic template helpers.
|
|
|
|
autoload :DefaultHelpers, "middleman/core_extensions/default_helpers"
|
|
|
|
|
|
|
|
# Data looks at the data/ folder for YAML files and makes them available
|
|
|
|
# to dynamic requests.
|
|
|
|
autoload :Data, "middleman/core_extensions/data"
|
2011-07-06 19:15:31 +02:00
|
|
|
|
|
|
|
# Parse YAML from templates
|
|
|
|
autoload :FrontMatter, "middleman/core_extensions/front_matter"
|
|
|
|
|
|
|
|
# Extended version of Padrino's rendering
|
|
|
|
autoload :Rendering, "middleman/core_extensions/rendering"
|
2011-07-11 00:10:49 +02:00
|
|
|
|
|
|
|
# Compass framework for Sass
|
|
|
|
autoload :Compass, "middleman/core_extensions/compass"
|
|
|
|
|
|
|
|
# Sprockets 2
|
|
|
|
autoload :Sprockets, "middleman/core_extensions/sprockets"
|
2011-07-06 19:46:06 +02:00
|
|
|
|
|
|
|
# Pass custom options to views
|
|
|
|
autoload :Routing, "middleman/core_extensions/routing"
|
2011-07-06 18:50:34 +02:00
|
|
|
end
|
2010-09-07 03:48:25 +02:00
|
|
|
|
2011-07-06 19:15:31 +02:00
|
|
|
module Features
|
|
|
|
# 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"
|
|
|
|
|
2011-07-10 22:55:40 +02:00
|
|
|
# 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.
|
2011-07-06 19:15:31 +02:00
|
|
|
autoload :AssetHost, "middleman/features/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"
|
|
|
|
|
2011-07-10 22:55:40 +02:00
|
|
|
# AutomaticImageSizes inspects the images used in your dynamic templates
|
|
|
|
# and automatically adds width and height attributes to their HTML
|
|
|
|
# elements.
|
2011-07-06 19:15:31 +02:00
|
|
|
autoload :AutomaticImageSizes, "middleman/features/automatic_image_sizes"
|
|
|
|
|
|
|
|
# MinifyCss uses the YUI compressor to shrink CSS files
|
|
|
|
autoload :MinifyCss, "middleman/features/minify_css"
|
|
|
|
|
|
|
|
# MinifyJavascript uses the YUI compressor to shrink JS files
|
|
|
|
autoload :MinifyJavascript, "middleman/features/minify_javascript"
|
|
|
|
|
2011-07-10 22:55:40 +02:00
|
|
|
# Lorem provides a handful of helpful prototyping methods to generate
|
|
|
|
# words, paragraphs, fake images, names and email addresses.
|
2011-07-06 19:15:31 +02:00
|
|
|
autoload :Lorem, "middleman/features/lorem"
|
2011-07-14 03:45:15 +02:00
|
|
|
|
2011-07-28 04:59:38 +02:00
|
|
|
# Automatically convert filename.html files into filename/index.html
|
|
|
|
autoload :DirectoryIndexes, "middleman/features/directory_indexes"
|
2011-11-08 09:00:33 +01:00
|
|
|
|
|
|
|
# Organize the sitemap as a tree
|
|
|
|
autoload :SitemapTree, "middleman/features/sitemap_tree"
|
2011-07-13 09:38:04 +02:00
|
|
|
end
|
|
|
|
|
2011-08-29 21:35:08 +02:00
|
|
|
EXTENSION_FILE = File.join("lib", "middleman_init.rb")
|
2011-08-19 02:33:45 +02:00
|
|
|
def self.load_extensions_in_path
|
2011-08-29 20:53:11 +02:00
|
|
|
extensions = rubygems_latest_specs.select do |spec|
|
|
|
|
spec_has_file?(spec, EXTENSION_FILE)
|
2011-08-19 02:33:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
extensions.each do |spec|
|
|
|
|
require spec.name
|
2011-08-21 02:09:30 +02:00
|
|
|
# $stderr.puts "require: #{spec.name}"
|
2011-08-19 02:33:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-29 20:53:11 +02:00
|
|
|
def self.rubygems_latest_specs
|
|
|
|
# If newer Rubygems
|
2011-10-18 23:24:24 +02:00
|
|
|
if ::Gem::Specification.respond_to? :latest_specs
|
|
|
|
::Gem::Specification.latest_specs
|
2011-08-29 20:53:11 +02:00
|
|
|
else
|
2011-10-18 23:24:24 +02:00
|
|
|
::Gem.source_index.latest_specs
|
2011-08-29 20:53:11 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.spec_has_file?(spec, path)
|
|
|
|
full_path = File.join(spec.full_gem_path, path)
|
|
|
|
File.exists?(full_path)
|
|
|
|
end
|
|
|
|
|
2011-07-13 09:38:04 +02:00
|
|
|
def self.server(&block)
|
|
|
|
sandbox = Class.new(Sinatra::Base)
|
|
|
|
sandbox.register Base
|
|
|
|
sandbox.class_eval(&block) if block_given?
|
|
|
|
sandbox
|
2011-07-06 19:15:31 +02:00
|
|
|
end
|
2011-08-09 23:37:55 +02:00
|
|
|
|
|
|
|
def self.start_server(options={})
|
|
|
|
opts = {
|
2011-10-14 22:13:21 +02:00
|
|
|
:Port => options[:port] || 4567,
|
2011-08-09 23:37:55 +02:00
|
|
|
:AccessLog => []
|
|
|
|
}
|
|
|
|
|
2011-11-08 23:57:55 +01:00
|
|
|
app_class = options[:app] ||= ::Middleman.server.new
|
|
|
|
opts[:app] = app_class
|
2011-08-09 23:37:55 +02:00
|
|
|
opts[:server] = 'thin'
|
2011-08-09 23:55:48 +02:00
|
|
|
|
2011-11-08 07:34:02 +01:00
|
|
|
server = ::Rack::Server.new(opts)
|
|
|
|
server.start
|
|
|
|
server
|
2011-08-09 23:37:55 +02:00
|
|
|
end
|
2010-08-06 18:59:38 +02:00
|
|
|
end
|
2011-08-06 23:56:05 +02:00
|
|
|
|
|
|
|
require "middleman/version"
|
2011-11-08 02:58:07 +01:00
|
|
|
Middleman.load_extensions_in_path
|