From b19e8bc185ad39671fcf8b7786011b69fe7ad5e2 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sun, 19 May 2013 13:23:49 -0700 Subject: [PATCH] reorg some of the more stuff --- .../lib/middleman-core/application.rb | 17 ++- .../lib/middleman-core/core_extensions.rb | 67 ++++++++++++ .../core_extensions/extensions.rb | 9 ++ .../lib/middleman-core/extensions.rb | 4 + .../lib/middleman-core/templates.rb | 5 +- middleman-core/lib/middleman-more.rb | 103 +----------------- .../middleman-more/core_extensions/compass.rb | 6 +- 7 files changed, 104 insertions(+), 107 deletions(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 5dd3058b..9f0ac3b5 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -1,6 +1,9 @@ # Using Tilt for templating require "tilt" +# i18n Built-in +require "i18n" + # Use ActiveSupport JSON require "active_support/json" require "active_support/core_ext/integer/inflections" @@ -11,8 +14,8 @@ require "middleman-core/vendor/hooks-0.2.0/lib/hooks" require "middleman-core/sitemap" -require "middleman-core/core_extensions" require "middleman-core/configuration" +require "middleman-core/core_extensions" # Core Middleman Class module Middleman @@ -220,3 +223,15 @@ module Middleman end end + +if defined?(Middleman::CoreExtensions::DefaultHelpers) + Middleman::CoreExtensions::DefaultHelpers.activate +end + +Middleman::CoreExtensions::Internationalization.register(:i18n) + +if defined?(Middleman::CoreExtensions::Compass) + Middleman::CoreExtensions::Compass.activate +end + +Middleman::Extensions::Lorem.activate diff --git a/middleman-core/lib/middleman-core/core_extensions.rb b/middleman-core/lib/middleman-core/core_extensions.rb index ff17629b..6fd7435e 100644 --- a/middleman-core/lib/middleman-core/core_extensions.rb +++ b/middleman-core/lib/middleman-core/core_extensions.rb @@ -25,3 +25,70 @@ require "middleman-core/core_extensions/routing" # Catch and show exceptions at the Rack level require "middleman-core/core_extensions/show_exceptions" + +begin + # Setup default helpers + require "middleman-more/core_extensions/default_helpers" +rescue LoadError + $stderr.puts "Default helpers not installed: #{$!}" +end + +require "middleman-more/core_extensions/i18n" + +# Compass framework +begin + require "middleman-more/core_extensions/compass" +rescue LoadError + $stderr.puts "Compass not installed: #{$!}" +end + +### +# Setup Optional Extensions +### + +# CacheBuster adds a query string to assets in dynamic templates to +# avoid browser caches failing to update to your new content. +require "middleman-more/extensions/cache_buster" +Middleman::Extensions::CacheBuster.register + +# RelativeAssets allow any asset path in dynamic templates to be either +# relative to the root of the project or use an absolute URL. +require "middleman-more/extensions/relative_assets" +Middleman::Extensions::RelativeAssets.register + +# 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. +require "middleman-more/extensions/asset_host" +Middleman::Extensions::AssetHost.register + +# MinifyCss compresses CSS +require "middleman-more/extensions/minify_css" +Middleman::Extensions::MinifyCss.register + +# MinifyJavascript compresses JS +require "middleman-more/extensions/minify_javascript" +Middleman::Extensions::MinifyJavascript.register + +# GZIP assets and pages during build +require "middleman-more/extensions/gzip" +Middleman::Extensions::Gzip.register + +# AssetHash appends a hash of the file contents to the assets filename +# to avoid browser caches failing to update to your new content. +require "middleman-more/extensions/asset_hash" +Middleman::Extensions::AssetHash.register + +# Provide Apache-style index.html files for directories +require "middleman-more/extensions/directory_indexes" +Middleman::Extensions::DirectoryIndexes.register + +# Lorem provides a handful of helpful prototyping methods to generate +# words, paragraphs, fake images, names and email addresses. +require "middleman-more/extensions/lorem" + +# AutomaticImageSizes inspects the images used in your dynamic templates +# and automatically adds width and height attributes to their HTML +# elements. +require "middleman-more/extensions/automatic_image_sizes" +Middleman::Extensions::AutomaticImageSizes.register \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/core_extensions/extensions.rb b/middleman-core/lib/middleman-core/core_extensions/extensions.rb index 0401fed4..7b541383 100644 --- a/middleman-core/lib/middleman-core/core_extensions/extensions.rb +++ b/middleman-core/lib/middleman-core/core_extensions/extensions.rb @@ -158,6 +158,15 @@ module Middleman run_hook :initialized + # This is for making the tests work - since the tests + # don't completely reload middleman, I18n.load_path can get + # polluted with paths from other test app directories that don't + # exist anymore. + if ENV["TEST"] + ::I18n.load_path.delete_if {|path| path =~ %r{tmp/aruba}} + ::I18n.reload! + end + run_hook :after_configuration logger.debug "Loaded extensions:" diff --git a/middleman-core/lib/middleman-core/extensions.rb b/middleman-core/lib/middleman-core/extensions.rb index 1347f228..32571b8c 100644 --- a/middleman-core/lib/middleman-core/extensions.rb +++ b/middleman-core/lib/middleman-core/extensions.rb @@ -127,6 +127,10 @@ module Middleman def register(n=self.extension_name) ::Middleman::Extensions.register(n, self) end + + def activate + new(::Middleman::Application) + end end attr_accessor :app, :options diff --git a/middleman-core/lib/middleman-core/templates.rb b/middleman-core/lib/middleman-core/templates.rb index 8aee9fd2..336b81e0 100644 --- a/middleman-core/lib/middleman-core/templates.rb +++ b/middleman-core/lib/middleman-core/templates.rb @@ -86,5 +86,8 @@ require "middleman-core/templates/html5" # HTML5 Mobile template require "middleman-core/templates/mobile" +# SMACSS templates +require "middleman-more/templates/smacss" + # Local templates -require "middleman-core/templates/local" +require "middleman-core/templates/local" \ No newline at end of file diff --git a/middleman-core/lib/middleman-more.rb b/middleman-core/lib/middleman-more.rb index cfb24c57..af18c46f 100644 --- a/middleman-core/lib/middleman-more.rb +++ b/middleman-core/lib/middleman-more.rb @@ -1,102 +1 @@ -module Middleman - module More - - # Setup extension - class << self - - # Once registered - def registered(app, options={}) - ### - # Setup Core Extensions - ### - - require "middleman-core/templates" - require "middleman-more/templates/smacss" - - begin - # Setup default helpers - require "middleman-more/core_extensions/default_helpers" - Middleman::CoreExtensions::DefaultHelpers.new(app) - rescue LoadError - $stderr.puts "Default helpers not installed: #{$!}" - end - - require "i18n" - app.after_configuration do - # This is for making the tests work - since the tests - # don't completely reload middleman, I18n.load_path can get - # polluted with paths from other test app directories that don't - # exist anymore. - ::I18n.load_path.delete_if {|path| path =~ %r{tmp/aruba}} - ::I18n.reload! - end if ENV["TEST"] - - require "middleman-more/core_extensions/i18n" - Middleman::CoreExtensions::Internationalization.register(:i18n) - - # Compass framework - begin - require "compass" - require "middleman-more/core_extensions/compass" - Middleman::CoreExtensions::Compass.new(app) - rescue LoadError - $stderr.puts "Compass not installed: #{$!}" - end - - ### - # Setup Optional Extensions - ### - - # CacheBuster adds a query string to assets in dynamic templates to - # avoid browser caches failing to update to your new content. - require "middleman-more/extensions/cache_buster" - Middleman::Extensions::CacheBuster.register - - # RelativeAssets allow any asset path in dynamic templates to be either - # relative to the root of the project or use an absolute URL. - require "middleman-more/extensions/relative_assets" - Middleman::Extensions::RelativeAssets.register - - # 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. - require "middleman-more/extensions/asset_host" - Middleman::Extensions::AssetHost.register - - # MinifyCss compresses CSS - require "middleman-more/extensions/minify_css" - Middleman::Extensions::MinifyCss.register - - # MinifyJavascript compresses JS - require "middleman-more/extensions/minify_javascript" - Middleman::Extensions::MinifyJavascript.register - - # GZIP assets and pages during build - require "middleman-more/extensions/gzip" - Middleman::Extensions::Gzip.register - - # AssetHash appends a hash of the file contents to the assets filename - # to avoid browser caches failing to update to your new content. - require "middleman-more/extensions/asset_hash" - Middleman::Extensions::AssetHash.register - - # Provide Apache-style index.html files for directories - require "middleman-more/extensions/directory_indexes" - Middleman::Extensions::DirectoryIndexes.register - - # Lorem provides a handful of helpful prototyping methods to generate - # words, paragraphs, fake images, names and email addresses. - require "middleman-more/extensions/lorem" - Middleman::Extensions::Lorem.new(app) - - # AutomaticImageSizes inspects the images used in your dynamic templates - # and automatically adds width and height attributes to their HTML - # elements. - require "middleman-more/extensions/automatic_image_sizes" - Middleman::Extensions::AutomaticImageSizes.register - end - end - end -end - -Middleman::Application.register Middleman::More +# Stub for backwards-compat \ No newline at end of file diff --git a/middleman-core/lib/middleman-more/core_extensions/compass.rb b/middleman-core/lib/middleman-more/core_extensions/compass.rb index 5798c6f0..7b34788d 100644 --- a/middleman-core/lib/middleman-more/core_extensions/compass.rb +++ b/middleman-core/lib/middleman-more/core_extensions/compass.rb @@ -1,11 +1,11 @@ +require "middleman-core/renderers/sass" +require "compass" + class Middleman::CoreExtensions::Compass < ::Middleman::Extension def initialize(app, options_hash={}, &block) super - # Require the library - require "compass" - # Hooks to manually update the compass config after we're # done with it app.define_hook :compass_config