Commit 4076cabf authored by Bat's avatar Bat
Browse files

Merge branch 'master' into 'master'

Cleaned code

And updated README.md

See merge request !9
parents dab494a3 4e8afd84
Pipeline #9404 passed with stage
in 4 minutes
......@@ -43,7 +43,9 @@ You can find a nginx.config file to do that [here](https://framagit.org/valse/va
Then, on Linux do `make test` and go on `http://localhost/` to test what you want.
On windows, tests shall start by themselve after the compilation, so make sure to run nginx before compiling.
On windows, tests would start by themselve after the compilation, so make sure to run nginx before compiling.
You can also compile and run unit tests with `make unit`.
## Styleguide
......
# Add .exe if you are on Windows
TESTOUTPUT = test/serv
TESTOUTPUT = tests/serv
LINUXLIB = --pkg libscgi-1.0 -X "-I." -X libscgi-1.0.so --pkg libsoup-2.4 --pkg gee-0.8 --pkg sqlite3
WINDOWSLIB = --pkg libscgi-1.0 -X "-I." -X libscgi-1.0.dll --pkg libsoup-2.4 --pkg gee-1.0 --pkg sqlite3
FILES = valse/*.vala valse/core/*.vala valse/wala/*.vala valse/default/*.vala
......@@ -20,14 +20,14 @@ windows:
valac --vapidir=. $(WINDOWSLIB) $(FILES) $(LIBOUT) -o $(WINOUT) -X -w
.ONESHELL:
test: linux
cp ./out/valse.o ./test
cp ./out/valse.h ./test
cp ./out/valse.vapi ./test
cp libscgi-1.0.so ./test
cp libscgi-1.0.vapi ./test
cp libscgi-1.0.h ./test
cd ./test
tests: linux
cp ./out/valse.o ./tests
cp ./out/valse.h ./tests
cp ./out/valse.vapi ./tests
cp libscgi-1.0.so ./tests
cp libscgi-1.0.vapi ./tests
cp libscgi-1.0.h ./tests
cd ./tests
export LD_LIBRARY_PATH=.
valac *.vala models/*.vala --vapidir=. --pkg valse --pkg libscgi-1.0 --pkg gio-2.0 --pkg gee-0.8 --pkg libsoup-2.4 -X "-I." -X "valse.o" -X "-I." -X libscgi-1.0.so -o serv
./serv
......
......@@ -11,7 +11,7 @@ If you want to help us, please check out [the contribution guide](CONTRIBUTING.m
*main.vala* :
```csharp
```vala
using Valse;
void main () {
......@@ -24,8 +24,8 @@ void main () {
*home-controller.vala* :
```csharp
using Valse
```vala
using Valse;
// This is our controller, where all the logic happens
public class HomeController : Controller {
......@@ -46,19 +46,23 @@ public class HomeController : Controller {
<html>
<head>
<meta charset="utf-8">
<title>Démo de Valse</title>
<title>Valse sample</title>
</head>
<body>
<h1>Valse, c'est trop bien !</h1>
<h1>Hello, Valse's world!</h1>
</body>
</html>
```
Then compile with :
In a perfect world, you would compile with `valac --pkg valse *.vala`, but Valse can't be installed and integrated with
valac easely yet (it's still an alpha :grin:). So you'll first have to download the sources, then compile them
(see [CONTRIBUTING.md](CONTRIBUTING.md)) and copy the content of the `out` directory and the libscgi files in the folder
that contains the source of your website. Then compile with:
```
valac --pkg valse *.vala
```bash
# Use .dll instead of .so and .o on Windows
valac *.vala --vapidir=. --pkg valse --pkg libscgi-1.0 --pkg gio-2.0 --pkg gee-0.8 --pkg libsoup-2.4 -X "-I." -X valse.o -X "-I." -X libscgi-1.0.so -o mywebiste
```
Then launch Nginx, or any web server, and make it listening for SimpleCGI (or SCGI) on port 9000.
Run your website's binary, and go on localhost.
Run your website's binary (with `LD_LIBRARY_PATH=. ./mywebiste` to make sure that valse will be found), and go on localhost. Enjoy!
using Valse;
public class UserList : Object {
public Many<User> users {get; set;}
}
public class User : Object {
public string pseudo {get; set;}
public string sign {get; set;}
public string avatar {get; set;}
public string website {get; set;}
public DateTime register_date {get; set;}
}
File deleted
using Valse;
/*
* Controller on /
*/
public class HomeController : Controller {
public HomeController () {
this.add_action ("index", this.index);
this.add_action ("truc", this.truc);
this.add_action ("wala", wala);
}
/*
* The home page.
*
* Accessible at /
*/
public Response index () {
return page ("views/home.html");
}
/*
* A page to test the router.
*
* Accessible at /truc
*/
public Response truc () {
return page ("views/truc.html");
}
/*
* Wala-related tests
*
* Accessible at /wala
*/
public Response wala () {
// KTM
return page ("views/wala.wala", model("page", new Page () {
title = "Valse KTM"
},
"site", new Site () {
name = "With the model method !"
}));
}
}
/*
* A model used in KillTheMod tests.
*/
public class Page : Object {
public string title { get; set; }
}
/*
* Anoher model used in KillTheMod tests.
*/
public class Site : Object {
public string name { get; set; }
}
/*
* A model to make tests.
*/
public class TestModel : Object {
public TestModel (string b, string u) {
......@@ -5,7 +8,7 @@ public class TestModel : Object {
this.url = u;
}
public string blob {get; set; default = "plop";}
public string blob { get; set; default = "plop"; }
public string url {get; set; default = "/zds";}
public string url { get; set; default = "/zds"; }
}
using Valse;
/*
* A list of users.
*
* Because @{link Valse.Many} can't be used as models yet.
*/
public class UserList : Object {
/*
* The list
*/
public Many<User> users { get; set; }
}
/*
* Represents an user.
*
* Used in tests.
*/
public class User : Object {
/*
* The username of this user.
*/
public string pseudo { get; set; }
/*
* The signature of this user.
*/
public string sign { get; set; }
/*
* The URL of the avatar to use for this user.
*/
public string avatar { get; set; }
/*
* The website of the user.
*/
public string website { get; set; }
/*
* The date on which the user created his account.
*
* Used to test dates.
*/
public DateTime register_date { get; set; }
}
using Valse;
using Soup;
/*
* We setup our test server here.
*
* It contains manual tests.
*/
void main (string[] args) {
Router r = new Router (9000);
......
......@@ -2,8 +2,16 @@ using Valse;
using Valse.Errors;
using Gee;
/*
* User-related actions (create, view, list, etc).
*
* Useful to test Wala and DataBase.
*/
public class UserController : Controller {
/*
* Setup of the controller.
*/
public UserController () {
this.db.register<User> ();
......@@ -18,14 +26,15 @@ public class UserController : Controller {
this.add_complete_action ("view", view, {"id"});
this.add_complete_action ("profile", view, {"id"});
this.add_action ("wala", wala);
// TODO : update
}
/*
* List all the registred users.
*/
public Response list (Request req, Response res) {
User [] base_arr = new User [] {};
User[] base_arr = new User[] {};
foreach (var user in this.db.all<User> ()) {
Value val = Value (typeof (string));
......@@ -50,6 +59,11 @@ public class UserController : Controller {
return page ("views/user/list.wala", model);
}
/*
* Delete an user
*
* Takes an option: the ID of the user to delete, else it will send an error.
*/
public Response delete (Request req, Response res) {
if (req.query_ids.size == 0) {
return server_error ("You should give an ID.");
......@@ -62,6 +76,11 @@ public class UserController : Controller {
return list (req, res);
}
/*
* Creates a new user.
*
* Useful to test forms.
*/
public Response create (Request req, Response res) {
if (req.method == "POST") {
User usr = new User ();
......@@ -78,17 +97,9 @@ public class UserController : Controller {
}
}
// Wala-related tests
public Response wala () {
// KTM
return page ("views/wala.wala", model("page", new Page () {
title = "Valse KTM"
},
"site", new Site () {
name = "With the model method !"
}));
}
/*
* Shows the profile of an user.
*/
public Response view (Request req, Response res) {
if (req.query_ids.size == 0) {
return list (req, res);
......@@ -104,12 +115,3 @@ public class UserController : Controller {
}
}
// Little models used for KTM tests.
public class Page : Object {
public string title { get; set; }
}
public class Site : Object {
public string name { get; set; }
}
File added
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment