chris-website/source/project.d

62 lines
1.9 KiB
D

import std.array;
import std.algorithm;
import std.typecons;
import dyaml;
import vibe.vibe;
import page;
import staticpaths;
import utils;
/**
* Represents a project, like an unfinished application
*/
class Project : Page {
alias Link= Tuple!(string, "name", string, "url");
protected immutable string PROJECT_ICON_DIR = IMG_DIR ~ "projects/icons/";
protected immutable string PROJECT_IMAGE_DIR = IMG_DIR ~ "projects/images/";
protected string m_state;
protected string[] m_platforms;
protected string[] m_technologies;
protected string m_icon;
protected string[] m_images;
protected string m_description;
protected Link[] m_sourceCode = [];
/**
* Creates a project from a file
*/
this(string file) {
super(file);
}
@safe
override protected void loadHeader(Node headerNode) {
super.loadHeader(headerNode);
this.m_state = headerNode.getOr!string("state", "unknown");
this.m_platforms = headerNode.getArray!string("platforms", []);
this.m_technologies = headerNode.getArray!string("technologies", []);
this.m_icon = PROJECT_ICON_DIR ~ headerNode.getOr!string("icon", "");
this.m_images = headerNode.getArray!string("images", [])
.map!(x => PROJECT_IMAGE_DIR ~ x).array;
this.m_description = headerNode.getOr!string("description", "<no description>");
if ("sourceCode" in headerNode) {
m_sourceCode.reserve(headerNode.length);
foreach(Node node; headerNode["sourceCode"]) {
m_sourceCode ~= tuple!("name", "url")(node.getOr!string("name", "link"),
node.getOr!string("url", "#"));
}
}
}
@property string state() { return m_state; }
@property string[] platforms() { return m_platforms; }
@property string[] technologies() { return m_technologies; }
@property string icon() { return m_icon; }
@property string[] images() { return m_images; }
@property string description() { return m_description; }
@property Link[] sourceCode() { return m_sourceCode; }
}