Run static directories, woot

This commit is contained in:
Thomas Reynolds 2011-12-28 15:29:19 -08:00
parent 0b7e7582d5
commit 2b3354472c
15 changed files with 80 additions and 18 deletions

View file

@ -20,6 +20,8 @@
* Support for placekitten.com
* Added MM_ROOT environmental variable
* activating extensions can now take an options hash
* Don't re-minify files with ".min" in their name
* Serve purely static folders directly (without source/ and config.rb)
2.0.14
====

View file

@ -14,17 +14,17 @@ def locate_middleman_root!(cwd = Pathname.new(Dir.pwd))
locate_middleman_root!(cwd.parent)
end
if !ENV['MM_ROOT'] && found_path = locate_middleman_root!
ENV['MM_ROOT'] = found_path
if !ENV["MM_ROOT"] && found_path = locate_middleman_root!
ENV["MM_ROOT"] = found_path
end
if ENV['MM_ROOT']
if ENV["MM_ROOT"]
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ENV['MM_ROOT'])
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ENV["MM_ROOT"])
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
end
require 'middleman'
Dir.chdir(ENV['MM_ROOT'] || Dir.pwd) do
Dir.chdir(ENV["MM_ROOT"] || Dir.pwd) do
Middleman::Cli::Base.start
end

View file

@ -0,0 +1,12 @@
Feature: CSS and Javascripts which are minify shouldn't be re-minified
Scenario: CSS file
Scenario: JS files containing ".min" should not be re-compressed
And the Server is running at "already-minified-app"
When I go to "/javascripts/test.min.js"
Then I should see "10" lines
Scenario: CSS files containing ".min" should not be re-compressed
And the Server is running at "already-minified-app"
When I go to "/stylesheets/test.min.css"
Then I should see "10" lines

View file

@ -0,0 +1,6 @@
Feature: Middleman should serve plain directories without config
Scenario: Preview a folder of static pages
Given the Server is running at "plain-app"
When I go to "/index.html"
Then I should see "I am index"

View file

@ -0,0 +1,2 @@
activate :minify_javascript
activate :minify_css

View file

@ -0,0 +1,10 @@
var numbers = [ 1,
2,
3,
4,
5,
6,
7,
8,
9,
10 ];

View file

@ -0,0 +1,10 @@
body { one: 1;
two: 2;
three: 3;
four: 4;
five: 5;
six: 6;
seven: 7;
eight: 8;
nine: 9;
ten: 10; }

View file

@ -0,0 +1 @@
I am index

View file

@ -159,7 +159,7 @@ class Middleman::Base
# Root project directory (overwritten in middleman build/server)
# @return [String]
set :root, ENV['MM_ROOT'] || Dir.pwd
set :root, ENV["MM_ROOT"] || Dir.pwd
# Name of the source directory
# @return [String]
@ -301,7 +301,10 @@ class Middleman::Base
instance_exec(&block) if block_given?
# Build expanded source path once paths have been parsed
set :source_dir, File.join(root, source)
path = root.dup
source_path = ENV["MM_SOURCE"] || self.source
path = File.join(root, source_path) unless source_path.empty?
set :source_dir, path
super
end

View file

@ -12,7 +12,6 @@ module Middleman::Cli
method_option :host,
:type => :string,
:aliases => "-h",
# :required => true,
:default => "0.0.0.0",
:desc => "Bind to HOST address"
method_option "port",
@ -25,8 +24,10 @@ module Middleman::Cli
:desc => 'Print debug messages'
def server
if !ENV["MM_ROOT"]
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
exit(1)
puts "== Warning: Could not find a Middleman project config.rb"
puts "== Treating directory as a static site to be served"
ENV["MM_ROOT"] = Dir.pwd
ENV["MM_SOURCE"] = ""
end
params = {

View file

@ -25,7 +25,10 @@ module Middleman::CoreExtensions::FrontMatter
super
exts = frontmatter_extensions.join("|").gsub(".", "\.")
matcher = %r{source/.*(#{exts})}
static_path = source_dir.sub(self.root, "").sub(/^\//, "").sub(/\/$/, "") + "/"
matcher = %r{#{static_path}.*(#{exts})}
file_changed matcher do |file|
frontmatter_extension.touch_file(file)

View file

@ -28,7 +28,10 @@ module Middleman::CoreExtensions::Rendering
def initialize
super
file_changed %r{^source/} do |file|
static_path = source_dir.sub(self.root, "").sub(/^\//, "")
render_regex = static_path.empty? ? // : (%r{^#{static_path + "/"}})
file_changed render_regex do |file|
path = File.expand_path(file, root)
cache.remove(:raw_template, path)
end

View file

@ -28,11 +28,14 @@ module Middleman::CoreExtensions::Sitemap
def initialize
super
file_changed %r{^source/} do |file|
static_path = source_dir.sub(self.root, "").sub(/^\//, "")
sitemap_regex = static_path.empty? ? // : (%r{^#{static_path + "/"}})
file_changed sitemap_regex do |file|
sitemap.touch_file(file)
end
file_deleted %r{^source/} do |file|
file_deleted sitemap_regex do |file|
sitemap.remove_file(file)
end
end

View file

@ -4,7 +4,6 @@ module Middleman::Sitemap
def initialize(app)
@app = app
@source = File.expand_path(@app.source, @app.root)
@pages = {}
end
@ -88,7 +87,7 @@ module Middleman::Sitemap
def file_to_path(file)
file = File.expand_path(file, @app.root)
prefix = @source + "/"
prefix = @app.source_dir.sub(/\/$/, "") + "/"
return false unless file.include?(prefix)
path = file.sub(prefix, "")
@ -98,7 +97,7 @@ module Middleman::Sitemap
end
def touch_file(file)
return false if file == @source || File.directory?(file)
return false if file == @app.source_dir || File.directory?(file)
path = file_to_path(file)
return false unless path

View file

@ -24,9 +24,16 @@ end
Given /^the Server is running at "([^\"]*)"$/ do |app_path|
step %Q{a project at "#{app_path}"}
root_dir = File.join(PROJECT_ROOT_PATH, "fixtures", app_path)
if File.exists?(File.join(root_dir, "source"))
ENV["MM_SOURCE"] = "source"
else
ENV["MM_SOURCE"] = ""
end
initialize_commands = @initialize_commands || []
initialize_commands.unshift lambda {
set :root, File.join(PROJECT_ROOT_PATH, "fixtures", app_path)
set :root, root_dir
set :environment, @current_env || :development
set :show_exceptions, false
}