Skip to content

Misc fixes #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions step3.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ <h2>Step 3</h2>
<p>Adding some data is pretty simple. Ur/Web does some automatic table name generation. Looking inside the <span class="code">urblog</span> database, there is one table: <span class="code">uw_Urblog_entry</span>. Tables are named according to the modules they belong to (and module names are in turn defined by file names -- our <span class="code">entry</span> table is defined inside a file called <span class="code">urblog.ur</span>, which leads to an implied module <span class="code">Urblog</span>). This separation is used by Ur/Web to achieve useful encapsulation of tables, such that one module cannot (inadvertantly or intentionally) interfere with tables that are owned by some other module. I added some test data like this:</p>

<pre class="code">
insert into uw_Urblog_entry (uw_id, uw_title, uw_created, uw_author, uw_body)
insert into uw_urblog_entry (uw_id, uw_title, uw_created, uw_author, uw_body)
values (0, "This is a test entry", now(), "Gian", "This is a test entry. I hope you like it");
insert into uw_Urblog_entry (uw_id, uw_title, uw_created, uw_author, uw_body)
insert into uw_urblog_entry (uw_id, uw_title, uw_created, uw_author, uw_body)
values (1, "This is also a test entry", now(), "Gian", "This is yet another test entry. I hope you like it");
</pre>

Expand Down Expand Up @@ -85,7 +85,7 @@ <h3>urblog.ur</h3>
<h3>urblog.urp</h3>

<pre class="code">
allow url http://expdev.net/urtutorial/step4/style.css
allow url http://expdev.net/urtutorial/step3/style.css
rewrite style Urblog/blogEntry blogEntry
database dbname=urblog
sql urblog.sql
Expand Down
24 changes: 23 additions & 1 deletion step4.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ <h3>urblog.ur</h3>
[...]
</pre>

<p>Since we added a new style.css url, we add a line allowing access to the url to our .urp file:</p>

<pre class="code">
allow url http://expdev.net/urtutorial/step3/style.css
allow url http://expdev.net/urtutorial/step4/style.css
rewrite style Urblog/blogEntry blogEntry
database dbname=urblog
sql urblog.sql

urblog
</pre>


<h3>urblog.urs</h3>

<p>To ensure our new detail function visible to the outside world, so we add its signature to the signature definition:</p>
Expand Down Expand Up @@ -108,6 +121,15 @@ <h3>urblog.ur</h3>

<p>We also introduce a new style <span class="code">blogComment</span>.</p>

<pre class="code">
[...]
style blogEntry

style blogComment
[...]
</pre>


<p>Our comment function is pretty simple. The only thing we have to do is specify a type annotation -- Ur/Web can't always figure out the type of functions on its own. In this case we specify that our function is <span class="code">transaction xbody</span>. This type (<span class="code">xbody</span>) is that of XML that is suitable for inclusion within a <span class="code">body</span> tag. The transaction, as before, indicates that this is part of a monad, and is therefore suitable for inclusion within other transactions (as all content that will be delivered to users must be).</p>

<pre class="code">
Expand Down Expand Up @@ -137,7 +159,7 @@ <h3>urblog.ur</h3>

<h3>urblog.urp</h3>

<p>We need to update our project file and style sheet (adding the rewrite for the new style declaration):</p>
<p>We need to update our project file and style sheet (adding the rewrite for the new style declaration). Since our new stylesheet contains our old css, we can replace our original link (in the list function) with <span class="code">http://expdev.net/urtutorial/step4/style.css</span> and shorten our .urp as shown:</p>

<pre class="code">
allow url http://expdev.net/urtutorial/step4/style.css
Expand Down
4 changes: 2 additions & 2 deletions step5.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h3>urblog.ur</h3>
[...]
</pre>

<p>We also add a new style and add an appropriate rewrite for the style name.</p>
<p>We also add a new style and add an appropriate rewrite for the style name. The style.css file can be found at <span class="code">http://expdev.net/urtutorial/step5/style.css</span>. We can replace references to the old link in our .ur and .urp files with the current one, similarly to what we did at the end of step4.</p>

<h3>Updating the database</h3>

Expand All @@ -114,7 +114,7 @@ <h3>Updating the database</h3>

<h2>Putting it all together</h2>

<p>As ever, you can compile the application. Make sure you have at least one test blog entry you can work with in your database, and then you can test the application by going to:</p>
<p>As ever, you can compile the application. Notice, since we added the sequence <span class="code">commentS</span>, compiling updates our urblog.sql with a new <span class="code">uw_urblog_comments</span> table. You'll need to create this table, possibly by wiping your current ones and reloading urblog.sql as shown earlier. Make sure you have at least one test blog entry you can work with in your database, and then you can test the application by going to:</p>

<p><a href="http://localhost:8080/Urblog/list">http://localhost:8080/Urblog/list</a></p>

Expand Down
2 changes: 1 addition & 1 deletion step6.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h2>Step 6</h2>

<p>How does this differ from components parameterised on table structure, you might ask? Well, that's a reasonable way of thinking about some of what this metaprogramming enables, but in Ur/Web it goes further. We can use familiar programming constructs (e.g. map and fold) to compute new types from old ones. We can invoke appropriate display functions based upon the types of the fields in a row. This gives much of the same flexibility that dynamic web languages can provide; however, Ur/Web does it in a way that is statically checked at compile time.</p>

<p>The Crud component is reasonably simple. We'll skip over most explanation of how it actually works, because you can divert back to that later. The component consists of two files -- a signature and an implementation.</p>
<p>The Crud component is reasonably simple. We'll skip over the code and explanation of how it actually works, because you can divert back to that later. The component consists of two files -- a signature and an implementation. They can be found <a href="https://github.com/gian/urtutorial/tree/master/step6">here</a>.</p>

<h3>urblog.urp</h3>

Expand Down