lib/hanami/assets/compiler.rb in hanami-assets-0.2.0 vs lib/hanami/assets/compiler.rb in hanami-assets-0.2.1
- old
+ new
@@ -1,5 +1,7 @@
+require 'find'
+
module Hanami
module Assets
class MissingAsset < Error
def initialize(name, sources)
sources = sources.map(&:to_s).join(', ')
@@ -31,11 +33,11 @@
# @api private
COMPILE_PATTERN = '*.*.*'.freeze # Example hello.js.es6
# @since 0.1.0
# @api private
- EXTENSIONS = {'.js' => true, '.css' => true}.freeze
+ EXTENSIONS = {'.js' => true, '.css' => true, '.map' => true}.freeze
# @since 0.1.0
# @api private
SASS_CACHE_LOCATION = Pathname(Hanami.respond_to?(:root) ?
Hanami.root : Dir.pwd).join('tmp', 'sass-cache')
@@ -168,11 +170,11 @@
#
# NOTE: We need another option to pass for Sass: `:cache_location'.
#
# This is needed to don't create a `.sass-cache' directory at the root of the project,
# but to have it under `tmp/sass-cache'.
- write { Tilt.new(source, nil, load_paths: @configuration.sources.to_a, cache_location: sass_cache_location).render }
+ write { Tilt.new(source, nil, load_paths: sass_load_paths, cache_location: sass_cache_location).render }
rescue RuntimeError
raise UnknownAssetEngine.new(source)
end
# @since 0.1.0
@@ -189,18 +191,32 @@
# @since 0.1.0
# @api private
def write
destination.dirname.mkpath
- destination.open(File::WRONLY|File::CREAT, DEFAULT_PERMISSIONS) do |file|
+ destination.open(File::WRONLY|File::TRUNC|File::CREAT, DEFAULT_PERMISSIONS) do |file|
file.write(yield)
end
end
# @since 0.1.0
# @api private
def cache
self.class.cache
+ end
+
+ # @since x.x.x
+ # @api private
+ def sass_load_paths
+ result = []
+
+ @configuration.sources.each do |source|
+ Find.find(source) do |path|
+ result << path if File.directory?(path)
+ end
+ end
+
+ result
end
# @since 0.1.0
# @api private
def sass_cache_location