extract compass into core_ext, allow other features to execute after its init, add map support to sinatra, prep Sprockets feature
This commit is contained in:
parent
7828b07dad
commit
01eccafde2
12 changed files with 171 additions and 57 deletions
59
lib/middleman/core_extensions/compass.rb
Normal file
59
lib/middleman/core_extensions/compass.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
module Middleman::CoreExtensions::Compass
|
||||
class << self
|
||||
def registered(app)
|
||||
app.extend ClassMethods
|
||||
|
||||
require "compass"
|
||||
|
||||
# Susy grids
|
||||
begin
|
||||
require "susy"
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
app.after_feature_init do
|
||||
views_root = File.basename(app.views)
|
||||
::Compass.configuration do |config|
|
||||
config.cache = false # For sassc files
|
||||
config.project_path = app.root
|
||||
config.sass_dir = File.join(views_root, app.css_dir)
|
||||
config.output_style = :nested
|
||||
config.fonts_dir = File.join(views_root, app.fonts_dir)
|
||||
config.css_dir = File.join(views_root, app.css_dir)
|
||||
config.images_dir = File.join(views_root, app.images_dir)
|
||||
config.http_images_path = app.http_images_path rescue File.join(app.http_prefix || "/", app.images_dir)
|
||||
config.http_stylesheets_path = app.http_css_path rescue File.join(app.http_prefix || "/", app.css_dir)
|
||||
config.asset_cache_buster :none
|
||||
|
||||
config.add_import_path(config.sass_dir)
|
||||
end
|
||||
|
||||
# configure :build do
|
||||
# build_root = File.basename(self.build_dir)
|
||||
# ::Compass.configuration do |config|
|
||||
# config.css_dir = File.join(build_root, self.css_dir)
|
||||
# config.images_dir = File.join(build_root, self.images_dir)
|
||||
# end
|
||||
# end
|
||||
|
||||
app.execute_after_compass_init!
|
||||
|
||||
app.set :sass, ::Compass.configuration.to_sass_engine_options
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Add a block/proc to be run after features have been setup
|
||||
def after_compass_init(&block)
|
||||
@run_after_compass ||= []
|
||||
@run_after_compass << block
|
||||
end
|
||||
|
||||
def execute_after_compass_init!
|
||||
@run_after_compass ||= []
|
||||
@run_after_compass.each { |block| class_eval(&block) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -84,7 +84,7 @@ module Middleman::CoreExtensions::Features
|
|||
end
|
||||
|
||||
# Add in defaults
|
||||
default_extensions.each do |ext|
|
||||
default_features.each do |ext|
|
||||
activate ext
|
||||
end
|
||||
|
||||
|
|
34
lib/middleman/core_extensions/rack_map.rb
Normal file
34
lib/middleman/core_extensions/rack_map.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
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(*args, &bk)
|
||||
builder = ::Rack::Builder.new
|
||||
builder.use ::Sinatra::ShowExceptions if show_exceptions?
|
||||
builder.use ::Rack::CommonLogger if logging?
|
||||
builder.use ::Rack::Head
|
||||
middleware.each { |c,a,b| builder.use(c, *a, &b) }
|
||||
maps.each { |p,b| builder.map(p, &b) }
|
||||
builder.map "/" do
|
||||
run Middleman::Server.new!(*args, &bk)
|
||||
end
|
||||
builder
|
||||
end
|
||||
end
|
||||
end
|
29
lib/middleman/core_extensions/sprockets.rb
Normal file
29
lib/middleman/core_extensions/sprockets.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require "sprockets"
|
||||
|
||||
module Middleman::CoreExtensions::Sprockets
|
||||
class << self
|
||||
def registered(app)
|
||||
# app.map '/assets' do
|
||||
# run ::Sprockets::Environment.new
|
||||
# end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
class Environment < Sprockets::Environment
|
||||
|
||||
# Pass in the project you want the pipeline to manage.
|
||||
def initialize(app, mode = :debug)
|
||||
# Views/ ?
|
||||
super app.root
|
||||
|
||||
# Disable css for now
|
||||
# unregister_processor "text/css", Sprockets::DirectiveProcessor
|
||||
|
||||
# configure search paths
|
||||
# append_path File.dirname project_path
|
||||
# append_path File.join project_path, 'assets'
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue