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) $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
# Top-level Middleman namespace # Top-level Middleman namespace
module Middleman; end module Middleman
# Backwards compatibility namespace
module Features; end
end
require "middleman-core/version" require "middleman-core/version"
require "middleman-core/util" 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/sitemap"
require "middleman-core/core_extensions"
# Core Middleman Class # Core Middleman Class
module Middleman module Middleman
class Application class Application
@ -160,14 +162,35 @@ module Middleman
register Middleman::CoreExtensions::I18n register Middleman::CoreExtensions::I18n
# Built-in Extensions # Built-in Extensions
Middleman::Extensions.register(:directory_indexes) {
Middleman::Extensions::DirectoryIndexes } # Provide Apache-style index.html files for directories
Middleman::Extensions.register(:lorem) { Middleman::Extensions.register(:directory_indexes) do
Middleman::Extensions::Lorem } require "middleman-core/extensions/directory_indexes"
Middleman::Extensions.register(:automatic_image_sizes) { Middleman::Extensions::DirectoryIndexes
Middleman::Extensions::AutomaticImageSizes } end
Middleman::Extensions.register(:asset_host) {
Middleman::Extensions::AssetHost } # 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 # Initialize the Middleman project
def initialize(&block) def initialize(&block)

View file

@ -5,13 +5,6 @@ require "thor/group"
# CLI Module # CLI Module
module Middleman::Cli 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 # The base task from which everything else etends
class Base < Thor 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 @@
# Base helper to manipulate asset paths module Middleman
module Middleman::CoreExtensions::Assets module CoreExtensions
# Base helper to manipulate asset paths
module Assets
# Extension registered # Extension registered
class << self class << self
# @private
def registered(app) def registered(app)
# Disable Padrino cache buster # Disable Padrino cache buster
app.set :asset_stamp, false app.set :asset_stamp, false
@ -36,4 +38,6 @@ module Middleman::CoreExtensions::Assets
end end
end end
end end
end
end
end end

View file

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

View file

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

View file

@ -1,13 +1,15 @@
require "active_support/core_ext/integer/inflections" module Middleman
require 'padrino-helpers' module CoreExtensions
# Built-in helpers
# Built-in helpers module DefaultHelpers
module Middleman::CoreExtensions::DefaultHelpers
# Extension registered # Extension registered
class << self class << self
# @private # @private
def registered(app) def registered(app)
require "active_support/core_ext/integer/inflections"
require 'padrino-helpers'
app.helpers ::Padrino::Helpers::OutputHelpers app.helpers ::Padrino::Helpers::OutputHelpers
app.helpers ::Padrino::Helpers::TagHelpers app.helpers ::Padrino::Helpers::TagHelpers
app.helpers ::Padrino::Helpers::AssetTagHelpers app.helpers ::Padrino::Helpers::AssetTagHelpers
@ -116,4 +118,6 @@ module Middleman::CoreExtensions::DefaultHelpers
super(*args, &block) super(*args, &block)
end end
end 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 # methods to use in your views. Some modify the output on-the-fly. And some
# apply computationally-intensive changes to your final build files. # apply computationally-intensive changes to your final build files.
# Using for version parsing
require "rubygems"
# Namespace extensions module # Namespace extensions module
module Middleman::CoreExtensions::Extensions module Middleman
module CoreExtensions
module Extensions
# Register extension # Register extension
class << self class << self
# @private # @private
def included(app) def included(app)
# Using for version parsing
require "rubygems"
# app.set :default_extensions, [] # app.set :default_extensions, []
app.define_hook :after_configuration app.define_hook :after_configuration
app.define_hook :before_configuration app.define_hook :before_configuration
@ -149,4 +151,6 @@ module Middleman::CoreExtensions::Extensions
end end
end end
end end
end
end
end end

View file

@ -1,5 +1,7 @@
# Load helpers in helpers/ # Load helpers in helpers/
module Middleman::CoreExtensions::ExternalHelpers module Middleman
module CoreExtensions
module ExternalHelpers
# Setup extension # Setup extension
class << self class << self
@ -32,4 +34,6 @@ module Middleman::CoreExtensions::ExternalHelpers
end end
alias :included :registered alias :included :registered
end end
end
end
end end

