Skip to content

Using Diamond : Website

Jacob Jensen edited this page May 21, 2016 · 10 revisions

To use Diamond for a website you must have dub installed.

If it's the first time you use Diamond, then it's recommended to follow the guide below.

If you're already familiar with dub then an empty project corresponding the below can be found here: github to empty project

Just download the project as zip.

Create a new folder for your project. Ex. diamondproject

Create the following folders and files within it. (Don't worry about content right now.)

  • \diamondproject
    • \config
      • web-build.json
    • \controllers
      • package.d
      • homecontroller.d
    • \core
      • web.d
    • \models
      • package.d
      • home.d
    • \public
    • \views
      • layout.dd
      • errors.dd
      • home.dd
    • dub.json
    • web-runtime.json

Below is all the content for the files. Just copy-paste it into the files. Explanations of them are right below.

dub.json

{
	"name": "diamondproject",
	"description": "A diamond website project",
	"authors": ["Jacob Jensen"],
	"homepage": "http://mydiamondwebsiteproject.com/",
	"license": "http://mydiamondwebsiteproject.com/license",
	"dependencies": {
		"vibe-d": "~>0.7.28",
		"diamond": "~>0.2.2"
	},
	"versions": ["VibeDefaultMain", "WebServer"],
	"sourcePaths": ["core", "models", "controllers"],
	"stringImportPaths": ["views", "config"],
	"targetType": "executable"
}

name is the name of the project.

description is the description of the project.

authors is the authors of the project.

homepage is the homepage of the project.

license is the license of the project.

dependencies is the dependencies of the project. A webserver using Diamond has a dependency to vibe.d

versions are all versions to compile with. For a webserver you must compile with "WebServer"

sourcePaths are all paths that dub will look for code. By defualt Diamond only uses core, models and controllers.

stringImportPaths are all paths dub will look for string imports. By default Diamond only uses views and config.

targetType are the type of the output. For a Diamond project, it'll typically be executable.

web-runtime.json

{
  "bindAddresses": [
	"::1",
	"127.0.0.1"
  ],
  "port": 8080,
  "defaultHeaders": {
	"Content-Type": "text/html; charset=UTF-8",
	"Server": "vibe.d - Diamond MVC/Template Framework"
  }
}

bindAddresses are all addresses that should bound to.

port is the port that should be bound to.

defaultHeaders are all default headers to append to the responses headers. (Note these are not appended to the static files headers.)

config\web-build.json

{
  "name": "diamondproject",
  "views":{
	"layout": "layout.dd",
	"errors": "errors.dd",
	"home": "home.dd"
  },
  "homeRoute": "home",
  "staticFileRoute": "public"
}

name is the name of the project.

views are all the views associated with the project.

homeRoute is the route used to get to the home page. It's an alternative route to "/"

staticFileRoute is a route used to get to the static files. (The public folder)

Clone this wiki locally