cleanup calls to self. throughout

This commit is contained in:
Thomas Reynolds 2011-11-20 21:21:19 -08:00
parent 1fbeedb573
commit 6de8d5dde5
22 changed files with 201 additions and 230 deletions

View file

@ -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 end
if in_middleman_project? if in_middleman_project?
did_locate_middleman_project(cwd, args) did_locate_middleman_project(cwd, args)
return return
end end
Dir.chdir("..") do Dir.chdir("..") do
# Recurse in a chdir block: if the search fails we want to be sure # Recurse in a chdir block: if the search fails we want to be sure
# the application is generated in the original working directory. # the application is generated in the original working directory.
locate_middleman_root!(args) unless cwd == Dir.pwd locate_middleman_root!(args) unless cwd == Dir.pwd
end
rescue SystemCallError
# could not chdir, no problem just return
end end
rescue SystemCallError
# could not chdir, no problem just return
end
def self.in_middleman_project? def in_middleman_project?
File.exists?('config.rb') File.exists?('config.rb')
end end
def self.in_middleman_project_subdirectory?(path = Pathname.new(Dir.pwd)) def in_middleman_project_subdirectory?(path = Pathname.new(Dir.pwd))
File.exists?(File.join(path, 'config.rb')) || !path.root? && in_middleman_project_subdirectory?(path.parent) File.exists?(File.join(path, 'config.rb')) || !path.root? && in_middleman_project_subdirectory?(path.parent)
end end
def self.did_locate_middleman_project(path, args) def did_locate_middleman_project(path, args)
# Set up gems listed in the Gemfile. # Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', path) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', path)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
start_cli!(args) start_cli!(args)
end end
def self.start_cli!(args) def start_cli!(args)
require 'middleman' require 'middleman'
Middleman::CLI.start(args) Middleman::CLI.start(args)
end
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])

View file

@ -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|
end spec_has_file?(spec, EXTENSION_FILE)
end
extensions.each do |spec| extensions.each do |spec|
require spec.name require spec.name
# $stderr.puts "require: #{spec.name}" # $stderr.puts "require: #{spec.name}"
end
end end
end
def self.rubygems_latest_specs def rubygems_latest_specs
# If newer Rubygems # If newer Rubygems
if ::Gem::Specification.respond_to? :latest_specs if ::Gem::Specification.respond_to? :latest_specs
::Gem::Specification.latest_specs ::Gem::Specification.latest_specs
else else
::Gem.source_index.latest_specs ::Gem.source_index.latest_specs
end
end end
end
def self.spec_has_file?(spec, path) def spec_has_file?(spec, path)
full_path = File.join(spec.full_gem_path, path) full_path = File.join(spec.full_gem_path, path)
File.exists?(full_path) File.exists?(full_path)
end end
def self.server(&block) def server(&block)
sandbox = Class.new(Middleman::Base) Class.new(Middleman::Base)
# sandbox.class_eval(&block) if block_given? end
sandbox
end
def self.start_server(options={}) def start_server(options={})
opts = { opts = {
:Port => options[:port] || 4567, :Port => options[:port] || 4567,
:AccessLog => [] :AccessLog => []
} }
app_class = options[:app] ||= ::Middleman.server.new app_class = options[:app] ||= ::Middleman.server.new
opts[:app] = app_class opts[:app] = app_class
opts[:server] = 'thin' opts[:server] = 'thin'
# require "thin" # require "thin"
# ::Thin::Logging.silent = true if options[:debug] != "true" # ::Thin::Logging.silent = true if options[:debug] != "true"
server = ::Rack::Server.new(opts) server = ::Rack::Server.new(opts)
server.start server.start
server server
end
end end
end end

View file

@ -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?

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)
@ -121,16 +133,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)

View file

@ -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/, '')

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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]

View file

@ -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)

View file

@ -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

View file

@ -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('/')

View file

@ -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
}
guardfile_contents = %Q{
guard 'middleman'#{options_hash} do
watch(%r{(.*)})
end
}
::Guard.start({ :guardfile_contents => guardfile_contents }) ::Guard.start({ :guardfile_contents => guardfile_contents })
end
end end
end end
end end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -10,10 +10,8 @@ module Middleman::Renderers::Sass
end end
alias :included :registered alias :included :registered
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

View file

@ -1,3 +1,3 @@
module Middleman module Middleman
VERSION = "3.0.0.alpha.2" VERSION = "3.0.0.alpha.3"
end end