initial import

This commit is contained in:
tdreyno 2009-07-27 16:25:32 -07:00
parent 493089d4b0
commit 321dc9c0ce
19 changed files with 278 additions and 4 deletions

View file

@ -1,4 +1,4 @@
Copyright (c) 2009 tdreyno Copyright (c) 2009 Thomas Reynolds
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the

View file

@ -1,7 +1,7 @@
= middleman = middleman
Description goes here. The Middleman is ever-vigilant against tag-soup, unreadable CSS and repetition. He stands-watch over your Haml and Sass producing only the cleanest and efficient markup.
== Copyright == Copyright
Copyright (c) 2009 tdreyno. See LICENSE for details. Copyright (c) 2009 Thomas Reynolds. See LICENSE for details.

View file

@ -8,9 +8,14 @@ begin
gem.summary = %Q{A static site generator utilizing Haml and Sass} gem.summary = %Q{A static site generator utilizing Haml and Sass}
gem.email = "tdreyno@gmail.com" gem.email = "tdreyno@gmail.com"
gem.homepage = "http://github.com/tdreyno/middleman" gem.homepage = "http://github.com/tdreyno/middleman"
gem.authors = ["tdreyno"] gem.authors = ["Thomas Reynolds"]
gem.rubyforge_project = "middleman" gem.rubyforge_project = "middleman"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
gem.executables = %w(sm-init sm-build sm-server)
gem.add_dependency("templater")
gem.add_dependency("sinatra")
gem.add_dependency("haml", ">=2.1.0")
gem.add_dependency("chriseppstein-compass")
end end
Jeweler::RubyforgeTasks.new Jeweler::RubyforgeTasks.new

68
bin/mm-build Executable file
View file

@ -0,0 +1,68 @@
#!/usr/bin/env ruby
# Require app
require 'rubygems'
require 'templater'
require 'open-uri'
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
module Generators
extend Templater::Manifold
desc "Build a staticmatic site"
class Builder < Templater::Generator
# Define source and desintation
def self.source_root; Dir.pwd; end
def destination_root; File.join(Dir.pwd, 'build'); end
# Override template to ask staticmatic for the correct extension to output
def self.template(name, *args, &block)
return if args.first.include?('layout')
return if File.basename(args.first)[0,1] == '_'
if (args[0] === args[1])
newext = case File.extname(args.first)
when '.haml'
'.html'
when '.sass'
'.css'
else
File.extname(args.first)
end
args[1] = args[0].gsub(File.extname(args.first), newext).gsub('views/', '')
end
super(name, *args, &block)
end
def self.file(name, *args, &block)
args[1] = args[0].gsub('views/', '') if (args[0] === args[1])
super(name, *args, &block)
end
public_files_glob = File.join(source_root, "public", '**/*')
Dir[public_files_glob].each do |action|
next if File.directory?(action)
action = action.sub("#{source_root}/", '')
file(action.downcase.gsub(/[^a-z0-9]+/, '_').to_sym, action, action.gsub('public/', ''))
end
glob! "views", %w(haml sass)
end
add :build, Builder
end
# Monkey-patch to use a dynamic renderer, not just ERb
class Templater::Actions::Template
def render
return ""
#request_path = destination.gsub(File.join(Dir.pwd, 'build'), "")
#Rack Handler
end
end
# Start app
#Middleman.run!(:root => Dir.pwd) do
Generators.run_cli(Dir.pwd, 'mm-build', 1, %w(build --force).concat(ARGV))
#end

32
bin/mm-init Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'templater'
module Generators
extend Templater::Manifold
desc "Generator for streamlining staticmatic"
class NewSite < Templater::Generator
desc "Creates a new staticmatic scaffold."
first_argument :location, :required => true, :desc => "Project location"
def destination_root
File.expand_path(location)
end
def self.source_root
File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'template')
end
glob! :views
glob! :public
empty_directory :stylesheets, "public/stylesheets"
empty_directory :javascripts, "public/javascripts"
empty_directory :images, "public/images"
end
add :setup, NewSite
end
Generators.run_cli(Dir.pwd, 'mm-init', 1, %w(setup).concat(ARGV))

7
bin/mm-server Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
# Require Middleman
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
# Start Middleman
Middleman.run!(:root => Dir.pwd)

View file

