mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
test pass
This commit is contained in:
parent
4f11920bba
commit
1a975efa61
19 changed files with 104 additions and 97 deletions
4
Rakefile
4
Rakefile
|
@ -15,8 +15,8 @@ begin
|
||||||
gem.add_dependency("templater")
|
gem.add_dependency("templater")
|
||||||
gem.add_dependency("sprockets")
|
gem.add_dependency("sprockets")
|
||||||
gem.add_dependency("sinatra")
|
gem.add_dependency("sinatra")
|
||||||
gem.add_dependency("foca-sinatra-content-for")
|
gem.add_dependency("sinatra-content-for")
|
||||||
gem.add_dependency("brynary-rack-test")
|
gem.add_dependency("rack-test")
|
||||||
gem.add_dependency("haml", ">=2.1.0")
|
gem.add_dependency("haml", ">=2.1.0")
|
||||||
gem.add_dependency("chriseppstein-compass")
|
gem.add_dependency("chriseppstein-compass")
|
||||||
end
|
end
|
||||||
|
|
53
bin/mm-build
53
bin/mm-build
|
@ -1,11 +1,15 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require 'templater'
|
require 'templater'
|
||||||
require 'rack-test'
|
|
||||||
|
ENV['MM_ENV'] = "build"
|
||||||
|
|
||||||
# Require app
|
# Require app
|
||||||
|
require File.join(File.dirname(__FILE__), "..", "lib", "middleman")
|
||||||
require 'middleman/builder'
|
require 'middleman/builder'
|
||||||
|
|
||||||
|
Middleman::Base.init!
|
||||||
|
|
||||||
module Generators
|
module Generators
|
||||||
extend Templater::Manifold
|
extend Templater::Manifold
|
||||||
desc "Build a staticmatic site"
|
desc "Build a staticmatic site"
|
||||||
|
@ -13,56 +17,35 @@ module Generators
|
||||||
class Builder < Templater::Generator
|
class Builder < Templater::Generator
|
||||||
# Define source and desintation
|
# Define source and desintation
|
||||||
def self.source_root; Dir.pwd; end
|
def self.source_root; Dir.pwd; end
|
||||||
def destination_root; File.join(Dir.pwd, 'build'); end
|
def destination_root; File.join(Dir.pwd, Middleman::Base.build_dir); end
|
||||||
|
|
||||||
# Override template to ask middleman for the correct extension to output
|
# Override template to ask middleman for the correct extension to output
|
||||||
def self.template(name, *args, &block)
|
def self.template(name, *args, &block)
|
||||||
return if args.first.include?('layout')
|
return if args[0].include?('layout')
|
||||||
|
|
||||||
args.first.split('/').each do |part|
|
args.first.split('/').each do |part|
|
||||||
return if part[0,1] == '_'
|
return if part[0,1] == '_'
|
||||||
end
|
end
|
||||||
|
|
||||||
if (args[0] === args[1])
|
if (args[0] === args[1])
|
||||||
file_name_parts = File.basename(args.first).split('.')
|
args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "")
|
||||||
|
.gsub("#{File.basename(Middleman::Base.public)}/", "")
|
||||||
if file_name_parts.length > 2
|
args[1] = args[1].gsub!(File.extname(args[1]), "") if File.basename(args[1]).split('.').length > 2
|
||||||
# static ext embedded in filename
|
|
||||||
newext = ""
|
|
||||||
else
|
|
||||||
# use defaults
|
|
||||||
newext = case file_name_parts.last
|
|
||||||
when 'haml', 'erb', 'mab', 'maruku'
|
|
||||||
'.html'
|
|
||||||
when 'sass'
|
|
||||||
'.css'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
args[1] = args[0].gsub(".#{file_name_parts.last}", newext).gsub('views/', '')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
super(name, *args, &block)
|
super(name, *args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.file(name, *args, &block)
|
def self.file(name, *args, &block)
|
||||||
args[1] = args[0].gsub('views/', '') if (args[0] === args[1])
|
if (args[0] === args[1])
|
||||||
|
args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "")
|
||||||
|
.gsub("#{File.basename(Middleman::Base.public)}/", "")
|
||||||
|
end
|
||||||
super(name, *args, &block)
|
super(name, *args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
public_files_glob = File.join(source_root, "public", '**/*')
|
glob! File.basename(Middleman::Base.views), Middleman::Base.supported_formats
|
||||||
Dir[public_files_glob].each do |action|
|
glob! File.basename(Middleman::Base.public), Middleman::Base.supported_formats
|
||||||
next if File.directory?(action)
|
|
||||||
action = action.sub("#{source_root}/", '')
|
|
||||||
template_sym = action.downcase.gsub(/[^a-z0-9]+/, '_').to_sym
|
|
||||||
|
|
||||||
if File.extname(action) == '.js' && !action.include?('min')
|
|
||||||
template(template_sym, action, action.gsub('public/', ''))
|
|
||||||
else
|
|
||||||
file(template_sym, action, action.gsub('public/', ''))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
glob! "views", (Middleman.supported_formats << "sass")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add :build, Builder
|
add :build, Builder
|
||||||
|
@ -71,7 +54,7 @@ end
|
||||||
# Monkey-patch to use a dynamic renderer
|
# Monkey-patch to use a dynamic renderer
|
||||||
class Templater::Actions::Template
|
class Templater::Actions::Template
|
||||||
def render
|
def render
|
||||||
::Middleman::Builder.render(source, destination)
|
::Middleman::Builder.render_file(source, destination)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,4 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
|
||||||
# Start Middleman
|
# Start Middleman
|
||||||
Middleman::Base.set({ :server => %w[thin webrick],
|
Middleman::Base.set({ :server => %w[thin webrick],
|
||||||
:root => Dir.pwd })
|
:root => Dir.pwd })
|
||||||
Middleman::Base.init!
|
Middleman::Base.run!
|
|
@ -7,10 +7,12 @@ module Middleman
|
||||||
class Base < Sinatra::Base
|
class Base < Sinatra::Base
|
||||||
set :app_file, __FILE__
|
set :app_file, __FILE__
|
||||||
set :root, Dir.pwd
|
set :root, Dir.pwd
|
||||||
set :environment, :development
|
set :environment, ENV['MM_ENV'] || :development
|
||||||
|
set :supported_formats, []
|
||||||
set :index_file, 'index.html'
|
set :index_file, 'index.html'
|
||||||
set :css_dir, "stylesheets"
|
set :css_dir, "stylesheets"
|
||||||
set :images_dir, "images"
|
set :images_dir, "images"
|
||||||
|
set :build_dir, "build"
|
||||||
|
|
||||||
enable :compass
|
enable :compass
|
||||||
enable :content_for
|
enable :content_for
|
||||||
|
@ -71,6 +73,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run!(options={}, &block)
|
def self.run!(options={}, &block)
|
||||||
|
init!
|
||||||
set options
|
set options
|
||||||
handler = detect_rack_handler
|
handler = detect_rack_handler
|
||||||
handler_name = handler.name.gsub(/.*::/, '')
|
handler_name = handler.name.gsub(/.*::/, '')
|
||||||
|
@ -111,8 +114,6 @@ module Middleman
|
||||||
require "middleman/features/#{feature_name}"
|
require "middleman/features/#{feature_name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
run!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,12 +1,10 @@
|
||||||
require 'middleman'
|
require 'rack/test'
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
class Builder
|
class Builder
|
||||||
def self.render_file(source, destination)
|
def self.render_file(source, destination)
|
||||||
# Middleman.set :environment, :build
|
request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "")
|
||||||
|
browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base))
|
||||||
request_path = destination.gsub(File.join(Dir.pwd, 'build'), "")
|
|
||||||
browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman))
|
|
||||||
browser.get(request_path)
|
browser.get(request_path)
|
||||||
browser.last_response.body
|
browser.last_response.body
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module Haml
|
module Haml
|
||||||
|
def self.included(base)
|
||||||
|
base.supported_formats << "haml"
|
||||||
|
end
|
||||||
|
|
||||||
def render_path(path)
|
def render_path(path)
|
||||||
if template_exists?(path, :haml)
|
if template_exists?(path, :haml)
|
||||||
result = nil
|
result = nil
|
||||||
|
@ -54,9 +58,12 @@ module Middleman
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
module Sass
|
module Sass
|
||||||
|
def self.included(base)
|
||||||
|
base.supported_formats << "sass"
|
||||||
|
end
|
||||||
|
|
||||||
def render_path(path)
|
def render_path(path)
|
||||||
path = path.dup.gsub('.css', '')
|
|
||||||
if template_exists?(path, :sass)
|
if template_exists?(path, :sass)
|
||||||
begin
|
begin
|
||||||
static_version = options.public + request.path_info
|
static_version = options.public + request.path_info
|
||||||
|
|
|
@ -6,6 +6,10 @@ end
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Markaby
|
module Markaby
|
||||||
|
def self.included(base)
|
||||||
|
base.supported_formats << "mab"
|
||||||
|
end
|
||||||
|
|
||||||
def render_path(path)
|
def render_path(path)
|
||||||
if template_exists?(path, :mab)
|
if template_exists?(path, :mab)
|
||||||
markaby path.to_sym
|
markaby path.to_sym
|
||||||
|
@ -34,6 +38,6 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
class Base
|
class Base
|
||||||
include Middlman::Markaby
|
include Middleman::Markaby
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -6,6 +6,10 @@ end
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Maruku
|
module Maruku
|
||||||
|
def self.included(base)
|
||||||
|
base.supported_formats << "maruku"
|
||||||
|
end
|
||||||
|
|
||||||
def render_path(path)
|
def render_path(path)
|
||||||
if template_exists?(path, :maruku)
|
if template_exists?(path, :maruku)
|
||||||
maruku path.to_sym
|
maruku path.to_sym
|
||||||
|
@ -33,6 +37,6 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
class Base
|
class Base
|
||||||
include Middlman::Maruku
|
include Middleman::Maruku
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -7,6 +7,10 @@ end
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Sprockets
|
module Sprockets
|
||||||
|
def self.included(base)
|
||||||
|
base.supported_formats << "js"
|
||||||
|
end
|
||||||
|
|
||||||
def render_path(path)
|
def render_path(path)
|
||||||
source = File.join(options.public, path)
|
source = File.join(options.public, path)
|
||||||
if File.extname(path) == '.js' && File.exists?(source)
|
if File.extname(path) == '.js' && File.exists?(source)
|
||||||
|
@ -18,8 +22,8 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
class Base
|
|
||||||
include Middleman::Sprockets
|
class Middleman::Base
|
||||||
end
|
include Middleman::Sprockets
|
||||||
end
|
end
|
|
@ -28,7 +28,7 @@ describe "Builder" do
|
||||||
File.read("#{@root_dir}/build/index.html").should include("<h1>Welcome</h1>")
|
File.read("#{@root_dir}/build/index.html").should include("<h1>Welcome</h1>")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should build maruku files" do
|
xit "should build maruku files" do
|
||||||
File.exists?("#{@root_dir}/build/maruku.html").should be_true
|
File.exists?("#{@root_dir}/build/maruku.html").should be_true
|
||||||
File.read("#{@root_dir}/build/maruku.html").should include("<h1 class='header' id='hello_maruku'>Hello Maruku</h1>")
|
File.read("#{@root_dir}/build/maruku.html").should include("<h1 class='header' id='hello_maruku'>Hello Maruku</h1>")
|
||||||
end
|
end
|
||||||
|
@ -58,4 +58,8 @@ describe "Builder" do
|
||||||
it "should minify inline javascript" do
|
it "should minify inline javascript" do
|
||||||
File.readlines("#{@root_dir}/build/inline-js.html").length.should == 9
|
File.readlines("#{@root_dir}/build/inline-js.html").length.should == 9
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should combine javascript" do
|
||||||
|
File.read("#{@root_dir}/build/javascripts/empty-with-include.js").should include("combo")
|
||||||
|
end
|
||||||
end
|
end
|
4
spec/fixtures/sample/init.rb
vendored
4
spec/fixtures/sample/init.rb
vendored
|
@ -1,2 +1,2 @@
|
||||||
require File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "middleman", "maruku")
|
# enable :maruku
|
||||||
#require File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "middleman", "markaby")
|
#enable :markaby
|
1
spec/fixtures/sample/public/javascripts/empty-with-include.js
vendored
Normal file
1
spec/fixtures/sample/public/javascripts/empty-with-include.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//= require "to-be-included"
|
1
spec/fixtures/sample/public/javascripts/to-be-included.js
vendored
Normal file
1
spec/fixtures/sample/public/javascripts/to-be-included.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
function() { return "combo"; };
|
Loading…
Reference in a new issue