experimental rack-only middleman

This commit is contained in:
Thomas Reynolds 2011-11-17 19:56:55 -08:00
parent fc91179b4a
commit f4fa1acd3e
14 changed files with 397 additions and 397 deletions

View file

@ -55,13 +55,11 @@
libdir = File.dirname(__FILE__) libdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
# We're riding on Sinatra, so let's include it.
require "sinatra/base"
# Top-level Middleman object # Top-level Middleman object
module Middleman module Middleman
# Auto-load modules on-demand # Auto-load modules on-demand
autoload :Base, "middleman/base" autoload :Base, "middleman/base"
autoload :Hooks, "middleman/hooks"
autoload :Builder, "middleman/builder" autoload :Builder, "middleman/builder"
autoload :CLI, "middleman/cli" autoload :CLI, "middleman/cli"
autoload :Templates, "middleman/templates" autoload :Templates, "middleman/templates"
@ -86,9 +84,6 @@ module Middleman
# Add Builder callbacks # Add Builder callbacks
autoload :Builder, "middleman/core_extensions/builder" autoload :Builder, "middleman/core_extensions/builder"
# Add Rack::Builder.map support
autoload :RackMap, "middleman/core_extensions/rack_map"
# Custom Feature API # Custom Feature API
autoload :Features, "middleman/core_extensions/features" autoload :Features, "middleman/core_extensions/features"
@ -181,9 +176,8 @@ module Middleman
end end
def self.server(&block) def self.server(&block)
sandbox = Class.new(Sinatra::Base) sandbox = Class.new(Middleman::Base)
sandbox.register Base # sandbox.class_eval(&block) if block_given?
sandbox.class_eval(&block) if block_given?
sandbox sandbox
end end
@ -197,8 +191,8 @@ module Middleman
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

View file

