Skip to content

Commit 8fec299

Browse files
committed
update
1 parent 8dbc101 commit 8fec299

File tree

5 files changed

+38
-53
lines changed

5 files changed

+38
-53
lines changed

getting-started/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <h3>2.2 Creating the Blog application</h3>
103103
</tr>
104104
<tr>
105105
<td>config/</td>
106-
<td>Configure your application's database, <a href="../request_pipeline">request pipeline</a> and several optional features of Crails.</td>
106+
<td>Configure your application's server, database, <a href="../request_pipeline">request pipeline</a> and several optional features of Crails.</td>
107107
</tr>
108108
<tr>
109109
<td>lib/</td>
@@ -231,10 +231,10 @@ <h3>3.2 Say "Hello", Crails</h3>
231231
</p>
232232

233233
<pre class="filepath">app/routes.cpp</pre>
234-
<pre><code class="language-cpp">#include &lt;crails/router.hpp&gt;
234+
<pre><code class="language-cpp">#include "config/router.hpp"
235235
#include "controllers/welcome.hpp"
236236

237-
void Crails::Router::initialize()
237+
ApplicationRouter::ApplicationRouter()
238238
{
239239
match_action("GET", "/", WelcomeController, index);
240240
}
@@ -408,9 +408,9 @@ <h3>4.2 Creating an MVC resource</h3>
408408
<pre class="filepath">app/routes.cpp</pre>
409409
<pre><code class="language-cpp">#include "app/controllers/article.hpp"
410410
#include "app/controllers/welcome.hpp"
411-
#include &lt;crails/router.hpp&gt;
411+
#include "config/router.hpp"
412412

413-
void Crails::Router::initialize()
413+
ApplicationRouter::ApplicationRouter()
414414
{
415415
resource_actions(article, ArticleController);
416416
match_action("GET", "/", WelcomeController, index);
@@ -1025,9 +1025,9 @@ <h3>6.2 Adding a route for comments</h3>
10251025
<pre><code class="language-cpp">#include "app/controllers/comment.hpp" // Add comment controller include
10261026
#include "app/controllers/article.hpp"
10271027
#include "app/controllers/welcome.hpp"
1028-
#include &lt;crails/router.hpp&gt;
1028+
#include "config/router.hpp"
10291029

1030-
void Crails::Router::initialize()
1030+
ApplicationRouter::ApplicationRouter()
10311031
{
10321032
resource_actions(article, ArticleController);
10331033
scope("article/:article_id", [this]()

request_pipeline/index.html

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@ <h2>1. Introduction</h2>
4141
#include &lt;crails/request_parsers/url_parser.hpp&gt;
4242
#include &lt;crails/request_parsers/form_parser.hpp&gt;
4343
#include &lt;crails/request_parsers/multipart_parser.hpp&gt;
44+
#include "server.hpp"
4445

4546
using namespace Crails;
4647

47-
const std::string Server::temporary_path = "/tmp";
48-
49-
void Server::initialize_request_pipe()
48+
void ApplicationServer::initialize_request_pipe()
5049
{
5150
add_request_parser(new RequestUrlParser);
5251
add_request_parser(new RequestFormParser);
5352
add_request_parser(new RequestMultipartParser);
54-
5553
add_request_handler(new ActionRequestHandler);
5654
add_request_handler(new FileRequestHandler);
5755
}
@@ -76,12 +74,11 @@ <h3>1.1 Adding support for queries in json format</h3>
7674

7775
<pre><code class="language-cpp">#include &lt;crails/request_parsers/json_parser.hpp&gt;
7876
#include &lt;crails/request_handlers/action.hpp&gt;
77+
#include "server.hpp"
7978

8079
using namespace Crails;
8180

82-
const std::string Server::temporary_path = "/tmp";
83-
84-
void Server::initialize_request_pipe()
81+
void ApplicationServer::initialize_request_pipe()
8582
{
8683
add_request_parser(new RequestJsonParser);
8784
add_request_handler(new ActionRequestHandler);
@@ -127,7 +124,8 @@ <h2>2. Writing your own request handler</h2>
127124
</code></pre>
128125

129126
<p>
130-
Simple stuff, really: overload <code>operator()</code>, receive a <code>Crails::Context</code>
127+
Simple stuff, really: overload <code>operator()</code>, receive a
128+
<a href="https://crails-framework.github.io/api-reference/#/classes/::Crails::Context" target="_blank">Crails::Context</a>
131129
and a callback object.
132130
</p>
133131
<p>
@@ -424,24 +422,15 @@ <h3>3.3 Fill in the Params object</h3>
424422

425423
load_yaml_tree(node, context.params);
426424
}
427-
CPP ).to_s); _erbout.&lt;&lt; "
425+
</code></pre>
428426

429-
&lt;p&gt;
430-
Now there's still an issue remaining: if the parsing fail, &lt;code&gt;YAML::Load&lt;/code&gt; will throw an
427+
<p>
428+
Now there's still an issue remaining: if the parsing fail, <code>YAML::Load</code> will throw an
431429
exception, and our server will respond with an error 500. That would be inaccurate, as the error
432-
lies in the query. Let's update our &lt;code&gt;body_received&lt;/code&gt; method to handle parsing errors:
433-
&lt;/p&gt;
434-
435-
".freeze
436-
437-
438-
439-
440-
441-
430+
lies in the query. Let's update our <code>body_received</code> method to handle parsing errors:
431+
</p>
442432

443-
; _erbout.&lt;&lt;(( code_block &lt;&lt;CPP
444-
void MyRequestParser::body_received(Crails::Context&amp; context, const std::string&amp; body) const
433+
<pre><code class="language-cpp">void MyRequestParser::body_received(Crails::Context&amp; context, const std::string&amp; body) const
445434
{
446435
try
447436
{

tutorials/layouts/index.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ <h3>2.3 Sharing variables with a view</h3>
214214

215215
void index()
216216
{
217-
vars["message"] = std::string("Howdy, little birdie !");
217+
vars["message"] = "Howdy, little birdie !";
218218
render("home/index");
219219
}
220220
};
@@ -223,9 +223,13 @@ <h3>2.3 Sharing variables with a view</h3>
223223
</code></pre>
224224

225225
<p>
226-
Note how we explicitely created a <code>std::string</code> when assignin the variable: that's
227-
because our template specify the <code>std::string</code> type for the message variable, rather
228-
than the <code>const char*</code> type.
226+
Note that in this example, <code>"Howdy, little birdie !"</code> has the <code>const char*</code>
227+
type, which does not match the variable <code>std::string</code> type we set for the <i>message</i>
228+
variable in our template.<br>
229+
With any other types, this would be a mistake: you need to be careful that the rvalue you assign
230+
to a shared variable is exactly the same as the template's. However, Crails will automatically
231+
convert between <code>std::string</code>, <code>std::string_view</code> and <code>const char*</code>,
232+
making this example valid.
229233
</p>
230234

231235
<p>
@@ -246,7 +250,7 @@ <h3>2.3 Sharing variables with a view</h3>
246250
void index()
247251
{
248252
render("home/index", {
249-
{"message", std::string("Howdy, little birdie !")}
253+
{"message", "Howdy, little birdie !"}
250254
});
251255
}
252256
};
@@ -331,7 +335,7 @@ <h3>3.2 Setting a default layout</h3>
331335
public:
332336
HomeController(Crails::Context&amp; context) : Crails::Controller(context)
333337
{
334-
vars["layout"] = std::string("home/my_layout");
338+
vars["layout"] = "home/my_layout";
335339
}
336340

337341
void index()
@@ -350,7 +354,7 @@ <h3>3.2 Setting a default layout</h3>
350354
<pre><code class="language-cpp"> void index()
351355
{
352356
render("home/index", {
353-
{"layout", std::string("home/my_layout")}
357+
{"layout", "home/my_layout"}
354358
});
355359
}
356360
</code></pre>

tutorials/mail/index.html

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,22 +209,14 @@ <h4>2.1.3 Recipient options</h4>
209209
mail.add_recipient("[email protected]", "Jean Piaget", Crails::Mail::CarbonCopy);
210210
return mail;
211211
}
212-
).to_s); _erbout.&lt;&lt; "
212+
</code></pre>
213213

214-
&lt;p&gt;
214+
<p>
215215
Moreover, you may also want some recipients to be hidden from other recipients. This is called
216-
&lt;i&gt;Blind Carbon Copy&lt;/i&gt;, and is supported with the &lt;code&gt;Crails::Mail::Blind&lt;/code&gt; option:
217-
&lt;/p&gt;
218-
219-
".freeze
220-
221-
222-
223-
224-
216+
<i>Blind Carbon Copy</i>, and is supported with the <code>Crails::Mail::Blind</code> option:
217+
</p>
225218

226-
; _erbout.&lt;&lt;(( code_block &lt;&lt;CPP
227-
#include &lt;crails/mail.hpp&gt;
219+
<pre><code class="language-cpp">#include &lt;crails/mail.hpp&gt;
228220

229221
Crails::Mail make_mail()
230222
{

tutorials/routing/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ <h3>1.2 Configuring the Crails Router</h3>
5555
and typically look like this:
5656
</p>
5757

58-
<pre><code class="language-cpp">#include &lt;crails/router.hpp&gt;
58+
<pre><code class="language-cpp">#include "config/router.hpp"
5959
#include "controllers/brands.hpp"
6060
#include "controllers/products.hpp"
6161

62-
void Crails::Router::initialize()
62+
ApplicationRouter::ApplicationRouter()
6363
{
6464
match_action("GET", "brands", Brands, index);
6565
scope("brands/:brand_id", [&amp;]()
@@ -87,7 +87,7 @@ <h3>1.3 Using the router without controllers</h3>
8787
callback();
8888
}
8989

90-
void Crails::Router::initialize()
90+
ApplicationRouter::ApplicationRouter()
9191
{
9292
match("GET", "hello_world", hello_world);
9393
}

0 commit comments

Comments
 (0)