lib/vitrine.rb in vitrine-0.0.9 vs lib/vitrine.rb in vitrine-0.0.10
- old
+ new
@@ -8,21 +8,20 @@
require_relative 'atomic_write'
require_relative 'sourcemaps'
module Vitrine
DEFAULTS = { root: Dir.getwd, port: 4000, host: '127.0.0.1' }
- SEED = rand
def self.check_dirs_present!
views = DEFAULTS[:root] + '/views'
unless File.exist?(views) and File.directory?(views)
$stderr.puts "WARNING: `views' directory not found under the current tree, you might want to create it"
end
- public = DEFAULTS[:root] + '/public'
- unless File.exist?(views) and File.directory?(views)
- $stderr.puts "ERROR: `public' directory not found under the current tree, you might want to create it"
+ public_dir = DEFAULTS[:root] + '/public'
+ unless File.exist?(public_dir) and File.directory?(public_dir)
+ $stderr.puts "ERROR: `public' directory not found under the current tree, you should create it. Vitrine won't run without it"
exit 1
end
end
# Run the server, largely stolen from Serve
@@ -186,28 +185,29 @@
# inject it into the document
'console.error(%s)' % [e.class, "\n", "--> ", e.message].join.inspect
end
end
+ require 'fileutils'
def mtime_cache(path, &blk)
# Mix in the request URL into the cache key so that we can hash
# .map sourcemaps and .js compiles based off of the same file path
# and mtime
-
- key = [File.expand_path(path), File.mtime(path), request.path_info, Vitrine::SEED]
+ key = [File.expand_path(path), File.mtime(path), request.path_info, settings.root]
cache_sha = Digest::SHA1.hexdigest(Marshal.dump(key))
- p = File.join('/tmp', cache_sha)
- if File.exist?(p)
- return File.read(p)
- else
+ # Store in a temp dir
+ FileUtils.mkdir_p '/tmp/vitrine'
+ p = '/tmp/vitrine/%s' % cache_sha
+ begin
+ File.read(p)
+ rescue Errno::ENOENT => e
Vitrine.atomic_write(p) do |f|
- $stderr.puts "---> Recompiling #{path}"
- body = yield
- f.write(body)
- return body
+ $stderr.puts "---> Recompiling #{path} for #{request.path_info}"
+ f.write(yield)
end
+ retry
end
end
def get_layout
layouts = Dir.glob(File.join(settings.views, 'layout.*'))
\ No newline at end of file