@ -1,134 +1,55 @@
require "rack"
require "tilt"
require "i18n" require "i18n"
require "hooks" require "hooks"
require "active_support" require "active_support"
require "active_support/json" require "active_support/json"
require "active_support/core_ext/class/attribute_accessors" require "active_support/core_ext/string/inflections"
# require "active_support/core_ext/class/attribute_accessors"
class Middleman::Base
include Hooks
define_hook :build_config
define_hook :development_config
module Padrino
class << self class << self
attr_accessor :root_dir, :env def reset!
def root(*args) @app = nil
File.expand_path(File.join(root_dir, *args)) @prototype = nil
end
end
end
ENV['PADRINO_LOG_LEVEL'] = "debug"
require "padrino-core/logger"
module Middleman::Base
class << self
def registered(app)
app.send :include, ::Hooks
app.define_hook :initialized
app.extend ClassMethods
app.send :include, InstanceMethods
# Basic Sinatra config
app.set :app_file, __FILE__
app.set :root, Dir.pwd
app.set :sessions, false
app.set :logging, false
app.set :protection, false
app.set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
# Middleman-specific options
app.set :index_file, "index.html" # What file responds to folder requests
# Such as the homepage (/) or subfolders (/about/)
# These directories are passed directly to Compass
app.set :js_dir, "javascripts" # Where to look for javascript files
app.set :css_dir, "stylesheets" # Where to look for CSS files
app.set :images_dir, "images" # Where to look for images
app.set :build_dir, "build" # Which folder are builds output to
app.set :http_prefix, nil # During build, add a prefix for absolute paths
# Pass all request to Middleman, even "static" files
app.set :static, false
app.set :views, "source"
# Add Builder Callbacks
app.register Middleman::CoreExtensions::Builder
# Add Rack::Builder.map to Sinatra
app.register Middleman::CoreExtensions::RackMap
# Activate custom features
app.register Middleman::CoreExtensions::Features
# Add Builder Callbacks
app.register Middleman::CoreExtensions::FileWatcher
# Sitemap
app.register Middleman::CoreExtensions::Sitemap
# Activate Yaml Data package
app.register Middleman::CoreExtensions::Data
# Setup custom rendering
app.register Middleman::CoreExtensions::Rendering
# Compass framework
app.register Middleman::CoreExtensions::Compass
# Sprockets asset handling
app.register Middleman::CoreExtensions::Sprockets
# Setup asset path pipeline
app.register Middleman::CoreExtensions::Assets
# Activate built-in helpers
app.register Middleman::CoreExtensions::DefaultHelpers
# with_layout and page routing
app.register Middleman::CoreExtensions::Routing
# Parse YAML from templates
app.register Middleman::CoreExtensions::FrontMatter
app.set :default_features, [
:lorem,
# :sitemap_tree
]
# Default layout name
app.set :layout, :layout
# This will match all requests not overridden in the project's config.rb
app.not_found do
process_request
end end
# Custom 404 handler (to be styled) def app
app.error Sinatra::NotFound do @app ||= Rack::Builder.new
content_type 'text/html'
"<html><body><h1>File Not Found</h1><p>#{request.path_info}</p></body>"
end
end
alias :included :registered
end end
module ClassMethods def prototype
# Override Sinatra's set to accept a block @prototype ||= app.to_app
# Specifically for the asset_host feature
def set(option, value = (not_set = true), ignore_setter = false, &block)
if block_given?
value = Proc.new { block }
end end
super(option, value, ignore_setter, &nil) def call(env)
prototype.call(env)
end end
def full_path(path) def use(middleware, *args, &block)
parts = path ? path.split('/') : [] app.use(middleware, *args, &block)
if parts.last.nil? || parts.last.split('.').length == 1
path = File.join(path, index_file)
end end
"/" + path.sub(%r{^/}, '')
def map(map, &block)
app.map(map, &block)
end
def helpers(*extensions, &block)
class_eval(&block) if block_given?
include(*extensions) if extensions.any?
end
def defaults
@defaults ||= {}
end
def set(key, value)
@defaults ||= {}
@defaults[key] = value
end end
def before_processing(name=:unnamed, idx=-1, &block) def before_processing(name=:unnamed, idx=-1, &block)
@ -144,114 +65,284 @@ module Middleman::Base
end end
end end
# Convenience method to check if we're in build mode def configure(env, &block)
def build?; environment == :build; end send("#{env}_config", &block)
# Creates a Rack::Builder instance with all the middleware set up and
# an instance of this class as end point.
def build_new(inst=false)
builder = Rack::Builder.new
setup_default_middleware builder
setup_middleware builder
builder.run inst || new!
builder.to_app
end
def logger
Padrino.logger
end end
end end
module InstanceMethods def set(key, value)
def logger setter = "#{key}=".to_sym
Padrino.logger self.class.send(:attr_accessor, key) if !respond_to?(setter)
send(setter, value)
end end
def initialize(*args) def configure(env, &block)
self.class.configure(env, &block)
end
# Basic Sinatra config
set :root, Dir.pwd
set :source, "source"
set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
set :logging, false
# Middleman-specific options
set :index_file, "index.html" # What file responds to folder requests
# Such as the homepage (/) or subfolders (/about/)
# These directories are passed directly to Compass
set :js_dir, "javascripts" # Where to look for javascript files
set :css_dir, "stylesheets" # Where to look for CSS files
set :images_dir, "images" # Where to look for images
set :build_dir, "build" # Which folder are builds output to
set :http_prefix, nil # During build, add a prefix for absolute paths
set :views, "source"
set :default_features, [
:lorem,
# :sitemap_tree
]
# Default layout name
set :layout, :layout
# Activate custom features and extensions
include Middleman::CoreExtensions::Features
# Add Builder Callbacks
register Middleman::CoreExtensions::Builder
# Add Guard Callbacks
register Middleman::CoreExtensions::FileWatcher
# Sitemap
register Middleman::CoreExtensions::Sitemap
# Activate Data package
register Middleman::CoreExtensions::Data
# Setup custom rendering
register Middleman::CoreExtensions::Rendering
# Compass framework
register Middleman::CoreExtensions::Compass
# Sprockets asset handling
register Middleman::CoreExtensions::Sprockets
# Setup asset path pipeline
register Middleman::CoreExtensions::Assets
# Activate built-in helpers
register Middleman::CoreExtensions::DefaultHelpers
# with_layout and page routing
register Middleman::CoreExtensions::Routing
# Parse YAML from templates
register Middleman::CoreExtensions::FrontMatter
define_hook :initialized
def initialize(&block)
self.class.superclass.defaults.each do |k, v|
set(k, v)
end
set :source_dir, File.join(root, source)
super super
run_hook :initialized, settings
Padrino.root_dir = settings.root run_hook :initialized
Padrino.env = settings.environment
Padrino::Logger::Config[:debug] = { :stream => :stderr }
# Padrino::Logger::Config[:development][:stream] = StringIO.new
end end
def forward def call(env)
raise ::Sinatra::NotFound @env = env
@req = Rack::Request.new(env)
@res = Rack::Response.new
process_request
end end
# Custom 404 handler (to be styled)
# app.error Sinatra::NotFound do
# content_type 'text/html'
# "<html><body><h1>File Not Found</h1><p>#{request.path_info}</p></body>"
# end
# Convenience methods to check if we're in a mode
def development?; environment == :development; end
def build?; environment == :build; end
# Internal method to look for templates and evaluate them if found # Internal method to look for templates and evaluate them if found
def process_request def process_request
if !settings.views.include?(settings.root)
settings.set :views, File.join(settings.root, settings.views)
end
# Normalize the path and add index if we're looking at a directory # Normalize the path and add index if we're looking at a directory
request_path = settings.full_path(request.path.gsub("%20", " ")) original_path = @env["PATH_INFO"].dup
original_path = request_path.dup request_path = full_path(@env["PATH_INFO"].gsub("%20", " "))
return status(404) if settings.sitemap.ignored_path?(request_path) # return not_found if sitemap.ignored_path?(request_path)
if settings.sitemap.path_is_proxy?(request_path) # if sitemap.path_is_proxy?(request_path)
request["is_proxy"] = true # request["is_proxy"] = true
request_path = "/" + settings.sitemap.path_target(request_path) # request_path = "/" + sitemap.path_target(request_path)
end # end
found_template = resolve_template(request_path, :raise_exceptions => false) found_template = resolve_template(request_path)
return status(404) unless found_template return not_found unless found_template
path, engine = found_template path, engine = found_template
if !::Tilt.mappings.has_key?(engine.to_s) # Static File
matched_mime = mime_type(File.extname(request_path)) return send_file(path) if engine.nil?
matched_mime = "application/octet-stream" if matched_mime.nil?
content_type matched_mime
status 200
send_file File.join(settings.views, request_path)
return
end
return unless settings.execute_before_processing!(self, found_template) # return unless settings.execute_before_processing!(self, found_template)
context = settings.sitemap.get_context(original_path) || {} # context = settings.sitemap.get_context(original_path) || {}
#
options = {}
# options = context.has_key?(:options) ? context[:options] : {}
# options.merge!(request['custom_options'] || {})
#
options = context.has_key?(:options) ? context[:options] : {} local_layout = if options.has_key?(:layout)
options.merge!(request['custom_options'] || {}) options[:layout]
old_layout = settings.layout
settings.set :layout, options[:layout] if !options[:layout].nil?
local_layout = if settings.layout
if options[:layout] == false || request_path =~ /\.(css|js)$/
false
else else
settings.fetch_layout_path(settings.layout).to_sym layout
end end
# if context.has_key?(:block) && context[:block]
# instance_eval(&context[:block])
# end
# locals = request['custom_locals'] || {}
locals = {}
# content_type mime_type(File.extname(request_path))
@res.status = 200
output = if layout
layout_engine = if options.has_key?(:layout_engine)
options[:layout_engine]
else
engine
end
layout_path, *etc = resolve_template(layout, :preferred_engine => layout_engine)
render(layout_path, locals) do
render(path, locals)
end
else
render(path, locals)
end
@res.write output
@res.finish
end
public
protected
def full_path(path)
parts = path ? path.split('/') : []
if parts.last.nil? || parts.last.split('.').length == 1
path = File.join(path, index_file)
end
"/" + path.sub(%r{^/}, '')
end
def not_found
@res.status == 404
@res.write "<html><body><h1>File Not Found</h1><p>#{@env["PATH_INFO"]}</p></body>"
@res.finish
end
def resolve_template(request_path, options={})
request_path = request_path.to_s
@_resolved_templates ||= {}
if !@_resolved_templates.has_key?(request_path)
relative_path = request_path.sub(%r{^/}, "")
on_disk_path = File.expand_path(relative_path, source_dir)
preferred_engine = if options.has_key?(:preferred_engine)
extension_class = Tilt[options[:preferred_engine]]
matched_exts = []
# TODO: Cache this
Tilt.mappings.each do |ext, engines|
next unless engines.include? extension_class
matched_exts << ext
end
"{" + matched_exts.join(",") + "}"
else
"*"
end
path_with_ext = on_disk_path + "." + preferred_engine
found_engine = nil
found_path = Dir[path_with_ext].find do |path|
::Tilt[path]
end
result = if found_path || File.exists?(on_disk_path)
engine = found_path ? File.extname(found_path)[1..-1].to_sym : nil
[ found_path || on_disk_path, engine ]
else else
false false
end end
render_options = { :layout => local_layout } @_resolved_templates[request_path] = result
render_options[:layout_engine] = options[:layout_engine] if options.has_key?(:layout_engine)
locals = request['custom_locals'] || {}
if context.has_key?(:block) && context[:block]
instance_eval(&context[:block])
end end
begin @_resolved_templates[request_path]
result = render(engine, path, render_options, locals) end
if result def extensionless_path(file)
content_type mime_type(File.extname(request_path)) @_extensionless_path_cache ||= {}
status 200
body result if @_extensionless_path_cache.has_key?(file)
end @_extensionless_path_cache[file]
ensure else
settings.set :layout, old_layout path = file.dup
end_of_the_line = false
while !end_of_the_line
file_extension = File.extname(path)
if ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, ""))
path = path.sub(file_extension, "")
else
end_of_the_line = true
end end
end end
@_extensionless_path_cache[file] = path
path
end
end
def send_file(path)
# matched_mime = mime_type(File.extname(request_path))
# matched_mime = "application/octet-stream" if matched_mime.nil?
# content_type matched_mime
file = ::Rack::File.new nil
file.path = path
file.serving# env
end
def render(path, locals = {}, options = {}, &block)
path = path.to_s
template = ::Tilt.new(path, 1, options)
template.render(self, locals, &block)
end
def logging?
logging
end end
end end

