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/features.rb

121 lines
4.5 KiB
Ruby
Raw Normal View History

2011-02-18 19:25:18 -05:00
# Middleman provides an extension API which allows you to hook into the
# lifecycle of a page request, or static build, and manipulate the output.
# Internal to Middleman, these extensions are called "features," but we use
# the exact same API as is made available to the public.
#
# A Middleman extension looks like this:
#
# module MyExtension
# class << self
# def registered(app)
# # My Code
# end
# end
# end
#
# In your `config.rb`, you must load your extension (if it is not defined in
# that file) and call `activate`.
#
# require "my_extension"
# activate MyExtension
#
# This will call the `registered` method in your extension and provide you
# with the `app` parameter which is a Middleman::Server context. From here
# you can choose to respond to requests for certain paths or simply attach
2011-02-18 19:25:18 -05:00
# Rack middleware to the stack.
#
# The built-in features cover a wide range of functions. Some provide helper
# 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::Features
2011-02-18 19:25:18 -05:00
# 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-02-18 19:25:18 -05: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/features/asset_host"
2011-02-18 19:25:18 -05:00
# 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-02-18 19:25:18 -05:00
# DefaultHelpers are the built-in dynamic template helpers.
autoload :DefaultHelpers, "middleman/features/default_helpers"
2011-02-18 19:25:18 -05:00
# 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"
2011-02-18 19:25:18 -05:00
# UglyHaml enables the non-indented output format from Haml templates. Useful
# for somewhat obfuscating the output and hiding the fact that you're using Haml.
autoload :UglyHaml, "middleman/features/ugly_haml"
2011-02-18 19:25:18 -05:00
# MinifyCss uses the YUI compressor to shrink CSS files
autoload :MinifyCss, "middleman/features/minify_css"
2011-02-18 19:25:18 -05:00
# MinifyJavascript uses the YUI compressor to shrink JS files
autoload :MinifyJavascript, "middleman/features/minify_javascript"
2011-02-18 19:25:18 -05:00
# CodeRay is a syntax highlighter.
2010-09-21 21:30:17 -04:00
autoload :CodeRay, "middleman/features/code_ray"
2011-02-18 19:25:18 -05:00
# Lorem provides a handful of helpful prototyping methods to generate words,
# paragraphs, fake images, names and email addresses.
autoload :Lorem, "middleman/features/lorem"
2011-04-14 18:35:41 -04:00
# Data looks at the data/ folder for YAML files and makes them available
# to dynamic requests.
autoload :Data, "middleman/features/data"
2011-05-06 17:31:15 -04:00
# Proxy web services requests in dev mode only
# autoload :Proxy, "middleman/features/proxy"
2011-04-25 16:45:54 -04:00
# Automatically resize images for mobile devises
# autoload :TinySrc, "middleman/features/tiny_src"
2011-02-21 16:07:32 -05:00
# LiveReload will auto-reload browsers with the live reload extension installed after changes
# Currently disabled and untested.
#autoload :LiveReload, "middleman/features/live_reload"
2011-02-18 19:25:18 -05:00
# The Feature API is itself a Feature. Mind blowing!
class << self
def registered(app)
app.extend ClassMethods
end
alias :included :registered
end
module ClassMethods
# This method is available in the project's `config.rb`.
2011-02-18 19:25:18 -05:00
# It takes a underscore-separated symbol, finds the appropriate
# feature module and includes it.
#
2011-02-18 19:25:18 -05:00
# activate :lorem
#
# Alternatively, you can pass in a Middleman feature module directly.
#
# activate MyFeatureModule
def activate(feature)
feature = feature.to_s if feature.is_a? Symbol
if feature.is_a? String
feature = feature.camelize
feature = Middleman::Features.const_get(feature)
end
register feature
end
2011-02-18 19:25:18 -05:00
# Deprecated API. Please use `activate` instead.
def enable(feature_name)
$stderr.puts "Warning: Feature activation has been renamed from enable to activate"
activate(feature_name)
super(feature_name)
end
end
end