Permalink
Browse files

Added some improved logging and an interactive mode to sc-server

  • Loading branch information...
1 parent 1d769af commit e27e11b9273d53e2a679d2d1c41739fb2caea667 Charles Jolley committed Jan 22, 2009
View
@@ -68,7 +68,9 @@ mode :debug do
:minify_javascript => false,
:build_prefix => 'tmp/debug/build',
- :staging_prefix => 'tmp/debug/staging'
+ :staging_prefix => 'tmp/debug/staging',
+
+ :serve_exceptions => true
end
View
@@ -109,6 +109,11 @@ def self.builtin_project
@builtin_project ||= SC::Project.new(PATH)
end
+ # Returns the current project, if defined. This is normally only set
+ # when you start sc-server in interactive mode.
+ def self.project; @project; end
+ def self.project=(project); @project = project; end
+
end # module SC
SC = SproutCore # alias
@@ -81,6 +81,10 @@ def render
@entries.each { |entry| render_entry(entry) }
# then finally compile the layout.
+ if self.layout_path.nil?
+ raise "html_builder could not find a layout file for #{@layout}"
+ end
+
compile(SC::RenderEngine::Erubis.new(self), self.layout_path, :_final_)
return @content_for__final_
end
@@ -103,6 +107,10 @@ def build(dst_path)
# self
#
def compile(render_engine, input_path, content_for_key = :resources)
+ if !File.exist?(input_path)
+ raise "html_builder could compile file at #{input_path} because the file could not be found"
+ end
+
input = File.read(input_path)
content_for content_for_key do
_render_compiled_template( render_engine.compile(input) )
@@ -8,11 +8,13 @@ class Buildfile::BuildTask < ::SC::Buildfile::Task
def needed?
return true if DST_PATH.nil? || SRC_PATHS.nil? # just try to build...
-
+ return true if !File.exist?(DST_PATH)
ret = false
- dst_mtime = File.exist?(DST_PATH) ? File.mtime(DST_PATH) : EARLY
+ dst_mtime = File.mtime(DST_PATH)
SRC_PATHS.each do |path|
- timestamp = (path && File.exist?(path)) ? File.mtime(path) : EARLY
+ next if path.nil? # skip incase of bad src paths...
+
+ timestamp = File.exist?(path) ? File.mtime(path) : EARLY
ret = ret || (dst_mtime < timestamp)
break if ret
end
@@ -295,11 +295,11 @@ def find_entry(fragment, opts = {}, seen=nil)
# if no match was found, search the same manifests in required targets
if ret.nil?
seen = Set.new if seen.nil?
- seen << self
- target.expand_required_targets.each do |target|
- next if seen.include?(target) # avoid recursion
-
- manifest = target.manifest_for(self.variation).build!
+ seen << self.target
+ self.target.expand_required_targets.each do |t|
+ next if seen.include?(t) # avoid recursion
+
+ manifest = t.manifest_for(self.variation).build!
ret = manifest.find_entry(fragment, opts, seen)
break unless ret.nil?
end
@@ -66,6 +66,8 @@ class Builder
def initialize(project)
@project = project
@last_reload_time = Time.now
+
+ puts "Builder: #{project.project_root} - #{project.targets.keys * ","}"
end
# Main entry point for this Rack application. Returns 404 if no
@@ -100,7 +102,7 @@ def _call(env)
# Now build entry and return a file object
build_path = entry.build!.build_path
unless File.file?(build_path) && File.readable?(build_path)
- return not_found("File could not build")
+ return not_found("File could not build (entry: #{entry.filename} - build_paht: #{build_path}")
end
SC.logger << " ~ Serving #{target.target_name.to_s.sub(/^\//,'')}:#{entry.filename}\n"
@@ -121,8 +123,9 @@ def mutex; @mutex ||= Mutex.new; end
# Invoked when a resource cannot be found for some reason
def not_found(reason)
+ reason = "<html><body><p>#{reason}</p></body></html>"
return [404, {
- "Content-Type" => "text/plain",
+ "Content-Type" => "text/html",
"Content-Length" => reason.size.to_s
}, reason]
end
@@ -10,6 +10,7 @@ def initialize(project)
end
def call(env)
+ return [404, {}, "not found"]
end
end
end
@@ -9,6 +9,7 @@ def initialize(project)
end
def call(env)
+ return [404, {}, "not found"]
end
end
end
@@ -10,6 +10,7 @@ def initialize(project)
end
def call(env)
+ return [404, {}, "not found"]
end
end
end
@@ -1,19 +1,37 @@
module SC
+
class Tools
- desc "server [start|stop]", "Starts the development server"
+ desc "server", "Starts the development server"
method_options :daemonize => false,
:port => :optional,
- :host => :optional
- def server(command='start')
+ :host => :optional,
+ :irb => false
+ def server
prepare_mode!('debug') # set mode again, using debug as default
SC.env.build_prefix = options.buildroot if options.buildroot
SC.env.staging_prefix = options.stageroot if options.stageroot
# get project and start service.
project = requires_project!
- SC::Rack::Service.start(options.merge(:project => project))
+
+ # start shell if passed
+ if options.irb
+ require 'irb'
+ require 'irb/completion'
+ if File.exists? ".irbrc"
+ ENV['IRBRC'] = ".irbrc"
+ end
+
+ SC.project = project
+ SC.logger << "SproutCore v#{SC::VERSION} Interactive Shell\n"
+ SC.logger << "SC.project = #{project.project_root}\n"
+ ARGV.clear # do not pass onto IRB
+ IRB.start
+ else
+ SC::Rack::Service.start(options.merge(:project => project))
+ end
end
end

0 comments on commit e27e11b

Please sign in to comment.