Skip to content

Commit

Permalink
Merge pull request #60 from LucioFranco/master
Browse files Browse the repository at this point in the history
Fix for copy files bug
  • Loading branch information
tak1n committed Mar 17, 2016
2 parents 2a5f416 + c0e3658 commit 2b1d499
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/cobalt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub fn build(config: &Config) -> Result<()> {
let dest = dest.as_path();

let template_extensions: Vec<&OsStr> = config.template_extensions
.iter()
.map(OsStr::new)
.collect();
.iter()
.map(OsStr::new)
.collect();

let layouts_path = source.join(&config.layouts);
let posts_path = source.join(&config.posts);
Expand Down Expand Up @@ -141,6 +141,11 @@ pub fn build(config: &Config) -> Result<()> {
try!(fs::create_dir_all(&dest.join(relative)));
debug!("Created new directory {:?}", dest.join(relative));
} else {
let parent_folder_path = dest.clone()
.join(Path::new(relative).parent().unwrap());

try!(fs::create_dir_all(&parent_folder_path));

try!(fs::copy(entry.path(), &dest.join(relative))
.map_err(|_| format!("Could not copy {:?}", entry.path())));
debug!("Copied {:?} to {:?}", entry.path(), dest.join(relative));
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/copy_files/_layouts/default.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>{{ name }}</h1>

{{ content }}
</body>
</html>

10 changes: 10 additions & 0 deletions tests/fixtures/copy_files/_layouts/posts.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>My blog - {{ title }}</title>
</head>
<body>
{{ content }}
</body>
</html>

10 changes: 10 additions & 0 deletions tests/fixtures/copy_files/_posts/2014-08-24-my-first-blogpost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends: posts.tpl

title: My first Blogpost
date: 24/08/2014 at 15:36
---
# {{ title }}

Hey there this is my first blogpost and this is super awesome.

My Blog is lorem ipsum like, yes it is..
7 changes: 7 additions & 0 deletions tests/fixtures/copy_files/index.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends: default.tpl
---
This is my Index page!

{% for post in posts %}
<a href="{{post.path}}">{{ post.title }}</a>
{% endfor %}
1 change: 1 addition & 0 deletions tests/fixtures/copy_files/some.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var test = require('test');
3 changes: 3 additions & 0 deletions tests/fixtures/copy_files/style/blog.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.body {
width: 30px;
}
5 changes: 5 additions & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ pub fn rss() {
run_test("rss").expect("Build error");
}

#[test]
pub fn copy_files() {
run_test("copy_files").unwrap();
}

#[test]
pub fn yaml_error() {
let err = run_test("yaml_error");
Expand Down
15 changes: 15 additions & 0 deletions tests/target/copy_files/_posts/2014-08-24-my-first-blogpost.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>My blog - My first Blogpost</title>
</head>
<body>
<h1 id='my_first_blogpost'>My first Blogpost</h1>

<p>Hey there this is my first blogpost and this is super awesome.</p>

<p>My Blog is lorem ipsum like, yes it is..</p>

</body>
</html>

18 changes: 18 additions & 0 deletions tests/target/copy_files/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>index</h1>


This is my Index page!


<a href="_posts/2014-08-24-my-first-blogpost.html">My first Blogpost</a>


</body>
</html>

1 change: 1 addition & 0 deletions tests/target/copy_files/some.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var test = require('test');
3 changes: 3 additions & 0 deletions tests/target/copy_files/style/blog.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.body {
width: 30px;
}

0 comments on commit 2b1d499

Please sign in to comment.