lib/plezi/handlers/http_router.rb in plezi-0.10.17 vs lib/plezi/handlers/http_router.rb in plezi-0.11.0
- old
+ new
@@ -105,45 +105,44 @@
# get file requested
source_file = File.join(params[:assets], *(request.path.match(/^#{params[:assets_public]}\/(.+)/)[1].split('/')))
# stop if file name is reserved / has security issues
- return false if source_file.match(/(scss|sass|coffee|\.\.\/)$/)
+ return false if File.directory?(source_file) || source_file.match(/(scss|sass|coffee|\.\.\/)$/)
# set where to store the rendered asset
- target_file = false
- target_file = File.join( params[:root], params[:assets_public], *request.path.match(/^#{params[:assets_public]}\/(.*)/)[1].split('/') ) if params[:root]
+ target_file = File.join( params[:public].to_s, params[:assets_public].to_s, *request.path.match(/^#{params[:assets_public]}\/(.*)/)[1].split('/') )
# send the file if it exists (no render needed)
if File.exists?(source_file)
- data = Plezi.cache_needs_update?(source_file) ? Plezi.save_file(target_file, Plezi.reload_file(source_file), params[:save_assets]) : Plezi.load_file(source_file)
+ data = Plezi.cache_needs_update?(source_file) ? Plezi.save_file(target_file, Plezi.reload_file(source_file), (params[:public] && params[:save_assets])) : Plezi.load_file(source_file)
return (data ? Base::HTTPSender.send_raw_data(request, response, data, MimeTypeHelper::MIME_DICTIONARY[::File.extname(source_file)]) : false)
end
# render supported assets
case source_file
when /\.css$/
- sass = source_file.gsub /css$/, 'sass'
- sass.gsub! /sass$/, 'scss' unless Plezi.file_exists?(sass)
+ sass = source_file.sub /css$/, 'sass'
+ sass.sub! /sass$/, 'scss' unless Plezi.file_exists?(sass)
return false unless Plezi.file_exists?(sass)
# review mtime and render sass if necessary
if defined?(::Sass) && refresh_sass?(sass)
eng = Sass::Engine.for_file(sass, cache_store: @sass_cache)
Plezi.cache_data sass, eng.dependencies
css, map = eng.render_with_sourcemap(params[:assets_public])
- Plezi.save_file target_file, css, params[:save_assets]
- Plezi.save_file (target_file + ".map"), map, params[:save_assets]
+ Plezi.save_file target_file, css, (params[:public] && params[:save_assets])
+ Plezi.save_file (target_file + ".map"), map, (params[:public] && params[:save_assets])
end
# try to send the cached css file which started the request.
return Base::HTTPSender.send_file request, response, target_file
when /\.js$/
- coffee = source_file.gsub /js$/i, 'coffee'
+ coffee = source_file.sub /js$/i, 'coffee'
return false unless Plezi.file_exists?(coffee)
# review mtime and render coffee if necessary
if defined?(::CoffeeScript) && Plezi.cache_needs_update?(coffee)
# render coffee to cache
Plezi.cache_data coffee, nil
- Plezi.save_file target_file, CoffeeScript.compile(IO.binread coffee), params[:save_assets]
+ Plezi.save_file target_file, CoffeeScript.compile(IO.binread coffee), (params[:public] && params[:save_assets])
end
# try to send the cached js file which started the request.
return Base::HTTPSender.send_file request, response, target_file
end
false