./lib/lux_assets/base.rb in lux_assets-0.1.10 vs ./lib/lux_assets/base.rb in lux_assets-0.2.1

- old
+ new

@@ -21,11 +21,11 @@ # end module LuxAssets extend self - CONFIG_PATH = Pathname.new ENV.fetch('ASSET_CONFIG') { './config/assets.rb' } + CONFIG_PATH = Pathname.new ENV.fetch('ASSETS_CONFIG') { './config/assets.rb' } ASSET_TYPES ||= { js: ['js', 'coffee', 'ts'], css: ['css', 'scss'] } @@ -50,36 +50,16 @@ def configure &block class_eval &block end - def run what, cache_file=nil - puts what.yellow - - stdin, stdout, stderr, wait_thread = Open3.popen3(what) - - error = stderr.gets - while line = stderr.gets do - error += line - end - - # node-sass prints to stderror on complete - error = nil if error && error.index('Rendering Complete, saving .css file...') - - if error - cache_file.unlink if cache_file && cache_file.exist? - - puts error.red - end - end - def js name=nil, &block - add_files :js, name, block + add_files :js, name, &block end def css name=nil, &block - add_files :css, name, block + add_files :css, name, &block end # adds file or list of files # add 'plugin:js_widgets/*' # add 'js/vendor/*' @@ -117,15 +97,23 @@ end end end # get list of files in the resource - def files name - parts = name.split('/', 2) - to_h[parts.first.to_sym][parts[1]] + def files ext, name=nil + ext, name = ext.split('/', 2) unless name + ext = ext.to_sym + + raise ArgumentError.new('name not deinfed') if name.empty? + + to_h[ext][name.to_s] end + def compile path + LuxAssets::Element.new(path).compile + end + def compile_all # generate master file for every resource for ext in [:js, :css] for name in to_h[ext].keys path = LuxAssets.send(ext, name).compile @@ -170,10 +158,30 @@ end end end end + def run what, cache_file=nil + puts what.yellow + + stdin, stdout, stderr, wait_thread = Open3.popen3(what) + + error = stderr.gets + while line = stderr.gets do + error += line + end + + # node-sass prints to stderror on complete + error = nil if error && error.index('Rendering Complete, saving .css file...') + + if error + cache_file.unlink if cache_file && cache_file.exist? + + puts error.red + end + end + private def add_local_files files files = files.select { |it| ASSET_TYPES[@ext].include?(it.split('.').last) } @@ -184,15 +192,16 @@ @files += files files end - def add_files ext, name, block - @name = name.to_s if name - return Asset.new ext, @name unless block - - @files = [] - @ext = ext - class_eval &block - @assets[ext][@name] = @files + def add_files ext, name=nil, &block + if block_given? + @files = [] + @ext = ext + class_eval &block + @assets[ext][@name] = @files + else + Asset.new ext, name + end end end \ No newline at end of file