comparison doc/web_framework/quick_start.rst @ 1170:4648a333b33f

doc: use "sourcecode" directive instead of "code" + small mistakes fixes: RST "code" directive is not always working well with "jinja" code. It has been replaced with sphinx specific "sourcecode" (alias of "code-block", nicer to read in not formatted doc) which is working better.
author Goffi <goffi@goffi.org>
date Fri, 12 Apr 2019 14:12:53 +0200
parents 28789926852a
children fe5c282461bd
comparison
equal deleted inserted replaced
1169:97e850e6fae9 1170:4648a333b33f
27 ``i18n`` is used for translating your site in other languages, but we'll get to this later. 27 ``i18n`` is used for translating your site in other languages, but we'll get to this later.
28 28
29 Now we have to declare this new site to Salut à Toi and Libervia. When installing Salut à Toi, you should have created a ``sat.conf`` file, if not, just create one at ``~/.sat.conf``. 29 Now we have to declare this new site to Salut à Toi and Libervia. When installing Salut à Toi, you should have created a ``sat.conf`` file, if not, just create one at ``~/.sat.conf``.
30 Edit this file, and in the section ``[DEFAULT]``, add the following setting: 30 Edit this file, and in the section ``[DEFAULT]``, add the following setting:
31 31
32 .. code:: javascript 32 .. sourcecode:: javascript
33 33
34 sites_path_public_dict = { 34 sites_path_public_dict = {
35 "quick_start": "~/dev/libervia_quick_start" 35 "quick_start": "~/dev/libervia_quick_start"
36 } 36 }
37 37
38 This declare the templates of your websites, you'll now be able to use them with tools like ``jp``. 38 This declare the templates of your websites, you'll now be able to use them with tools like ``jp``.
39 39
40 Now you have to add your site to Libervia. Choose a host name, and link it the site name by adding a ``vhost_dict`` setting in your ``[libervia]`` section of ``sat.conf``: 40 Now you have to add your site to Libervia. Choose a host name, and link it to the site name by adding a ``vhost_dict`` setting in your ``[libervia]`` section of ``sat.conf``:
41 41
42 .. code:: javascript 42 .. sourcecode:: javascript
43 43
44 vhosts_dict = {"quickstart.int": "quick_start"} 44 vhosts_dict = {"quickstart.int": "quick_start"}
45 45
46 That means that when you'll get to ``quickstart.int``, you'll land to your own site instead of official Libervia one. 46 That means that when you'll get to ``quickstart.int``, you'll land to your own site instead of official Libervia one.
47 47
48 Last but not least, you have to declare this website as alias for your localhost during developments. On GNU/Linux, this is done by editing ``/etc/hosts`` (as root user), to have something like that:: 48 Last but not least, you have to declare this website as alias for your localhost during developments. On GNU/Linux, this is done by editing ``/etc/hosts`` (as root user), to have something like that::
49 49
50 127.0.0.1 localhost.localdomain localhost quickstart.int 50 127.0.0.1 localhost.localdomain localhost quickstart.int
51 ::1 localhost.localdomain localhost quickstart.int 51 ::1 localhost.localdomain localhost quickstart.int
52 52
53 To see your website, you'll have to use the specified host name, and the port used by Libervia (8080 by default). If you kept default configuration, let's go to http://quickstart.int:8080. 53 To see your website, you'll have to use the specified host name, and the port used by Libervia (8080 by default). If you kept default configuration, let's go to http://quickstart.int:8080.
54 54
55 But for now, you'll just see ``No Such Resource`` (if you see standard Libervia site, that means that something is not working, you can check for assistance in our XMPP room (`sat@chat.jabberfr.org <xmpp:sat@chat.jabberfr.org?join>`_)). 55 But for now, you'll just see ``No Such Resource`` (if you see standard Libervia site, that means that something is not working, you can check for assistance in our XMPP room at `sat@chat.jabberfr.org <xmpp:sat@chat.jabberfr.org?join>`_).
56 56
57 All right? Good, let's start then. 57 All right? Good, let's start then.
58 58
59 A first template 59 A first template
60 ---------------- 60 ----------------
61 61
62 For this simple page, we won't have any data to manipulate, so let's start directly with the template. 62 For this simple page, we won't have any data to manipulate, so let's start directly with the template.
63 Create a ``salut.html`` file at ``templates/default/salut/salut.html`` inside your development directory, and put the following content inside: 63 Create a ``salut.html`` file at ``templates/default/salut/salut.html`` inside your development directory, and put the following content inside:
64 64
65 .. code:: jinja 65 .. sourcecode:: jinja
66 66
67 {% if not embedded %}{% extends 'base/base.html' %}{% endif %} 67 {% if not embedded %}{% extends 'base/base.html' %}{% endif %}
68 68
69 {% block body %} 69 {% block body %}
70 Salut à Toi le monde ! 70 Salut à Toi le monde !
72 72
73 Let's explain a bit. 73 Let's explain a bit.
74 74
75 The template use Jinja2_ engine, which is easy to learn and powerful. You have the documentation available on the official website, you should read in particular the `Template Designer Documentation <http://jinja.pocoo.org/docs/latest/templates/>`_. 75 The template use Jinja2_ engine, which is easy to learn and powerful. You have the documentation available on the official website, you should read in particular the `Template Designer Documentation <http://jinja.pocoo.org/docs/latest/templates/>`_.
76 76
77 .. code:: jinja 77 .. sourcecode:: jinja
78 78
79 {% if not embedded %}{% extends 'base/base.html' %}{% endif %} 79 {% if not embedded %}{% extends 'base/base.html' %}{% endif %}
80 80
81 This firt line should be present on every front page, it extends the base template which handle many things for you and to facilitate integration with the backend. "But I have not written any ``base/base.html`` template" you may say. That's right, that's because SàT template engine is looking for file in several places. When you link a template, first it will check the current theme of your site, then the ``default`` theme, and finally the ``default`` theme of SàT official site. That allows you to have access to the generic features like the backend integration. 81 This firt line should be present on every front page, it extends the base template which handle many things for you and to facilitate integration with the backend. "But I have not written any ``base/base.html`` template" you may say. That's right, that's because SàT template engine is looking for file in several places. When you link a template, first it will check the current theme of your site, then the ``default`` theme, and finally the ``default`` theme of SàT official site. That allows you to have access to the generic features like the backend integration.
82 82
83 .. code:: jinja 83 .. sourcecode:: jinja
84 84
85 {% block body %} 85 {% block body %}
86 Salut à Toi le monde ! 86 Salut à Toi le monde !
87 {% endblock body %} 87 {% endblock body %}
88 88
92 A first page 92 A first page
93 ------------ 93 ------------
94 We have a template, but we need a page to use it. 94 We have a template, but we need a page to use it.
95 Pages are put in a directories hierarchy which correspond directly to your URL hierarchy, simple! To be used as a Libervia page, a directory must contain a file named ``page_meta.py``. So to create your first page, you just have to create the file ``pages/salut/page_meta.py`` and put this inside: 95 Pages are put in a directories hierarchy which correspond directly to your URL hierarchy, simple! To be used as a Libervia page, a directory must contain a file named ``page_meta.py``. So to create your first page, you just have to create the file ``pages/salut/page_meta.py`` and put this inside:
96 96
97 .. code:: python 97 .. sourcecode:: python
98 98
99 #!/usr/bin/env python2.7 99 #!/usr/bin/env python2.7
100 #-*- coding: utf-8 -*- 100 #-*- coding: utf-8 -*-
101 101
102 template = "salut/salut.html" 102 template = "salut/salut.html"
111 Now let's go to http://quickstart.int:8080/salut and admire your first Libervia page :). 111 Now let's go to http://quickstart.int:8080/salut and admire your first Libervia page :).
112 112
113 But if you go to http://quickstart.int:8080 you still see this annoying ``No Such Resource``, would not it be nice to land directly to your salut page? 113 But if you go to http://quickstart.int:8080 you still see this annoying ``No Such Resource``, would not it be nice to land directly to your salut page?
114 All you have to do for that, is to add a couple of lines in your ``sat.conf``, once again in ``[libervia]`` section: 114 All you have to do for that, is to add a couple of lines in your ``sat.conf``, once again in ``[libervia]`` section:
115 115
116 .. code:: javascript 116 .. sourcecode:: javascript
117 117
118 url_redirections_dict = { 118 url_redirections_dict = {
119 "quick_start": { 119 "quick_start": {
120 "/": "/salut" 120 "/": "/salut"
121 } 121 }