relative assets working better
This commit is contained in:
parent
087f48c98d
commit
dbe067ee15
|
@ -1,9 +1,19 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'optparse'
|
||||
|
||||
# Require Middleman
|
||||
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
|
||||
|
||||
# Start Middleman
|
||||
Middleman::Base.set({ :server => %w[thin webrick],
|
||||
:root => Dir.pwd })
|
||||
Middleman::Base.run!
|
||||
class Middleman::Base
|
||||
set :root, Dir.pwd
|
||||
|
||||
OptionParser.new { |op|
|
||||
op.on('-e env') { |val| set :environment, val.to_sym }
|
||||
op.on('-s server') { |val| set :server, val }
|
||||
op.on('-p port') { |val| set :port, val.to_i }
|
||||
}.parse!(ARGV.dup)
|
||||
|
||||
# Start Middleman
|
||||
run!
|
||||
end
|
|
@ -1,7 +1,10 @@
|
|||
# Be nice to other library systems, like the wonderful Rip
|
||||
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
||||
require 'sinatra/base'
|
||||
require 'middleman/helpers'
|
||||
|
||||
# We're riding on Sinatra, so let's include it
|
||||
require 'sinatra/base'
|
||||
|
||||
# Rack helper for adding mime-types during local preview
|
||||
def mime(ext, type)
|
||||
ext = ".#{ext}" unless ext.to_s[0] == ?.
|
||||
Rack::Mime::MIME_TYPES[ext.to_s] = type
|
||||
|
@ -20,9 +23,12 @@ module Middleman
|
|||
set :build_dir, "build"
|
||||
set :http_prefix, "/"
|
||||
|
||||
# Features enabled by default
|
||||
enable :compass
|
||||
enable :content_for
|
||||
enable :sprockets
|
||||
|
||||
# Features disabled by default
|
||||
disable :slickmap
|
||||
disable :cache_buster
|
||||
disable :minify_css
|
||||
|
@ -31,9 +37,6 @@ module Middleman
|
|||
disable :markaby
|
||||
disable :maruku
|
||||
|
||||
# include helpers
|
||||
helpers Middleman::Helpers
|
||||
|
||||
# Default build features
|
||||
configure :build do
|
||||
enable :minify_css
|
||||
|
@ -41,6 +44,7 @@ module Middleman
|
|||
enable :cache_buster
|
||||
end
|
||||
|
||||
# Convenience function to discover if a tempalte exists for the requested renderer (haml, sass, etc)
|
||||
def template_exists?(path, renderer=nil)
|
||||
template_path = path.dup
|
||||
template_path << ".#{renderer}" if renderer
|
||||
|
@ -55,21 +59,25 @@ module Middleman
|
|||
end
|
||||
include StaticRender
|
||||
|
||||
# All other files
|
||||
# Disable static asset handling in Rack, so we can customize it here
|
||||
disable :static
|
||||
|
||||
# This will match all requests not overridden in the project's init.rb
|
||||
not_found do
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
path = request.path
|
||||
path << options.index_file if path.match(%r{/$})
|
||||
path.gsub!(%r{^/}, '')
|
||||
|
||||
# If the enabled renderers succeed, return the content, mime-type and an HTTP 200
|
||||
if content = render_path(path)
|
||||
content_type media_type(File.extname(path)), :charset => 'utf-8'
|
||||
status 200
|
||||
content
|
||||
else
|
||||
# Otherwise, send the static file
|
||||
# If no template handler renders the template, return the static file if it exists
|
||||
path = File.join(options.public, request.path)
|
||||
if File.exists?(path)
|
||||
if !File.directory?(path) && File.exists?(path)
|
||||
status 200
|
||||
send_file(path)
|
||||
else
|
||||
|
@ -78,6 +86,8 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
# Copy, pasted & edited version of the setup in Sinatra.
|
||||
# Basically just changed the app's name and call out feature & configuration init.
|
||||
def self.run!(options={}, &block)
|
||||
init!
|
||||
set options
|
||||
|
@ -101,15 +111,21 @@ module Middleman
|
|||
puts "== The Middleman is already standing watch on port #{port}!"
|
||||
end
|
||||
|
||||
# Require the features for this project
|
||||
def self.init!
|
||||
# Check for local config
|
||||
# Built-in helpers
|
||||
require 'middleman/helpers'
|
||||
helpers Middleman::Helpers
|
||||
|
||||
# Haml is required & includes helpers
|
||||
require "middleman/features/haml"
|
||||
|
||||
# Check for and evaluate local configuration
|
||||
local_config = File.join(self.root, "init.rb")
|
||||
if File.exists? local_config
|
||||
puts "== Local config at: #{local_config}"
|
||||
class_eval File.read(local_config)
|
||||
end
|
||||
|
||||
require "middleman/features/haml"
|
||||
|
||||
# loop over enabled feature
|
||||
features_path = File.expand_path("features/*.rb", File.dirname(__FILE__))
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
# Use Rack::Test to access Sinatra without starting up a full server
|
||||
require 'rack/test'
|
||||
|
||||
# Placeholder for any methods the builder needs to abstract to allow feature integration
|
||||
module Middleman
|
||||
class Builder
|
||||
# The default render just requests the page over Rack and writes the response
|
||||
def self.render_file(source, destination)
|
||||
request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "")
|
||||
browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base))
|
||||
|
|
|
@ -72,7 +72,7 @@ module Middleman
|
|||
static_version = options.public + request.path_info
|
||||
send_file(static_version) if File.exists? static_version
|
||||
|
||||
location_of_sass_file = options.environment == "build" ? "build" : "views"
|
||||
location_of_sass_file = options.environment == "build" ? "build" : "public"
|
||||
css_filename = File.join(Dir.pwd, location_of_sass_file) + request.path_info
|
||||
sass(path.to_sym, Compass.sass_engine_options.merge({ :css_filename => css_filename }))
|
||||
rescue Exception => e
|
||||
|
|
|
@ -14,8 +14,9 @@ class Middleman::Base
|
|||
if path.include?("://")
|
||||
path
|
||||
else
|
||||
path = path[1,path.length-1] if path[0,1] == '/'
|
||||
request_path = request.path_info.dup
|
||||
request_path << self.index_file if path.match(%r{/$})
|
||||
request_path << options.index_file if path.match(%r{/$})
|
||||
request_path.gsub!(%r{^/}, '')
|
||||
parts = request_path.split('/')
|
||||
|
||||
|
|
|
@ -2,21 +2,17 @@
|
|||
helpers do
|
||||
end
|
||||
|
||||
# Or inject more templating languages
|
||||
# helpers Sinatra::Markdown
|
||||
# Generic configuration
|
||||
# enable :slickmap
|
||||
|
||||
# Build-specific configuration
|
||||
configure :build do
|
||||
Compass.configuration do |config|
|
||||
# For example, change the Compass output style for deployment
|
||||
# config.output_style = :compressed
|
||||
|
||||
# Or use a different image path
|
||||
# config.http_images_path = "/Content/images/"
|
||||
|
||||
# Disable cache buster
|
||||
# config.asset_cache_buster do
|
||||
# false
|
||||
# end
|
||||
end
|
||||
# For example, change the Compass output style for deployment
|
||||
# enable :minified_css
|
||||
|
||||
# Or use a different image path
|
||||
# set :http_path, "/Content/images/"
|
||||
|
||||
# Disable cache buster
|
||||
# disable :cache_buster
|
||||
end
|
|
@ -1 +1,4 @@
|
|||
- content_for :head do
|
||||
%title Custom head title
|
||||
|
||||
%h1 The Middleman is watching.
|
|
@ -1,6 +1,7 @@
|
|||
%html
|
||||
%head
|
||||
%title The Middleman!
|
||||
= yield_content :head
|
||||
|
||||
%body
|
||||
= yield
|
Loading…
Reference in a new issue