Skip to content

Commit

Permalink
get all the tests working with the new binary
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Jul 27, 2011
1 parent 4569d59 commit 2634c41
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 27 deletions.
10 changes: 8 additions & 2 deletions bin/mm
@@ -1,3 +1,9 @@
#!/usr/bin/env ruby
require 'middleman/cli'
Middleman::CLI.start

require "rubygems"

libdir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)

require 'middleman'
Middleman::CLI.start
9 changes: 5 additions & 4 deletions features/step_definitions/builder_steps.rb
@@ -1,15 +1,16 @@
require 'fileutils'
require 'middleman/cli'

Given /^a built test app$/ do
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-build"))
`cd #{target} && MM_DIR="#{target}" #{build_cmd}`
build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm build"))
`cd #{target} && #{build_cmd}`
end

Given /^a built test app with flags "([^"]*)"$/ do |flags|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-build"))
`cd #{target} && MM_DIR="#{target}" #{build_cmd} #{flags}`
build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm build"))
`cd #{target} && #{build_cmd} #{flags}`
end

Given /^cleanup built test app$/ do
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/generator_steps.rb
Expand Up @@ -2,7 +2,7 @@

Given /^generated directory at "([^\"]*)"$/ do |dirname|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname)
init_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-init"))
init_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm init"))
`cd #{File.dirname(target)} && #{init_cmd} #{File.basename(target)}`
end

Expand Down
1 change: 0 additions & 1 deletion features/support/env.rb
@@ -1,4 +1,3 @@
root_path = File.dirname(File.dirname(File.dirname(__FILE__)))
ENV["MM_DIR"] = File.join(root_path, "fixtures", "test-app")
require File.join(root_path, 'lib', 'middleman')
require "rack/test"
10 changes: 6 additions & 4 deletions lib/middleman.rb
Expand Up @@ -8,10 +8,10 @@
#
# To accomplish its goals, Middleman supports provides access to:
#
#### Command-line tools:
# * **mm-init**: A tool for creating to new static sites.
# * **mm-server**: A tool for rapidly developing your static site.
# * **mm-build**: A tool for exporting your site into optimized HTML, CSS & JS.
#### Command-line tool:
# * **mm init**: A tool for creating to new static sites.
# * **mm server**: A tool for rapidly developing your static site.
# * **mm build**: A tool for exporting your site into optimized HTML, CSS & JS.
#
#### Tons of templating languages including:
# * ERB (.erb)
Expand Down Expand Up @@ -63,6 +63,8 @@ module Middleman
# Auto-load modules on-demand
autoload :Base, "middleman/base"
autoload :Builder, "middleman/builder"
autoload :CLI, "middleman/cli"
autoload :Templates, "middleman/templates"
autoload :Guard, "middleman/guard"

# Custom Renderers
Expand Down
2 changes: 1 addition & 1 deletion lib/middleman/base.rb
Expand Up @@ -6,7 +6,7 @@ def registered(app)

# Basic Sinatra config
app.set :app_file, __FILE__
app.set :root, ENV["MM_DIR"] || Dir.pwd
app.set :root, Dir.pwd
app.set :sessions, false
app.set :logging, false
app.set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
Expand Down
1 change: 1 addition & 0 deletions lib/middleman/builder.rb
Expand Up @@ -3,6 +3,7 @@
require 'rack/test'

SHARED_SERVER = Middleman.server
SHARED_SERVER.set :environment, :build

module Middleman
module ThorActions
Expand Down
34 changes: 21 additions & 13 deletions lib/middleman/cli.rb
@@ -1,6 +1,4 @@
require 'thor'
require 'middleman'
require "middleman/templates"

module Middleman
class CLI < Thor
Expand All @@ -11,8 +9,7 @@ class CLI < Thor
class_option "help", :type => :boolean, :default => false, :aliases => "-h"
def initialize(*)
super
config_check
help_check
help_check if options[:help]
end

desc "init NAME", "Create new Middleman project directory NAME"
Expand All @@ -23,31 +20,42 @@ def initialize(*)
method_option "images_dir", :default => "images", :desc => 'The path to the image files'
def init(name)
key = options[:template].to_sym
key = :default unless Middleman::Templates.registered_templates.has_key?(key)

Middleman::Templates.registered_templates[key].start
unless Middleman::Templates.registered_templates.has_key?(key)
key = :default
end

thor_group = Middleman::Templates.registered_templates[key]
thor_group.new([name], options).invoke_all
end

desc "server [-p 4567] [-e development]", "Starts the Middleman preview server"
method_option "environment", :aliases => "-e", :default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development', :desc => "The environment Middleman will run under"
method_option "port", :aliases => "-p", :default => "4567", :desc => "The port Middleman will listen on"
method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on"
method_option "livereload", :default => false, :type => :boolean, :desc => "Whether to enable Livereload or not"
method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on"
def server
ENV['RACK_ENV'] = options[:environment]
livereload_options = {:port => options["livereload-port"]} if options["livereload"]
Middleman::Guard.start({:port => options[:port]}, livereload_options)
config_check
if options["livereload"]
livereload_options = {:port => options["livereload-port"]}
end

Middleman::Guard.start({
:port => options[:port],
:environment => options[:environment]
}, livereload_options)
end

desc "build", "Builds the static site for deployment"
method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
def build
ENV['MM_ENV'] = "build"
Middleman::Builder.start
config_check
thor_group = Middleman::Builder.new([], options).invoke_all
end

desc "migrate", "Migrates an older Middleman project to the 2.0 structure"
def migrate
config_check
return if File.exists?("source")
`mv public source`
`cp -R views/* source/`
`rm -rf views`
Expand Down
4 changes: 3 additions & 1 deletion lib/middleman/guard.rb
Expand Up @@ -61,7 +61,9 @@ def server_start
# :Logger => ::WEBrick::Log.new('/dev/null')
}
@server_job = fork do
@server_options[:app] = ::Middleman.server.new
app = ::Middleman.server
app.set :environment, @options[:environment]
@server_options[:app] = app.new
@server_options[:server] = 'thin'
::Rack::Server.new(@server_options).start
end
Expand Down

0 comments on commit 2634c41

Please sign in to comment.