rename old padrino tests, remove sinatra tests, use metadata hooks for frontmatter and liquid
This commit is contained in:
parent
c82a40dde5
commit
0e5ce50787
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,3 +11,4 @@ docs
|
||||||
.rbenv-version
|
.rbenv-version
|
||||||
fixtures/test-app/build
|
fixtures/test-app/build
|
||||||
.*.swp
|
.*.swp
|
||||||
|
build
|
||||||
|
|
|
@ -3,7 +3,7 @@ Feature: Built-in macro view helpers
|
||||||
|
|
||||||
Scenario: Using the link_to helper
|
Scenario: Using the link_to helper
|
||||||
Given the Server is running at "test-app"
|
Given the Server is running at "test-app"
|
||||||
When I go to "/padrino_test.html"
|
When I go to "/former_padrino_test.html"
|
||||||
And I should see 'href="test2.com"'
|
And I should see 'href="test2.com"'
|
||||||
And I should see 'src="/images/test2.png"'
|
And I should see 'src="/images/test2.png"'
|
||||||
Then I should see 'src="/javascripts/test1.js"'
|
Then I should see 'src="/javascripts/test1.js"'
|
|
@ -1,6 +0,0 @@
|
||||||
Feature: Sinatra Routes
|
|
||||||
|
|
||||||
Scenario: Rendering html
|
|
||||||
Given the Server is running at "test-app"
|
|
||||||
When I go to "/sinatra_test"
|
|
||||||
Then I should see "Ratpack"
|
|
|
@ -1,8 +1,9 @@
|
||||||
Given /^I am using an asset host$/ do
|
Given /^I am using an asset host$/ do
|
||||||
@server ||= Middleman.server
|
@initialize_commands ||= []
|
||||||
@server.set :show_exceptions, false
|
@initialize_commands << lambda {
|
||||||
@server.activate :asset_host
|
activate :asset_host
|
||||||
@server.set :asset_host do |asset|
|
set :asset_host do |asset|
|
||||||
"http://assets%d.example.com" % (asset.hash % 4)
|
"http://assets%d.example.com" % (asset.hash % 4)
|
||||||
end
|
end
|
||||||
|
}
|
||||||
end
|
end
|
|
@ -1,23 +1,18 @@
|
||||||
Given /^a clean server$/ do
|
Given /^a clean server$/ do
|
||||||
@server = Middleman.server
|
@initialize_commands = []
|
||||||
@server.set :show_exceptions, false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
|
Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
|
||||||
@server = Middleman.server
|
@initialize_commands ||= []
|
||||||
@server.set :show_exceptions, false
|
|
||||||
|
|
||||||
if state == "enabled"
|
if state == "enabled"
|
||||||
@server.activate(feature.to_sym)
|
@initialize_commands << lambda { activate(feature.to_sym) }
|
||||||
end
|
end
|
||||||
|
|
||||||
@server.set :environment, @current_env || :development
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^"([^\"]*)" is set to "([^\"]*)"$/ do |variable, value|
|
Given /^"([^\"]*)" is set to "([^\"]*)"$/ do |variable, value|
|
||||||
@server ||= Middleman.server
|
@initialize_commands ||= []
|
||||||
@server.set :show_exceptions, false
|
@initialize_commands << lambda { set(variable.to_sym, value) }
|
||||||
@server.set variable.to_sym, value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^current environment is "([^\"]*)"$/ do |env|
|
Given /^current environment is "([^\"]*)"$/ do |env|
|
||||||
|
@ -25,13 +20,22 @@ Given /^current environment is "([^\"]*)"$/ do |env|
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^the Server is running at "([^\"]*)"$/ do |app_path|
|
Given /^the Server is running at "([^\"]*)"$/ do |app_path|
|
||||||
@server ||= Middleman.server
|
root_dir = File.dirname(File.dirname(File.dirname(__FILE__)))
|
||||||
@server.set :show_exceptions, false
|
|
||||||
root = File.dirname(File.dirname(File.dirname(__FILE__)))
|
initialize_commands = @initialize_commands || []
|
||||||
@server.set :root, File.join(root, "fixtures", app_path)
|
initialize_commands.unshift lambda {
|
||||||
@app = @server.new!
|
set :root, File.join(root_dir, "fixtures", app_path)
|
||||||
app_rack = @server.build_new(@app)
|
set :environment, @current_env || :development
|
||||||
@browser = Rack::Test::Session.new(Rack::MockSession.new(app_rack))
|
}
|
||||||
|
|
||||||
|
@server_inst = Middleman.server.inst do
|
||||||
|
initialize_commands.each do |p|
|
||||||
|
instance_exec(&p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
app_rack = @server_inst.class.to_rack_app
|
||||||
|
@browser = ::Rack::Test::Session.new(::Rack::MockSession.new(app_rack))
|
||||||
end
|
end
|
||||||
|
|
||||||
When /^I go to "([^\"]*)"$/ do |url|
|
When /^I go to "([^\"]*)"$/ do |url|
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
|
Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
|
||||||
@server ||= Middleman.server
|
@initialize_commands ||= []
|
||||||
@server.set :show_exceptions, false
|
@initialize_commands << lambda {
|
||||||
@server.page(url, :layout => layout.to_sym)
|
page(url, :layout => layout.to_sym)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout|
|
Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout|
|
||||||
@server ||= Middleman.server
|
@initialize_commands ||= []
|
||||||
@server.set :show_exceptions, false
|
@initialize_commands << lambda {
|
||||||
@server.with_layout(layout.to_sym) do
|
with_layout(layout.to_sym) do
|
||||||
page(url)
|
page(url)
|
||||||
end
|
end
|
||||||
|
}
|
||||||
end
|
end
|
|
@ -1,46 +0,0 @@
|
||||||
html, body, div, span, applet, object, iframe,
|
|
||||||
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
|
||||||
a, abbr, acronym, address, big, cite, code,
|
|
||||||
del, dfn, em, img, ins, kbd, q, s, samp,
|
|
||||||
small, strike, strong, sub, sup, tt, var,
|
|
||||||
b, u, i, center,
|
|
||||||
dl, dt, dd, ol, ul, li,
|
|
||||||
fieldset, form, label, legend,
|
|
||||||
table, caption, tbody, tfoot, thead, tr, th, td,
|
|
||||||
article, aside, canvas, details, embed,
|
|
||||||
figure, figcaption, footer, header, hgroup,
|
|
||||||
menu, nav, output, ruby, section, summary,
|
|
||||||
time, mark, audio, video {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
border: 0;
|
|
||||||
font-size: 100%;
|
|
||||||
font: inherit;
|
|
||||||
vertical-align: baseline; }
|
|
||||||
|
|
||||||
body {
|
|
||||||
line-height: 1; }
|
|
||||||
|
|
||||||
ol, ul {
|
|
||||||
list-style: none; }
|
|
||||||
|
|
||||||
table {
|
|
||||||
border-collapse: collapse;
|
|
||||||
border-spacing: 0; }
|
|
||||||
|
|
||||||
caption, th, td {
|
|
||||||
text-align: left;
|
|
||||||
font-weight: normal;
|
|
||||||
vertical-align: middle; }
|
|
||||||
|
|
||||||
q, blockquote {
|
|
||||||
quotes: none; }
|
|
||||||
q:before, q:after, blockquote:before, blockquote:after {
|
|
||||||
content: "";
|
|
||||||
content: none; }
|
|
||||||
|
|
||||||
a img {
|
|
||||||
border: none; }
|
|
||||||
|
|
||||||
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary {
|
|
||||||
display: block; }
|
|
|
@ -9,6 +9,7 @@ require "active_support/core_ext/string/inflections"
|
||||||
|
|
||||||
class Middleman::Base
|
class Middleman::Base
|
||||||
include Hooks
|
include Hooks
|
||||||
|
define_hook :before
|
||||||
define_hook :build_config
|
define_hook :build_config
|
||||||
define_hook :development_config
|
define_hook :development_config
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def map(map, &block)
|
def map(map, &block)
|
||||||
app.map(map, &block)
|
# app.map(map, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def helpers(*extensions, &block)
|
def helpers(*extensions, &block)
|
||||||
|
@ -79,9 +80,10 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(key, value)
|
def set(key, value=nil, &block)
|
||||||
setter = "#{key}=".to_sym
|
setter = "#{key}=".to_sym
|
||||||
self.class.send(:attr_accessor, key) if !respond_to?(setter)
|
self.class.send(:attr_accessor, key) if !respond_to?(setter)
|
||||||
|
value = block if block_given?
|
||||||
send(setter, value)
|
send(setter, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -159,28 +161,37 @@ class Middleman::Base
|
||||||
set(k, v)
|
set(k, v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
instance_exec(&block) if block_given?
|
||||||
|
|
||||||
set :source_dir, File.join(root, source)
|
set :source_dir, File.join(root, source)
|
||||||
|
|
||||||
super
|
super
|
||||||
|
|
||||||
instance_exec(&block) if block_given?
|
|
||||||
|
|
||||||
run_hook :initialized
|
run_hook :initialized
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr :env
|
||||||
|
attr :req
|
||||||
|
attr :res
|
||||||
|
attr :options
|
||||||
|
attr :locals
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
@env = env
|
@env = env
|
||||||
@req = Rack::Request.new(env)
|
@req = Rack::Request.new(env)
|
||||||
@res = Rack::Response.new
|
@res = Rack::Response.new
|
||||||
|
|
||||||
|
catch(:halt) do
|
||||||
process_request
|
process_request
|
||||||
|
|
||||||
|
res.status = 404
|
||||||
|
res.finish
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Custom 404 handler (to be styled)
|
def halt(response)
|
||||||
# app.error Sinatra::NotFound do
|
throw :halt, response
|
||||||
# content_type 'text/html'
|
end
|
||||||
# "<html><body><h1>File Not Found</h1><p>#{request.path_info}</p></body>"
|
|
||||||
# end
|
|
||||||
|
|
||||||
# Convenience methods to check if we're in a mode
|
# Convenience methods to check if we're in a mode
|
||||||
def development?; environment == :development; end
|
def development?; environment == :development; end
|
||||||
|
@ -188,14 +199,15 @@ class Middleman::Base
|
||||||
|
|
||||||
# Internal method to look for templates and evaluate them if found
|
# Internal method to look for templates and evaluate them if found
|
||||||
def process_request
|
def process_request
|
||||||
|
run_hook :before
|
||||||
|
|
||||||
# Normalize the path and add index if we're looking at a directory
|
# Normalize the path and add index if we're looking at a directory
|
||||||
original_path = @env["PATH_INFO"].dup
|
original_path = env["PATH_INFO"].dup
|
||||||
request_path = full_path(@env["PATH_INFO"].gsub("%20", " "))
|
request_path = full_path(env["PATH_INFO"].gsub("%20", " "))
|
||||||
|
|
||||||
return not_found if sitemap.ignored_path?(request_path)
|
return not_found if sitemap.ignored_path?(request_path)
|
||||||
|
|
||||||
if sitemap.path_is_proxy?(request_path)
|
if sitemap.path_is_proxy?(request_path)
|
||||||
# request["is_proxy"] = true
|
|
||||||
request_path = "/" + sitemap.path_target(request_path)
|
request_path = "/" + sitemap.path_target(request_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -212,12 +224,12 @@ class Middleman::Base
|
||||||
|
|
||||||
context = sitemap.get_context(original_path) || {}
|
context = sitemap.get_context(original_path) || {}
|
||||||
|
|
||||||
options = context.has_key?(:options) ? context[:options] : {}
|
@options = context.has_key?(:options) ? context[:options] : {}
|
||||||
# options.merge!(request['custom_options'] || {})
|
@locals = context.has_key?(:locals) ? context[:locals] : {}
|
||||||
|
|
||||||
provides_metadata.each do |callback, matcher|
|
provides_metadata.each do |callback, matcher|
|
||||||
next if !matcher.nil? && !path.match(matcher)
|
next if !matcher.nil? && !path.match(matcher)
|
||||||
options.merge!(instance_exec(path, &callback) || {})
|
instance_exec(path, &callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
local_layout = if options.has_key?(:layout)
|
local_layout = if options.has_key?(:layout)
|
||||||
|
@ -232,11 +244,8 @@ class Middleman::Base
|
||||||
instance_eval(&context[:block])
|
instance_eval(&context[:block])
|
||||||
end
|
end
|
||||||
|
|
||||||
# locals = request['custom_locals'] || {}
|
|
||||||
locals = {}
|
|
||||||
|
|
||||||
# content_type mime_type(File.extname(request_path))
|
# content_type mime_type(File.extname(request_path))
|
||||||
@res.status = 200
|
res.status = 200
|
||||||
|
|
||||||
output = if local_layout
|
output = if local_layout
|
||||||
layout_engine = if options.has_key?(:layout_engine)
|
layout_engine = if options.has_key?(:layout_engine)
|
||||||
|
@ -256,8 +265,8 @@ class Middleman::Base
|
||||||
render(path, locals)
|
render(path, locals)
|
||||||
end
|
end
|
||||||
|
|
||||||
@res.write output
|
res.write output
|
||||||
@res.finish
|
halt res.finish
|
||||||
end
|
end
|
||||||
|
|
||||||
public
|
public
|
||||||
|
@ -318,7 +327,6 @@ public
|
||||||
# raw_templates_cache[key]
|
# raw_templates_cache[key]
|
||||||
# end
|
# end
|
||||||
|
|
||||||
protected
|
|
||||||
def full_path(path)
|
def full_path(path)
|
||||||
parts = path ? path.split('/') : []
|
parts = path ? path.split('/') : []
|
||||||
if parts.last.nil? || parts.last.split('.').length == 1
|
if parts.last.nil? || parts.last.split('.').length == 1
|
||||||
|
@ -329,14 +337,13 @@ protected
|
||||||
|
|
||||||
def not_found
|
def not_found
|
||||||
@res.status == 404
|
@res.status == 404
|
||||||
@res.write "<html><body><h1>File Not Found</h1><p>#{@env["PATH_INFO"]}</p></body>"
|
@res.write "<html><body><h1>File Not Found</h1><p>#{env["PATH_INFO"]}</p></body>"
|
||||||
@res.finish
|
@res.finish
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_template(request_path, options={})
|
def resolve_template(request_path, options={})
|
||||||
request_path = request_path.to_s
|
request_path = request_path.to_s
|
||||||
@_resolved_templates ||= {}
|
@_resolved_templates ||= {}
|
||||||
|
|
||||||
if !@_resolved_templates.has_key?(request_path)
|
if !@_resolved_templates.has_key?(request_path)
|
||||||
relative_path = request_path.sub(%r{^/}, "")
|
relative_path = request_path.sub(%r{^/}, "")
|
||||||
on_disk_path = File.expand_path(relative_path, source_dir)
|
on_disk_path = File.expand_path(relative_path, source_dir)
|
||||||
|
@ -384,7 +391,7 @@ protected
|
||||||
|
|
||||||
file = ::Rack::File.new nil
|
file = ::Rack::File.new nil
|
||||||
file.path = path
|
file.path = path
|
||||||
file.serving(@env)
|
file.serving(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(path, locals = {}, options = {}, &block)
|
def render(path, locals = {}, options = {}, &block)
|
||||||
|
|
|
@ -17,7 +17,7 @@ module Middleman
|
||||||
|
|
||||||
request_path = destination.sub(/^#{SHARED_SERVER_INST.build_dir}/, "")
|
request_path = destination.sub(/^#{SHARED_SERVER_INST.build_dir}/, "")
|
||||||
|
|
||||||
# begin
|
begin
|
||||||
# destination, request_path = SHARED_SERVER.reroute_builder(destination, request_path)
|
# destination, request_path = SHARED_SERVER.reroute_builder(destination, request_path)
|
||||||
|
|
||||||
request_path.gsub!(/\s/, "%20")
|
request_path.gsub!(/\s/, "%20")
|
||||||
|
@ -26,8 +26,9 @@ module Middleman
|
||||||
create_file destination, nil, config do
|
create_file destination, nil, config do
|
||||||
response.body
|
response.body
|
||||||
end if response.status == 200
|
end if response.status == 200
|
||||||
# rescue
|
rescue
|
||||||
# end
|
say_status :error, destination, :red
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
data
|
@options.merge!(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
|
|
|
@ -1,53 +1,55 @@
|
||||||
module Middleman::Features::DirectoryIndexes
|
module Middleman::Features::DirectoryIndexes
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.set :ignored_directory_indexes, []
|
app.send :include, InstanceMethods
|
||||||
app.extend ClassMethods
|
|
||||||
|
|
||||||
app.build_reroute do |destination, request_path|
|
|
||||||
index_ext = File.extname(app.settings.index_file)
|
|
||||||
new_index_path = "/#{app.settings.index_file}"
|
|
||||||
|
|
||||||
indexed_path = request_path.gsub(/\/$/, "") + index_ext
|
|
||||||
|
|
||||||
if app.settings.ignored_directory_indexes.include?(request_path)
|
|
||||||
false
|
|
||||||
elsif request_path =~ /#{new_index_path}$/
|
|
||||||
false
|
|
||||||
else
|
|
||||||
[
|
|
||||||
destination.gsub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
|
|
||||||
request_path
|
|
||||||
]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
app.before do
|
app.before do
|
||||||
indexed_path = request.path_info.gsub(/\/$/, "") + "/" + app.settings.index_file
|
indexed_path = env["PATH_INFO"].sub(/\/$/, "") + "/" + self.index_file
|
||||||
indexed_exists = resolve_template(indexed_path, :raise_exceptions => false)
|
indexed_exists = resolve_template(indexed_path)
|
||||||
|
|
||||||
extensioned_path = request.path_info.gsub(/\/$/, "") + File.extname(app.settings.index_file)
|
extensioned_path = env["PATH_INFO"].sub(/\/$/, "") + File.extname(self.index_file)
|
||||||
is_ingored = settings.ignored_directory_indexes.include?(extensioned_path)
|
is_ignored = self.ignored_directory_indexes.include?(extensioned_path)
|
||||||
|
|
||||||
if !indexed_exists && !is_ingored
|
if !indexed_exists && !is_ignored
|
||||||
parts = request.path_info.split("/")
|
parts = env["PATH_INFO"].split("/")
|
||||||
last_part = parts.last
|
last_part = parts.last
|
||||||
last_part_ext = File.extname(last_part)
|
last_part_ext = File.extname(last_part)
|
||||||
|
|
||||||
if last_part_ext.blank?
|
if last_part_ext.blank?
|
||||||
# This is a folder, redirect to index
|
# This is a folder, redirect to index
|
||||||
request.path_info = extensioned_path
|
env["PATH_INFO"] = extensioned_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# app.build_reroute do |destination, request_path|
|
||||||
|
# index_ext = File.extname(app.settings.index_file)
|
||||||
|
# new_index_path = "/#{app.settings.index_file}"
|
||||||
|
#
|
||||||
|
# indexed_path = request_path.gsub(/\/$/, "") + index_ext
|
||||||
|
#
|
||||||
|
# if app.settings.ignored_directory_indexes.include?(request_path)
|
||||||
|
# false
|
||||||
|
# elsif request_path =~ /#{new_index_path}$/
|
||||||
|
# false
|
||||||
|
# else
|
||||||
|
# [
|
||||||
|
# destination.gsub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
|
||||||
|
# request_path
|
||||||
|
# ]
|
||||||
|
# end
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module InstanceMethods
|
||||||
|
def ignored_directory_indexes
|
||||||
|
@_ignored_directory_indexes ||= []
|
||||||
|
end
|
||||||
|
|
||||||
def page(url, options={}, &block)
|
def page(url, options={}, &block)
|
||||||
if options.has_key?(:directory_index) && !options["directory_index"]
|
if options.has_key?(:directory_index) && !options["directory_index"]
|
||||||
settings.ignored_directory_indexes << url
|
ignored_directory_indexes << url
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,13 +9,8 @@ module Middleman::Renderers::Liquid
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
Liquid::Template.file_system = Liquid::LocalFileSystem.new(self.source_dir)
|
Liquid::Template.file_system = Liquid::LocalFileSystem.new(self.source_dir)
|
||||||
|
|
||||||
app.before_processing(:liquid) do |result|
|
provides_metadata %r{\.liquid$} do |path|
|
||||||
if result && result[1] == :liquid
|
@locals.merge!(:data => data.to_h)
|
||||||
request['custom_locals'] ||= {}
|
|
||||||
request['custom_locals'][:data] = data.to_h
|
|
||||||
end
|
|
||||||
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
Loading…
Reference in a new issue