View file

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

View file

@ -5,7 +5,9 @@ require "yaml"
require "tilt" require "tilt"
# Frontmatter namespace # Frontmatter namespace
module Middleman::CoreExtensions::FrontMatter module Middleman
module CoreExtensions
module FrontMatter
# Setup extension # Setup extension
class << self class << self
@ -205,4 +207,6 @@ module Middleman::CoreExtensions::FrontMatter
[data, content] [data, content]
end end
end end
end
end
end end

View file

@ -1,5 +1,7 @@
# i18n Namespace # i18n Namespace
module Middleman::CoreExtensions::I18n module Middleman
module CoreExtensions
module I18n
# Setup extension # Setup extension
class << self class << self
@ -139,4 +141,6 @@ module Middleman::CoreExtensions::I18n
end end
end end
end end
end
end
end end

View file

@ -9,7 +9,9 @@ class Tilt::Template
end end
# Rendering extension # Rendering extension
module Middleman::CoreExtensions::Rendering module Middleman
module CoreExtensions
module Rendering
# Setup extension # Setup extension
class << self class << self
@ -364,4 +366,6 @@ module Middleman::CoreExtensions::Rendering
end end
end end
end end
end
end
end end

View file

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

View file

@ -1,5 +1,7 @@
# Routing extension # Routing extension
module Middleman::CoreExtensions::Routing module Middleman
module CoreExtensions
module Routing
# Setup extension # Setup extension
class << self class << self
@ -85,4 +87,6 @@ module Middleman::CoreExtensions::Routing
end end
end end
end end
end
end
end end

View file

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

View file

@ -1,71 +1,6 @@
module Middleman 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 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 class << self
def registered def registered

View file

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

View file

@ -192,7 +192,4 @@ module Middleman::Extensions
end end
end end
end end
# Register the extension
register :lorem, Lorem
end 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 # Core Sitemap Extensions
module Middleman::Sitemap module Middleman
autoload :Store, "middleman-core/sitemap/store" module Sitemap
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
# Setup Extension # Setup Extension
class << self class << self
@ -75,4 +74,5 @@ module Middleman::Sitemap
end end
end end
end
end end

View file

@ -1,4 +1,8 @@
module Middleman::Sitemap::Extensions module Middleman
module Sitemap
module Extensions
module Ignores module Ignores
@ -82,4 +86,6 @@ module Middleman::Sitemap::Extensions
end end
end end
end end
end
end
end end

View file

@ -1,6 +1,11 @@
require 'set' require 'set'
module Middleman::Sitemap::Extensions module Middleman
module Sitemap
module Extensions
class OnDisk class OnDisk
attr_accessor :sitemap attr_accessor :sitemap
@ -74,4 +79,6 @@ module Middleman::Sitemap::Extensions
end end
end end
end end
end
end
end end

View file

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

View file

@ -1,4 +1,9 @@
module Middleman::Sitemap::Extensions module Middleman
module Sitemap
module Extensions
module Traversal module Traversal
# This resource's parent resource # This resource's parent resource
# @return [Middleman::Sitemap::Resource, nil] # @return [Middleman::Sitemap::Resource, nil]
@ -74,4 +79,6 @@ module Middleman::Sitemap::Extensions
path.sub(ext, '/').sub(/\/$/, "") + "/" path.sub(ext, '/').sub(/\/$/, "") + "/"
end end
end end
end
end
end end

View file

@ -1,5 +1,9 @@
# Sitemap namespace require "middleman-core/sitemap/extensions/traversal"
module Middleman::Sitemap
module Middleman
# Sitemap namespace
module Sitemap
# Sitemap Resource class # Sitemap Resource class
class Resource class Resource
@ -145,4 +149,5 @@ module Middleman::Sitemap
'/' + destination_path.sub(/#{Regexp.escape(app.index_file)}$/, '') '/' + destination_path.sub(/#{Regexp.escape(app.index_file)}$/, '')
end end
end end
end
end end

View file

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