split out monkey patching
This commit is contained in:
parent
7095b2750f
commit
abeb9095ae
1
Rakefile
1
Rakefile
|
@ -63,6 +63,7 @@ Rake::RDocTask.new do |rdoc|
|
|||
rdoc.rdoc_files.include('README*')
|
||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||
rdoc.rdoc_files.exclude('lib/middleman/features/sprockets+ruby19.rb')
|
||||
rdoc.rdoc_files.exclude('lib/middleman/templater+dynamic_renderer.rb')
|
||||
end
|
||||
|
||||
desc "Build and publish documentation using GitHub Pages."
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'templater'
|
||||
require 'middleman/templater+dynamic_renderer.rb'
|
||||
require 'rack/test' # Use Rack::Test to access Sinatra without starting up a full server
|
||||
|
||||
# Placeholder for any methods the builder needs to abstract to allow feature integration
|
||||
|
@ -46,34 +47,3 @@ module Middleman
|
|||
add :build, ::Middleman::Builder
|
||||
end
|
||||
end
|
||||
|
||||
# Monkey-patch to use a dynamic renderer
|
||||
class Templater::Actions::File
|
||||
def identical?
|
||||
if exists?
|
||||
return true if File.mtime(source) < File.mtime(destination)
|
||||
FileUtils.identical?(source, destination)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Templater::Actions::Template
|
||||
def render
|
||||
# The default render just requests the page over Rack and writes the response
|
||||
request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "")
|
||||
browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base))
|
||||
browser.get(request_path)
|
||||
browser.last_response.body
|
||||
end
|
||||
|
||||
def identical?
|
||||
if File.exists?(destination)
|
||||
return true if File.exists?(source) && File.mtime(source) < File.mtime(destination)
|
||||
File.read(destination) == render
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue