Run static directories, woot
This commit is contained in:
parent
0b7e7582d5
commit
2b3354472c
|
@ -20,6 +20,8 @@
|
||||||
* Support for placekitten.com
|
* Support for placekitten.com
|
||||||
* Added MM_ROOT environmental variable
|
* Added MM_ROOT environmental variable
|
||||||
* activating extensions can now take an options hash
|
* 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
|
2.0.14
|
||||||
====
|
====
|
||||||
|
|
|
@ -14,17 +14,17 @@ def locate_middleman_root!(cwd = Pathname.new(Dir.pwd))
|
||||||
locate_middleman_root!(cwd.parent)
|
locate_middleman_root!(cwd.parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
if !ENV['MM_ROOT'] && found_path = locate_middleman_root!
|
if !ENV["MM_ROOT"] && found_path = locate_middleman_root!
|
||||||
ENV['MM_ROOT'] = found_path
|
ENV["MM_ROOT"] = found_path
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENV['MM_ROOT']
|
if ENV["MM_ROOT"]
|
||||||
# Set up gems listed in the Gemfile.
|
# 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'])
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'middleman'
|
require 'middleman'
|
||||||
Dir.chdir(ENV['MM_ROOT'] || Dir.pwd) do
|
Dir.chdir(ENV["MM_ROOT"] || Dir.pwd) do
|
||||||
Middleman::Cli::Base.start
|
Middleman::Cli::Base.start
|
||||||
end
|
end
|
12
features/ignore_already_minified.features
Normal file
12
features/ignore_already_minified.features
Normal 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
|
6
features/static_server.feature
Normal file
6
features/static_server.feature
Normal 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"
|
2
fixtures/already-minified-app/config.rb
Normal file
2
fixtures/already-minified-app/config.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
activate :minify_javascript
|
||||||
|
activate :minify_css
|
10
fixtures/already-minified-app/source/javascripts/test.min.js
vendored
Normal file
10
fixtures/already-minified-app/source/javascripts/test.min.js
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
var numbers = [ 1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
8,
|
||||||
|
9,
|
||||||
|
10 ];
|
10
fixtures/already-minified-app/source/stylesheets/test.min.css
vendored
Normal file
10
fixtures/already-minified-app/source/stylesheets/test.min.css
vendored
Normal 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; }
|
1
fixtures/plain-app/index.html
Normal file
1
fixtures/plain-app/index.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
I am index
|
|
@ -159,7 +159,7 @@ class Middleman::Base
|
||||||
|
|
||||||
# Root project directory (overwritten in middleman build/server)
|
# Root project directory (overwritten in middleman build/server)
|
||||||
# @return [String]
|
# @return [String]
|
||||||
set :root, ENV['MM_ROOT'] || Dir.pwd
|
set :root, ENV["MM_ROOT"] || Dir.pwd
|
||||||
|
|
||||||
# Name of the source directory
|
# Name of the source directory
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
@ -301,7 +301,10 @@ class Middleman::Base
|
||||||
instance_exec(&block) if block_given?
|
instance_exec(&block) if block_given?
|
||||||
|
|
||||||
# Build expanded source path once paths have been parsed
|
# 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
|
super
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,6 @@ module Middleman::Cli
|
||||||
method_option :host,
|
method_option :host,
|
||||||
:type => :string,
|
:type => :string,
|
||||||
:aliases => "-h",
|
:aliases => "-h",
|
||||||
# :required => true,
|
|
||||||
:default => "0.0.0.0",
|
:default => "0.0.0.0",
|
||||||
:desc => "Bind to HOST address"
|
:desc => "Bind to HOST address"
|
||||||
method_option "port",
|
method_option "port",
|
||||||
|
@ -25,8 +24,10 @@ module Middleman::Cli
|
||||||
:desc => 'Print debug messages'
|
:desc => 'Print debug messages'
|
||||||
def server
|
def server
|
||||||
if !ENV["MM_ROOT"]
|
if !ENV["MM_ROOT"]
|
||||||
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
puts "== Warning: Could not find a Middleman project config.rb"
|
||||||
exit(1)
|
puts "== Treating directory as a static site to be served"
|
||||||
|
ENV["MM_ROOT"] = Dir.pwd
|
||||||
|
ENV["MM_SOURCE"] = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
|
|
|
@ -25,7 +25,10 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
super
|
super
|
||||||
|
|
||||||
exts = frontmatter_extensions.join("|").gsub(".", "\.")
|
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|
|
file_changed matcher do |file|
|
||||||
frontmatter_extension.touch_file(file)
|
frontmatter_extension.touch_file(file)
|
||||||
|
|
|
@ -28,7 +28,10 @@ module Middleman::CoreExtensions::Rendering
|
||||||
def initialize
|
def initialize
|
||||||
super
|
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)
|
path = File.expand_path(file, root)
|
||||||
cache.remove(:raw_template, path)
|
cache.remove(:raw_template, path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,11 +28,14 @@ module Middleman::CoreExtensions::Sitemap
|
||||||
def initialize
|
def initialize
|
||||||
super
|
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)
|
sitemap.touch_file(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
file_deleted %r{^source/} do |file|
|
file_deleted sitemap_regex do |file|
|
||||||
sitemap.remove_file(file)
|
sitemap.remove_file(file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,6 @@ module Middleman::Sitemap
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
@source = File.expand_path(@app.source, @app.root)
|
|
||||||
@pages = {}
|
@pages = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -88,7 +87,7 @@ module Middleman::Sitemap
|
||||||
def file_to_path(file)
|
def file_to_path(file)
|
||||||
file = File.expand_path(file, @app.root)
|
file = File.expand_path(file, @app.root)
|
||||||
|
|
||||||
prefix = @source + "/"
|
prefix = @app.source_dir.sub(/\/$/, "") + "/"
|
||||||
return false unless file.include?(prefix)
|
return false unless file.include?(prefix)
|
||||||
|
|
||||||
path = file.sub(prefix, "")
|
path = file.sub(prefix, "")
|
||||||
|
@ -98,7 +97,7 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
def touch_file(file)
|
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)
|
path = file_to_path(file)
|
||||||
return false unless path
|
return false unless path
|
||||||
|
|
|
@ -24,9 +24,16 @@ end
|
||||||
Given /^the Server is running at "([^\"]*)"$/ do |app_path|
|
Given /^the Server is running at "([^\"]*)"$/ do |app_path|
|
||||||
step %Q{a project at "#{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 = @initialize_commands || []
|
||||||
initialize_commands.unshift lambda {
|
initialize_commands.unshift lambda {
|
||||||
set :root, File.join(PROJECT_ROOT_PATH, "fixtures", app_path)
|
set :root, root_dir
|
||||||
set :environment, @current_env || :development
|
set :environment, @current_env || :development
|
||||||
set :show_exceptions, false
|
set :show_exceptions, false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue