Diamond is a very powerful MVC / Template Framework written in the D Programming Language. It scales well for large projects.
Github:
Some of its features include:
(General)
- Full controller over requests / responses when wanted.
- "Websettings" file that lets you control requests and responses
- Multiple static file paths
- Let's you bind to multiple ip addresses and ports
- Let's you control the default headers of each type of requests (default, static files, errors, not found etc.)
- Uses vibe.d for backend, so it's very powerful and all vibe.d features can be used
- Easy control over the application's type using static if constructs
(Views)
- Views can be parsed at compile-time , thus rendering of views are super fast
- Views can have layout views
- Views have a metadata section that lets you change view configurations such as layout, controller, model, route and placeholders
- Views can encode their data
- Has a rich syntax that allows for complex and innovative rendering
- Easy access to the current request / response using the properts: httpRequest and httpResponse
- Can render other views within itself
- Any type of D code can be written within views
- Allows for sections, which is useful to only render a part of the view. (Very useful for responsive designs.)
(Models)
- Models can be of any datatype (classes, structs, enums, scalar etc.)
- Models are optional
- Models can be passed around in view rendering
- "Models" can easily be converted to json from controllers
(Controllers)
- Controller actions are mapped through attributes
- Controller actions can easily control how the response is handled, as they require a status returned
- Can map mandatory actions that are executed on every requests. (Useful for authentication etc.) -- However authentication can be implemented using the attributes available for it too
- Easy integrated authentication
(Controllers - WebServer)
- Can access the view directly by the view property
- Can easily return json data either by return models that are serialized as json or by composing json strings.
- Can easily redirect by calling redirectTo()
(Controllers - WebApi)
- Can access the request, response etc. directly
FAQ
What is Diamond?
Diamond is a MVC / Template library written in Diamond. It was written originally as an alternative to the Diet templates in vibe.d, but now its functonality and capabilities are far beyond templating only.
What does Diamond depend on?
Diamond can be used stand-alone without depending on any third-party libraries, other than the standard library Phobos. It has 3 types of usage, websites and webservices, where it's used on-top of vibe.d and as a stand-alone mvc/template library.
What is the dependency to Vibe.d?
Diamond was originally written to be used in a hobby project as an alternative syntax to the "standard" diet templates. Thus it was originally build on-top vibe.d as a pure website template. It has now evolved to be able to run stand-alone however.
What syntax does Diamond use?
Diamond is heavily inspired by the ASP.NET Razor syntax, but still differs a lot from it. You can read more about that in the wiki under Syntax Reference or the comparison with ASP.NET Razor
What advantage does Diamond have over Diet?
It let's you control the markup entirely, can be integrated with any-type of D code, not limited to vibe.d and can be used as standard template library for any type of project such as email templates etc. It also allows for special rendering, easy controller implementations and management of request data, response etc.
Another advantage is that Diamond is very light-weight when used standa-lone; where Diet depends on vibe.d and to use it you must have the whole library referenced.
Does Diamond parse on every request like ex. PHP?
No. Views are parsed once during compile-time and then compiled into D code that gets executed on run-time; keeping view generation to a minimum, while performance and speed is kept high. The downside of this is that on every changes in code you'll need to recompile. However it's recommended to setup an environment that checks for changes and then simply recompiles when changes are found. On Windows this can be done with or if you don't mind .NET you can use (Not sure about *nix systems as I have very little experience with those.)
In the future (At least for Windows as a starter) an application will be developed that can be used to automate build-processing etc.
View the repository Cryztal for more information.
What are some main features of Diamond?
Please view the feature section above.
Is it easy to use Diamond?
Diamond has been made in a way that it's very easy to use and integrate into projects. It also takes care of all background setup for vibe.d projects, letting you focus on just writing your websites / webservices logic, rather than a huge hassle of setup.
Are there any syntax guide-lines?
The wiki has two syntax guide-lines one for the specific syntax of Diamond and one that compares it with ASP.NET Razor.
Thank you, that's all!