Skip to content

Commit

Permalink
Start getting middleman-more tests passing. About 50% done
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Dec 30, 2011
1 parent c8a134a commit 73913f0
Show file tree
Hide file tree
Showing 97 changed files with 266 additions and 160 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -3,3 +3,7 @@ rvm:
- 1.9.2
- 1.9.3
script: "bundle exec rake test"

branches:
only:
- master
10 changes: 9 additions & 1 deletion Gemfile
Expand Up @@ -7,10 +7,18 @@ group :development do
gem "rspec", "~> 2.7"
gem "rdoc", "~> 3.9"
gem "yard"
end

group :test do
# For actual tests
gem "sinatra"
gem "slim"
gem "coffee-filter", "~> 0.1.1"
gem "liquid", "~> 2.2"
gem "jquery-rails"
gem "bootstrap-rails", "0.0.5"
end

gem "middleman-core", :path => "middleman-core"
# gem "middleman-more", :path => "middleman-more"
gem "middleman-more", :path => "middleman-more"
gem "middleman", :path => "middleman"
20 changes: 19 additions & 1 deletion Rakefile
@@ -1,7 +1,25 @@
require 'rubygems' unless defined?(Gem)
# require 'fileutils' unless defined?(FileUtils)
require 'rake'
require 'yard'
# require File.expand_path("../middleman-core/lib/middleman-core/version.rb", __FILE__)

ROOT = File.expand_path(File.dirname(__FILE__))
GEM_NAME = 'middleman'

middleman_gems = %w(middleman-core middleman-more)

desc "Run tests for all middleman gems"
task :test do
["middleman-core"].each do |g|
middleman_gems.each do |g|
sh "cd #{File.join(ROOT, g)} && bundle exec rake test"
end
end

desc "Run tests for all middleman gems"
task :default => :test

desc "Generate documentation"
task :doc do
YARD::CLI::Yardoc.new.run
end
18 changes: 8 additions & 10 deletions gem_rake_helper.rb
Expand Up @@ -5,19 +5,17 @@
require 'yard'

# Skip the releasing tag
# class Bundler::GemHelper
# def release_gem
# guard_clean
# guard_already_tagged
# built_gem_path = build_gem
# rubygem_push(built_gem_path)
# end
# end
class Bundler::GemHelper
def release_gem
guard_clean
guard_already_tagged
built_gem_path = build_gem
rubygem_push(built_gem_path)
end
end

Cucumber::Rake::Task.new(:test, 'Run features that should pass') do |t|
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
end

YARD::Rake::YardocTask.new

task :default => :test
8 changes: 8 additions & 0 deletions middleman-core/bin/middleman
Expand Up @@ -36,6 +36,14 @@ ARGV << "server" if ARGV.length < 1
# Require Middleman
require 'middleman-core'

begin
# Rubygems
require "middleman-more"
rescue LoadError
# Local
require File.expand_path(File.join(File.dirname(File.dirname(libdir)), "middleman-more", "lib", "middleman-more"))
end

# Change directory to the root
Dir.chdir(ENV["MM_ROOT"] || Dir.pwd) do

Expand Down
12 changes: 12 additions & 0 deletions middleman-core/features/asset_host.feature
@@ -0,0 +1,12 @@
Feature: Alternate between multiple asset hosts
In order to speed up page loading

# Scenario: Rendering css with the feature enabled
# Given the Server is running at "asset-host-app"
# When I go to "/stylesheets/asset_host.css"
# Then I should see "http://assets"

Scenario: Rendering html with the feature enabled
Given the Server is running at "asset-host-app"
When I go to "/asset_host.html"
Then I should see "http://assets"
Expand Up @@ -3,14 +3,14 @@ Feature: Automatically detect and insert image dimensions into tags

Scenario: Rendering an image with the feature disabled
Given "automatic_image_sizes" feature is "disabled"
And the Server is running at "test-app"
And the Server is running at "automatic-image-size-app"
When I go to "/auto-image-sizes.html"
Then I should not see "width="
And I should not see "height="

Scenario: Rendering an image with the feature enabled
Given "automatic_image_sizes" feature is "enabled"
And the Server is running at "test-app"
And the Server is running at "automatic-image-size-app"
When I go to "/auto-image-sizes.html"
Then I should see "width="
And I should see "height="
@@ -0,0 +1 @@
<%= image_tag "blank.gif" %>
@@ -0,0 +1 @@
<%= image_tag "blank.gif" %>
31 changes: 23 additions & 8 deletions middleman-core/lib/middleman-core.rb
Expand Up @@ -20,8 +20,8 @@ def camelize

# Top-level Middleman object
module Middleman
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i)
JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i)
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i) unless const_defined?(:WINDOWS)
JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i) unless const_defined?(:JRUBY)

# Auto-load modules on-demand
autoload :Base, "middleman-core/base"
Expand Down Expand Up @@ -85,14 +85,24 @@ module CoreExtensions

module Extensions
# Provide Apache-style index.html files for directories
autoload :DirectoryIndexes, "middleman-core/extensions/directory_indexes"
autoload :DirectoryIndexes, "middleman-core/extensions/directory_indexes"

# Lorem provides a handful of helpful prototyping methods to generate
# words, paragraphs, fake images, names and email addresses.
autoload :Lorem, "middleman-core/extensions/lorem"
autoload :Lorem, "middleman-core/extensions/lorem"

# AutomaticImageSizes inspects the images used in your dynamic templates
# and automatically adds width and height attributes to their HTML
# elements.
autoload :AutomaticImageSizes, "middleman-core/extensions/automatic_image_sizes"

# AssetHost allows you to setup multiple domains to host your static
# assets. Calls to asset paths in dynamic templates will then rotate
# through each of the asset servers to better spread the load.
autoload :AssetHost, "middleman-core/extensions/asset_host"
end

module Extensions
module Extensions
class << self
def registered
@_registered ||= {}
Expand All @@ -117,7 +127,7 @@ def register(name, namespace=nil, version=nil, &block)
end

registered[name.to_sym] = if !passed_version_check
"== #{name} failed version check. Requested #{version}, got #{Middleman::Core::VERSION}"
"== #{name} failed version check. Requested #{version}, got #{Middleman::VERSION}"
elsif block_given?
block
elsif namespace
Expand All @@ -141,7 +151,7 @@ def load(name)
end

# Where to look in gems for extensions to auto-register
EXTENSION_FILE = File.join("lib", "middleman_extension.rb")
EXTENSION_FILE = File.join("lib", "middleman_extension.rb") unless const_defined?(:EXTENSION_FILE)

class << self

Expand Down Expand Up @@ -175,7 +185,7 @@ def load_extensions_in_path
extensions = rubygems_latest_specs.select do |spec|
spec_has_file?(spec, EXTENSION_FILE)
end

extensions.each do |spec|
require spec.name
end
Expand Down Expand Up @@ -222,11 +232,15 @@ def server(&block)
# @param [Hash] options to pass to Rack::Server.new
# @return [Rack::Server]
def start_server(options={})
require "webrick"

opts = {
:Port => options[:port] || 4567,
:Host => options[:host] || "0.0.0.0",
:AccessLog => []
}

opts[:Logger] = WEBrick::Log::new("/dev/null", 7) if !options[:logging]

app_class = options[:app] ||= ::Middleman.server.inst
opts[:app] = app_class
Expand All @@ -235,6 +249,7 @@ def start_server(options={})
# require "thin"
# ::Thin::Logging.silent = !options[:logging]
# opts[:server] = 'thin'
opts[:server] = 'webrick'

server = ::Rack::Server.new(opts)
server.start
Expand Down
8 changes: 6 additions & 2 deletions middleman-core/lib/middleman-core/base.rb
Expand Up @@ -198,7 +198,7 @@ def set(key, value=nil, &block)

# Automatically loaded extensions
# @return [Array<Symbol>]
set :default_extensions, [:lorem]
set :default_extensions, [ :lorem ]

# Default layout name
# @return [String, Symbold]
Expand Down Expand Up @@ -242,6 +242,10 @@ def set(key, value=nil, &block)
Middleman::Extensions::DirectoryIndexes }
Middleman::Extensions.register(:lorem) {
Middleman::Extensions::Lorem }
Middleman::Extensions.register(:automatic_image_sizes) {
Middleman::Extensions::AutomaticImageSizes }
Middleman::Extensions.register(:asset_host) {
Middleman::Extensions::AssetHost }

# Backwards-compatibility with old request.path signature
attr :request
Expand All @@ -258,7 +262,7 @@ def current_path
# @return [void]
def current_path=(path)
@_current_path = path
@request = Thor::CoreExt::HashWithIndifferentAccess.new({ :path => path })
@request = ::Thor::CoreExt::HashWithIndifferentAccess.new({ :path => path })
end

# Initialize the Middleman project
Expand Down
2 changes: 1 addition & 1 deletion middleman-core/lib/middleman-core/cli.rb
Expand Up @@ -11,7 +11,7 @@ class Base < Thor
desc "version", "Show version"
def version
require 'middleman-core/version'
say "Middleman #{Middleman::Core::VERSION}"
say "Middleman #{Middleman::VERSION}"
end

# Override the Thor help method to find help for subtasks
Expand Down
Expand Up @@ -4,11 +4,11 @@ class << self
def registered(app)
app.set :asset_host, false

app.compass_config do |config|
if asset_host.is_a?(Proc)
config.asset_host(&asset_host)
end
end
# app.compass_config do |config|
# if asset_host.is_a?(Proc)
# config.asset_host(&asset_host)
# end
# end

app.send :include, InstanceMethods
end
Expand Down
@@ -1,3 +1,3 @@
source :rubygems

gem "middleman", "~><%= Middleman::Core::VERSION %>"
gem "middleman", "~><%= Middleman::VERSION %>"
16 changes: 11 additions & 5 deletions middleman-core/lib/middleman-core/version.rb
@@ -1,7 +1,13 @@
# Using for version parsing
require "rubygems"

module Middleman
module Core
# Current Version
# @return [String]
VERSION = "3.0.0.alpha.6"
end
# Current Version
# @return [String]
VERSION = "3.0.0.alpha.7" unless const_defined?(:VERSION)

# Parsed version for RubyGems
# @private
# @return [String]
GEM_VERSION = ::Gem::Version.create(VERSION) unless const_defined?(:GEM_VERSION)
end
9 changes: 7 additions & 2 deletions middleman-core/middleman-core.gemspec
Expand Up @@ -4,7 +4,7 @@ require "middleman-core/version"

Gem::Specification.new do |s|
s.name = "middleman-core"
s.version = Middleman::Core::VERSION
s.version = Middleman::VERSION
s.platform = Gem::Platform::RUBY
s.license = "MIT"
s.authors = ["Thomas Reynolds"]
Expand All @@ -18,11 +18,16 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

# Thin
# s.add_dependency("thin", ["~> 1.3.1"])

# Core
s.add_dependency("rack", ["~> 1.3.5"])
s.add_dependency("rack-test", ["~> 0.6.1"])
s.add_dependency("tilt", ["~> 1.3.1"])

# Builder
s.add_dependency("rack-test", ["~> 0.6.1"])

# CLI
s.add_dependency("thor", ["~> 0.14.0"])

Expand Down
3 changes: 0 additions & 3 deletions middleman-more/Gemfile

This file was deleted.

20 changes: 4 additions & 16 deletions middleman-more/Rakefile
@@ -1,17 +1,5 @@
require 'bundler'
Bundler::GemHelper.install_tasks :name => ENV["NAME"] || "middleman"
# coding:utf-8
RAKE_ROOT = __FILE__

require 'cucumber/rake/task'

Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
end

require 'rake/clean'

task :test => ["cucumber"]

desc "Build HTML documentation"
task :doc do
sh 'bundle exec yard'
end
require 'rubygems'
require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
Expand Up @@ -4,9 +4,4 @@ Feature: Alternate between multiple asset hosts
Scenario: Rendering css with the feature enabled
Given the Server is running at "asset-host-app"
When I go to "/stylesheets/asset_host.css"
Then I should see "http://assets"

Scenario: Rendering html with the feature enabled
Given the Server is running at "asset-host-app"
When I go to "/asset_host.html"
Then I should see "http://assets"

0 comments on commit 73913f0

Please sign in to comment.