Skip to content

Commit 0107300

Browse files
committed
Finish c3s2
1 parent e6b55e8 commit 0107300

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

_layouts/default.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<link rel="stylesheet" href="{{relative}}bootstrap/css/bootstrap.css">
1313
<link rel="stylesheet" href="{{relative}}bootstrap/css/bootstrap-responsive.css">
1414

15+
16+
1517
<!-- syntax highlighting CSS -->
1618
<link rel="stylesheet" href="{{relative}}css/syntax.css">
1719
<!-- Google webfont link -->

_sessions/c3s2/1_conditionals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Conditionals
2+
title: If statements and comparisons
33
---
44

55
So far we've just used ruby to evaluate simple expressions. Coding becomes a lot more interesting when you can use your code for simple logic tasks:

_sessions/c3s2/3_deploying.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ You'll see that it created an app for you. In my case the app is called `arcane-
5858
origin [email protected]:code61/sinatra_project_1.git (fetch)
5959
origin [email protected]:code61/sinatra_project_1.git (push)
6060

61-
### A bit about git remotes
62-
61+
<!-- Put a bit about git remotes here -->
6362

6463
### Deploying
6564

_sessions/c3s2/4_templates.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ end
3535
</html>
3636
{% endhighlight %}
3737

38-
The line `erb :form` tells sinatra to look for a file called `form.erb` in a folder called `views`. It then processes that file using the `erb` (**e**mbedded **r**u**b**y) templating language and returns the result to the user.
38+
The line `erb :form` tells sinatra to look for a file called `form.erb` in a folder called `views`. It then processes that file using the `erb` (embedded ruby) templating language and returns the result to the user.
3939

4040
The `form.erb` above isn't very interesting: it is jsut a static template and doesn't have any ruby embedded in it. Let's look at a slightly better example:
4141

@@ -71,6 +71,23 @@ The important bits are:
7171
* In `app.rb` we assign `params[:name]` to a special type of variable `@name`. The special type of variable is an *instance variable* which **has to begin with a single `@`**.
7272
* We use the instance variable in the `views/greet.erb` inside a special erb tag `<%= ... %>`. The erb templater looks for these tags and interprets the inside as ruby.
7373

74+
Sinatra emphasises *convention* over *configuration*: rather than specifying the exact place to find the template, you just give the name and Sinatra 'knows' where to look. This means you have to write less code in the long run, but also that you have to know the conventions before you start.
75+
76+
<div class="panel panel-primary">
77+
<div class="panel-heading">
78+
<h3 class="panel-title">Sinatra template summary</h3>
79+
</div>
80+
<div class='panel-body'>
81+
<ol>
82+
<li>You call a template with the line <code>erb :template_name</code>.</li>
83+
<li>For this to work, you will need a template called <code>template_name.erb</code> in the <code>views</code> folder.</li>
84+
<li>Instance variables (ones that start with <code>@</code>) will be shared with the template.</li>
85+
<li>You use these shared instance variables in the template by putting them inside an erb tag: <code>&lt;%= @my_variable &gt;</code> </li>
86+
</ol>
87+
</div>
88+
</div>
89+
90+
7491
{% exercise %}
7592
1. Uncomment the bottom part of `sinatra_c3s2/app.rb` and comment out the top two blocks.
7693
2. Restart your server and check you can see the new page `h1` sections.

_sessions/c3s2/info.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title: Intro to Ruby 2
2+
strapline: Adding logic to app

0 commit comments

Comments
 (0)