First pass at combining views and public folders

This commit is contained in:
Thomas Reynolds 2011-05-30 22:33:11 -07:00
parent ba2cbb0ceb
commit 993be281c7
62 changed files with 57 additions and 91 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ pkg
.tmp
Gemfile.lock
docs
.rvmrc

4
CHANGELOG Normal file
View file

@ -0,0 +1,4 @@
2.0.0
=====
- Combine views/ and public/ into a single source/ folder.

View file

@ -1,22 +1,5 @@
#!/usr/bin/env ruby
# Non-blocking site rebuilding
trap("TSTP") do
fork do
require "open3"
first_run = true
Open3.popen3(%Q{cd "#{Dir.pwd}" && #{File.join(File.dirname(__FILE__), "mm-build")} | grep FORCED}) do |stdin, stdout, stderr|
puts "\n== Building the site..."
stdout.readlines.each do |l|
puts "== Updated:" if first_run
puts " " + l.split("[FORCED]").last.chomp
first_run = false
end
puts "== Build complete"
end
end
end if Signal.list.has_key? "TSTP"
require 'optparse'
# Require Middleman
@ -25,6 +8,7 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
options = { :Port => 4567, :AccessLog => [] }
# TODO: Switch to Thor
OptionParser.new { |opts|
opts.banner = "Usage: mm-server [rack options]"
opts.separator ""
@ -51,10 +35,9 @@ ENV['RACK_ENV'] = env
while (!@found_root && (@path_parts.length > 0))
@current_path = File.join(*@path_parts)
public_folder = File.join(@current_path, "public")
views_folder = File.join(@current_path, "views")
source_folder = File.join(@current_path, "source")
if File.exists?(public_folder) && File.exists?(views_folder)
if File.exists?(source_folder)
@found_root = true
next
end
@ -67,20 +50,25 @@ if !@found_root
exit
end
# If the old init.rb exists, use it, but issue warning
# If the old init.rb exists, issue warning
old_config = File.join(@current_path, "init.rb")
if File.exists? old_config
$stderr.puts "== Error: The init.rb file (deprecated) needs to be be renamed to config.rb"
exit
end
# If the old directories exists, use it, but issue warning
old_views = File.join(@current_path, "views")
old_public = File.join(@current_path, "public")
if File.exists?(old_views) || File.exists?(old_public)
$stderr.puts "== Error: The views and public folders are have been combined. Create a new 'source' folder, add the contents of views and public to it and then remove the empty views and public folders."
exit
end
# require 'shotgun'
# config = File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'config.ru')
# app = Shotgun.new(config, &lambda { |inner_app| Middleman::Server })
Middleman::Server.root = @current_path
app = Middleman::Server.new
# TODO: Remove this
require 'rubygems'
unless defined?(JRUBY_VERSION)

View file

@ -27,25 +27,3 @@ Then /^"([^"]*)" should not exist$/ do |target_file|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build", target_file)
File.exists?(target).should be_false
end
# require 'fileutils'
#
# describe "Builder" do
# def project_file(*parts)
# File.expand_path(File.join(File.dirname(__FILE__), "..", *parts))
# end
#
# before :all do
# @root_dir = project_file("spec", "fixtures", "sample")
# end
#
# before :each do
# build_cmd = project_file("bin", "mm-build")
# `cd #{@root_dir} && MM_DIR="#{@root_dir}" #{build_cmd}`
# end
#
# after :each do
# FileUtils.rm_rf(File.join(@root_dir, "build"))
# end

View file

@ -19,7 +19,7 @@ end
Then /^empty directories should exist at "([^\"]*)"$/ do |dirname|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname)
%w(views/stylesheets public/stylesheets public/javascripts public/images).each do |d|
%w(source/stylesheets source/javascripts source/images).each do |d|
File.exists?("#{target}/#{d}").should be_true
end
end

View file

Before

Width:  |  Height:  |  Size: 43 B

After

Width:  |  Height:  |  Size: 43 B

View file

@ -0,0 +1 @@
// Success

View file

