mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
rackmap hates me
This commit is contained in:
parent
f4fa1acd3e
commit
c82a40dde5
27 changed files with 265 additions and 262 deletions
|
@ -1 +0,0 @@
|
||||||
I am real
|
|
|
@ -1 +0,0 @@
|
||||||
I am real: one
|
|
|
@ -1 +0,0 @@
|
||||||
I am real: two
|
|
|
@ -1,12 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>My Sample Site</title>
|
|
||||||
<!-- Comment in layout -->
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Welcome</h1>
|
|
||||||
<h2 id='h2'>H2</h2>
|
|
||||||
|
|
||||||
<p>Paragraph</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1 +0,0 @@
|
||||||
I am real
|
|
|
@ -1 +0,0 @@
|
||||||
I am real:
|
|
|
@ -1 +0,0 @@
|
||||||
Static, no code!
|
|
|
@ -1 +0,0 @@
|
||||||
<h1>Ignore me! 3</h1>
|
|
Binary file not shown.
|
@ -1,3 +0,0 @@
|
||||||
@font-face {
|
|
||||||
font-family: "St Marie";
|
|
||||||
src: url('/fonts/StMarie-Thin.otf') format('opentype'); }
|
|
|
@ -1 +0,0 @@
|
||||||
Indexable
|
|
|
@ -1 +0,0 @@
|
||||||
Stay away
|
|
|
@ -1 +0,0 @@
|
||||||
Indexable
|
|
|
@ -1 +0,0 @@
|
||||||
Regular
|
|
|
@ -51,7 +51,3 @@ with_layout false do
|
||||||
page path
|
page path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/sinatra_test" do
|
|
||||||
"Ratpack"
|
|
||||||
end
|
|
|
@ -22,6 +22,15 @@ class Middleman::Base
|
||||||
@app ||= Rack::Builder.new
|
@app ||= Rack::Builder.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inst(&block)
|
||||||
|
@inst ||= new(&block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_rack_app(&block)
|
||||||
|
app.run inst(&block)
|
||||||
|
app
|
||||||
|
end
|
||||||
|
|
||||||
def prototype
|
def prototype
|
||||||
@prototype ||= app.to_app
|
@prototype ||= app.to_app
|
||||||
end
|
end
|
||||||
|
@ -154,6 +163,8 @@ class Middleman::Base
|
||||||
|
|
||||||
super
|
super
|
||||||
|
|
||||||
|
instance_exec(&block) if block_given?
|
||||||
|
|
||||||
run_hook :initialized
|
run_hook :initialized
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -181,39 +192,45 @@ class Middleman::Base
|
||||||
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["is_proxy"] = true
|
||||||
# request_path = "/" + sitemap.path_target(request_path)
|
request_path = "/" + sitemap.path_target(request_path)
|
||||||
# end
|
end
|
||||||
|
|
||||||
found_template = resolve_template(request_path)
|
found_template = resolve_template(request_path)
|
||||||
return not_found unless found_template
|
return not_found unless found_template
|
||||||
|
|
||||||
|
@current_path = request_path
|
||||||
path, engine = found_template
|
path, engine = found_template
|
||||||
|
|
||||||
# Static File
|
# Static File
|
||||||
return send_file(path) if engine.nil?
|
return send_file(path) if engine.nil?
|
||||||
|
|
||||||
# return unless settings.execute_before_processing!(self, found_template)
|
return unless self.class.execute_before_processing!(self, found_template)
|
||||||
|
|
||||||
# context = settings.sitemap.get_context(original_path) || {}
|
context = sitemap.get_context(original_path) || {}
|
||||||
#
|
|
||||||
options = {}
|
options = context.has_key?(:options) ? context[:options] : {}
|
||||||
# options = context.has_key?(:options) ? context[:options] : {}
|
|
||||||
# options.merge!(request['custom_options'] || {})
|
# options.merge!(request['custom_options'] || {})
|
||||||
#
|
|
||||||
|
provides_metadata.each do |callback, matcher|
|
||||||
|
next if !matcher.nil? && !path.match(matcher)
|
||||||
|
options.merge!(instance_exec(path, &callback) || {})
|
||||||
|
end
|
||||||
|
|
||||||
local_layout = if options.has_key?(:layout)
|
local_layout = if options.has_key?(:layout)
|
||||||
options[:layout]
|
options[:layout]
|
||||||
|
elsif %w(.js .css).include?(File.extname(request_path))
|
||||||
|
false
|
||||||
else
|
else
|
||||||
layout
|
layout
|
||||||
end
|
end
|
||||||
|
|
||||||
# if context.has_key?(:block) && context[:block]
|
if context.has_key?(:block) && context[:block]
|
||||||
# instance_eval(&context[:block])
|
instance_eval(&context[:block])
|
||||||
# end
|
end
|
||||||
|
|
||||||
# locals = request['custom_locals'] || {}
|
# locals = request['custom_locals'] || {}
|
||||||
locals = {}
|
locals = {}
|
||||||
|
@ -221,14 +238,16 @@ class Middleman::Base
|
||||||
# content_type mime_type(File.extname(request_path))
|
# content_type mime_type(File.extname(request_path))
|
||||||
@res.status = 200
|
@res.status = 200
|
||||||
|
|
||||||
output = if layout
|
output = if local_layout
|
||||||
layout_engine = if options.has_key?(:layout_engine)
|
layout_engine = if options.has_key?(:layout_engine)
|
||||||
options[:layout_engine]
|
options[:layout_engine]
|
||||||
else
|
else
|
||||||
engine
|
engine
|
||||||
end
|
end
|
||||||
|
|
||||||
layout_path, *etc = resolve_template(layout, :preferred_engine => layout_engine)
|
layout_path, *etc = resolve_template(local_layout, :preferred_engine => layout_engine)
|
||||||
|
|
||||||
|
throw "Could not locate layout: #{local_layout}" unless layout_path
|
||||||
|
|
||||||
render(layout_path, locals) do
|
render(layout_path, locals) do
|
||||||
render(path, locals)
|
render(path, locals)
|
||||||
|
@ -242,9 +261,64 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
public
|
public
|
||||||
|
def extensionless_path(file)
|
||||||
|
@_extensionless_path_cache ||= {}
|
||||||
|
|
||||||
|
if @_extensionless_path_cache.has_key?(file)
|
||||||
|
@_extensionless_path_cache[file]
|
||||||
|
else
|
||||||
|
path = file.dup
|
||||||
|
end_of_the_line = false
|
||||||
|
while !end_of_the_line
|
||||||
|
file_extension = File.extname(path)
|
||||||
|
|
||||||
|
if ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, ""))
|
||||||
|
path = path.sub(file_extension, "")
|
||||||
|
else
|
||||||
|
end_of_the_line = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@_extensionless_path_cache[file] = path
|
||||||
|
path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def logging?
|
||||||
|
logging
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_path
|
||||||
|
@current_path || nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def raw_templates_cache
|
||||||
|
@_raw_templates_cache ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_raw_template(path)
|
||||||
|
if !raw_templates_cache.has_key?(path)
|
||||||
|
raw_templates_cache[path] = File.read(path)
|
||||||
|
end
|
||||||
|
|
||||||
|
raw_templates_cache[path]
|
||||||
|
end
|
||||||
|
|
||||||
|
# def compiled_templates_cache
|
||||||
|
# @_compiled_templates_cache ||= {}
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# def read_compiled_template(path, locals, options, &block)
|
||||||
|
# key = [path, locals, options]
|
||||||
|
#
|
||||||
|
# if !raw_templates_cache.has_key?(key)
|
||||||
|
# raw_templates_cache[key] = yield
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# raw_templates_cache[key]
|
||||||
|
# end
|
||||||
|
|
||||||
protected
|
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
|
||||||
|
@ -302,29 +376,6 @@ protected
|
||||||
@_resolved_templates[request_path]
|
@_resolved_templates[request_path]
|
||||||
end
|
end
|
||||||
|
|
||||||
def extensionless_path(file)
|
|
||||||
@_extensionless_path_cache ||= {}
|
|
||||||
|
|
||||||
if @_extensionless_path_cache.has_key?(file)
|
|
||||||
@_extensionless_path_cache[file]
|
|
||||||
else
|
|
||||||
path = file.dup
|
|
||||||
end_of_the_line = false
|
|
||||||
while !end_of_the_line
|
|
||||||
file_extension = File.extname(path)
|
|
||||||
|
|
||||||
if ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, ""))
|
|
||||||
path = path.sub(file_extension, "")
|
|
||||||
else
|
|
||||||
end_of_the_line = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@_extensionless_path_cache[file] = path
|
|
||||||
path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def send_file(path)
|
def send_file(path)
|
||||||
|
|
||||||
# matched_mime = mime_type(File.extname(request_path))
|
# matched_mime = mime_type(File.extname(request_path))
|
||||||
|
@ -333,16 +384,14 @@ 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)
|
||||||
path = path.to_s
|
path = path.to_s
|
||||||
template = ::Tilt.new(path, 1, options)
|
|
||||||
|
body = read_raw_template(path)
|
||||||
|
template = ::Tilt.new(path, 1, options) { body }
|
||||||
template.render(self, locals, &block)
|
template.render(self, locals, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def logging?
|
|
||||||
logging
|
|
||||||
end
|
|
||||||
end
|
end
|
|
@ -4,8 +4,10 @@ require 'rack/test'
|
||||||
require 'find'
|
require 'find'
|
||||||
require 'hooks'
|
require 'hooks'
|
||||||
|
|
||||||
SHARED_SERVER = Middleman.server
|
SHARED_SERVER_INST = Middleman.server.inst do
|
||||||
SHARED_SERVER.set :environment, :build
|
set :environment, :build
|
||||||
|
end
|
||||||
|
SHARED_SERVER = SHARED_SERVER_INST.class
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module ThorActions
|
module ThorActions
|
||||||
|
@ -13,10 +15,10 @@ module Middleman
|
||||||
config = args.last.is_a?(Hash) ? args.pop : {}
|
config = args.last.is_a?(Hash) ? args.pop : {}
|
||||||
destination = args.first || source
|
destination = args.first || source
|
||||||
|
|
||||||
request_path = destination.sub(/^#{SHARED_SERVER.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")
|
||||||
response = Middleman::Builder.shared_rack.get(request_path)
|
response = Middleman::Builder.shared_rack.get(request_path)
|
||||||
|
@ -24,8 +26,8 @@ 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
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,9 +40,7 @@ module Middleman
|
||||||
|
|
||||||
def self.shared_rack
|
def self.shared_rack
|
||||||
@shared_rack ||= begin
|
@shared_rack ||= begin
|
||||||
app = SHARED_SERVER.new!
|
mock = ::Rack::MockSession.new(SHARED_SERVER.to_rack_app)
|
||||||
app_rack = SHARED_SERVER.build_new(app)
|
|
||||||
mock = ::Rack::MockSession.new(app_rack)
|
|
||||||
sess = ::Rack::Test::Session.new(mock)
|
sess = ::Rack::Test::Session.new(mock)
|
||||||
response = sess.get("__middleman__")
|
response = sess.get("__middleman__")
|
||||||
sess
|
sess
|
||||||
|
@ -54,13 +54,13 @@ module Middleman
|
||||||
super
|
super
|
||||||
|
|
||||||
if options.has_key?("relative") && options["relative"]
|
if options.has_key?("relative") && options["relative"]
|
||||||
SHARED_SERVER.activate :relative_assets
|
SHARED_SERVER_INST.activate :relative_assets
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def source_paths
|
def source_paths
|
||||||
@source_paths ||= [
|
@source_paths ||= [
|
||||||
SHARED_SERVER.root
|
SHARED_SERVER_INST.root
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ module Middleman
|
||||||
opts[:glob] = options["glob"] if options.has_key?("glob")
|
opts[:glob] = options["glob"] if options.has_key?("glob")
|
||||||
opts[:clean] = options["clean"] if options.has_key?("clean")
|
opts[:clean] = options["clean"] if options.has_key?("clean")
|
||||||
|
|
||||||
action GlobAction.new(self, SHARED_SERVER, opts)
|
action GlobAction.new(self, SHARED_SERVER_INST, opts)
|
||||||
|
|
||||||
run_hook :after_build
|
run_hook :after_build
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,23 +6,36 @@ module Middleman::CoreExtensions::Data
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.set :data_dir, "data"
|
app.set :data_dir, "data"
|
||||||
app.extend ClassMethods
|
app.send :include, InstanceMethods
|
||||||
app.helpers Helpers
|
|
||||||
|
|
||||||
app.file_changed DataStore.matcher do |file|
|
|
||||||
data.touch_file(file) if file.match(%r{^#{settings.data_dir}\/})
|
|
||||||
end
|
|
||||||
|
|
||||||
app.file_deleted DataStore.matcher do |file|
|
|
||||||
data.remove_file(file) if file.match(%r{^#{settings.data_dir}\/})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helpers
|
module InstanceMethods
|
||||||
|
def initialize
|
||||||
|
file_changed DataStore.matcher do |file|
|
||||||
|
data.touch_file(file) if file.match(%r{^#{data_dir}\/})
|
||||||
|
end
|
||||||
|
|
||||||
|
file_deleted DataStore.matcher do |file|
|
||||||
|
data.remove_file(file) if file.match(%r{^#{data_dir}\/})
|
||||||
|
end
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
settings.data
|
@data ||= DataStore.new(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Makes a hash available on the data var with a given name
|
||||||
|
def data_content(name, content)
|
||||||
|
DataStore.data_content(name, content)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Makes a hash available on the data var with a given name
|
||||||
|
def data_callback(name, &block)
|
||||||
|
DataStore.data_callback(name, block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -49,7 +62,7 @@ module Middleman::CoreExtensions::Data
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.logger.debug :data_update, Time.now, basename if @app.settings.logging?
|
# @app.logger.debug :data_update, Time.now, basename if @app.logging?
|
||||||
@local_data[basename] = recursively_enhance(data)
|
@local_data[basename] = recursively_enhance(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -137,20 +150,4 @@ module Middleman::CoreExtensions::Data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
|
||||||
def data
|
|
||||||
@data ||= DataStore.new(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Makes a hash available on the data var with a given name
|
|
||||||
def data_content(name, content)
|
|
||||||
DataStore.data_content(name, content)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Makes a hash available on the data var with a given name
|
|
||||||
def data_callback(name, &block)
|
|
||||||
DataStore.data_callback(name, block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
|
@ -1,11 +1,6 @@
|
||||||
require "padrino-helpers"
|
|
||||||
|
|
||||||
module Middleman::CoreExtensions::DefaultHelpers
|
module Middleman::CoreExtensions::DefaultHelpers
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Use Padrino Helpers
|
|
||||||
app.register Padrino::Helpers
|
|
||||||
|
|
||||||
# Middleman Helpers
|
# Middleman Helpers
|
||||||
app.helpers Helpers
|
app.helpers Helpers
|
||||||
end
|
end
|
||||||
|
@ -13,6 +8,11 @@ module Middleman::CoreExtensions::DefaultHelpers
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helpers
|
module Helpers
|
||||||
|
|
||||||
|
# TODO: Implement
|
||||||
|
def javascript_include_tag(path)
|
||||||
|
end
|
||||||
|
|
||||||
def auto_stylesheet_link_tag(separator="/")
|
def auto_stylesheet_link_tag(separator="/")
|
||||||
auto_tag(:css, separator) do |path|
|
auto_tag(:css, separator) do |path|
|
||||||
stylesheet_link_tag path
|
stylesheet_link_tag path
|
||||||
|
@ -28,25 +28,25 @@ module Middleman::CoreExtensions::DefaultHelpers
|
||||||
def auto_tag(asset_ext, separator="/", asset_dir=nil)
|
def auto_tag(asset_ext, separator="/", asset_dir=nil)
|
||||||
if asset_dir.nil?
|
if asset_dir.nil?
|
||||||
asset_dir = case asset_ext
|
asset_dir = case asset_ext
|
||||||
when :js then self.class.js_dir
|
when :js then self.js_dir
|
||||||
when :css then self.class.css_dir
|
when :css then self.css_dir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
path = request.path_info.dup
|
path = current_path.dup
|
||||||
# If the basename of the request as no extension, assume we are serving a
|
# If the basename of the request as no extension, assume we are serving a
|
||||||
# directory and join index_file to the path.
|
# directory and join index_file to the path.
|
||||||
path = File.join(path, self.class.index_file) if File.extname(path).empty?
|
path = File.join(path, self.index_file) if File.extname(path).empty?
|
||||||
path = path.gsub(%r{^/}, '')
|
path = path.gsub(%r{^/}, '')
|
||||||
path = path.gsub(File.extname(path), ".#{asset_ext}")
|
path = path.gsub(File.extname(path), ".#{asset_ext}")
|
||||||
path = path.gsub("/", separator)
|
path = path.gsub("/", separator)
|
||||||
|
|
||||||
view = File.join(self.class.views, asset_dir, path)
|
view = File.join(self.views, asset_dir, path)
|
||||||
yield path if File.exists?(view) or Dir["#{view}.*"].any?
|
yield path if File.exists?(view) or Dir["#{view}.*"].any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_classes
|
def page_classes
|
||||||
path = request.path_info.dup
|
path = current_path.dup
|
||||||
path << settings.index_file if path.match(%r{/$})
|
path << self.index_file if path.match(%r{/$})
|
||||||
path = path.gsub(%r{^/}, '')
|
path = path.gsub(%r{^/}, '')
|
||||||
|
|
||||||
classes = []
|
classes = []
|
||||||
|
@ -60,9 +60,9 @@ module Middleman::CoreExtensions::DefaultHelpers
|
||||||
def asset_path(kind, source)
|
def asset_path(kind, source)
|
||||||
return source if source =~ /^http/
|
return source if source =~ /^http/
|
||||||
asset_folder = case kind
|
asset_folder = case kind
|
||||||
when :css then settings.css_dir
|
when :css then self.css_dir
|
||||||
when :js then settings.js_dir
|
when :js then self.js_dir
|
||||||
when :images then settings.images_dir
|
when :images then self.images_dir
|
||||||
else kind.to_s
|
else kind.to_s
|
||||||
end
|
end
|
||||||
source = source.to_s.gsub(/\s/, '')
|
source = source.to_s.gsub(/\s/, '')
|
||||||
|
|
|
@ -89,8 +89,7 @@ module Middleman::CoreExtensions::Features
|
||||||
local_config = File.join(self.root, "config.rb")
|
local_config = File.join(self.root, "config.rb")
|
||||||
if File.exists? local_config
|
if File.exists? local_config
|
||||||
puts "== Reading: Local config" if logging?
|
puts "== Reading: Local config" if logging?
|
||||||
# instance_eval File.read(local_config)
|
instance_eval File.read(local_config)
|
||||||
# set :app_file, File.expand_path(local_config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
run_hook :after_configuration
|
run_hook :after_configuration
|
||||||
|
|
|
@ -11,7 +11,6 @@ module Middleman::CoreExtensions::FileWatcher
|
||||||
file_did_change(path.sub("#{root}/", ""))
|
file_did_change(path.sub("#{root}/", ""))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
@ -31,8 +30,8 @@ module Middleman::CoreExtensions::FileWatcher
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
def file_changed(*args)
|
def file_changed(*args, &block)
|
||||||
self.class.file_changed(*args)
|
self.class.file_changed(*args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_did_change(path)
|
def file_did_change(path)
|
||||||
|
|
|
@ -4,56 +4,47 @@ require "tilt"
|
||||||
module Middleman::CoreExtensions::FrontMatter
|
module Middleman::CoreExtensions::FrontMatter
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.extend ClassMethods
|
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
|
|
||||||
app.file_changed FrontMatter.matcher do |file|
|
|
||||||
frontmatter.touch_file(file)
|
|
||||||
end
|
|
||||||
|
|
||||||
app.file_deleted do |file|
|
|
||||||
frontmatter.remove_file(file)
|
|
||||||
end
|
|
||||||
|
|
||||||
app.after_configuration do
|
|
||||||
app.before_processing(:front_matter) do |result|
|
|
||||||
if result && Tilt.mappings.has_key?(result[1].to_s)
|
|
||||||
extensionless_path, template_engine = result
|
|
||||||
full_file_path = "#{extensionless_path}.#{template_engine}"
|
|
||||||
|
|
||||||
if app.frontmatter.has_data?(full_file_path)
|
|
||||||
data = app.frontmatter.data(full_file_path).first
|
|
||||||
|
|
||||||
request['custom_options'] = {}
|
|
||||||
%w(layout layout_engine).each do |opt|
|
|
||||||
if data.has_key?(opt)
|
|
||||||
request['custom_options'][opt.to_sym] = data[opt]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
data = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
# Forward remaining data to helpers
|
|
||||||
app.data_content("page", data)
|
|
||||||
end
|
|
||||||
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module InstanceMethods
|
||||||
def frontmatter
|
def initialize
|
||||||
@frontmatter ||= FrontMatter.new(self)
|
file_changed FrontMatter.matcher do |file|
|
||||||
|
frontmatter.touch_file(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
file_deleted do |file|
|
||||||
|
frontmatter.remove_file(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
provides_metadata FrontMatter.matcher do |path|
|
||||||
|
relative_path = path.sub(source_dir, "")
|
||||||
|
|
||||||
|
data = if frontmatter.has_data?(relative_path)
|
||||||
|
frontmatter.data(relative_path).first
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Forward remaining data to helpers
|
||||||
|
data_content("page", data)
|
||||||
|
|
||||||
|
%w(layout layout_engine).each do |opt|
|
||||||
|
if data.has_key?(opt)
|
||||||
|
data[opt.to_sym] = data.delete(opt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
data
|
||||||
|
end
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
def frontmatter
|
def frontmatter
|
||||||
settings.frontmatter
|
@frontmatter ||= FrontMatter.new(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,7 +55,7 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
@source ||= File.expand_path(@app.views, @app.root)
|
@source = File.expand_path(@app.views, @app.root)
|
||||||
@local_data = {}
|
@local_data = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,22 +69,22 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
file = File.expand_path(file, @app.root)
|
file = File.expand_path(file, @app.root)
|
||||||
content = File.read(file)
|
content = File.read(file)
|
||||||
file = file.sub(@source, "")
|
file = file.sub(@app.source_dir, "")
|
||||||
|
|
||||||
@app.logger.debug :frontmatter_update, Time.now, file if @app.settings.logging?
|
# @app.logger.debug :frontmatter_update, Time.now, file if @app.logging?
|
||||||
result = parse_front_matter(content)
|
result = parse_front_matter(content)
|
||||||
|
|
||||||
if result
|
if result
|
||||||
@local_data[file] = result
|
@local_data[file] = result
|
||||||
path = @app.extensionless_path(file)
|
path = @app.extensionless_path(file)
|
||||||
@app.settings.templates[path.to_sym] = [result[1], path.to_s, 1]
|
@app.raw_templates_cache[path] = result[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_file(file)
|
def remove_file(file)
|
||||||
file = File.expand_path(file, @app.root)
|
file = File.expand_path(file, @app.root)
|
||||||
file = file.sub(@source, "")
|
file = file.sub(@app.source_dir, "")
|
||||||
@app.logger.debug :frontmatter_remove, Time.now, file if @app.settings.logging?
|
# @app.logger.debug :frontmatter_remove, Time.now, file if @app.logging?
|
||||||
|
|
||||||
if @local_data.has_key?(file)
|
if @local_data.has_key?(file)
|
||||||
@local_data.delete(file)
|
@local_data.delete(file)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
module Middleman::CoreExtensions::Routing
|
module Middleman::CoreExtensions::Routing
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.extend ClassMethods
|
app.send :include, InstanceMethods
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module InstanceMethods
|
||||||
# Takes a block which allows many pages to have the same layout
|
# Takes a block which allows many pages to have the same layout
|
||||||
# with_layout :admin do
|
# with_layout :admin do
|
||||||
# page "/admin/"
|
# page "/admin/"
|
||||||
|
@ -16,7 +16,7 @@ module Middleman::CoreExtensions::Routing
|
||||||
old_layout = layout
|
old_layout = layout
|
||||||
|
|
||||||
set :layout, layout_name
|
set :layout, layout_name
|
||||||
class_eval(&block) if block_given?
|
instance_exec(&block) if block_given?
|
||||||
ensure
|
ensure
|
||||||
set :layout, old_layout
|
set :layout, old_layout
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,27 +3,24 @@ require 'find'
|
||||||
module Middleman::CoreExtensions::Sitemap
|
module Middleman::CoreExtensions::Sitemap
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.extend ClassMethods
|
app.send :include, InstanceMethods
|
||||||
app.helpers Helpers
|
|
||||||
|
|
||||||
app.file_changed do |file|
|
|
||||||
sitemap.touch_file(file)
|
|
||||||
end
|
|
||||||
|
|
||||||
app.file_deleted do |file|
|
|
||||||
sitemap.remove_file(file)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helpers
|
module InstanceMethods
|
||||||
def sitemap
|
def initialize
|
||||||
self.class.sitemap
|
file_changed do |file|
|
||||||
end
|
sitemap.touch_file(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
file_deleted do |file|
|
||||||
|
sitemap.remove_file(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
|
||||||
def sitemap
|
def sitemap
|
||||||
@sitemap ||= SitemapStore.new(self)
|
@sitemap ||= SitemapStore.new(self)
|
||||||
end
|
end
|
||||||
|
@ -36,6 +33,12 @@ module Middleman::CoreExtensions::Sitemap
|
||||||
def reroute(url, target)
|
def reroute(url, target)
|
||||||
sitemap.set_path(url, target)
|
sitemap.set_path(url, target)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def provides_metadata(matcher=nil, &block)
|
||||||
|
@_provides_metadata ||= []
|
||||||
|
@_provides_metadata << [block, matcher] if block_given?
|
||||||
|
@_provides_metadata
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class SitemapStore
|
class SitemapStore
|
||||||
|
@ -216,7 +219,7 @@ module Middleman::CoreExtensions::Sitemap
|
||||||
return false if path == "layout" ||
|
return false if path == "layout" ||
|
||||||
path.match(/^layouts/)
|
path.match(/^layouts/)
|
||||||
|
|
||||||
@app.logger.debug :sitemap_update, Time.now, path if @app.settings.logging?
|
# @app.logger.debug :sitemap_update, Time.now, path if @app.logging?
|
||||||
set_path(path)
|
set_path(path)
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -2,6 +2,13 @@ require 'pathname'
|
||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
require "sprockets"
|
require "sprockets"
|
||||||
|
|
||||||
|
class RackThingy
|
||||||
|
def call(env)
|
||||||
|
$stderr.puts "thingy"
|
||||||
|
[200, {}, "Sup"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module Middleman::CoreExtensions::Sprockets
|
module Middleman::CoreExtensions::Sprockets
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
|
@ -20,48 +27,49 @@ module Middleman::CoreExtensions::Sprockets
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
app.after_configuration do
|
# app.after_configuration do
|
||||||
js_env = Middleman::CoreExtensions::Sprockets::JavascriptEnvironment.new(self)
|
# js_env = Middleman::CoreExtensions::Sprockets::JavascriptEnvironment.new(self)
|
||||||
|
#
|
||||||
vendor_dir = File.join("vendor", "assets", "javascripts")
|
# vendor_dir = File.join("vendor", "assets", "javascripts")
|
||||||
gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
|
# gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
|
||||||
::Middleman.spec_has_file?(spec, vendor_dir)
|
# ::Middleman.spec_has_file?(spec, vendor_dir)
|
||||||
end.each do |spec|
|
# end.each do |spec|
|
||||||
js_env.append_path File.join(spec.full_gem_path, vendor_dir)
|
# js_env.append_path File.join(spec.full_gem_path, vendor_dir)
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
app_dir = File.join("app", "assets", "javascripts")
|
# app_dir = File.join("app", "assets", "javascripts")
|
||||||
gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
|
# gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
|
||||||
::Middleman.spec_has_file?(spec, app_dir)
|
# ::Middleman.spec_has_file?(spec, app_dir)
|
||||||
end.each do |spec|
|
# end.each do |spec|
|
||||||
js_env.append_path File.join(spec.full_gem_path, app_dir)
|
# js_env.append_path File.join(spec.full_gem_path, app_dir)
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# add paths to js_env (vendor/assets/javascripts)
|
# # add paths to js_env (vendor/assets/javascripts)
|
||||||
app.map "/#{self.js_dir}" do
|
# app.map "/#{self.js_dir}" do
|
||||||
run js_env
|
# run js_env
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
app.after_compass_config do
|
app.after_compass_config do
|
||||||
css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self)
|
# css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self)
|
||||||
|
#
|
||||||
vendor_dir = File.join("vendor", "assets", "stylesheets")
|
# vendor_dir = File.join("vendor", "assets", "stylesheets")
|
||||||
gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
|
# gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
|
||||||
::Middleman.spec_has_file?(spec, vendor_dir)
|
# ::Middleman.spec_has_file?(spec, vendor_dir)
|
||||||
end.each do |spec|
|
# end.each do |spec|
|
||||||
css_env.append_path File.join(spec.full_gem_path, vendor_dir)
|
# css_env.append_path File.join(spec.full_gem_path, vendor_dir)
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
app_dir = File.join("app", "assets", "stylesheets")
|
# app_dir = File.join("app", "assets", "stylesheets")
|
||||||
gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
|
# gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
|
||||||
::Middleman.spec_has_file?(spec, app_dir)
|
# ::Middleman.spec_has_file?(spec, app_dir)
|
||||||
end.each do |spec|
|
# end.each do |spec|
|
||||||
css_env.append_path File.join(spec.full_gem_path, app_dir)
|
# css_env.append_path File.join(spec.full_gem_path, app_dir)
|
||||||
end
|
# end
|
||||||
|
|
||||||
app.map "/#{self.css_dir}" do
|
app.map "/#{self.css_dir}" do
|
||||||
run css_env
|
# run css_env
|
||||||
|
run ::RackThingy.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,17 +57,3 @@ module Middleman::Renderers::Sass
|
||||||
::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
|
::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
|
||||||
::Tilt.prefer(ScssPlusCSSFilenameTemplate)
|
::Tilt.prefer(ScssPlusCSSFilenameTemplate)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Use sass settings in Haml filters
|
|
||||||
# Other, tilt-based filters (like those used in Slim) will
|
|
||||||
# work automatically.
|
|
||||||
# module Middleman::Renderers::Haml
|
|
||||||
# module Sass
|
|
||||||
# include ::Haml::Filters::Base
|
|
||||||
#
|
|
||||||
# def render(text)
|
|
||||||
# sass_options = scope.settings.sass
|
|
||||||
# ::Sass::Engine.new(text, sass_options).render
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# end
|
|
|
@ -39,9 +39,10 @@ Gem::Specification.new do |s|
|
||||||
|
|
||||||
s.add_dependency("guard", ["~> 0.8.8"])
|
s.add_dependency("guard", ["~> 0.8.8"])
|
||||||
# s.add_dependency("eventmachine", ["1.0.0.beta.4"])
|
# s.add_dependency("eventmachine", ["1.0.0.beta.4"])
|
||||||
# s.add_dependency("middleman-livereload", ["~> 0.2.0"])
|
|
||||||
|
|
||||||
# Development and test
|
# Development and test
|
||||||
|
s.add_development_dependency("slim")
|
||||||
|
s.add_development_dependency("maruku")
|
||||||
s.add_development_dependency("coffee-filter", ["~> 0.1.1"])
|
s.add_development_dependency("coffee-filter", ["~> 0.1.1"])
|
||||||
s.add_development_dependency("liquid", ["~> 2.2.0"])
|
s.add_development_dependency("liquid", ["~> 2.2.0"])
|
||||||
s.add_development_dependency("cucumber", ["~> 1.1.0"])
|
s.add_development_dependency("cucumber", ["~> 1.1.0"])
|
||||||
|
|
Loading…
Reference in a new issue