Merge pull request #424 from middleman/remove_ruby_autoload

Remove usage of autoload statement in favor of require
This commit is contained in:
Thomas Reynolds 2012-05-08 16:56:53 -07:00
commit b486b5a31d
27 changed files with 2122 additions and 2048 deletions

View file

@ -3,7 +3,12 @@ libdir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
# Top-level Middleman namespace
module Middleman; end
module Middleman
# Backwards compatibility namespace
module Features; end
end
require "middleman-core/version"
require "middleman-core/util"

View file

@ -9,6 +9,8 @@ require "middleman-core/vendor/hooks-0.2.0/lib/hooks"
require "middleman-core/sitemap"
require "middleman-core/core_extensions"
# Core Middleman Class
module Middleman
class Application
@ -160,14 +162,35 @@ module Middleman
register Middleman::CoreExtensions::I18n
# Built-in Extensions
Middleman::Extensions.register(:directory_indexes) {
Middleman::Extensions::DirectoryIndexes }
Middleman::Extensions.register(:lorem) {
Middleman::Extensions::Lorem }
Middleman::Extensions.register(:automatic_image_sizes) {
Middleman::Extensions::AutomaticImageSizes }
Middleman::Extensions.register(:asset_host) {
Middleman::Extensions::AssetHost }
# 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
def initialize(&block)

View file

@ -5,13 +5,6 @@ require "thor/group"
# CLI Module
module Middleman::Cli
module Cli
autoload :Build, "middleman-core/cli/build"
autoload :Init, "middleman-core/cli/init"
autoload :Extension, "middleman-core/cli/extension"
autoload :Server, "middleman-core/cli/server"
end
# The base task from which everything else etends
class Base < Thor

View file

@ -0,0 +1,39 @@
# Rack Request
require "middleman-core/core_extensions/request"
# File Change Notifier
require "middleman-core/core_extensions/file_watcher"
# Add Builder callbacks
require "middleman-core/core_extensions/builder"
# Custom Feature API
require "middleman-core/core_extensions/extensions"
# Asset Path Pipeline
require "middleman-core/core_extensions/assets"
# Data looks at the data/ folder for YAML files and makes them available
# to dynamic requests.
require "middleman-core/core_extensions/data"
# Parse YAML from templates
require "middleman-core/core_extensions/front_matter"
# External helpers looks in the helpers/ folder for helper modules
require "middleman-core/core_extensions/external_helpers"
# DefaultHelpers are the built-in dynamic template helpers.
require "middleman-core/core_extensions/default_helpers"
# Extended version of Padrino's rendering
require "middleman-core/core_extensions/rendering"
# Pass custom options to views
require "middleman-core/core_extensions/routing"
# Catch and show exceptions at the Rack level
require "middleman-core/core_extensions/show_exceptions"
# i18n
require "middleman-core/core_extensions/i18n"

View file

@ -1,9 +1,11 @@
module Middleman
module CoreExtensions
# Base helper to manipulate asset paths
module Middleman::CoreExtensions::Assets
module Assets
# Extension registered
class << self
# @private
def registered(app)
# Disable Padrino cache buster
app.set :asset_stamp, false
@ -37,3 +39,5 @@ module Middleman::CoreExtensions::Assets
end
end
end
end
end

View file

@ -1,5 +1,8 @@
module Middleman
module CoreExtensions
# Convenience methods to allow config.rb to talk to the Builder
module Middleman::CoreExtensions::Builder
module Builder
# Extension registered
class << self
@ -10,3 +13,5 @@ module Middleman::CoreExtensions::Builder
alias :included :registered
end
end
end
end

View file

@ -1,15 +1,18 @@
# Data formats
require "yaml"
require "active_support/json"
module Middleman
module CoreExtensions
# The data extension parses YAML and JSON files in the data/ directory
# and makes them available to config.rb, templates and extensions
module Middleman::CoreExtensions::Data
module Data
# Extension registered
class << self
# @private
def registered(app)
# Data formats
require "yaml"
require "active_support/json"
app.set :data_dir, "data"
app.send :include, InstanceMethods
end
@ -173,3 +176,5 @@ module Middleman::CoreExtensions::Data
end
end
end
end
end

View file

@ -1,13 +1,15 @@
require "active_support/core_ext/integer/inflections"
require 'padrino-helpers'
module Middleman
module CoreExtensions
# Built-in helpers
module Middleman::CoreExtensions::DefaultHelpers
module DefaultHelpers
# Extension registered
class << self
# @private
def registered(app)
require "active_support/core_ext/integer/inflections"
require 'padrino-helpers'
app.helpers ::Padrino::Helpers::OutputHelpers
app.helpers ::Padrino::Helpers::TagHelpers
app.helpers ::Padrino::Helpers::AssetTagHelpers
@ -117,3 +119,5 @@ module Middleman::CoreExtensions::DefaultHelpers
end
end
end
end
end

View file

@ -28,16 +28,18 @@
# methods to use in your views. Some modify the output on-the-fly. And some
# apply computationally-intensive changes to your final build files.
# Using for version parsing
require "rubygems"
# Namespace extensions module
module Middleman::CoreExtensions::Extensions
module Middleman
module CoreExtensions
module Extensions
# Register extension
class << self
# @private
def included(app)
# Using for version parsing
require "rubygems"
# app.set :default_extensions, []
app.define_hook :after_configuration
app.define_hook :before_configuration
@ -150,3 +152,5 @@ module Middleman::CoreExtensions::Extensions
end
end
end
end
end

View file

@ -1,5 +1,7 @@
# Load helpers in helpers/
module Middleman::CoreExtensions::ExternalHelpers
module Middleman
module CoreExtensions
module ExternalHelpers
# Setup extension
class << self
@ -33,3 +35,5 @@ module Middleman::CoreExtensions::ExternalHelpers
alias :included :registered
end
end
end
end

View file

@ -1,15 +1,17 @@
require "find"
require "middleman-core/watcher"
require "set"
# API for watching file change events
module Middleman::CoreExtensions::FileWatcher
module Middleman
module CoreExtensions
module FileWatcher
# Setup extension
class << self
# Once registered
def registered(app)
require "find"
require "middleman-core/watcher"
require "set"
app.extend ClassMethods
app.send :include, InstanceMethods
@ -152,3 +154,5 @@ module Middleman::CoreExtensions::FileWatcher
end
end
end
end
end

View file

@ -5,7 +5,9 @@ require "yaml"
require "tilt"
# Frontmatter namespace
module Middleman::CoreExtensions::FrontMatter
module Middleman
module CoreExtensions
module FrontMatter
# Setup extension
class << self
@ -206,3 +208,5 @@ module Middleman::CoreExtensions::FrontMatter
end
end
end
end
end

View file

@ -1,5 +1,7 @@
# i18n Namespace
module Middleman::CoreExtensions::I18n
module Middleman
module CoreExtensions
module I18n
# Setup extension
class << self
@ -140,3 +142,5 @@ module Middleman::CoreExtensions::I18n
end
end
end
end
end

View file

@ -9,7 +9,9 @@ class Tilt::Template
end
# Rendering extension
module Middleman::CoreExtensions::Rendering
module Middleman
module CoreExtensions
module Rendering
# Setup extension
class << self
@ -365,3 +367,5 @@ module Middleman::CoreExtensions::Rendering
end
end
end
end
end

View file

@ -1,6 +1,7 @@
# Base helper to manipulate asset paths
module Middleman
module CoreExtensions
# Base helper to manipulate asset paths
module Request
# Extension registered

View file

@ -1,5 +1,7 @@
# Routing extension
module Middleman::CoreExtensions::Routing
module Middleman
module CoreExtensions
module Routing
# Setup extension
class << self
@ -86,3 +88,5 @@ module Middleman::CoreExtensions::Routing
end
end
end
end
end

View file

@ -1,14 +1,16 @@
# Require lib
require 'rack/showexceptions'
# Support rack/showexceptions during development
module Middleman::CoreExtensions::ShowExceptions
module Middleman
module CoreExtensions
module ShowExceptions
# Setup extension
class << self
# Once registered
def registered(app)
# Require lib
require 'rack/showexceptions'
# When in dev
app.configure :development do
# Include middlemare
@ -23,4 +25,7 @@ module Middleman::CoreExtensions::ShowExceptions
# TODO: Style this ourselves
class Middleware < ::Rack::ShowExceptions
end
end
end
end

View file

