1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/lib/middleman.rb

208 lines
7 KiB
Ruby
Raw Normal View History

2011-02-11 02:14:33 -05: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:
#
#### Command-line tool:
# * **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 02:14:33 -05:00
#
#### Tons of templating languages including:
# * ERB (.erb)
# * Interpolated String (.str)
# * Sass (.sass)
# * Scss (.scss)
# * Haml (.haml)
# * Slim (.slim)
2011-02-11 02:14:33 -05: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 extensions!
2011-02-11 02:14:33 -05:00
#
#### 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
# [Email the users group]: https://convore.com/middleman/
2011-02-11 02:14:33 -05:00
# [Submit bug reports]: https://github.com/tdreyno/middleman/issues
2011-07-27 00:05:13 -04:00
# Setup our load paths
libdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
2011-02-11 02:14:33 -05:00
# Top-level Middleman object
2010-03-03 01:00:46 -05:00
module Middleman
2011-02-11 02:14:33 -05:00
# Auto-load modules on-demand
2011-11-08 01:34:02 -05:00
autoload :Base, "middleman/base"
2011-11-19 21:53:18 -05:00
autoload :Cache, "middleman/cache"
2011-11-08 01:34:02 -05:00
autoload :Builder, "middleman/builder"
autoload :CLI, "middleman/cli"
autoload :Templates, "middleman/templates"
autoload :Guard, "middleman/guard"
2011-02-11 02:14:33 -05:00
# Custom Renderers
module Renderers
autoload :Sass, "middleman/renderers/sass"
autoload :Markdown, "middleman/renderers/markdown"
2011-10-27 12:24:48 -04:00
autoload :ERb, "middleman/renderers/erb"
autoload :Liquid, "middleman/renderers/liquid"
end
module Sitemap
autoload :Store, "middleman/sitemap/store"
autoload :Page, "middleman/sitemap/page"
autoload :Template, "middleman/sitemap/template"
end
module CoreExtensions
2011-11-08 18:38:15 -05:00
# File Change Notifier
2011-11-08 01:34:02 -05:00
autoload :FileWatcher, "middleman/core_extensions/file_watcher"
2011-11-08 18:38:15 -05:00
# In-memory Sitemap
autoload :Sitemap, "middleman/core_extensions/sitemap"
2011-11-08 01:34:02 -05:00
# Add Builder callbacks
autoload :Builder, "middleman/core_extensions/builder"
# Custom Feature API
autoload :Extensions, "middleman/core_extensions/extensions"
2011-07-06 13:40:17 -04:00
# Asset Path Pipeline
autoload :Assets, "middleman/core_extensions/assets"
# 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"
# Parse YAML from templates
autoload :FrontMatter, "middleman/core_extensions/front_matter"
# Extended version of Padrino's rendering
autoload :Rendering, "middleman/core_extensions/rendering"
# Compass framework for Sass
autoload :Compass, "middleman/core_extensions/compass"
# Sprockets 2
autoload :Sprockets, "middleman/core_extensions/sprockets"
2011-07-06 13:46:06 -04:00
# Pass custom options to views
autoload :Routing, "middleman/core_extensions/routing"
end
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/extensions/relative_assets"
2011-07-10 16:55:40 -04: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.
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/extensions/cache_buster"
2011-07-10 16:55:40 -04:00
# AutomaticImageSizes inspects the images used in your dynamic templates
# and automatically adds width and height attributes to their HTML
# elements.
autoload :AutomaticImageSizes, "middleman/extensions/automatic_image_sizes"
# MinifyCss uses the YUI compressor to shrink CSS files
autoload :MinifyCss, "middleman/extensions/minify_css"
# MinifyJavascript uses the YUI compressor to shrink JS files
autoload :MinifyJavascript, "middleman/extensions/minify_javascript"
2011-07-10 16:55:40 -04:00
# Lorem provides a handful of helpful prototyping methods to generate
# words, paragraphs, fake images, names and email addresses.
autoload :Lorem, "middleman/extensions/lorem"
2011-07-13 21:45:15 -04:00
# Automatically convert filename.html files into filename/index.html
autoload :DirectoryIndexes, "middleman/extensions/directory_indexes"
2011-11-08 03:00:33 -05:00
# Organize the sitemap as a tree
autoload :SitemapTree, "middleman/extensions/sitemap_tree"
end
EXTENSION_FILE = File.join("lib", "middleman_extension.rb")
2011-11-21 00:21:19 -05:00
class << self
def load_extensions_in_path
extensions = rubygems_latest_specs.select do |spec|
spec_has_file?(spec, EXTENSION_FILE)
end
2011-08-18 20:33:45 -04:00
2011-11-21 00:21:19 -05:00
extensions.each do |spec|
require spec.name
# $stderr.puts "require: #{spec.name}"
end
2011-08-18 20:33:45 -04:00
end
2011-11-21 00:21:19 -05:00
def rubygems_latest_specs
# If newer Rubygems
if ::Gem::Specification.respond_to? :latest_specs
::Gem::Specification.latest_specs
else
::Gem.source_index.latest_specs
end
2011-08-29 14:53:11 -04:00
end
2011-11-21 00:21:19 -05:00
def spec_has_file?(spec, path)
full_path = File.join(spec.full_gem_path, path)
File.exists?(full_path)
end
2011-08-29 14:53:11 -04:00
2011-11-21 00:21:19 -05:00
def server(&block)
Class.new(Middleman::Base)
end
2011-08-09 17:37:55 -04:00
2011-11-21 00:21:19 -05:00
def start_server(options={})
opts = {
:Port => options[:port] || 4567,
:AccessLog => []
}
2011-08-09 17:37:55 -04:00
2011-11-21 00:21:19 -05:00
app_class = options[:app] ||= ::Middleman.server.new
opts[:app] = app_class
opts[:server] = 'thin'
2011-11-11 15:31:28 -05:00
2011-11-21 00:21:19 -05:00
# require "thin"
# ::Thin::Logging.silent = true if options[:debug] != "true"
2011-08-09 17:55:48 -04:00
2011-11-21 00:21:19 -05:00
server = ::Rack::Server.new(opts)
server.start
server
end
2011-08-09 17:37:55 -04:00
end
2010-08-06 12:59:38 -04:00
end
require "middleman/version"
2011-11-07 20:58:07 -05:00
Middleman.load_extensions_in_path