fix frontmatter auto updater and switch to Padrino.logger

This commit is contained in:
Thomas Reynolds 2011-11-17 11:43:04 -08:00
parent 28e06e3e69
commit 34d3522d93
6 changed files with 91 additions and 30 deletions

View file

@ -5,6 +5,18 @@ require "active_support"
require "active_support/json"
require "active_support/core_ext/class/attribute_accessors"
module Padrino
class << self
attr_accessor :root_dir, :env
def root(*args)
File.expand_path(File.join(root_dir, *args))
end
end
end
ENV['PADRINO_LOG_LEVEL'] = "debug"
require "padrino-core/logger"
module Middleman::Base
class << self
def registered(app)
@ -144,12 +156,25 @@ module Middleman::Base
builder.run inst || new!
builder.to_app
end
def logger
Padrino.logger
end
end
module InstanceMethods
def logger
Padrino.logger
end
def initialize(*args)
super
run_hook :initialized, settings
Padrino.root_dir = settings.root
Padrino.env = settings.environment
Padrino::Logger::Config[:debug] = { :stream => :stderr }
# Padrino::Logger::Config[:development][:stream] = StringIO.new
end
def forward

View file

@ -5,13 +5,14 @@ module Middleman::CoreExtensions::FrontMatter
class << self
def registered(app)
app.extend ClassMethods
app.send :include, InstanceMethods
app.file_changed do |file|
data.touch_file(file)
frontmatter.touch_file(file)
end
app.file_deleted do |file|
data.remove_file(file)
frontmatter.remove_file(file)
end
app.after_configuration do
@ -21,17 +22,14 @@ module Middleman::CoreExtensions::FrontMatter
full_file_path = "#{extensionless_path}.#{template_engine}"
if app.frontmatter.has_data?(full_file_path)
result = app.frontmatter.data(full_file_path)
data = result.first.dup
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.delete(opt)
request['custom_options'][opt.to_sym] = data[opt]
end
end
app.settings.templates[extensionless_path] = [result[1], extensionless_path.to_s, 1]
else
data = {}
end
@ -53,6 +51,12 @@ module Middleman::CoreExtensions::FrontMatter
end
end
module InstanceMethods
def frontmatter
settings.frontmatter
end
end
class FrontmatterData
def initialize(app)
@app = app
@ -81,15 +85,21 @@ module Middleman::CoreExtensions::FrontMatter
content = File.read(file)
file = file.sub(@source, "")
@app.logger.debug :frontmatter_update, Time.now, file if @app.settings.logging?
result = parse_front_matter(content)
if result
@local_data[file] = result
path = @app.extensionless_path(file)
@app.settings.templates[path.to_sym] = [result[1], path.to_s, 1]
end
end
def remove_file(file)
file = file.sub(@source, "")
@app.logger.debug :frontmatter_remove, Time.now, file if @app.settings.logging?
if @local_data.has_key?(file)
@local_data.delete(file)
end

View file

@ -3,6 +3,9 @@ require "padrino-core/application/rendering"
module Middleman::CoreExtensions::Rendering
class << self
def registered(app)
app.extend ClassMethods
app.send :include, InstanceMethods
# Tilt-aware renderer
app.register Padrino::Rendering
@ -15,4 +18,35 @@ module Middleman::CoreExtensions::Rendering
end
alias :included :registered
end
module ClassMethods
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
end
module InstanceMethods
def extensionless_path(path)
settings.extensionless_path(path)
end
end
end

View file

@ -196,18 +196,7 @@ module Middleman::CoreExtensions::Sitemap
return false unless file.include?(prefix)
path = file.sub(prefix, "")
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
path = @app.extensionless_path(path)
@source_map[path] = file
path
end

View file

@ -6,15 +6,11 @@ if Config::CONFIG['host_os'].downcase =~ %r{mingw}
require "win32/process"
end
# Quiet down Guard
ENV['GUARD_ENV'] = 'test'
module Middleman
module Guard
def self.add_guard(&block)
# Deprecation Warning
$stderr.puts "== Middleman::Guard.add_guard has been removed. Update your extensions to versions which support this change."
exit
puts "== Middleman::Guard.add_guard has been removed. Update your extensions to versions which support this change."
end
def self.start(options={})
@ -59,6 +55,7 @@ module Guard
server_restart
elsif !@app.nil?
paths.each do |path|
@app.logger.debug :file_change, Time.now, path if @app.settings.logging?
@app.file_did_change(path)
end
end
@ -67,6 +64,7 @@ module Guard
def run_on_deletion(paths)
if !@app.nil?
paths.each do |path|
@app.logger.debug :file_remove, Time.now, path if @app.settings.logging?
@app.file_did_delete(path)
end
end
@ -80,8 +78,12 @@ module Guard
def server_start
app = ::Middleman.server
app.set :environment, @options[:environment].to_sym
app.set :logging, @options[:debug] == "true"
app.set :environment, (@options[:environment] || "development").to_sym
app.set :logging, @options.has_key?(:debug) && (@options[:debug] == "true")
# Quiet down Guard
# ENV['GUARD_ENV'] = 'test' if @options[:debug] == "true"
@app = app.new!
app_rack = app.build_new(@app)

View file

@ -34,14 +34,15 @@ Gem::Specification.new do |s|
s.add_dependency("compass", ["~> 0.11.3"])
s.add_dependency("coffee-script", ["~> 2.2.0"])
s.add_dependency("execjs", ["~> 1.2.7"])
s.add_dependency("sprockets", ["~> 2.0.3"])
s.add_dependency("sprockets", ["~> 2.0"])
s.add_dependency("sprockets-sass", ["~> 0.3.0"])
s.add_dependency("padrino-core", ["~> 0.10.5"])
s.add_dependency("padrino-helpers", ["~> 0.10.5"])
s.add_dependency("hooks", ["~> 0.2.0"])
s.add_dependency("rb-fsevent")
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