Fix Less load paths, simplify builder error output. Fixes #461
This commit is contained in:
parent
556f82afbc
commit
286c7352b6
94 changed files with 20630 additions and 26 deletions
|
@ -7,6 +7,8 @@ module Middleman::Cli
|
|||
class Build < Thor
|
||||
include Thor::Actions
|
||||
|
||||
attr_reader :debugging
|
||||
|
||||
check_unknown_options!
|
||||
|
||||
namespace :build
|
||||
|
@ -40,7 +42,10 @@ module Middleman::Cli
|
|||
|
||||
require 'find'
|
||||
|
||||
self.class.shared_instance(options["verbose"] || false)
|
||||
@debugging = Middleman::Cli::Base.debugging
|
||||
@had_errors = false
|
||||
|
||||
self.class.shared_instance(options["verbose"])
|
||||
|
||||
self.class.shared_rack
|
||||
|
||||
|
@ -50,6 +55,12 @@ module Middleman::Cli
|
|||
|
||||
action GlobAction.new(self, opts)
|
||||
|
||||
if @had_errors && !@debugging
|
||||
self.shell.say "There were errors during this build, re-run with --debug to see the full exception."
|
||||
end
|
||||
|
||||
exit(1) if @had_errors
|
||||
|
||||
self.class.shared_instance.run_hook :after_build, self
|
||||
end
|
||||
|
||||
|
@ -94,32 +105,42 @@ module Middleman::Cli
|
|||
end
|
||||
end
|
||||
|
||||
# Ignore following method
|
||||
desc "", "", :hide => true
|
||||
|
||||
# Render a resource to a file.
|
||||
#
|
||||
# @param [Middleman::Sitemap::Resource] resource
|
||||
# @return [String] The full path of the file that was written
|
||||
def render_to_file(resource)
|
||||
build_dir = self.class.shared_instance.build_dir
|
||||
output_file = File.join(build_dir, resource.destination_path)
|
||||
no_tasks {
|
||||
# Render a resource to a file.
|
||||
#
|
||||
# @param [Middleman::Sitemap::Resource] resource
|
||||
# @return [String] The full path of the file that was written
|
||||
def render_to_file(resource)
|
||||
build_dir = self.class.shared_instance.build_dir
|
||||
output_file = File.join(build_dir, resource.destination_path)
|
||||
|
||||
begin
|
||||
response = self.class.shared_rack.get(URI.escape(resource.destination_path))
|
||||
begin
|
||||
response = self.class.shared_rack.get(URI.escape(resource.destination_path))
|
||||
|
||||
if response.status == 200
|
||||
create_file(output_file, response.body, { :force => true })
|
||||
else
|
||||
raise Thor::Error.new response.body
|
||||
if response.status == 200
|
||||
create_file(output_file, response.body)
|
||||
else
|
||||
handle_error(output_file, response.body)
|
||||
end
|
||||
rescue => e
|
||||
handle_error(output_file, "#{e}\n#{e.backtrace.join("\n")}", e)
|
||||
end
|
||||
rescue => e
|
||||
say_status :error, output_file, :red
|
||||
raise Thor::Error.new "#{e}\n#{e.backtrace.join("\n")}"
|
||||
end
|
||||
|
||||
output_file
|
||||
end
|
||||
output_file
|
||||
end
|
||||
|
||||
def handle_error(file_name, response, e=Thor::Error.new(response))
|
||||
@had_errors = true
|
||||
|
||||
say_status :error, file_name, :red
|
||||
if self.debugging
|
||||
raise e
|
||||
exit(1)
|
||||
elsif options["verbose"]
|
||||
self.shell.error(response)
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
# A Thor Action, modular code, which does the majority of the work.
|
||||
|
@ -149,6 +170,7 @@ module Middleman::Cli
|
|||
end
|
||||
|
||||
protected
|
||||
|
||||
# Remove files which were not built in this cycle
|
||||
# @return [void]
|
||||
def clean!
|
||||
|
@ -239,3 +261,11 @@ module Middleman::Cli
|
|||
# Alias "b" to "build"
|
||||
Base.map({ "b" => "build" })
|
||||
end
|
||||
|
||||
# Quiet down create file
|
||||
class ::Thor::Actions::CreateFile
|
||||
def on_conflict_behavior(&block)
|
||||
say_status :create, :green
|
||||
block.call unless pretend?
|
||||
end
|
||||
end
|
|
@ -61,6 +61,13 @@ module Middleman
|
|||
app.register Middleman::Renderers::Slim
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
# Less Support
|
||||
begin
|
||||
require "middleman-core/renderers/less"
|
||||
app.register Middleman::Renderers::Less
|
||||
rescue LoadError
|
||||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
|
|
46
middleman-core/lib/middleman-core/renderers/less.rb
Normal file
46
middleman-core/lib/middleman-core/renderers/less.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require "less"
|
||||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Sass renderer
|
||||
module Less
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Default sass options
|
||||
app.set :less, {}
|
||||
|
||||
app.before_configuration do
|
||||
template_extensions :less => :css
|
||||
end
|
||||
|
||||
# Tell Tilt to use it as well (for inline sass blocks)
|
||||
::Tilt.register 'less', LocalLoadingLessTemplate
|
||||
::Tilt.prefer(LocalLoadingLessTemplate)
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
# A SassTemplate for Tilt which outputs debug messages
|
||||
class LocalLoadingLessTemplate < ::Tilt::LessTemplate
|
||||
|
||||
def prepare
|
||||
if ::Less.const_defined? :Engine
|
||||
@engine = ::Less::Engine.new(data)
|
||||
else
|
||||
$stderr.puts "HEEERE"
|
||||
parser = ::Less::Parser.new(options.merge :filename => eval_file, :line => line, :paths => [".", File.dirname(eval_file)])
|
||||
@engine = parser.parse(data)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue