Skip to content

Commit

Permalink
Merge pull request #4 from kitsched/old-pr-22
Browse files Browse the repository at this point in the history
Add dirname to Converter.
  • Loading branch information
janosrusiczki committed Mar 7, 2014
2 parents ea8ffa8 + 36ced31 commit a0aa0c0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/japr/asset.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/japr/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def initialize(asset)
@content = asset.content
@type = File.extname(asset.filename).downcase
@converted = convert
@dirname = asset.dirname
end

def converted
Expand Down
5 changes: 3 additions & 2 deletions lib/japr/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions spec/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
before do
asset.expect(:content, 'foo')
asset.expect(:filename, 'bar.baz')
asset.expect(:dirname, '.')
end

subject { Converter.new(asset) }
Expand Down Expand Up @@ -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) }
Expand Down

0 comments on commit a0aa0c0

Please sign in to comment.