Merge stable

This commit is contained in:
Thomas Reynolds 2015-04-26 11:32:47 -07:00
commit 2403fa2d81
17 changed files with 184 additions and 15 deletions

View file

@ -29,12 +29,17 @@ module Middleman::Cli
::Middleman::Logger.singleton(opts[:debug] ? 0 : 1, opts[:instrumenting] || false) ::Middleman::Logger.singleton(opts[:debug] ? 0 : 1, opts[:instrumenting] || false)
end end
# TODO: get file watcher / reload! working in console interact_with @app
end
# Start an interactive console in the context of the provided object.
# @param [Object] context
# @return [void]
def interact_with(context)
IRB.setup nil IRB.setup nil
IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
require 'irb/ext/multi-irb' require 'irb/ext/multi-irb'
IRB.irb nil, @app IRB.irb nil, context
end end
# Add to CLI # Add to CLI

View file

@ -11,11 +11,9 @@ module Middleman::Cli
class_option :host, class_option :host,
type: :string, type: :string,
aliases: '-h', aliases: '-h',
default: '0.0.0.0',
desc: 'Bind to HOST address' desc: 'Bind to HOST address'
class_option :port, class_option :port,
aliases: '-p', aliases: '-p',
default: '4567',
desc: 'The port Middleman will listen on' desc: 'The port Middleman will listen on'
class_option :verbose, class_option :verbose,
type: :boolean, type: :boolean,
@ -40,7 +38,7 @@ module Middleman::Cli
class_option :latency, class_option :latency,
type: :numeric, type: :numeric,
aliases: '-l', aliases: '-l',
default: 0.25, default: 0.5,
desc: 'Set file watcher latency, in seconds' desc: 'Set file watcher latency, in seconds'
# Start the server # Start the server

View file

@ -79,6 +79,13 @@ Feature: Assets get file hashes appended to them and references to them are upda
And I should see 'images/100px-5fd6fb90.jpg' And I should see 'images/100px-5fd6fb90.jpg'
And I should see 'images/100px-1242c368.png' And I should see 'images/100px-1242c368.png'
Scenario: Hashed assets work with Slim
Given the Server is running at "asset-hash-app"
When I go to "/slim.html"
And I should see 'src="images/300px-59adce76.jpg"'
And I should see 'src="images/100px-5fd6fb90.jpg"'
And I should see 'srcset="images/100px-5fd6fb90.jpg 1x, images/200px-c11eb203.jpg 2x, images/300px-59adce76.jpg 3x"'
Scenario: Enabling an asset host still produces hashed files and references Scenario: Enabling an asset host still produces hashed files and references
Given the Server is running at "asset-hash-host-app" Given the Server is running at "asset-hash-host-app"
When I go to "/" When I go to "/"

View file

@ -5,6 +5,24 @@ Feature: link_to helper
When I go to "/link_to_erb.html" When I go to "/link_to_erb.html"
Then I should see "erb <s>with html tags</s>" Then I should see "erb <s>with html tags</s>"
Scenario: link_to works with absolute URLs (where the relative part matches a local path)
Given a fixture app "link-to-app"
And a file named "config.rb" with:
"""
set :relative_links, true
"""
And a file named "source/test.html.erb" with:
"""
Hello
"""
And a file named "source/link_to_absolute.html.erb" with:
"""
<%= link_to "test", "http://google.com/test.html" %>
"""
And the Server is running at "link-to-app"
When I go to "/link_to_absolute.html"
Then I should see '<a href="http://google.com/test.html">test</a>'
Scenario: link_to works with blocks (slim) Scenario: link_to works with blocks (slim)
Given the Server is running at "link-to-app" Given the Server is running at "link-to-app"
When I go to "/link_to_slim.html" When I go to "/link_to_slim.html"

View file

@ -0,0 +1,7 @@
Feature: Support srcset property as params for image_tag helper
This lets you specify responsive image sizes
Scenario: Rendering an image with the feature enabled
Given the Server is running at "image-srcset-paths-app"
When I go to "/image-srcset-paths.html"
Then I should see '//example.com/remote-image.jpg 2x, /images/blank_3x.jpg 3x'