@ -33,6 +33,7 @@ module Middleman
super
Middleman::Server.new
if options.has_key?("relative") && options["relative"]
Middleman::Server.activate :relative_assets
end
@ -41,17 +42,12 @@ module Middleman
def source_paths
@source_paths ||= [
Middleman::Server.public,
Middleman::Server.views
Middleman::Server.root
]
end
def build_static_files
action Directory.new(self, Middleman::Server.public, :public, Middleman::Server.build_dir, { :force => true })
end
def build_dynamic_files
action Directory.new(self, Middleman::Server.views, :dynamic, Middleman::Server.build_dir, { :force => true })
def build_all_files
action Directory.new(self, Middleman::Server.views, Middleman::Server.build_dir, { :force => true })
end
@@hooks = {}
@ -69,8 +65,7 @@ module Middleman
class Directory < ::Thor::Actions::EmptyDirectory
attr_reader :source
def initialize(base, source, mode, destination=nil, config={}, &block)
@mode = mode
def initialize(base, source, destination=nil, config={}, &block)
@source = File.expand_path(base.find_in_source_paths(source.to_s))
@block = block
super(base, destination, { :recursive => true }.merge(config))
@ -96,22 +91,20 @@ module Middleman
end
next if file_source.include?('layout')
# Skip partials prefixed with an underscore
next unless file_source.split('/').select { |p| p[0,1] == '_' }.empty?
file_extension = File.extname(file_source)
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
file_destination.gsub!('/./', '/')
handled_by_tilt = ::Tilt.mappings.keys.include?(file_extension.gsub(/^\./, ""))
if handled_by_tilt || (file_extension == ".js")
new_file_extension = (file_extension == ".js") ? ".js" : ""
next if @mode == :dynamic && file_source.split('/').last.split('.').length < 3
file_destination.gsub!(file_extension, new_file_extension)
destination = base.tilt_template(file_source, file_destination, config, &@block)
else
destination = base.copy_file(file_source, file_destination, config, &@block)
handled_by_tilt = ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, ""))
if handled_by_tilt
file_destination.gsub!(file_extension, "")
end
destination = base.tilt_template(file_source, file_destination, config, &@block)
end
end

View file

@ -15,8 +15,6 @@ module Middleman
set :logging, false
set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
# Import padrino helper methods
# Middleman-specific options
set :index_file, "index.html" # What file responds to folder requests
# Such as the homepage (/) or subfolders (/about/)
@ -30,9 +28,14 @@ module Middleman
set :build_dir, "build" # Which folder are builds output to
set :http_prefix, nil # During build, add a prefix for absolute paths
set :static, false
set :views, "source"
# Disable Padrino cache buster until explicitly enabled
set :asset_stamp, false
# Use Padrino Helpers
register Padrino::Helpers
set :asset_stamp, false # Disable Padrino cache buster until explicitly enabled
# Activate custom features
register Middleman::Features
@ -140,11 +143,12 @@ module Middleman
# Normalize the path and add index if we're looking at a directory
path = self.class.path_to_index(request.path)
static_path = File.join(Middleman::Server.public, path)
# if File.exists? static_path
# send_file static_path
# return
# end
extensionless_path, template_engine = resolve_template(path)
if !::Tilt.mappings.has_key?(template_engine.to_s)
send_file File.join(Middleman::Server.views, path)
return
end
old_layout = settings.current_layout
settings.layout(options[:layout]) if !options[:layout].nil?
@ -183,9 +187,6 @@ class Middleman::Server
set :app_file, File.expand_path(local_config)
end
use ::Rack::ConditionalGet
use ::Rack::Static, :urls => ["/#{self.images_dir}"], :root => "public"
@@run_after_features.each { |block| class_eval(&block) }
super

View file

@ -6,10 +6,10 @@ class Middleman::Templates::Default < Middleman::Templates::Base
def build_scaffold
template "config.tt", File.join(location, "config.rb")
template "config.ru", File.join(location, "config.ru")
directory "views", File.join(location, "views")
empty_directory File.join(location, "public", options[:css_dir])
empty_directory File.join(location, "public", options[:js_dir])
empty_directory File.join(location, "public", options[:images_dir])
directory "source", File.join(location, "source")
empty_directory File.join(location, "source", options[:css_dir])
empty_directory File.join(location, "source", options[:js_dir])
empty_directory File.join(location, "source", options[:images_dir])
end
end

View file

@ -5,8 +5,8 @@ class Middleman::Templates::Html5 < Middleman::Templates::Base
def build_scaffold
template "config.tt", File.join(location, "config.rb")
directory "public", File.join(location, "public")
empty_directory File.join(location, "views")
directory "source", File.join(location, "source")
empty_directory File.join(location, "source")
end
end

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -6,10 +6,10 @@ class Middleman::Templates::Xhtml < Middleman::Templates::Base
def build_scaffold
template "config.tt", File.join(location, "config.rb")
template "config.ru", File.join(location, "config.ru")
directory "views", File.join(location, "views")
empty_directory File.join(location, "public", options[:css_dir])
empty_directory File.join(location, "public", options[:js_dir])
empty_directory File.join(location, "public", options[:images_dir])
directory "source", File.join(location, "source")
empty_directory File.join(location, "source", options[:css_dir])
empty_directory File.join(location, "source", options[:js_dir])
empty_directory File.join(location, "source", options[:images_dir])
end
end

View file

@ -1,3 +1,3 @@
module Middleman
VERSION = "1.2.7"
VERSION = "2.0.0.beta1"
end