View file

@ -18,45 +18,45 @@ module Middleman::CoreExtensions::Compass
# * line_comments # * line_comments
# * sprite_engine # * sprite_engine
# * chunky_png_options # * chunky_png_options
compass_config_file = File.join(app.root, "compass.config") compass_config_file = File.join(self.root, "compass.config")
if File.exists?(compass_config_file) if File.exists?(compass_config_file)
::Compass.add_project_configuration(compass_config_file) ::Compass.add_project_configuration(compass_config_file)
end end
::Compass.configuration do |config| ::Compass.configuration do |config|
config.project_path = app.root config.project_path = self.root
config.environment = :development config.environment = :development
config.cache_path = File.join(app.root, ".sass-cache") config.cache_path = File.join(self.root, ".sass-cache")
views_root = File.basename(app.views) views_root = File.basename(self.views)
config.sass_dir = File.join(views_root, app.css_dir) config.sass_dir = File.join(views_root, self.css_dir)
config.css_dir = File.join(views_root, app.css_dir) config.css_dir = File.join(views_root, self.css_dir)
config.javascripts_dir = File.join(views_root, app.js_dir) config.javascripts_dir = File.join(views_root, self.js_dir)
config.fonts_dir = File.join(views_root, app.fonts_dir) config.fonts_dir = File.join(views_root, self.fonts_dir)
config.images_dir = File.join(views_root, app.images_dir) config.images_dir = File.join(views_root, self.images_dir)
config.http_images_path = if app.respond_to? :http_images_path config.http_images_path = if self.respond_to? :http_images_path
app.http_images_path self.http_images_path
else else
File.join(app.http_prefix || "/", app.images_dir) File.join(self.http_prefix || "/", self.images_dir)
end end
config.http_stylesheets_path = if app.respond_to? :http_css_path config.http_stylesheets_path = if self.respond_to? :http_css_path
app.http_css_path self.http_css_path
else else
File.join(app.http_prefix || "/", app.css_dir) File.join(self.http_prefix || "/", self.css_dir)
end end
config.http_javascripts_path = if app.respond_to? :http_js_path config.http_javascripts_path = if self.respond_to? :http_js_path
app.http_js_path self.http_js_path
else else
File.join(app.http_prefix || "/", app.js_dir) File.join(self.http_prefix || "/", self.js_dir)
end end
config.http_fonts_path = if app.respond_to? :http_fonts_path config.http_fonts_path = if self.respond_to? :http_fonts_path
app.http_fonts_path self.http_fonts_path
else else
File.join(app.http_prefix || "/", app.fonts_dir) File.join(self.http_prefix || "/", self.fonts_dir)
end end
config.asset_cache_buster :none config.asset_cache_buster :none

View file

@ -30,18 +30,32 @@
module Middleman::CoreExtensions::Features module Middleman::CoreExtensions::Features
# The Feature API is itself a Feature. Mind blowing!
class << self class << self
def registered(app) def included(app)
app.set :default_features, [] # app.set :default_features, []
app.define_hook :after_configuration app.define_hook :after_configuration
app.define_hook :before_configuration app.define_hook :before_configuration
app.extend ClassMethods app.extend ClassMethods
app.send :include, InstanceMethods
end end
alias :included :registered
end end
module ClassMethods module ClassMethods
def extensions
@extensions ||= []
end
def register(*new_extensions)
@extensions ||= []
@extensions += new_extensions
new_extensions.each do |extension|
extend extension
extension.registered(self) if extension.respond_to?(:registered)
end
end
end
module InstanceMethods
# This method is available in the project's `config.rb`. # This method is available in the project's `config.rb`.
# It takes a underscore-separated symbol, finds the appropriate # It takes a underscore-separated symbol, finds the appropriate
# feature module and includes it. # feature module and includes it.
@ -58,39 +72,39 @@ module Middleman::CoreExtensions::Features
if feature.is_a? String if feature.is_a? String
feature = feature.camelize feature = feature.camelize
feature = Middleman::Features.const_get(feature) feature = ::Middleman::Features.const_get(feature)
end end
puts "== Activating: #{feature}" if logging? puts "== Activating: #{feature}" if logging?
register feature self.class.register feature
end end
# Load features before starting server # Load features before starting server
def new! def initialize
super
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(self.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?
class_eval File.read(local_config) # instance_eval File.read(local_config)
set :app_file, File.expand_path(local_config) # set :app_file, File.expand_path(local_config)
end
# Add in defaults
default_features.each do |ext|
activate ext
end end
run_hook :after_configuration run_hook :after_configuration
# Add in defaults
default_features.each do |ext|
# activate ext
end
if logging? if logging?
extensions.each do |ext| extensions.each do |ext|
puts "== Extension: #{ext}" puts "== Extension: #{ext}"
end end
end end
super
end end
end end
end end

View file

@ -6,9 +6,9 @@ module Middleman::CoreExtensions::FileWatcher
app.extend ClassMethods app.extend ClassMethods
app.send :include, InstanceMethods app.send :include, InstanceMethods
app.before_configuration do app.before_configuration do
Find.find(settings.root) do |path| Find.find(root) do |path|
next if File.directory?(path) next if File.directory?(path)
file_did_change(path.sub("#{settings.root}/", "")) file_did_change(path.sub("#{root}/", ""))
end end
end end
@ -28,6 +28,12 @@ module Middleman::CoreExtensions::FileWatcher
@_file_deleted << [block, matcher] if block_given? @_file_deleted << [block, matcher] if block_given?
@_file_deleted @_file_deleted
end end
end
module InstanceMethods
def file_changed(*args)
self.class.file_changed(*args)
end
def file_did_change(path) def file_did_change(path)
file_changed.each do |callback, matcher| file_changed.each do |callback, matcher|
@ -37,6 +43,10 @@ module Middleman::CoreExtensions::FileWatcher
end end
end end
def file_deleted(*args)
self.class.file_deleted(*args)
end
def file_did_delete(path) def file_did_delete(path)
file_deleted.each do |callback, matcher| file_deleted.each do |callback, matcher|
next if path.match(%r{^#{build_dir}/}) next if path.match(%r{^#{build_dir}/})
@ -45,14 +55,4 @@ module Middleman::CoreExtensions::FileWatcher
end end
end end
end end
module InstanceMethods
def file_did_change(path)
settings.file_did_change(path)
end
def file_did_delete(path)
settings.file_did_delete(path)
end
end
end end

View file

@ -1,35 +0,0 @@
module Middleman::CoreExtensions::RackMap
class << self
def registered(app)
app.extend ClassMethods
end
alias :included :registered
end
module ClassMethods
def map(path, &block)
@maps ||= []
@maps << [path, block]
end
def maps
@maps || []
end
# Creates a Rack::Builder instance with all the middleware set up and
# an instance of this class as end point.
def build_new(inst=false)
builder = Rack::Builder.new
setup_default_middleware builder
setup_middleware builder
maps.each { |p,b| builder.map(p, &b) }
app = self
builder.map "/" do
run (inst || app.new!)
end
builder
end
end
end

View file

@ -1,52 +1,12 @@
require "padrino-core/application/rendering"
module Middleman::CoreExtensions::Rendering module Middleman::CoreExtensions::Rendering
class << self class << self
def registered(app) def registered(app)
app.extend ClassMethods
app.send :include, InstanceMethods
# Tilt-aware renderer
app.register Padrino::Rendering
# Activate custom renderers # Activate custom renderers
app.register Middleman::Renderers::Sass app.register Middleman::Renderers::Sass
app.register Middleman::Renderers::Markdown app.register Middleman::Renderers::Markdown
app.register Middleman::Renderers::ERb app.register Middleman::Renderers::ERb
app.register Middleman::Renderers::CoffeeScript
app.register Middleman::Renderers::Liquid app.register Middleman::Renderers::Liquid
end end
alias :included :registered alias :included :registered
end end
module ClassMethods
def extensionless_path(file)
@_extensionless_path_cache ||= {}
if @_extensionless_path_cache.has_key?(file)
@_extensionless_path_cache[file]
else
path = file.dup
end_of_the_line = false
while !end_of_the_line
file_extension = File.extname(path)
if ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, ""))
path = path.sub(file_extension, "")
else
end_of_the_line = true
end
end
@_extensionless_path_cache[file] = path
path
end
end
end
module InstanceMethods
def extensionless_path(path)
settings.extensionless_path(path)
end
end
end end

View file

@ -21,7 +21,7 @@ module Middleman::CoreExtensions::Sprockets
end end
app.after_configuration do app.after_configuration do
js_env = Middleman::CoreExtensions::Sprockets::JavascriptEnvironment.new(app) js_env = Middleman::CoreExtensions::Sprockets::JavascriptEnvironment.new(self)
vendor_dir = File.join("vendor", "assets", "javascripts") vendor_dir = File.join("vendor", "assets", "javascripts")
gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec| gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
@ -38,13 +38,13 @@ module Middleman::CoreExtensions::Sprockets
end end
# add paths to js_env (vendor/assets/javascripts) # add paths to js_env (vendor/assets/javascripts)
app.map "/#{app.js_dir}" do app.map "/#{self.js_dir}" do
run js_env run js_env
end end
end end
app.after_compass_config do app.after_compass_config do
css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(app) css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self)
vendor_dir = File.join("vendor", "assets", "stylesheets") vendor_dir = File.join("vendor", "assets", "stylesheets")
gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec| gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
@ -60,7 +60,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
app.map "/#{app.css_dir}" do app.map "/#{self.css_dir}" do
run css_env run css_env
end end
end end
@ -96,7 +96,7 @@ module Middleman::CoreExtensions::Sprockets
# Disable css # Disable css
# unregister_processor "text/css", ::Sprockets::DirectiveProcessor # unregister_processor "text/css", ::Sprockets::DirectiveProcessor
self.js_compressor = app.settings.js_compressor self.js_compressor = app.js_compressor
# configure search paths # configure search paths
append_path app.js_dir append_path app.js_dir
@ -115,7 +115,7 @@ module Middleman::CoreExtensions::Sprockets
# Disable js # Disable js
# unregister_processor "application/javascript", ::Sprockets::DirectiveProcessor # unregister_processor "application/javascript", ::Sprockets::DirectiveProcessor
self.css_compressor = app.settings.css_compressor self.css_compressor = app.css_compressor
# configure search paths # configure search paths
append_path app.css_dir append_path app.css_dir

View file

@ -78,14 +78,15 @@ module Guard
def server_start def server_start
app = ::Middleman.server app = ::Middleman.server
app.set :environment, (@options[:environment] || "development").to_sym
app.set :logging, @options.has_key?(:debug) && (@options[:debug] == "true")
# Quiet down Guard # Quiet down Guard
# ENV['GUARD_ENV'] = 'test' if @options[:debug] == "true" # ENV['GUARD_ENV'] = 'test' if @options[:debug] == "true"
@app = app.new! @app = app.new
app_rack = app.build_new(@app) @app.set :environment, (@options[:environment] || "development").to_sym
@app.set :logging, @options.has_key?(:debug) && (@options[:debug] == "true")
app_rack = ::Middleman::Base.app
app_rack.run @app
@server_job = fork do @server_job = fork do
opts = @options.dup opts = @options.dup

View file

@ -1,8 +0,0 @@
module Middleman::Renderers::CoffeeScript
class << self
def registered(app)
require "coffee_script"
end
alias :included :registered
end
end

View file

@ -3,32 +3,27 @@ require "tilt"
module Middleman::Renderers::ERb module Middleman::Renderers::ERb
class << self class << self
def registered(app) def registered(app)
app.extend ClassMethods app.send :include, InstanceMethods
app.set :erb_engine, :erb app.set :erb_engine, :erb
if !app.respond_to? :erb_engine_prefix
app.set :erb_engine_prefix, ::Tilt app.set :erb_engine_prefix, ::Tilt
end
app.after_configuration do app.after_configuration do
engine = app.settings.erb_engine if erb_engine.is_a? Symbol
erb_engine = erb_tilt_template_from_symbol(erb_engine)
if engine.is_a? Symbol
engine = app.erb_tilt_template_from_symbol(engine)
end end
::Tilt.prefer(engine) ::Tilt.prefer(erb_engine)
end end
end end
alias :included :registered alias :included :registered
end end
module ClassMethods module InstanceMethods
def erb_tilt_template_from_symbol(engine) def erb_tilt_template_from_symbol(engine)
engine = engine.to_s engine = engine.to_s
engine = engine == "erb" ? "ERB" : engine.camelize engine = engine == "erb" ? "ERB" : engine.camelize
settings.erb_engine_prefix.const_get("#{engine}Template") erb_engine_prefix.const_get("#{engine}Template")
end end
end end
end end

View file

@ -7,10 +7,7 @@ module Middleman::Renderers::Liquid
require "liquid" require "liquid"
app.after_configuration do app.after_configuration do
full_path = app.views Liquid::Template.file_system = Liquid::LocalFileSystem.new(self.source_dir)
full_path = File.join(app.root, app.views) unless app.views.include?(app.root)
Liquid::Template.file_system = Liquid::LocalFileSystem.new(full_path)
app.before_processing(:liquid) do |result| app.before_processing(:liquid) do |result|
if result && result[1] == :liquid if result && result[1] == :liquid

View file

@ -1,34 +1,29 @@
module Middleman::Renderers::Markdown module Middleman::Renderers::Markdown
class << self class << self
def registered(app) def registered(app)
app.extend ClassMethods app.send :include, InstanceMethods
app.set :markdown_engine, nil app.set :markdown_engine, nil
if !app.respond_to? :markdown_engine_prefix
app.set :markdown_engine_prefix, ::Tilt app.set :markdown_engine_prefix, ::Tilt
end
app.after_configuration do app.after_configuration do
engine = app.settings.markdown_engine unless markdown_engine.nil?
if markdown_engine.is_a? Symbol
unless engine.nil? markdown_engine = markdown_tilt_template_from_symbol(markdown_engine)
if engine.is_a? Symbol
engine = app.markdown_tilt_template_from_symbol(engine)
end end
::Tilt.prefer(engine) ::Tilt.prefer(markdown_engine)
end end
end end
end end
alias :included :registered alias :included :registered
end end
module ClassMethods module InstanceMethods
def markdown_tilt_template_from_symbol(engine) def markdown_tilt_template_from_symbol(engine)
engine = engine.to_s engine = engine.to_s
engine = engine == "rdiscount" ? "RDiscount" : engine.camelize engine = engine == "rdiscount" ? "RDiscount" : engine.camelize
settings.markdown_engine_prefix.const_get("#{engine}Template") markdown_engine_prefix.const_get("#{engine}Template")
end end
end end
end end

View file

@ -24,20 +24,16 @@ Gem::Specification.new do |s|
s.add_dependency("thin", ["~> 1.2.11"]) s.add_dependency("thin", ["~> 1.2.11"])
s.add_dependency("thor", ["~> 0.14.0"]) s.add_dependency("thor", ["~> 0.14.0"])
s.add_dependency("tilt", ["~> 1.3.1"]) s.add_dependency("tilt", ["~> 1.3.1"])
s.add_dependency("maruku", ["~> 0.6.0"])
s.add_dependency("sinatra", ["~> 1.3.1"])
s.add_dependency("rack-test", ["~> 0.6.1"]) s.add_dependency("rack-test", ["~> 0.6.1"])
s.add_dependency("uglifier", ["~> 1.1.0"]) s.add_dependency("uglifier", ["~> 1.1.0"])
s.add_dependency("slim", ["~> 1.0.2"])
s.add_dependency("haml", ["~> 3.1.0"]) s.add_dependency("haml", ["~> 3.1.0"])
s.add_dependency("sass", ["~> 3.1.7"]) s.add_dependency("sass", ["~> 3.1.7"])
s.add_dependency("activesupport", ["~> 3.1.0"])
s.add_dependency("compass", ["~> 0.11.3"]) s.add_dependency("compass", ["~> 0.11.3"])
s.add_dependency("coffee-script", ["~> 2.2.0"]) s.add_dependency("coffee-script", ["~> 2.2.0"])
s.add_dependency("execjs", ["~> 1.2.7"]) s.add_dependency("execjs", ["~> 1.2.7"])
s.add_dependency("sprockets", ["~> 2.0"]) s.add_dependency("sprockets", ["~> 2.0"])
s.add_dependency("sprockets-sass", ["~> 0.3.0"]) s.add_dependency("sprockets-sass", ["~> 0.3.0"])
s.add_dependency("padrino-core", ["~> 0.10.5"])
s.add_dependency("padrino-helpers", ["~> 0.10.5"])
s.add_dependency("hooks", ["~> 0.2.0"]) s.add_dependency("hooks", ["~> 0.2.0"])
s.add_dependency("rb-fsevent") s.add_dependency("rb-fsevent")