Merge stable

remove_hooks
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)
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.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
require 'irb/ext/multi-irb'
IRB.irb nil, @app
IRB.irb nil, context
end
# Add to CLI

View File

@ -11,11 +11,9 @@ module Middleman::Cli
class_option :host,
type: :string,
aliases: '-h',
default: '0.0.0.0',
desc: 'Bind to HOST address'
class_option :port,
aliases: '-p',
default: '4567',
desc: 'The port Middleman will listen on'
class_option :verbose,
type: :boolean,
@ -40,7 +38,7 @@ module Middleman::Cli
class_option :latency,
type: :numeric,
aliases: '-l',
default: 0.25,
default: 0.5,
desc: 'Set file watcher latency, in seconds'
# 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-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
Given the Server is running at "asset-hash-host-app"
When I go to "/"

View File

@ -5,6 +5,24 @@ Feature: link_to helper
When I go to "/link_to_erb.html"
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)
Given the Server is running at "link-to-app"
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
[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"
When I go to "/link_and_image/"
Then I should see "/link_target/"
Then I should see "/images/image_2x.jpg 2x"
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
config[:port] = 5555

View File

@ -81,6 +81,14 @@ module Middleman
define_hook :before_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
# @return [String]
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)
super
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

View File

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

View File

@ -128,7 +128,11 @@ module Middleman
def listen!
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
@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)
resource = path_or_resource
resource_url = url
elsif this_resource && uri.path
elsif this_resource && uri.path && !uri.host
# Handle relative urls
url_path = Pathname(uri.path)
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_url = resource.url if resource
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_url = resource.url if resource
end

View File

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