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/json"
require "active_support/core_ext/class/attribute_accessors" 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 module Middleman::Base
class << self class << self
def registered(app) def registered(app)
@ -144,12 +156,25 @@ module Middleman::Base
builder.run inst || new! builder.run inst || new!
builder.to_app builder.to_app
end end
def logger
Padrino.logger
end
end end
module InstanceMethods module InstanceMethods
def logger
Padrino.logger
end
def initialize(*args) def initialize(*args)
super super
run_hook :initialized, settings 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 end
def forward def forward

View file

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

View file

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

View file

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

View file

@ -6,15 +6,11 @@ if Config::CONFIG['host_os'].downcase =~ %r{mingw}
require "win32/process" require "win32/process"
end end
# Quiet down Guard
ENV['GUARD_ENV'] = 'test'
module Middleman module Middleman
module Guard module Guard
def self.add_guard(&block) def self.add_guard(&block)
# Deprecation Warning # Deprecation Warning
$stderr.puts "== Middleman::Guard.add_guard has been removed. Update your extensions to versions which support this change." puts "== Middleman::Guard.add_guard has been removed. Update your extensions to versions which support this change."
exit
end end
def self.start(options={}) def self.start(options={})
@ -59,6 +55,7 @@ module Guard
server_restart server_restart
elsif !@app.nil? elsif !@app.nil?
paths.each do |path| paths.each do |path|
@app.logger.debug :file_change, Time.now, path if @app.settings.logging?
@app.file_did_change(path) @app.file_did_change(path)
end end
end end
@ -67,6 +64,7 @@ module Guard
def run_on_deletion(paths) def run_on_deletion(paths)
if !@app.nil? if !@app.nil?
paths.each do |path| paths.each do |path|
@app.logger.debug :file_remove, Time.now, path if @app.settings.logging?
@app.file_did_delete(path) @app.file_did_delete(path)
end end
end end
@ -80,8 +78,12 @@ module Guard
def server_start def server_start
app = ::Middleman.server app = ::Middleman.server
app.set :environment, @options[:environment].to_sym app.set :environment, (@options[:environment] || "development").to_sym
app.set :logging, @options[:debug] == "true" 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 = app.new!
app_rack = app.build_new(@app) 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("compass", ["~> 0.11.3"])
s.add_dependency("coffee-script", ["~> 2.2.0"]) s.add_dependency("coffee-script", ["~> 2.2.0"])
s.add_dependency("execjs", ["~> 1.2.7"]) 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("sprockets-sass", ["~> 0.3.0"])
s.add_dependency("padrino-core", ["~> 0.10.5"]) s.add_dependency("padrino-core", ["~> 0.10.5"])
s.add_dependency("padrino-helpers", ["~> 0.10.5"]) s.add_dependency("padrino-helpers", ["~> 0.10.5"])
s.add_dependency("hooks", ["~> 0.2.0"]) s.add_dependency("hooks", ["~> 0.2.0"])
s.add_dependency("rb-fsevent")
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"]) # s.add_dependency("middleman-livereload", ["~> 0.2.0"])
# Development and test # Development and test