cleanup calls to self. throughout
This commit is contained in:
parent
1fbeedb573
commit
6de8d5dde5
22 changed files with 201 additions and 230 deletions
|
@ -8,48 +8,50 @@ require 'rubygems'
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module ProjectLocator
|
module ProjectLocator
|
||||||
def self.locate_middleman_root!(args)
|
class << self
|
||||||
cwd = Dir.pwd
|
def locate_middleman_root!(args)
|
||||||
|
cwd = Dir.pwd
|
||||||
|
|
||||||
if !in_middleman_project? && !in_middleman_project_subdirectory?
|
if !in_middleman_project? && !in_middleman_project_subdirectory?
|
||||||
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
||||||
return
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if in_middleman_project?
|
||||||
|
did_locate_middleman_project(cwd, args)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
Dir.chdir("..") do
|
||||||
|
# Recurse in a chdir block: if the search fails we want to be sure
|
||||||
|
# the application is generated in the original working directory.
|
||||||
|
locate_middleman_root!(args) unless cwd == Dir.pwd
|
||||||
|
end
|
||||||
|
rescue SystemCallError
|
||||||
|
# could not chdir, no problem just return
|
||||||
end
|
end
|
||||||
|
|
||||||
if in_middleman_project?
|
def in_middleman_project?
|
||||||
did_locate_middleman_project(cwd, args)
|
File.exists?('config.rb')
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir.chdir("..") do
|
def in_middleman_project_subdirectory?(path = Pathname.new(Dir.pwd))
|
||||||
# Recurse in a chdir block: if the search fails we want to be sure
|
File.exists?(File.join(path, 'config.rb')) || !path.root? && in_middleman_project_subdirectory?(path.parent)
|
||||||
# the application is generated in the original working directory.
|
|
||||||
locate_middleman_root!(args) unless cwd == Dir.pwd
|
|
||||||
end
|
end
|
||||||
rescue SystemCallError
|
|
||||||
# could not chdir, no problem just return
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.in_middleman_project?
|
def did_locate_middleman_project(path, args)
|
||||||
File.exists?('config.rb')
|
# Set up gems listed in the Gemfile.
|
||||||
end
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', path)
|
||||||
|
|
||||||
def self.in_middleman_project_subdirectory?(path = Pathname.new(Dir.pwd))
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||||
File.exists?(File.join(path, 'config.rb')) || !path.root? && in_middleman_project_subdirectory?(path.parent)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.did_locate_middleman_project(path, args)
|
start_cli!(args)
|
||||||
# Set up gems listed in the Gemfile.
|
end
|
||||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', path)
|
|
||||||
|
|
||||||
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
def start_cli!(args)
|
||||||
|
require 'middleman'
|
||||||
start_cli!(args)
|
Middleman::CLI.start(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start_cli!(args)
|
|
||||||
require 'middleman'
|
|
||||||
Middleman::CLI.start(args)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,7 +61,8 @@ args = ARGV.dup
|
||||||
ARG_ALIASES = {
|
ARG_ALIASES = {
|
||||||
"s" => "server",
|
"s" => "server",
|
||||||
"b" => "build",
|
"b" => "build",
|
||||||
"i" => "init"
|
"i" => "init",
|
||||||
|
"w" => "watch"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ARG_ALIASES.has_key?(args[0])
|
if ARG_ALIASES.has_key?(args[0])
|
||||||
|
|
|
@ -154,53 +154,53 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
EXTENSION_FILE = File.join("lib", "middleman_init.rb")
|
EXTENSION_FILE = File.join("lib", "middleman_init.rb")
|
||||||
def self.load_extensions_in_path
|
class << self
|
||||||
extensions = rubygems_latest_specs.select do |spec|
|
def load_extensions_in_path
|
||||||
spec_has_file?(spec, EXTENSION_FILE)
|
extensions = rubygems_latest_specs.select do |spec|
|
||||||
|
spec_has_file?(spec, EXTENSION_FILE)
|
||||||
|
end
|
||||||
|
|
||||||
|
extensions.each do |spec|
|
||||||
|
require spec.name
|
||||||
|
# $stderr.puts "require: #{spec.name}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
extensions.each do |spec|
|
def rubygems_latest_specs
|
||||||
require spec.name
|
# If newer Rubygems
|
||||||
# $stderr.puts "require: #{spec.name}"
|
if ::Gem::Specification.respond_to? :latest_specs
|
||||||
|
::Gem::Specification.latest_specs
|
||||||
|
else
|
||||||
|
::Gem.source_index.latest_specs
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.rubygems_latest_specs
|
def spec_has_file?(spec, path)
|
||||||
# If newer Rubygems
|
full_path = File.join(spec.full_gem_path, path)
|
||||||
if ::Gem::Specification.respond_to? :latest_specs
|
File.exists?(full_path)
|
||||||
::Gem::Specification.latest_specs
|
|
||||||
else
|
|
||||||
::Gem.source_index.latest_specs
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.spec_has_file?(spec, path)
|
def server(&block)
|
||||||
full_path = File.join(spec.full_gem_path, path)
|
Class.new(Middleman::Base)
|
||||||
File.exists?(full_path)
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.server(&block)
|
def start_server(options={})
|
||||||
sandbox = Class.new(Middleman::Base)
|
opts = {
|
||||||
# sandbox.class_eval(&block) if block_given?
|
:Port => options[:port] || 4567,
|
||||||
sandbox
|
:AccessLog => []
|
||||||
end
|
}
|
||||||
|
|
||||||
def self.start_server(options={})
|
app_class = options[:app] ||= ::Middleman.server.new
|
||||||
opts = {
|
opts[:app] = app_class
|
||||||
:Port => options[:port] || 4567,
|
opts[:server] = 'thin'
|
||||||
:AccessLog => []
|
|
||||||
}
|
|
||||||
|
|
||||||
app_class = options[:app] ||= ::Middleman.server.new
|
# require "thin"
|
||||||
opts[:app] = app_class
|
# ::Thin::Logging.silent = true if options[:debug] != "true"
|
||||||
opts[:server] = 'thin'
|
|
||||||
|
|
||||||
# require "thin"
|
server = ::Rack::Server.new(opts)
|
||||||
# ::Thin::Logging.silent = true if options[:debug] != "true"
|
server.start
|
||||||
|
server
|
||||||
server = ::Rack::Server.new(opts)
|
end
|
||||||
server.start
|
|
||||||
server
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
require "rack"
|
require "rack"
|
||||||
require "tilt"
|
require "tilt"
|
||||||
require "i18n"
|
|
||||||
require "middleman/vendor/hooks-0.2.0/lib/hooks"
|
require "middleman/vendor/hooks-0.2.0/lib/hooks"
|
||||||
|
|
||||||
require "active_support"
|
require "active_support"
|
||||||
|
@ -62,8 +61,6 @@ class Middleman::Base
|
||||||
@defaults ||= {}
|
@defaults ||= {}
|
||||||
@defaults[key] = value
|
@defaults[key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
def asset_stamp; false; end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(key, value=nil, &block)
|
def set(key, value=nil, &block)
|
||||||
|
@ -89,7 +86,7 @@ class Middleman::Base
|
||||||
set :images_dir, "images" # Where to look for images
|
set :images_dir, "images" # Where to look for images
|
||||||
|
|
||||||
set :build_dir, "build" # Which folder are builds output to
|
set :build_dir, "build" # Which folder are builds output to
|
||||||
set :http_prefix, nil # During build, add a prefix for absolute paths
|
set :http_prefix, "/" # During build, add a prefix for absolute paths
|
||||||
|
|
||||||
set :views, "source"
|
set :views, "source"
|
||||||
|
|
||||||
|
@ -140,9 +137,7 @@ class Middleman::Base
|
||||||
def initialize(&block)
|
def initialize(&block)
|
||||||
@current_path = nil
|
@current_path = nil
|
||||||
|
|
||||||
self.class.superclass.defaults.each do |k, v|
|
self.class.superclass.defaults.each { |k,v| set k,v }
|
||||||
set(k, v)
|
|
||||||
end
|
|
||||||
|
|
||||||
instance_exec(&block) if block_given?
|
instance_exec(&block) if block_given?
|
||||||
|
|
||||||
|
|
|
@ -31,12 +31,14 @@ module Middleman
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
include Middleman::ThorActions
|
include Middleman::ThorActions
|
||||||
|
|
||||||
def self.shared_rack
|
class << self
|
||||||
@shared_rack ||= begin
|
def shared_rack
|
||||||
mock = ::Rack::MockSession.new(SHARED_SERVER.to_rack_app)
|
@shared_rack ||= begin
|
||||||
sess = ::Rack::Test::Session.new(mock)
|
mock = ::Rack::MockSession.new(SHARED_SERVER.to_rack_app)
|
||||||
response = sess.get("__middleman__")
|
sess = ::Rack::Test::Session.new(mock)
|
||||||
sess
|
response = sess.get("__middleman__")
|
||||||
|
sess
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
module Middleman::CoreExtensions::Assets
|
module Middleman::CoreExtensions::Assets
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Disable Padrino cache buster until explicitly enabled
|
# Disable Padrino cache buster
|
||||||
# app.set :asset_stamp, false
|
app.set :asset_stamp, false
|
||||||
|
|
||||||
app.send :include, InstanceMethod
|
app.send :include, InstanceMethod
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ module Middleman::CoreExtensions::Assets
|
||||||
|
|
||||||
module InstanceMethod
|
module InstanceMethod
|
||||||
def asset_url(path, prefix="")
|
def asset_url(path, prefix="")
|
||||||
path.include?("://") ? path : File.join(self.http_prefix || "/", prefix, path)
|
path.include?("://") ? path : File.join(http_prefix, prefix, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,79 +1,59 @@
|
||||||
require "compass"
|
|
||||||
|
|
||||||
module Middleman::CoreExtensions::Compass
|
module Middleman::CoreExtensions::Compass
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
|
require "compass"
|
||||||
|
|
||||||
# Where to look for fonts
|
# Where to look for fonts
|
||||||
app.set :fonts_dir, "fonts"
|
app.set :fonts_dir, "fonts"
|
||||||
app.define_hook :compass_config
|
app.define_hook :compass_config
|
||||||
app.define_hook :after_compass_config
|
app.define_hook :after_compass_config
|
||||||
|
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
# Support a stand-alone compass config file
|
|
||||||
# Many options are overwritten by Middleman, but the config is a good
|
|
||||||
# place to add:
|
|
||||||
# * output_style
|
|
||||||
# * disable_warnings
|
|
||||||
# * sass_options
|
|
||||||
# * line_comments
|
|
||||||
# * sprite_engine
|
|
||||||
# * chunky_png_options
|
|
||||||
compass_config_file = File.join(self.root, "compass.config")
|
|
||||||
if File.exists?(compass_config_file)
|
|
||||||
::Compass.add_project_configuration(compass_config_file)
|
|
||||||
end
|
|
||||||
|
|
||||||
::Compass.configuration do |config|
|
::Compass.configuration do |config|
|
||||||
config.project_path = self.root
|
config.project_path = root
|
||||||
config.environment = :development
|
config.environment = :development
|
||||||
config.cache_path = File.join(self.root, ".sass-cache")
|
config.cache_path = File.join(root, ".sass-cache")
|
||||||
|
config.sass_dir = File.join(views, css_dir)
|
||||||
|
config.css_dir = File.join(views, css_dir)
|
||||||
|
config.javascripts_dir = File.join(views, js_dir)
|
||||||
|
config.fonts_dir = File.join(views, fonts_dir)
|
||||||
|
config.images_dir = File.join(views, images_dir)
|
||||||
|
|
||||||
views_root = File.basename(self.views)
|
config.http_images_path = if respond_to? :http_images_path
|
||||||
config.sass_dir = File.join(views_root, self.css_dir)
|
http_images_path
|
||||||
config.css_dir = File.join(views_root, self.css_dir)
|
|
||||||
config.javascripts_dir = File.join(views_root, self.js_dir)
|
|
||||||
config.fonts_dir = File.join(views_root, self.fonts_dir)
|
|
||||||
config.images_dir = File.join(views_root, self.images_dir)
|
|
||||||
|
|
||||||
config.http_images_path = if self.respond_to? :http_images_path
|
|
||||||
self.http_images_path
|
|
||||||
else
|
else
|
||||||
File.join(self.http_prefix || "/", self.images_dir)
|
File.join(http_prefix, images_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
config.http_stylesheets_path = if self.respond_to? :http_css_path
|
config.http_stylesheets_path = if respond_to? :http_css_path
|
||||||
self.http_css_path
|
http_css_path
|
||||||
else
|
else
|
||||||
File.join(self.http_prefix || "/", self.css_dir)
|
File.join(http_prefix, css_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
config.http_javascripts_path = if self.respond_to? :http_js_path
|
config.http_javascripts_path = if respond_to? :http_js_path
|
||||||
self.http_js_path
|
http_js_path
|
||||||
else
|
else
|
||||||
File.join(self.http_prefix || "/", self.js_dir)
|
File.join(http_prefix, js_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
config.http_fonts_path = if self.respond_to? :http_fonts_path
|
config.http_fonts_path = if respond_to? :http_fonts_path
|
||||||
self.http_fonts_path
|
http_fonts_path
|
||||||
else
|
else
|
||||||
File.join(self.http_prefix || "/", self.fonts_dir)
|
File.join(http_prefix, fonts_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
config.asset_cache_buster :none
|
config.asset_cache_buster :none
|
||||||
config.output_style = :nested
|
config.output_style = :nested
|
||||||
|
|
||||||
# config.add_import_path(config.sass_dir)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Required for relative paths
|
# Required for relative paths
|
||||||
configure :build do
|
configure :build do
|
||||||
::Compass.configuration do |config|
|
::Compass.configuration do |config|
|
||||||
config.environment = :production
|
config.environment = :production
|
||||||
|
config.css_dir = File.join(build_dir, css_dir)
|
||||||
build_root = File.basename(self.build_dir)
|
config.images_dir = File.join(build_dir, images_dir)
|
||||||
config.css_dir = File.join(build_root, self.css_dir)
|
config.fonts_dir = File.join(build_dir, fonts_dir)
|
||||||
config.images_dir = File.join(build_root, self.images_dir)
|
|
||||||
config.fonts_dir = File.join(build_root, self.fonts_dir)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,20 @@ module Middleman::CoreExtensions::Data
|
||||||
end
|
end
|
||||||
|
|
||||||
class DataStore
|
class DataStore
|
||||||
def self.matcher
|
class << self
|
||||||
%r{[\w-]+\.(yml|yaml|json)$}
|
def matcher
|
||||||
|
%r{[\w-]+\.(yml|yaml|json)$}
|
||||||
|
end
|
||||||
|
|
||||||
|
def data_content(name, content)
|
||||||
|
@@local_sources ||= {}
|
||||||
|
@@local_sources[name.to_s] = content
|
||||||
|
end
|
||||||
|
|
||||||
|
def data_callback(name, proc)
|
||||||
|
@@callback_sources ||= {}
|
||||||
|
@@callback_sources[name.to_s] = proc
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
|
@ -122,16 +134,6 @@ module Middleman::CoreExtensions::Data
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.data_content(name, content)
|
|
||||||
@@local_sources ||= {}
|
|
||||||
@@local_sources[name.to_s] = content
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.data_callback(name, proc)
|
|
||||||
@@callback_sources ||= {}
|
|
||||||
@@callback_sources[name.to_s] = proc
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def recursively_enhance(data)
|
def recursively_enhance(data)
|
||||||
if data.is_a? Hash
|
if data.is_a? Hash
|
||||||
|
|
|
@ -22,6 +22,10 @@ module Middleman::CoreExtensions::DefaultHelpers
|
||||||
app.helpers ::Padrino::Helpers::TranslationHelpers
|
app.helpers ::Padrino::Helpers::TranslationHelpers
|
||||||
|
|
||||||
app.helpers Helpers
|
app.helpers Helpers
|
||||||
|
|
||||||
|
app.initialized do
|
||||||
|
::I18n.load_path = Dir["#{File.join(root, 'locales', '*.yml')}"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
@ -42,15 +46,14 @@ module Middleman::CoreExtensions::DefaultHelpers
|
||||||
def auto_tag(asset_ext, separator="/", asset_dir=nil)
|
def auto_tag(asset_ext, separator="/", asset_dir=nil)
|
||||||
if asset_dir.nil?
|
if asset_dir.nil?
|
||||||
asset_dir = case asset_ext
|
asset_dir = case asset_ext
|
||||||
when :js then self.js_dir
|
when :js then js_dir
|
||||||
when :css then self.css_dir
|
when :css then css_dir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# If the basename of the request as no extension, assume we are serving a
|
# If the basename of the request as no extension, assume we are serving a
|
||||||
# directory and join index_file to the path.
|
# directory and join index_file to the path.
|
||||||
path = full_path(current_path.dup)
|
path = full_path(current_path.dup)
|
||||||
|
|
||||||
path = path.sub(%r{^/}, '')
|
path = path.sub(%r{^/}, '')
|
||||||
path = path.gsub(File.extname(path), ".#{asset_ext}")
|
path = path.gsub(File.extname(path), ".#{asset_ext}")
|
||||||
path = path.gsub("/", separator)
|
path = path.gsub("/", separator)
|
||||||
|
@ -60,7 +63,7 @@ module Middleman::CoreExtensions::DefaultHelpers
|
||||||
|
|
||||||
def page_classes
|
def page_classes
|
||||||
path = current_path.dup
|
path = current_path.dup
|
||||||
path << self.index_file if path.match(%r{/$})
|
path << index_file if path.match(%r{/$})
|
||||||
path = path.gsub(%r{^/}, '')
|
path = path.gsub(%r{^/}, '')
|
||||||
|
|
||||||
classes = []
|
classes = []
|
||||||
|
@ -74,9 +77,9 @@ module Middleman::CoreExtensions::DefaultHelpers
|
||||||
def asset_path(kind, source)
|
def asset_path(kind, source)
|
||||||
return source if source =~ /^http/
|
return source if source =~ /^http/
|
||||||
asset_folder = case kind
|
asset_folder = case kind
|
||||||
when :css then self.css_dir
|
when :css then css_dir
|
||||||
when :js then self.js_dir
|
when :js then js_dir
|
||||||
when :images then self.images_dir
|
when :images then images_dir
|
||||||
else kind.to_s
|
else kind.to_s
|
||||||
end
|
end
|
||||||
source = source.to_s.gsub(/\s/, '')
|
source = source.to_s.gsub(/\s/, '')
|
||||||
|
|
|
@ -96,7 +96,7 @@ module Middleman::CoreExtensions::Features
|
||||||
run_hook :before_configuration
|
run_hook :before_configuration
|
||||||
|
|
||||||
# Check for and evaluate local configuration
|
# Check for and evaluate local configuration
|
||||||
local_config = File.join(self.root, "config.rb")
|
local_config = File.join(root, "config.rb")
|
||||||
if File.exists? local_config
|
if File.exists? local_config
|
||||||
puts "== Reading: Local config" if logging?
|
puts "== Reading: Local config" if logging?
|
||||||
instance_eval File.read(local_config)
|
instance_eval File.read(local_config)
|
||||||
|
|
|
@ -49,8 +49,10 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
end
|
end
|
||||||
|
|
||||||
class FrontMatter
|
class FrontMatter
|
||||||
def self.matcher
|
class << self
|
||||||
%r{source/.*\.html}
|
def matcher
|
||||||
|
%r{source/.*\.html}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
|
|
|
@ -38,10 +38,11 @@ module Middleman::CoreExtensions::Sprockets
|
||||||
end
|
end
|
||||||
|
|
||||||
# add paths to js_env (vendor/assets/javascripts)
|
# add paths to js_env (vendor/assets/javascripts)
|
||||||
map "/#{self.js_dir}" do
|
map "/#{js_dir}" do
|
||||||
run js_env
|
run js_env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sass.each { |k, v| ::Sprockets::Sass.options[k] = v }
|
||||||
css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self)
|
css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self)
|
||||||
|
|
||||||
vendor_dir = File.join("vendor", "assets", "stylesheets")
|
vendor_dir = File.join("vendor", "assets", "stylesheets")
|
||||||
|
@ -58,7 +59,7 @@ module Middleman::CoreExtensions::Sprockets
|
||||||
css_env.append_path File.join(spec.full_gem_path, app_dir)
|
css_env.append_path File.join(spec.full_gem_path, app_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
map("/#{self.css_dir}") do
|
map("/#{css_dir}") do
|
||||||
run css_env
|
run css_env
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,8 +4,8 @@ module Middleman::Features::AssetHost
|
||||||
app.set :asset_host, nil
|
app.set :asset_host, nil
|
||||||
|
|
||||||
app.compass_config do |config|
|
app.compass_config do |config|
|
||||||
if self.asset_host.is_a?(Proc)
|
if asset_host.is_a?(Proc)
|
||||||
config.asset_host(&self.asset_host)
|
config.asset_host(&asset_host)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,10 +20,10 @@ module Middleman::Features::AssetHost
|
||||||
|
|
||||||
valid_extensions = %w(.png .gif .jpg .jpeg .js .css)
|
valid_extensions = %w(.png .gif .jpg .jpeg .js .css)
|
||||||
|
|
||||||
asset_prefix = if self.asset_host.is_a?(Proc)
|
asset_prefix = if asset_host.is_a?(Proc)
|
||||||
self.asset_host.call(original_output)
|
asset_host.call(original_output)
|
||||||
elsif self.asset_host.is_a?(String)
|
elsif asset_host.is_a?(String)
|
||||||
self.asset_host
|
asset_host
|
||||||
end
|
end
|
||||||
|
|
||||||
File.join(asset_prefix, original_output)
|
File.join(asset_prefix, original_output)
|
||||||
|
|
|
@ -12,12 +12,12 @@ module Middleman::Features::AutomaticImageSizes
|
||||||
def image_tag(path, params={})
|
def image_tag(path, params={})
|
||||||
if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://")
|
if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://")
|
||||||
params[:alt] ||= ""
|
params[:alt] ||= ""
|
||||||
http_prefix = self.http_images_path rescue self.images_dir
|
http_prefix = http_images_path rescue images_dir
|
||||||
|
|
||||||
begin
|
begin
|
||||||
real_path = File.join(self.views, self.images_dir, path)
|
real_path = File.join(views, images_dir, path)
|
||||||
full_path = File.expand_path(real_path, self.root)
|
full_path = File.expand_path(real_path, root)
|
||||||
http_prefix = self.http_images_path rescue self.images_dir
|
http_prefix = http_images_path rescue images_dir
|
||||||
if File.exists? full_path
|
if File.exists? full_path
|
||||||
dimensions = ::FastImage.size(full_path, :raise_on_failure => true)
|
dimensions = ::FastImage.size(full_path, :raise_on_failure => true)
|
||||||
params[:width] = dimensions[0]
|
params[:width] = dimensions[0]
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Middleman::Features::CacheBuster
|
||||||
app.compass_config do |config|
|
app.compass_config do |config|
|
||||||
config.asset_cache_buster do |path, real_path|
|
config.asset_cache_buster do |path, real_path|
|
||||||
real_path = real_path.path if real_path.is_a? File
|
real_path = real_path.path if real_path.is_a? File
|
||||||
real_path = real_path.gsub(File.join(self.root, self.build_dir), self.views)
|
real_path = real_path.gsub(File.join(root, build_dir), views)
|
||||||
if File.readable?(real_path)
|
if File.readable?(real_path)
|
||||||
File.mtime(real_path).strftime("%s")
|
File.mtime(real_path).strftime("%s")
|
||||||
else
|
else
|
||||||
|
@ -26,15 +26,15 @@ module Middleman::Features::CacheBuster
|
||||||
http_path
|
http_path
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
prefix = self.images_dir if prefix == self.http_images_path
|
prefix = images_dir if prefix == http_images_path
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
|
|
||||||
real_path_static = File.join(prefix, path)
|
real_path_static = File.join(prefix, path)
|
||||||
|
|
||||||
if self.build?
|
if build?
|
||||||
real_path_dynamic = File.join(self.build_dir, prefix, path)
|
real_path_dynamic = File.join(build_dir, prefix, path)
|
||||||
real_path_dynamic = File.expand_path(real_path_dynamic, self.root)
|
real_path_dynamic = File.expand_path(real_path_dynamic, root)
|
||||||
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
||||||
elsif sitemap.exists?(real_path_static)
|
elsif sitemap.exists?(real_path_static)
|
||||||
page = sitemap.page(real_path_static)
|
page = sitemap.page(real_path_static)
|
||||||
|
|
|
@ -4,10 +4,10 @@ module Middleman::Features::DirectoryIndexes
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
app.before do
|
app.before do
|
||||||
prefix = @original_path.sub(/\/$/, "")
|
prefix = @original_path.sub(/\/$/, "")
|
||||||
indexed_path = prefix + "/" + self.index_file
|
indexed_path = prefix + "/" + index_file
|
||||||
|
|
||||||
extensioned_path = prefix + File.extname(self.index_file)
|
extensioned_path = prefix + File.extname(index_file)
|
||||||
is_ignored = self.ignored_directory_indexes.include?(extensioned_path)
|
is_ignored = ignored_directory_indexes.include?(extensioned_path)
|
||||||
|
|
||||||
if !sitemap.exists?(indexed_path) && !is_ignored
|
if !sitemap.exists?(indexed_path) && !is_ignored
|
||||||
parts = @original_path.split("/")
|
parts = @original_path.split("/")
|
||||||
|
@ -22,12 +22,12 @@ module Middleman::Features::DirectoryIndexes
|
||||||
end
|
end
|
||||||
|
|
||||||
app.build_reroute do |destination, request_path|
|
app.build_reroute do |destination, request_path|
|
||||||
index_ext = File.extname(self.index_file)
|
index_ext = File.extname(index_file)
|
||||||
new_index_path = "/#{self.index_file}"
|
new_index_path = "/#{index_file}"
|
||||||
|
|
||||||
indexed_path = request_path.sub(/\/$/, "") + index_ext
|
indexed_path = request_path.sub(/\/$/, "") + index_ext
|
||||||
|
|
||||||
if self.ignored_directory_indexes.include?(request_path)
|
if ignored_directory_indexes.include?(request_path)
|
||||||
false
|
false
|
||||||
elsif request_path =~ /#{new_index_path}$/
|
elsif request_path =~ /#{new_index_path}$/
|
||||||
false
|
false
|
||||||
|
|
|
@ -13,7 +13,7 @@ module Middleman::Features::RelativeAssets
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
def asset_url(path, prefix="")
|
def asset_url(path, prefix="")
|
||||||
begin
|
begin
|
||||||
prefix = self.images_dir if prefix == self.http_images_path
|
prefix = images_dir if prefix == http_images_path
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ module Middleman::Features::RelativeAssets
|
||||||
else
|
else
|
||||||
path = File.join(prefix, path) if prefix.length > 0
|
path = File.join(prefix, path) if prefix.length > 0
|
||||||
request_path = @request_path.dup
|
request_path = @request_path.dup
|
||||||
request_path << self.index_file if path.match(%r{/$})
|
request_path << index_file if path.match(%r{/$})
|
||||||
request_path.gsub!(%r{^/}, '')
|
request_path.gsub!(%r{^/}, '')
|
||||||
parts = request_path.split('/')
|
parts = request_path.split('/')
|
||||||
|
|
||||||
|
|
|
@ -8,24 +8,26 @@ end
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Guard
|
module Guard
|
||||||
def self.add_guard(&block)
|
class << self
|
||||||
# Deprecation Warning
|
def add_guard(&block)
|
||||||
puts "== Middleman::Guard.add_guard has been removed. Update your extensions to versions which support this change."
|
# Deprecation Warning
|
||||||
end
|
puts "== Middleman::Guard.add_guard has been removed. Update your extensions to versions which support this change."
|
||||||
|
|
||||||
def self.start(options={})
|
|
||||||
options_hash = ""
|
|
||||||
options.each do |k,v|
|
|
||||||
options_hash << ", :#{k} => '#{v}'"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
guardfile_contents = %Q{
|
def start(options={})
|
||||||
guard 'middleman'#{options_hash} do
|
options_hash = ""
|
||||||
watch(%r{(.*)})
|
options.each do |k,v|
|
||||||
|
options_hash << ", :#{k} => '#{v}'"
|
||||||
end
|
end
|
||||||
}
|
|
||||||
|
|
||||||
::Guard.start({ :guardfile_contents => guardfile_contents })
|
guardfile_contents = %Q{
|
||||||
|
guard 'middleman'#{options_hash} do
|
||||||
|
watch(%r{(.*)})
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
::Guard.start({ :guardfile_contents => guardfile_contents })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
require "tilt"
|
|
||||||
|
|
||||||
module Middleman::Renderers::ERb
|
module Middleman::Renderers::ERb
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.send :include, InstanceMethods
|
|
||||||
|
|
||||||
app.set :erb_engine, :erb
|
app.set :erb_engine, :erb
|
||||||
app.set :erb_engine_prefix, ::Tilt
|
app.set :erb_engine_prefix, ::Tilt
|
||||||
|
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
if erb_engine.is_a? Symbol
|
if erb_engine.is_a? Symbol
|
||||||
erb_engine = erb_tilt_template_from_symbol(erb_engine)
|
engine = engine.to_s
|
||||||
|
engine = engine == "erb" ? "ERB" : engine.camelize
|
||||||
|
erb_engine = erb_engine_prefix.const_get("#{engine}Template")
|
||||||
end
|
end
|
||||||
|
|
||||||
::Tilt.prefer(erb_engine)
|
::Tilt.prefer(erb_engine)
|
||||||
|
@ -18,12 +16,4 @@ module Middleman::Renderers::ERb
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
def erb_tilt_template_from_symbol(engine)
|
|
||||||
engine = engine.to_s
|
|
||||||
engine = engine == "erb" ? "ERB" : engine.camelize
|
|
||||||
erb_engine_prefix.const_get("#{engine}Template")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
|
@ -2,17 +2,16 @@ module Middleman::Renderers::Liquid
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Liquid is not included in the default gems,
|
# Liquid is not included in the default gems,
|
||||||
# but we'll support it if necessary.
|
# but we'll support it if available.
|
||||||
begin
|
begin
|
||||||
require "liquid"
|
require "liquid"
|
||||||
|
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
Liquid::Template.file_system = Liquid::LocalFileSystem.new(self.source_dir)
|
Liquid::Template.file_system = Liquid::LocalFileSystem.new(source_dir)
|
||||||
|
|
||||||
provides_metadata %r{\.liquid$} do |path|
|
provides_metadata %r{\.liquid$} do |path|
|
||||||
{ :locals => { :data => data.to_h } }
|
{ :locals => { :data => data.to_h } }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
module Middleman::Renderers::Markdown
|
module Middleman::Renderers::Markdown
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.send :include, InstanceMethods
|
app.set :markdown_engine, nil
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require "maruku"
|
require "maruku"
|
||||||
app.set :markdown_engine, :maruku
|
app.set :markdown_engine, :maruku
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
app.set :markdown_engine, nil
|
begin
|
||||||
|
require "rdiscount"
|
||||||
|
app.set :markdown_engine, :rdiscount
|
||||||
|
rescue LoadError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
app.set :markdown_engine_prefix, ::Tilt
|
app.set :markdown_engine_prefix, ::Tilt
|
||||||
|
@ -15,7 +19,9 @@ module Middleman::Renderers::Markdown
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
unless markdown_engine.nil?
|
unless markdown_engine.nil?
|
||||||
if markdown_engine.is_a? Symbol
|
if markdown_engine.is_a? Symbol
|
||||||
markdown_engine = markdown_tilt_template_from_symbol(markdown_engine)
|
engine = engine.to_s
|
||||||
|
engine = engine == "rdiscount" ? "RDiscount" : engine.camelize
|
||||||
|
markdown_engine = markdown_engine_prefix.const_get("#{engine}Template")
|
||||||
end
|
end
|
||||||
|
|
||||||
::Tilt.prefer(markdown_engine)
|
::Tilt.prefer(markdown_engine)
|
||||||
|
@ -24,12 +30,4 @@ module Middleman::Renderers::Markdown
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
def markdown_tilt_template_from_symbol(engine)
|
|
||||||
engine = engine.to_s
|
|
||||||
engine = engine == "rdiscount" ? "RDiscount" : engine.camelize
|
|
||||||
markdown_engine_prefix.const_get("#{engine}Template")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
|
@ -12,8 +12,6 @@ module Middleman::Renderers::Sass
|
||||||
end
|
end
|
||||||
|
|
||||||
class SassPlusCSSFilenameTemplate < ::Sprockets::Sass::SassTemplate
|
class SassPlusCSSFilenameTemplate < ::Sprockets::Sass::SassTemplate
|
||||||
self.default_mime_type = "text/css"
|
|
||||||
|
|
||||||
# Add exception messaging
|
# Add exception messaging
|
||||||
def evaluate(context, locals, &block)
|
def evaluate(context, locals, &block)
|
||||||
begin
|
begin
|
||||||
|
@ -35,9 +33,7 @@ module Middleman::Renderers::Sass
|
||||||
parts.pop
|
parts.pop
|
||||||
css_filename = File.join(location_of_sass_file, @context.css_dir, parts.join("."))
|
css_filename = File.join(location_of_sass_file, @context.css_dir, parts.join("."))
|
||||||
|
|
||||||
super.merge(
|
super.merge(:css_filename => css_filename)
|
||||||
:css_filename => css_filename
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
::Sprockets.register_engine ".sass", SassPlusCSSFilenameTemplate
|
::Sprockets.register_engine ".sass", SassPlusCSSFilenameTemplate
|
||||||
|
@ -45,8 +41,6 @@ module Middleman::Renderers::Sass
|
||||||
::Tilt.prefer(SassPlusCSSFilenameTemplate)
|
::Tilt.prefer(SassPlusCSSFilenameTemplate)
|
||||||
|
|
||||||
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
||||||
self.default_mime_type = "text/css"
|
|
||||||
|
|
||||||
# Define the expected syntax for the template
|
# Define the expected syntax for the template
|
||||||
def syntax
|
def syntax
|
||||||
:scss
|
:scss
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
VERSION = "3.0.0.alpha.2"
|
VERSION = "3.0.0.alpha.3"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue