1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ben Hollis 2012-02-23 21:33:05 -08:00
commit 81c83fafa6
26 changed files with 192 additions and 155 deletions

View file

@ -2,6 +2,7 @@ rvm:
- 1.8.7 - 1.8.7
- 1.9.2 - 1.9.2
- 1.9.3 - 1.9.3
# - jruby
script: "bundle exec rake test" script: "bundle exec rake test"
branches: branches:

View file

@ -25,6 +25,7 @@
* Serve purely static folders directly (without source/ and config.rb) * Serve purely static folders directly (without source/ and config.rb)
* Set ignored files and disable directory_indexes from YAML frontmatter * Set ignored files and disable directory_indexes from YAML frontmatter
* Automatically load helper modules in helpers/ directory * Automatically load helper modules in helpers/ directory
* Add pid for cleanup
2.0.14 2.0.14
==== ====

View file

@ -6,7 +6,7 @@ group :development do
gem "rake", "~> 0.9.2" gem "rake", "~> 0.9.2"
gem "rspec", "~> 2.7" gem "rspec", "~> 2.7"
gem "rdoc", "~> 3.9" gem "rdoc", "~> 3.9"
gem "yard" # gem "yard"
end end
group :test do group :test do
@ -15,8 +15,9 @@ group :test do
gem "slim" gem "slim"
gem "coffee-filter", "~> 0.1.1" gem "coffee-filter", "~> 0.1.1"
gem "liquid", "~> 2.2" gem "liquid", "~> 2.2"
gem "jquery-rails" gem "jquery-rails", "~> 2.0.0"
gem "bootstrap-rails", "0.0.5" # gem "bootstrap-rails", "0.0.5"
# gem "zurb-foundation"
end end
gem "middleman-core", :path => "middleman-core" gem "middleman-core", :path => "middleman-core"

View file

@ -57,9 +57,9 @@ http://rubydoc.info/github/middleman/middleman
# Community # Community
The official community forum is available on Convore at: The official community forum is available at:
https://convore.com/middleman/ http://forum.middlemanapp.com/
# Bug Reports # Bug Reports

View file

@ -1,7 +1,7 @@
require 'rubygems' unless defined?(Gem) require 'rubygems' unless defined?(Gem)
# require 'fileutils' unless defined?(FileUtils) # require 'fileutils' unless defined?(FileUtils)
require 'rake' require 'rake'
require 'yard' # require 'yard'
require File.expand_path("../middleman-core/lib/middleman-core/version.rb", __FILE__) require File.expand_path("../middleman-core/lib/middleman-core/version.rb", __FILE__)
@ -84,7 +84,7 @@ end
desc "Run tests for all middleman gems" desc "Run tests for all middleman gems"
task :default => :test task :default => :test
desc "Generate documentation" # desc "Generate documentation"
task :doc do # task :doc do
YARD::CLI::Yardoc.new.run # YARD::CLI::Yardoc.new.run
end # end

View file

@ -1,7 +1,7 @@
require 'rubygems' unless defined?(Gem) require 'rubygems' unless defined?(Gem)
require 'rake' require 'rake'
require 'cucumber/rake/task' require 'cucumber/rake/task'
require 'yard' # require 'yard'
require 'bundler' require 'bundler'
Bundler::GemHelper.install_tasks :name => GEM_NAME Bundler::GemHelper.install_tasks :name => GEM_NAME
@ -20,6 +20,6 @@ Cucumber::Rake::Task.new(:test, 'Run features that should pass') do |t|
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}" t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
end end
YARD::Rake::YardocTask.new # YARD::Rake::YardocTask.new
task :default => :test task :default => :test

View file

@ -17,7 +17,6 @@ Feature: Builder
Then the following files should not exist: Then the following files should not exist:
| _partial | | _partial |
| layout | | layout |
| other_layout |
| layouts/custom | | layouts/custom |
| layouts/content_for | | layouts/content_for |

View file

@ -0,0 +1,58 @@
Feature: Text Files Without Extensions Should Build and Preview
Scenario: Building Text Files without directory indexes
Given a fixture app "extensionless-text-files-app"
And a file named "config.rb" with:
"""
"""
And a successfully built app at "extensionless-text-files-app"
When I cd to "build"
Then the following files should exist:
| CNAME |
| LICENSE |
| README |
Scenario: Building Text Files with directory indexes
Given a fixture app "extensionless-text-files-app"
And a file named "config.rb" with:
"""
activate :directory_indexes
"""
And a successfully built app at "extensionless-text-files-app"
When I cd to "build"
Then the following files should exist:
| CNAME |
| LICENSE |
| README |
Then the following files should not exist:
| CNAME/index.html |
| LICENSE/index.html |
| README/index.html |
Scenario: Previewing Text Files without directory indexes
Given "directory_indexes" feature is "disabled"
Given the Server is running at "extensionless-text-files-app"
When I go to "/CNAME"
Then I should see "test.github.com"
When I go to "/LICENSE"
Then I should see "You have the right to remain classy."
When I go to "/README"
Then I should see "Bork bork bork"
Scenario: Previewing Text Files with directory indexes
Given "directory_indexes" feature is "enabled"
Given the Server is running at "extensionless-text-files-app"
When I go to "/CNAME"
Then I should see "test.github.com"
When I go to "/LICENSE"
Then I should see "You have the right to remain classy."
When I go to "/README"
Then I should see "Bork bork bork"
# When I go to "/CNAME/index.html"
# Then I should see "File Not Found"
# When I go to "/LICENSE/index.html"
# Then I should see "File Not Found"
# When I go to "/README/index.html"
# Then I should see "File Not Found"

View file

@ -0,0 +1 @@
test.github.com

View file

@ -0,0 +1 @@
You have the right to remain classy.

View file

@ -0,0 +1 @@
Bork bork bork

View file

@ -18,76 +18,78 @@ end
# Simple callback library # Simple callback library
require "middleman-core/vendor/hooks-0.2.0/lib/hooks" require "middleman-core/vendor/hooks-0.2.0/lib/hooks"
require "middleman-core/version"
# Top-level Middleman object # Top-level Middleman object
module Middleman module Middleman
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i) unless const_defined?(:WINDOWS) WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i) unless const_defined?(:WINDOWS)
JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i) unless const_defined?(:JRUBY) JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i) unless const_defined?(:JRUBY)
DARWIN = RbConfig::CONFIG['target_os'] =~ /darwin/i unless const_defined?(:DARWIN) DARWIN = RbConfig::CONFIG['target_os'] =~ /darwin/i unless const_defined?(:DARWIN)
LINUX = RbConfig::CONFIG['target_os'] =~ /linux/i unless const_defined?(:LINUX) LINUX = RbConfig::CONFIG['target_os'] =~ /linux/i unless const_defined?(:LINUX)
# Auto-load modules on-demand # Auto-load modules on-demand
autoload :Base, "middleman-core/base" autoload :Base, "middleman-core/base"
autoload :Cache, "middleman-core/cache" autoload :Cache, "middleman-core/cache"
autoload :Templates, "middleman-core/templates" autoload :Templates, "middleman-core/templates"
autoload :Watcher, "middleman-core/watcher" autoload :Watcher, "middleman-core/watcher"
module Cli module Cli
autoload :Base, "middleman-core/cli" autoload :Base, "middleman-core/cli"
autoload :Build, "middleman-core/cli/build" autoload :Build, "middleman-core/cli/build"
autoload :Init, "middleman-core/cli/init" autoload :Init, "middleman-core/cli/init"
autoload :Server, "middleman-core/cli/server" autoload :Server, "middleman-core/cli/server"
end end
# Custom Renderers # Custom Renderers
module Renderers module Renderers
autoload :ERb, "middleman-core/renderers/erb" autoload :ERb, "middleman-core/renderers/erb"
end end
module Sitemap module Sitemap
autoload :Store, "middleman-core/sitemap/store" autoload :Store, "middleman-core/sitemap/store"
autoload :Page, "middleman-core/sitemap/page" autoload :Page, "middleman-core/sitemap/page"
autoload :Template, "middleman-core/sitemap/template" autoload :Template, "middleman-core/sitemap/template"
end end
module CoreExtensions module CoreExtensions
# File Change Notifier # File Change Notifier
autoload :FileWatcher, "middleman-core/core_extensions/file_watcher" autoload :FileWatcher, "middleman-core/core_extensions/file_watcher"
# In-memory Sitemap # In-memory Sitemap
autoload :Sitemap, "middleman-core/core_extensions/sitemap" autoload :Sitemap, "middleman-core/core_extensions/sitemap"
# Add Builder callbacks # Add Builder callbacks
autoload :Builder, "middleman-core/core_extensions/builder" autoload :Builder, "middleman-core/core_extensions/builder"
# Custom Feature API # Custom Feature API
autoload :Extensions, "middleman-core/core_extensions/extensions" autoload :Extensions, "middleman-core/core_extensions/extensions"
# Asset Path Pipeline # Asset Path Pipeline
autoload :Assets, "middleman-core/core_extensions/assets" autoload :Assets, "middleman-core/core_extensions/assets"
# Data looks at the data/ folder for YAML files and makes them available # Data looks at the data/ folder for YAML files and makes them available
# to dynamic requests. # to dynamic requests.
autoload :Data, "middleman-core/core_extensions/data" autoload :Data, "middleman-core/core_extensions/data"
# Parse YAML from templates # Parse YAML from templates
autoload :FrontMatter, "middleman-core/core_extensions/front_matter" autoload :FrontMatter, "middleman-core/core_extensions/front_matter"
# External helpers looks in the helpers/ folder for helper modules # External helpers looks in the helpers/ folder for helper modules
autoload :ExternalHelpers, "middleman-core/core_extensions/external_helpers" autoload :ExternalHelpers, "middleman-core/core_extensions/external_helpers"
# DefaultHelpers are the built-in dynamic template helpers. # DefaultHelpers are the built-in dynamic template helpers.
autoload :DefaultHelpers, "middleman-core/core_extensions/default_helpers" autoload :DefaultHelpers, "middleman-core/core_extensions/default_helpers"
# Extended version of Padrino's rendering # Extended version of Padrino's rendering
autoload :Rendering, "middleman-core/core_extensions/rendering" autoload :Rendering, "middleman-core/core_extensions/rendering"
# Pass custom options to views # Pass custom options to views
autoload :Routing, "middleman-core/core_extensions/routing" autoload :Routing, "middleman-core/core_extensions/routing"
# Catch and show exceptions at the Rack level # Catch and show exceptions at the Rack level
autoload :ShowExceptions, "middleman-core/core_extensions/show_exceptions" autoload :ShowExceptions, "middleman-core/core_extensions/show_exceptions"
end end
module Extensions module Extensions
# Provide Apache-style index.html files for directories # Provide Apache-style index.html files for directories
autoload :DirectoryIndexes, "middleman-core/extensions/directory_indexes" autoload :DirectoryIndexes, "middleman-core/extensions/directory_indexes"
@ -95,18 +97,18 @@ module Middleman
# Lorem provides a handful of helpful prototyping methods to generate # Lorem provides a handful of helpful prototyping methods to generate
# words, paragraphs, fake images, names and email addresses. # 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 # AutomaticImageSizes inspects the images used in your dynamic templates
# and automatically adds width and height attributes to their HTML # and automatically adds width and height attributes to their HTML
# elements. # elements.
autoload :AutomaticImageSizes, "middleman-core/extensions/automatic_image_sizes" autoload :AutomaticImageSizes, "middleman-core/extensions/automatic_image_sizes"
# AssetHost allows you to setup multiple domains to host your static # AssetHost allows you to setup multiple domains to host your static
# assets. Calls to asset paths in dynamic templates will then rotate # assets. Calls to asset paths in dynamic templates will then rotate
# through each of the asset servers to better spread the load. # through each of the asset servers to better spread the load.
autoload :AssetHost, "middleman-core/extensions/asset_host" autoload :AssetHost, "middleman-core/extensions/asset_host"
end end
module Extensions module Extensions
class << self class << self
def registered def registered
@ -114,9 +116,9 @@ module Middleman
end end
def register(name, namespace=nil, version=nil, &block) def register(name, namespace=nil, version=nil, &block)
# If we've already got a matching extension that passed the # If we've already got a matching extension that passed the
# version check, bail out. # version check, bail out.
return if registered.has_key?(name.to_sym) && return if registered.has_key?(name.to_sym) &&
!registered[name.to_sym].is_a?(String) !registered[name.to_sym].is_a?(String)
if block_given? if block_given?
@ -154,12 +156,12 @@ module Middleman
end end
end end
end end
# Where to look in gems for extensions to auto-register # Where to look in gems for extensions to auto-register
EXTENSION_FILE = File.join("lib", "middleman_extension.rb") unless const_defined?(:EXTENSION_FILE) EXTENSION_FILE = File.join("lib", "middleman_extension.rb") unless const_defined?(:EXTENSION_FILE)
class << self class << self
# Recursively convert a normal Hash into a HashWithIndifferentAccess # Recursively convert a normal Hash into a HashWithIndifferentAccess
# #
# @private # @private
@ -181,7 +183,7 @@ module Middleman
data data
end end
end end
# Automatically load extensions from available RubyGems # Automatically load extensions from available RubyGems
# which contain the EXTENSION_FILE # which contain the EXTENSION_FILE
# #
@ -190,12 +192,12 @@ module Middleman
extensions = rubygems_latest_specs.select do |spec| extensions = rubygems_latest_specs.select do |spec|
spec_has_file?(spec, EXTENSION_FILE) spec_has_file?(spec, EXTENSION_FILE)
end end
extensions.each do |spec| extensions.each do |spec|
require spec.name require spec.name
end end
end end
# Backwards compatible means of finding all the latest gemspecs # Backwards compatible means of finding all the latest gemspecs
# available on the system # available on the system
# #
@ -209,7 +211,7 @@ module Middleman
::Gem.source_index.latest_specs ::Gem.source_index.latest_specs
end end
end end
# Where a given Gem::Specification has a specific file. Used # Where a given Gem::Specification has a specific file. Used
# to discover extensions and Sprockets-supporting gems. # to discover extensions and Sprockets-supporting gems.
# #
@ -221,9 +223,9 @@ module Middleman
full_path = File.join(spec.full_gem_path, path) full_path = File.join(spec.full_gem_path, path)
File.exists?(full_path) File.exists?(full_path)
end end
# Create a new Class which is based on Middleman::Base # Create a new Class which is based on Middleman::Base
# Used to create a safe sandbox into which extensions and # Used to create a safe sandbox into which extensions and
# configuration can be included later without impacting # configuration can be included later without impacting
# other classes and instances. # other classes and instances.
# #
@ -231,34 +233,34 @@ module Middleman
def server(&block) def server(&block)
Class.new(Middleman::Base) Class.new(Middleman::Base)
end end
# Creates a new Rack::Server # Creates a new Rack::Server
# #
# @param [Hash] options to pass to Rack::Server.new # @param [Hash] options to pass to Rack::Server.new
# @return [Rack::Server] # @return [Rack::Server]
def start_server(options={}) def start_server(options={})
require "webrick" require "webrick"
opts = { opts = {
:Port => options[:port] || 4567, :Port => options[:port] || 4567,
:Host => options[:host] || "0.0.0.0", :Host => options[:host] || "0.0.0.0",
:AccessLog => [] :AccessLog => []
} }
opts[:Logger] = WEBrick::Log::new("/dev/null", 7) if !options[:logging] opts[:Logger] = WEBrick::Log::new("/dev/null", 7) if !options[:logging]
app_class = options[:app] ||= ::Middleman.server.inst app_class = options[:app] ||= ::Middleman.server.inst
opts[:app] = app_class opts[:app] = app_class
# Disable for Beta 1. See if people notice. # Disable for Beta 1. See if people notice.
# require "thin" # require "thin"
# ::Thin::Logging.silent = !options[:logging] # ::Thin::Logging.silent = !options[:logging]
# opts[:server] = 'thin' # opts[:server] = 'thin'
opts[:server] = 'webrick' opts[:server] = 'webrick'
server = ::Rack::Server.new(opts) server = ::Rack::Server.new(opts)
server.start server.start
server server
end end
end end
end end

View file

@ -187,6 +187,8 @@ module Middleman::CoreExtensions::FrontMatter
def parse_front_matter(content) def parse_front_matter(content)
yaml_regex = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m yaml_regex = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
if content =~ yaml_regex if content =~ yaml_regex
content = content[($1.size + $2.size)..-1]
begin begin
data = YAML.load($1) data = YAML.load($1)
rescue => e rescue => e
@ -194,7 +196,6 @@ module Middleman::CoreExtensions::FrontMatter
return false return false
end end
content = content.split(yaml_regex).last
else else
return false return false
end end

View file

@ -19,8 +19,12 @@ module Middleman::CoreExtensions::Sitemap
# Files starting with an underscore, but not a double-underscore # Files starting with an underscore, but not a double-underscore
:partials => proc { |file, path| (file.match(/\/_/) && !file.match(/\/__/)) }, :partials => proc { |file, path| (file.match(/\/_/) && !file.match(/\/__/)) },
:layout => proc { |file, path|
file.match(/^source\/layout\./) || file.match(/^source\/layouts\//)
},
# Files without any output extension (layouts, partials) # Files without any output extension (layouts, partials)
:extensionless => proc { |file, path| !path.match(/\./) }, # :extensionless => proc { |file, path| !path.match(/\./) },
} }
# Include instance methods # Include instance methods

View file

@ -88,7 +88,10 @@ module Middleman::Sitemap
def page_by_destination(destination_path) def page_by_destination(destination_path)
# TODO: memoize this # TODO: memoize this
destination_path = normalize_path(destination_path) destination_path = normalize_path(destination_path)
pages.find {|p| p.destination_path == destination_path } pages.find do |p|
p.destination_path == destination_path ||
p.destination_path == destination_path.sub("/#{@app.index_file}", "")
end
end end
# Whether a path is ignored # Whether a path is ignored
@ -107,42 +110,6 @@ module Middleman::Sitemap
false false
end end
# Get a list of ignored paths
# @return [Array<String>]
def ignored_paths
pages.select(&:ignored?).map(&:path)
end
# Whether the given path is generic
# @param [String] path
# @return [Boolean]
def generic?(path)
generic_paths.include?(normalize_path(path))
end
# Get a list of generic paths
# @return [Array<String>]
def generic_paths
app.cache.fetch :generic_paths do
pages.select(&:generic?).map(&:path)
end
end
# Whether the given path is proxied
# @param [String] path
# @return [Boolean]
def proxied?(path)
proxied_paths.include?(normalize_path(path))
end
# Get a list of proxied paths
# @return [Array<String>]
def proxied_paths
app.cache.fetch :proxied_paths do
pages.select(&:proxy?).map(&:path)
end
end
# Remove a file from the store # Remove a file from the store
# @param [String] file # @param [String] file
# @return [void] # @return [void]

View file

@ -3,6 +3,8 @@ require "net/http"
require "win32/process" if ::Middleman::WINDOWS require "win32/process" if ::Middleman::WINDOWS
require "fileutils"
module Middleman module Middleman
class Watcher class Watcher
class << self class << self
@ -63,12 +65,26 @@ module Middleman
if @options[:"disable-watcher"] if @options[:"disable-watcher"]
bootup bootup
else else
pid_name = ".mm-pid-#{@options[:port]||4567}"
if File.exists?(pid_name)
current_pid = File.open(pid_name, 'rb') { |f| f.read }
begin
Process.kill("INT", -current_pid.to_i)
rescue
ensure
FileUtils.rm(pid_name)
end
end
@server_job = fork { @server_job = fork {
trap("INT") { exit(0) } trap("INT") { exit(0) }
trap("TERM") { exit(0) } trap("TERM") { exit(0) }
trap("QUIT") { exit(0) } trap("QUIT") { exit(0) }
bootup bootup
} }
File.open(pid_name, "w+") { |f| f.write(Process.getpgrp) }
end end
end end

View file

@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.require_path = "lib" s.require_path = "lib"
# Core # Core
s.add_dependency("rack", ["~> 1.3.5"]) s.add_dependency("rack", ["~> 1.4.0"])
s.add_dependency("tilt", ["~> 1.3.1"]) s.add_dependency("tilt", ["~> 1.3.1"])
# Builder # Builder
@ -29,7 +29,7 @@ Gem::Specification.new do |s|
s.add_dependency("thor", ["~> 0.14.0"]) s.add_dependency("thor", ["~> 0.14.0"])
# Helpers # Helpers
s.add_dependency("activesupport", ["~> 3.1.0"]) s.add_dependency("activesupport", ["~> 3.2.0"])
# Watcher # Watcher
s.add_dependency("fssm", ["~> 0.2.8"]) s.add_dependency("fssm", ["~> 0.2.8"])

View file

@ -1,4 +1,6 @@
Feature: Compass sprites should be generated on build and copied Feature: Compass sprites should be generated on build and copied
Scenario: Building a clean site with sprites Scenario: Building a clean site with sprites
Given a successfully built app at "compass-sprites-app" Given a successfully built app at "compass-sprites-app"
Then the output should contain "images/icon-" When I cd to "build"
Then the following files should exist:
| images/icon-s1a8aa64128.png |

View file

@ -3,8 +3,13 @@ Feature: Sprockets Gems
Given the Server is running at "sprockets-app" Given the Server is running at "sprockets-app"
When I go to "/library/js/jquery_include.js" When I go to "/library/js/jquery_include.js"
Then I should see "var jQuery =" Then I should see "var jQuery ="
# Scenario: Sprockets can pull CSS from gem # Scenario: Sprockets can pull CSS from gem
# Given the Server is running at "sprockets-app" # Given the Server is running at "sprockets-app"
# When I go to "/library/css/bootstrap_include.css" # When I go to "/library/css/bootstrap_include.css"
# Then I should see "Bootstrap" # Then I should see "Bootstrap"
Scenario: Sprockets can pull js from vendored assets
Given the Server is running at "sprockets-app"
When I go to "/library/js/vendored_include.js"
Then I should see "var vendored_js_included = true;"

View file

@ -0,0 +1 @@
//= require "vendored_js"

View file

@ -0,0 +1 @@
var vendored_js_included = true;

View file

@ -3,68 +3,42 @@ require "sprockets"
# Sprockets extension # Sprockets extension
module Middleman::CoreExtensions::Sprockets module Middleman::CoreExtensions::Sprockets
# Setup extension # Setup extension
class << self class << self
# Once registered # Once registered
def registered(app) def registered(app)
# Default compression to off # Default compression to off
app.set :js_compressor, false app.set :js_compressor, false
app.set :css_compressor, false app.set :css_compressor, false
# Once Middleman is setup # Once Middleman is setup
app.ready do app.ready do
# Create sprockets env for JS # Create sprockets env for JS and CSS
js_env = Middleman::CoreExtensions::Sprockets::JavascriptEnvironment.new(self) js_env = Middleman::CoreExtensions::Sprockets::JavascriptEnvironment.new(self)
css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self)
# Add any gems with vendor/assets/javascripts to paths # Add any gems with (vendor|app|.)/assets/javascripts to paths
vendor_dir = File.join("vendor", "assets", "javascripts") # also add similar directories from project root (like in rails)
gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec| root_paths = [%w{ app }, %w{ assets }, %w{ vendor }, %w{ app assets }, %w{ vendor assets }]
::Middleman.spec_has_file?(spec, vendor_dir) try_js_paths = root_paths.map{|rp| File.join(rp, 'javascripts')}
end.each do |spec| try_css_paths = root_paths.map{|rp| File.join(rp, 'stylesheets')}
js_env.append_path File.join(spec.full_gem_path, vendor_dir)
end
# Add any gems with app/assets/javascripts to paths { try_js_paths => js_env, try_css_paths => css_env }.each do |paths, env|
app_dir = File.join("app", "assets", "javascripts") ([root] + ::Middleman.rubygems_latest_specs.map(&:full_gem_path)).each do |root_path|
gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec| paths.map{|p| File.join(root_path, p)}.
::Middleman.spec_has_file?(spec, app_dir) select{|p| File.directory?(p)}.
end.each do |spec| each{|path| env.append_path(path)}
js_env.append_path File.join(spec.full_gem_path, app_dir) end
end
# Intercept requests to /javascripts and pass to sprockets
map "/#{js_dir}" do
run js_env
end end
# Setup Sprockets Sass options # Setup Sprockets Sass options
sass.each { |k, v| ::Sprockets::Sass.options[k] = v } sass.each { |k, v| ::Sprockets::Sass.options[k] = v }
# Create sprockets env for CSS # Intercept requests to /javascripts and /stylesheets and pass to sprockets
css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self) map("/#{js_dir}") { run js_env }
map("/#{css_dir}"){ run css_env }
# Add any gems with vendor/assets/stylesheets to paths
vendor_dir = File.join("vendor", "assets", "stylesheets")
gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
::Middleman.spec_has_file?(spec, vendor_dir)
end.each do |spec|
css_env.append_path File.join(spec.full_gem_path, vendor_dir)
end
# Add any gems with app/assets/stylesheets to paths
app_dir = File.join("app", "assets", "stylesheets")
gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
::Middleman.spec_has_file?(spec, app_dir)
end.each do |spec|
css_env.append_path File.join(spec.full_gem_path, app_dir)
end
# Intercept requests to /stylesheets and pass to sprockets
map("/#{css_dir}") do
run css_env
end
end end
end end
alias :included :registered alias :included :registered
@ -76,7 +50,7 @@ module Middleman::CoreExtensions::Sprockets
def initialize(app) def initialize(app)
@app = app @app = app
super app.source_dir super app.source_dir
# Make the app context available to Sprockets # Make the app context available to Sprockets
context_class.send(:define_method, :app) { app } context_class.send(:define_method, :app) { app }
context_class.class_eval do context_class.class_eval do
@ -89,26 +63,26 @@ module Middleman::CoreExtensions::Sprockets
end end
end end
end end
# During development, don't use the asset cache # During development, don't use the asset cache
def find_asset(path, options = {}) def find_asset(path, options = {})
expire_index! if @app.development? expire_index! if @app.development?
super super
end end
end end
# Javascript specific environment # Javascript specific environment
class JavascriptEnvironment < MiddlemanEnvironment class JavascriptEnvironment < MiddlemanEnvironment
# Init # Init
def initialize(app) def initialize(app)
super super
expire_index! expire_index!
# Remove old compressor # Remove old compressor
unregister_bundle_processor 'application/javascript', :js_compressor unregister_bundle_processor 'application/javascript', :js_compressor
# Register compressor from config # Register compressor from config
register_bundle_processor 'application/javascript', :js_compressor do |context, data| register_bundle_processor 'application/javascript', :js_compressor do |context, data|
if context.pathname.to_s =~ /\.min\./ if context.pathname.to_s =~ /\.min\./
@ -117,30 +91,30 @@ module Middleman::CoreExtensions::Sprockets
app.js_compressor.compress(data) app.js_compressor.compress(data)
end end
end if app.js_compressor end if app.js_compressor
# configure search paths # configure search paths
append_path app.js_dir append_path app.js_dir
end end
# Clear cache on error # Clear cache on error
def javascript_exception_response(exception) def javascript_exception_response(exception)
expire_index! expire_index!
super(exception) super(exception)
end end
end end
# CSS specific environment # CSS specific environment
class StylesheetEnvironment < MiddlemanEnvironment class StylesheetEnvironment < MiddlemanEnvironment
# Init # Init
def initialize(app) def initialize(app)
super super
expire_index! expire_index!
# Remove old compressor # Remove old compressor
unregister_bundle_processor 'text/css', :css_compressor unregister_bundle_processor 'text/css', :css_compressor
# Register compressor from config # Register compressor from config
register_bundle_processor 'text/css', :css_compressor do |context, data| register_bundle_processor 'text/css', :css_compressor do |context, data|
if context.pathname.to_s =~ /\.min\./ if context.pathname.to_s =~ /\.min\./
@ -149,11 +123,11 @@ module Middleman::CoreExtensions::Sprockets
app.css_compressor.compress(data) app.css_compressor.compress(data)
end end
end if app.css_compressor end if app.css_compressor
# configure search paths # configure search paths
append_path app.css_dir append_path app.css_dir
end end
# Clear cache on error # Clear cache on error
def css_exception_response(exception) def css_exception_response(exception)
expire_index! expire_index!

View file

@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.add_dependency("sass", ["~> 3.1.7"]) s.add_dependency("sass", ["~> 3.1.7"])
s.add_dependency("compass", ["0.12.rc.1"]) s.add_dependency("compass", ["0.12.rc.1"])
s.add_dependency("coffee-script", ["~> 2.2.0"]) s.add_dependency("coffee-script", ["~> 2.2.0"])
s.add_dependency("execjs", ["~> 1.2.7"]) s.add_dependency("execjs", ["~> 1.2"])
s.add_dependency("sprockets", ["~> 2.1.0"]) s.add_dependency("sprockets", ["~> 2.1.0"])
s.add_dependency("sprockets-sass", ["~> 0.6.0"]) s.add_dependency("sprockets-sass", ["~> 0.6.0"])
s.add_dependency("redcarpet", ["~> 2.0.0"]) s.add_dependency("redcarpet", ["~> 2.0.0"])