From 36ced31d4a3352c3c52f34788988dfc3ae08e367 Mon Sep 17 00:00:00 2001 From: Janos Rusiczki Date: Fri, 31 Jan 2014 16:47:15 +0200 Subject: [PATCH] Add dirname to Converter This is a pull request by @clee704 migrated from the old project. --- lib/japr/asset.rb | 5 +++-- lib/japr/converter.rb | 1 + lib/japr/pipeline.rb | 5 +++-- spec/converter_spec.rb | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/japr/asset.rb b/lib/japr/asset.rb index 2051883..d688afc 100644 --- a/lib/japr/asset.rb +++ b/lib/japr/asset.rb @@ -1,10 +1,11 @@ module JAPR class Asset - def initialize(content, filename) + def initialize(content, filename, dirname = '.') @content = content @filename = filename + @dirname = dirname end - attr_accessor :content, :filename, :output_path + attr_accessor :content, :filename, :dirname, :output_path end end diff --git a/lib/japr/converter.rb b/lib/japr/converter.rb index c838f15..771b1bc 100644 --- a/lib/japr/converter.rb +++ b/lib/japr/converter.rb @@ -6,6 +6,7 @@ def initialize(asset) @content = asset.content @type = File.extname(asset.filename).downcase @converted = convert + @dirname = asset.dirname end def converted diff --git a/lib/japr/pipeline.rb b/lib/japr/pipeline.rb index cc33dd5..918695f 100644 --- a/lib/japr/pipeline.rb +++ b/lib/japr/pipeline.rb @@ -106,8 +106,9 @@ def process # Collect assets based on manifest def collect @assets = YAML.load(@manifest).map! do |path| + full_path = File.join(@source, path) File.open(File.join(@source, path)) do |file| - JAPR::Asset.new(file.read, File.basename(path)) + JAPR::Asset.new(file.read, File.basename(path), File.dirname(full_path)) end end rescue Exception => e @@ -182,7 +183,7 @@ def compress def gzip @assets.map! do |asset| gzip_content = Zlib::Deflate.deflate(asset.content) - [asset, JAPR::Asset.new(gzip_content, "#{asset.filename}.gz")] + [asset, JAPR::Asset.new(gzip_content, "#{asset.filename}.gz", asset.dirname)] end.flatten! end diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb index 96d9fc1..04fa825 100644 --- a/spec/converter_spec.rb +++ b/spec/converter_spec.rb @@ -16,6 +16,7 @@ before do asset.expect(:content, 'foo') asset.expect(:filename, 'bar.baz') + asset.expect(:dirname, '.') end subject { Converter.new(asset) } @@ -51,6 +52,7 @@ before do asset.expect(:content, 'unconverted') asset.expect(:filename, 'some_filename.foo') + asset.expect(:dirname, '/some/path') end subject { TestConverter.new(asset) }