View file

@ -33,9 +33,10 @@ Feature: Markdown support in Haml (Kramdown)
:markdown :markdown
[A link](/link_target.html) [A link](/link_target.html)
![image](blank.gif) ![image](blank.gif){: srcset="image_2x.jpg 2x"}
""" """
Given the Server is running at "markdown-in-haml-app" Given the Server is running at "markdown-in-haml-app"
When I go to "/link_and_image/" When I go to "/link_and_image/"
Then I should see "/link_target/" Then I should see "/link_target/"
Then I should see "/images/image_2x.jpg 2x"
Then I should see 'src="/images/blank.gif"' Then I should see 'src="/images/blank.gif"'

View file

@ -0,0 +1,8 @@
---
directory_index: false
layout: false
---
= image_tag '100px.jpg', srcset: "100px.jpg 1x, 200px.jpg 2x, 300px.jpg 3x"
= image_tag "300px.jpg"

View file

@ -0,0 +1 @@
<%= image_tag 'blank.jpg', srcset: '//example.com/remote-image.jpg 2x, blank_3x.jpg 3x, http://example.com/remoteimage.jpg 4x' %>

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 B

View file

@ -1 +1,3 @@
page "/spaces in file.html", layout: false page "/spaces in file.html", layout: false
config[:port] = 5555

View file

@ -81,6 +81,14 @@ module Middleman
define_hook :before_render define_hook :before_render
define_hook :after_render define_hook :after_render
# Which host preview should start on.
# @return [Fixnum]
config.define_setting :host, '0.0.0.0', 'The preview server host'
# Which port preview should start on.
# @return [Fixnum]
config.define_setting :port, 4567, 'The preview server port'
# Name of the source directory # Name of the source directory
# @return [String] # @return [String]
config.define_setting :source, 'source', 'Name of the source directory' config.define_setting :source, 'source', 'Name of the source directory'

View file

@ -0,0 +1,86 @@
# CLI Module
module Middleman::Cli
# Server thor task
class Server < Thor
check_unknown_options!
namespace :server
desc 'server [options]', 'Start the preview server'
method_option :environment,
aliases: '-e',
default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
desc: 'The environment Middleman will run under'
method_option :host,
type: :string,
aliases: '-h',
desc: 'Bind to HOST address'
method_option :port,
aliases: '-p',
desc: 'The port Middleman will listen on'
method_option :verbose,
type: :boolean,
default: false,
desc: 'Print debug messages'
method_option :instrument,
type: :string,
default: false,
desc: 'Print instrument messages'
method_option :disable_watcher,
type: :boolean,
default: false,
desc: 'Disable the file change and delete watcher process'
method_option :profile,
type: :boolean,
default: false,
desc: 'Generate profiling report for server startup'
method_option :reload_paths,
type: :string,
default: false,
desc: 'Additional paths to auto-reload when files change'
method_option :force_polling,
type: :boolean,
default: false,
desc: 'Force file watcher into polling mode'
method_option :latency,
type: :numeric,
aliases: '-l',
default: 0.25,
desc: 'Set file watcher latency, in seconds'
# Start the server
def server
require 'middleman-core'
require 'middleman-core/preview_server'
unless ENV['MM_ROOT']
puts '== Could not find a Middleman project config.rb'
puts '== Treating directory as a static site to be served'
ENV['MM_ROOT'] = Dir.pwd
ENV['MM_SOURCE'] = ''
end
params = {
port: options['port'],
host: options['host'],
environment: options['environment'],
debug: options['verbose'],
instrumenting: options['instrument'],
disable_watcher: options['disable_watcher'],
reload_paths: options['reload_paths'],
force_polling: options['force_polling'],
latency: options['latency']
}
puts '== The Middleman is loading'
::Middleman::PreviewServer.start(params)
end
end
def self.exit_on_failure?
true
end
# Map "s" to "server"
Base.map('s' => 'server')
end

View file