@ -0,0 +1,63 @@
require 'rubygems'
require 'haml'
require 'compass' #must be loaded before sinatra
require 'sinatra/base'
class Middleman < Sinatra::Base
set :app_file, __FILE__
def self.run!(options={}, &block)
set options
handler = detect_rack_handler
handler_name = handler.name.gsub(/.*::/, '')
puts "== The Middleman is standing watch on port #{port}"
handler.run self, :Host => host, :Port => port do |server|
trap(:INT) do
## Use thins' hard #stop! if available, otherwise just #stop
server.respond_to?(:stop!) ? server.stop! : server.stop
puts "\n== The Middleman has ended his patrol"
end
if block_given?
block.call
## Use thins' hard #stop! if available, otherwise just #stop
server.respond_to?(:stop!) ? server.stop! : server.stop
end
end
rescue Errno::EADDRINUSE => e
puts "== The Middleman is already standing watch on port #{port}!"
end
configure do
Compass.configuration do |config|
config.project_path = Dir.pwd
config.sass_dir = File.join(File.expand_path(self.views), "stylesheets")
config.output_style = :nested
config.images_dir = File.join(File.expand_path(self.public), "images")
config.http_images_path = "/images/"
end
end
def render_haml_or_sass(path)
if path.match /.html$/
haml(path.gsub('.html', '').to_sym)
elsif path.match /.css$/
content_type 'text/css', :charset => 'utf-8'
sass(path.gsub('.css', '').to_sym, Compass.sass_engine_options)
end
end
get /(.*)/ do |path|
path = path.gsub(%r{^/}, '')
path = "index.html" if path == ''
if path.match /.html$/
haml(path.gsub('.html', '').to_sym)
elsif path.match /.css$/
content_type 'text/css', :charset => 'utf-8'
sass(path.gsub('.css', '').to_sym, Compass.sass_engine_options)
else
pass
end
end
end

View file

@ -0,0 +1 @@
%h1 The Middleman is watching.

View file

@ -0,0 +1,6 @@
%html
%head
%title The Middleman!
%body
= yield

View file

@ -0,0 +1 @@
@import compass/reset.sass

44
spec/builder_spec.rb Normal file
View file

@ -0,0 +1,44 @@
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} && #{build_cmd}`
end
after :each do
FileUtils.rm_rf(File.join(@root_dir, "build"))
end
it "should build normal files" do
File.exists?("#{@root_dir}/build/index.html").should be_true
end
it "should build static files" do
File.exists?("#{@root_dir}/build/static.html").should be_true
end
it "should build subdirectory files" do
File.exists?("#{@root_dir}/build/services/index.html").should be_true
end
it "should build sass files" do
File.exists?("#{@root_dir}/build/stylesheets/site.css").should be_true
end
it "should build static css files" do
File.exists?("#{@root_dir}/build/stylesheets/static.css").should be_true
end
it "should not build partial files" do
File.exists?("#{@root_dir}/build/_partial.html").should be_false
end
end

View file

@ -0,0 +1 @@
Static, no code!

View file

@ -0,0 +1,2 @@
body {
font-size: 12px; }

View file

@ -0,0 +1 @@
%p Test

1
spec/fixtures/sample/views/index.haml vendored Normal file
View file

@ -0,0 +1 @@
%h1 Welcome

View file

@ -0,0 +1,6 @@
%html
%head
%link{ :href => "/stylesheets/site.css", :rel => "stylesheet", :type => "text/css" }
%title My Sample Site
%body
= yield

View file

@ -0,0 +1 @@
%h2 Services

View file

@ -0,0 +1 @@
@import compass/reset.sass

34
spec/generator_spec.rb Normal file
View file

@ -0,0 +1,34 @@
require 'fileutils'
describe "Generator" do
def project_file(*parts)
File.expand_path(File.join(File.dirname(__FILE__), "..", *parts))
end
before :all do
@root_dir = project_file("spec", "fixtures", "generator-test")
end
before :each do
init_cmd = project_file("bin", "mm-init")
`cd #{File.dirname(@root_dir)} && #{init_cmd} #{File.basename(@root_dir)}`
end
after :each do
FileUtils.rm_rf(@root_dir)
end
it "should copy template files" do
template_dir = project_file("lib", "template", "**/*")
Dir[template_dir].each do |f|
next if File.directory?(f)
File.exists?("#{@root_dir}/#{f.split('template/')[1]}").should be_true
end
end
it "should create empty directories" do
%w(views/stylesheets public/stylesheets public/javascripts public/images).each do |d|
File.exists?("#{@root_dir}/#{d}").should be_true
end
end
end