forked from getzola/zola
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vincent Prouillet
committed
Dec 6, 2016
0 parents
commit 021b8ea
Showing
9 changed files
with
402 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[*.rs] | ||
end_of_line = lf | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
.idea/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "gutenberg" | ||
version = "0.1.0" | ||
authors = ["Vincent Prouillet <[email protected]>"] | ||
license = "MIT" | ||
readme = "README.md" | ||
description = "Static site generator" | ||
homepage = "https://github.com/Keats/gutenberg" | ||
repository = "https://github.com/Keats/gutenberg" | ||
keywords = ["static", "site", "generator", "blog"] | ||
|
||
[dependencies] | ||
error-chain = "0.7" | ||
clap = "2.19" | ||
clippy = {version = "~0.0.103", optional = true} | ||
|
||
[dependencies.toml] | ||
version = "0.2" | ||
default-features = false | ||
features = ["serde"] | ||
|
||
[features] | ||
default = [] | ||
dev = ["clippy"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod new; | ||
|
||
pub use self::new::create_new_project; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
use std::io::prelude::*; | ||
use std::fs::{create_dir, File}; | ||
use std::path::Path; | ||
|
||
use errors::{Result, ErrorKind}; | ||
|
||
|
||
const CONFIG: &'static str = r#" | ||
title = "My site" | ||
base_url = "https://replace-this-with-your-url.com" | ||
"#; | ||
|
||
|
||
pub fn create_new_project<P: AsRef<Path>>(name: P) -> Result<()> { | ||
let path = name.as_ref(); | ||
// Better error message than the rust default | ||
if path.exists() && path.is_dir() { | ||
return Err(ErrorKind::FolderExists(path.to_string_lossy().to_string()).into()); | ||
} | ||
|
||
// main folder | ||
create_dir(path)?; | ||
create_file(path.join("config.toml"), CONFIG.trim_left())?; | ||
|
||
// content folder | ||
create_dir(path.join("content"))?; | ||
|
||
// layouts folder | ||
create_dir(path.join("layouts"))?; | ||
|
||
create_dir(path.join("static"))?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn create_file<P: AsRef<Path>>(path: P, content: &str) -> Result<()> { | ||
let mut file = File::create(&path)?; | ||
file.write_all(content.as_bytes())?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// use std::path::Path; | ||
|
||
// use errors::{Result}; | ||
|
||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Config { | ||
pub title: String, | ||
pub base_url: String, | ||
} | ||
|
||
|
||
//impl Config { | ||
// pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Config> { | ||
// Ok(()) | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
error_chain! { | ||
foreign_links { | ||
Io(::std::io::Error); | ||
} | ||
|
||
errors { | ||
FolderExists(name: String) { | ||
description("folder already exists") | ||
display("Folder '{}' already exists.", name) | ||
} | ||
} | ||
} |
Oops, something went wrong.