The Crails Framework for C++ MVC development of web applications.
/!\ This repository has been moved and split to https://github.com/crails-framework.
The v2 of the framework has moved from cpp-netlib to boost.beast and no longer relies on Ruby for file generation and build management.
Many modules have been added, through the refactoring of all the projects I’ve developed using this framework: support for ssh, oauth,
deployment tools, etc.
This repository will no longer be maintained.
Crails Framework is an MVC web development framework aiming to bring a Rails-like experience to C++
developers. Despite being inspired by Ruby on Rails, it is much lighter and simpler.
It’s a cpp-netlib based HTTP server using a routing system, MVC design, C+±compiled templates, asset
precompilation and database abstraction.
Crails is modular, and comes by default with a bunch of modules:
This project has been compiled using gcc 4.9
. It should support clang
as well, though this support is not actively maintained for now.
Here’s a list of the dependecies:
MacOSX users: this project requires the thread_local
feature from C++11, which isn’t available on Apple’s clang.
To the root of the project’s directory, create a build directory, go in there, and once again, type:
cmake ..
make
sudo make install
When the developer mode is on, the Crails Framework provides a number of tools (disabled caching of assets, using renderers to display exceptions) that you simply need while working on a Crails application. On your development machine, you would want to compile the framework with this command line:
cmake -DDEVELOPER_MODE=ON
Developer and Production server do not conflict: you may want to compile the project twice, with and without the developer mode option, which would give you the ability to swap between developer and production mode simply by changing the CMAKE_BUILD_TYPE variable to Release or Debug in your project’s CMakeCache.txt.
There are two types of server available: aysnchronous and synchronous. To compile one or the other, use the -DUSE_MULTITHREAD=[ON|OFF]
option with cmake.
If you want to swap between environments, make sure you have installed every flavour of Crails that you are going to use.
The Crails Framework comes with the crails
command, which is a Ruby toolset giving you a large set of commands to create and manage your application.
The first step you’ll have to go through is the creation of your application:
crails new my_crails_app
This will generate all the necessary files in the folder ./my_crails_app
.
Once you’ve done that, the next thing you should do is pick which modules from crails you are going to be using. To do that, use the crails module
command.
cd my_crails_app
crails module # lists the available modules
crails module html install
crails module mongodb install
At any point, you may also change some of the framework internal settings, using crails set-env
:
# disable development mode
crails set-env production
# enable development mode
crails set-env development
Once your application is created and configured, you may launch the crails guard
tool. It has several applications:
assets
compiles your javascript and stylesheet assets;before_compile
generates code for modules that need it (crails-html, crails-json, …);compile
compiles your code and run the tests;Here’s how you’d use crails guard
:
crails guard # launches the guard shell
guard> assets
guard> before_compile
guard> compile
Now that everything is ready, you may launch your server by running the binary:
build/server -p 8080 -h 0.0.0.0
Note that by defaults, the server binds to port 3001 and host 127.0.0.1.