@ -221,5 +221,26 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
url = url_for(url, options) url = url_for(url, options)
super super
end end
# Modified Padrino image_tag so that it finds the paths for srcset
# using asset_path for the images listed in the srcset param
def image_tag(path, params={})
params.symbolize_keys!
if params.key?(:srcset)
images_sources = params[:srcset].split(',').map do |src_def|
if src_def.include?('//')
src_def
else
image_def, size_def = src_def.strip.split(/\s+/)
asset_path(:images, image_def) + ' ' + size_def
end
end
params[:srcset] = images_sources.join(', ')
end
super(path, params)
end
end end
end end

View file

@ -6,8 +6,6 @@ require 'middleman-core/rack'
# rubocop:disable GlobalVars # rubocop:disable GlobalVars
module Middleman module Middleman
module PreviewServer module PreviewServer
DEFAULT_PORT = 4567
class << self class << self
extend Forwardable extend Forwardable
@ -17,9 +15,7 @@ module Middleman
# Start an instance of Middleman::Application # Start an instance of Middleman::Application
# @return [void] # @return [void]
def start(opts={}) def start(opts={})
@options = opts.dup.freeze @options = opts
@host = @options[:host] || '0.0.0.0'
@port = @options[:port] || DEFAULT_PORT
mount_instance(new_app) mount_instance(new_app)
logger.info "== The Middleman is standing watch at #{uri}" logger.info "== The Middleman is standing watch at #{uri}"
@ -90,7 +86,7 @@ module Middleman
private private
def new_app def new_app
opts = @options opts = @options.dup
::Middleman::Logger.singleton( ::Middleman::Logger.singleton(
opts[:debug] ? 0 : 1, opts[:debug] ? 0 : 1,
@ -103,6 +99,9 @@ module Middleman
config[:watcher_force_polling] = opts[:force_polling] config[:watcher_force_polling] = opts[:force_polling]
config[:watcher_latency] = opts[:latency] config[:watcher_latency] = opts[:latency]
config[:host] = opts[:host] if opts[:host]
config[:port] = opts[:port] if opts[:port]
ready do ready do
match_against = [ match_against = [
%r{^config\.rb$}, %r{^config\.rb$},
@ -118,6 +117,9 @@ module Middleman
end end
end end
@host = app.config[:host]
@port = app.config[:port]
app.files.on_change :reload do app.files.on_change :reload do
$mm_reload = true $mm_reload = true
@webrick.stop @webrick.stop

View file

@ -128,7 +128,11 @@ module Middleman
def listen! def listen!
return if @disable_watcher || @listener || @waiting_for_existence return if @disable_watcher || @listener || @waiting_for_existence
config = { force_polling: @force_polling } config = {
force_polling: @force_polling,
wait_for_delay: 0.5
}
config[:latency] = @latency if @latency config[:latency] = @latency if @latency
@listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change)) @listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change))

View file

@ -283,7 +283,7 @@ module Middleman
if path_or_resource.is_a?(::Middleman::Sitemap::Resource) if path_or_resource.is_a?(::Middleman::Sitemap::Resource)
resource = path_or_resource resource = path_or_resource
resource_url = url resource_url = url
elsif this_resource && uri.path elsif this_resource && uri.path && !uri.host
# Handle relative urls # Handle relative urls
url_path = Pathname(uri.path) url_path = Pathname(uri.path)
current_source_dir = Pathname('/' + this_resource.path).dirname current_source_dir = Pathname('/' + this_resource.path).dirname
@ -299,7 +299,7 @@ module Middleman
resource = app.sitemap.find_resource_by_destination_path(url_path.to_s) resource = app.sitemap.find_resource_by_destination_path(url_path.to_s)
resource_url = resource.url if resource resource_url = resource.url if resource
end end
elsif options[:find_resource] && uri.path elsif options[:find_resource] && uri.path && !uri.host
resource = app.sitemap.find_resource_by_path(uri.path) resource = app.sitemap.find_resource_by_path(uri.path)
resource_url = resource.url if resource resource_url = resource.url if resource
end end

View file

@ -2,3 +2,4 @@ require 'middleman-core/load_paths'
::Middleman.setup_load_paths ::Middleman.setup_load_paths
require 'middleman-core' require 'middleman-core'
require 'middleman-core/application'