@ -1,71 +1,6 @@
module Middleman
# Backwards compatibility namespace
module Features
end
module CoreExtensions
# Rack Request
autoload :Request, "middleman-core/core_extensions/request"
# File Change Notifier
autoload :FileWatcher, "middleman-core/core_extensions/file_watcher"
# In-memory Sitemap
autoload :Sitemap, "middleman-core/core_extensions/sitemap"
# Add Builder callbacks
autoload :Builder, "middleman-core/core_extensions/builder"
# Custom Feature API
autoload :Extensions, "middleman-core/core_extensions/extensions"
# Asset Path Pipeline
autoload :Assets, "middleman-core/core_extensions/assets"
# Data looks at the data/ folder for YAML files and makes them available
# to dynamic requests.
autoload :Data, "middleman-core/core_extensions/data"
# Parse YAML from templates
autoload :FrontMatter, "middleman-core/core_extensions/front_matter"
# External helpers looks in the helpers/ folder for helper modules
autoload :ExternalHelpers, "middleman-core/core_extensions/external_helpers"
# DefaultHelpers are the built-in dynamic template helpers.
autoload :DefaultHelpers, "middleman-core/core_extensions/default_helpers"
# Extended version of Padrino's rendering
autoload :Rendering, "middleman-core/core_extensions/rendering"
# Pass custom options to views
autoload :Routing, "middleman-core/core_extensions/routing"
# Catch and show exceptions at the Rack level
autoload :ShowExceptions, "middleman-core/core_extensions/show_exceptions"
# i18n
autoload :I18n, "middleman-core/core_extensions/i18n"
end
module Extensions
# Provide Apache-style index.html files for directories
autoload :DirectoryIndexes, "middleman-core/extensions/directory_indexes"
# Lorem provides a handful of helpful prototyping methods to generate
# words, paragraphs, fake images, names and email addresses.
autoload :Lorem, "middleman-core/extensions/lorem"
# AutomaticImageSizes inspects the images used in your dynamic templates
# and automatically adds width and height attributes to their HTML
# elements.
autoload :AutomaticImageSizes, "middleman-core/extensions/automatic_image_sizes"
# 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-core/extensions/asset_host"
class << self
def registered

View file

@ -51,7 +51,4 @@ module Middleman::Extensions
end
end
end
# Register the extension
register :directory_indexes, DirectoryIndexes
end

View file

@ -192,7 +192,4 @@ module Middleman::Extensions
end
end
end
# Register the extension
register :lorem, Lorem
end

View file

@ -1,15 +1,14 @@
require "middleman-core/sitemap/store"
require "middleman-core/sitemap/resource"
require "middleman-core/sitemap/extensions/on_disk"
require "middleman-core/sitemap/extensions/proxies"
require "middleman-core/sitemap/extensions/ignores"
# Core Sitemap Extensions
module Middleman::Sitemap
module Middleman
autoload :Store, "middleman-core/sitemap/store"
autoload :Resource, "middleman-core/sitemap/resource"
module Extensions
autoload :OnDisk, "middleman-core/sitemap/extensions/on_disk"
autoload :Proxies, "middleman-core/sitemap/extensions/proxies"
autoload :Ignores, "middleman-core/sitemap/extensions/ignores"
autoload :Traversal, "middleman-core/sitemap/extensions/traversal"
end
module Sitemap
# Setup Extension
class << self
@ -76,3 +75,4 @@ module Middleman::Sitemap
end
end
end

View file

@ -1,4 +1,8 @@
module Middleman::Sitemap::Extensions
module Middleman
module Sitemap
module Extensions
module Ignores
@ -83,3 +87,5 @@ module Middleman::Sitemap::Extensions
end
end
end
end
end

View file

@ -1,6 +1,11 @@
require 'set'
module Middleman::Sitemap::Extensions
module Middleman
module Sitemap
module Extensions
class OnDisk
attr_accessor :sitemap
@ -75,3 +80,5 @@ module Middleman::Sitemap::Extensions
end
end
end
end
end

View file

@ -1,4 +1,8 @@
module Middleman::Sitemap::Extensions
module Middleman
module Sitemap
module Extensions
module Proxies
@ -95,5 +99,6 @@ module Middleman::Sitemap::Extensions
end
end
end
end
end
end

View file

@ -1,4 +1,9 @@
module Middleman::Sitemap::Extensions
module Middleman
module Sitemap
module Extensions
module Traversal
# This resource's parent resource
# @return [Middleman::Sitemap::Resource, nil]
@ -75,3 +80,5 @@ module Middleman::Sitemap::Extensions
end
end
end
end
end

View file

@ -1,5 +1,9 @@
require "middleman-core/sitemap/extensions/traversal"
module Middleman
# Sitemap namespace
module Middleman::Sitemap
module Sitemap
# Sitemap Resource class
class Resource
@ -146,3 +150,4 @@ module Middleman::Sitemap
end
end
end
end

View file

@ -1,8 +1,10 @@
# Used for merging results of metadata callbacks
require "active_support/core_ext/hash/deep_merge"
module Middleman
# Sitemap namespace
module Middleman::Sitemap
module Sitemap
# The Store class
#
@ -206,3 +208,4 @@ module Middleman::Sitemap
end
end
end
end