Skip to content

Commit

Permalink
Change asset files to cleanup the path to a file but not the filename…
Browse files Browse the repository at this point in the history
… itself. This is a more expectant result and also allows for asset filenames like `001.jpg`. Closes #7
  • Loading branch information
benschwarz committed Mar 20, 2010
1 parent c209882 commit 7ca6298
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
22 changes: 11 additions & 11 deletions lib/bonsai/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ def template

# This method is used for the exporter to copy assets
def assets
Dir["#{directory}/**/*"].select{|p| !File.directory?(p) && !File.basename(p).include?("yml") }.map do |a|
{
:name => File.basename(a),
:path => web_path(a),
:disk_path => a
}
Dir["#{directory}/**/*"].select{|path| !File.directory?(path) && !File.basename(path).include?("yml") }.map do |file|
file_to_hash(file)
end
end

Expand Down Expand Up @@ -183,11 +179,7 @@ def map_to_disk(path)

{
name.to_sym => Dir["#{path}/*"].map do |file|
{
:name => File.basename(file),
:path => web_path(file),
:disk_path => file
}
file_to_hash(file)
end
}
end
Expand All @@ -203,5 +195,13 @@ def template_name
def web_path(path)
path.gsub(self.class.path, '').gsub(/\/\d+\./, '/')
end

def file_to_hash(file)
{
:name => File.basename(file),
:path => "#{web_path(File.dirname(file))}/#{File.basename(file)}",

This comment has been minimized.

Copy link
@jridgewell

jridgewell Mar 20, 2010

Wow, I feel stupid not to have used dirname.

:disk_path => File.expand_path(file)
}
end
end
end
22 changes: 18 additions & 4 deletions spec/bonsai/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,24 @@
it "should respond to disk path" do
@page.disk_path.should == "#{Bonsai.root_dir}/content/1.about-us/history/demo-template.yml"
end

it "should have assets" do
@page.assets.should be_an_instance_of(Array)
@page.assets.length.should == 6

describe "assets" do
it "should have assets" do
@page.assets.should be_an_instance_of(Array)
@page.assets.length.should == 6
end

it "should have the correct name" do
@page.assets.first[:name].should == "001.jpg"
end

it "should have the correct path" do
@page.assets.first[:path].should == "/about-us/history/001.jpg"
end

it "should have the correct disk_path" do
@page.assets.first[:disk_path].should == "/Users/ben/Documents/Projects/bonsai/spec/support/content/1.about-us/history/001.jpg"
end
end

it "should be equal" do
Expand Down

0 comments on commit 7ca6298

Please sign in to comment.