Skip to content
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

check #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion erb_example.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
require 'erb'

x = 42
y = {name: "Huygens", age: 28, fav_quote: "We are what we think"}

template = ERB.new "The value of x is: <%= x %>"
puts template.result(binding)
block1 = ERB.new "Your name is <%= y[:name] %>"
block2 = ERB.new "If you were born in 1984, you would be <%= #{2012-1984} %> yrs old"
block3 = ERB.new("Hey Mr. <%= y[:name] %>. At <%= y[:age] %>, its good to have <%= y[:fav_quote] %> as your favorite quote")
#template2 = ERB.new("The number is greater than 40 <% if x>40 %>")
puts template.result(binding)
puts block1.result(binding)
puts block2.result(binding)
puts block3.result(binding)
#puts template2.result(binding)
32 changes: 29 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
<h1> Hello</h1>


<html>
<body>
<h1>You're using a layout</h1>
<p>
<h3> I'm a header</h3>
<p>Put things in the header</p>
<div>
<a href="http://www.nicholasgot.com", target="_blank">A link to my website</a>
</div>
<a href='me.html'>Me</a>
<p><a href='http://linkedin.com', target='_blank'>A link to linked-in</a></p>
</p>
<hr />
<div>
<h1> Hello</h1>
<p>
The time is now:
2012-06-16 16:00:08 -0500
The system time is now:
2012-09-04 06:40:18 +0300
</p>

<p>
My Name is:

</p>


</div>
<hr />
<div>
<h3> I'm a footer</h3>
<p>Put things in the footer</p>
<a href="http://www.twitter.com/", target="_blank">And here my twitter feed</a>
</div>
</body>
</html>
27 changes: 26 additions & 1 deletion public/me.html
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
foo


<html>
<body>
<h1>You're using a layout</h1>
<p>
<h3> I'm a header</h3>
<p>Put things in the header</p>
<div>
<a href="http://www.nicholasgot.com", target="_blank">A link to my website</a>
</div>
<a href='me.html'>Me</a>
<p><a href='http://linkedin.com', target='_blank'>A link to linked-in</a></p>
</p>
<hr />
<div>
foo
</div>
<hr />
<div>
<h3> I'm a footer</h3>
<p>Put things in the footer</p>
<a href="http://www.twitter.com/", target="_blank">And here my twitter feed</a>
</div>
</body>
</html>
45 changes: 45 additions & 0 deletions public/nick.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@


<html>
<body>
<h1>You're using a layout</h1>
<p>
<h3> I'm a header</h3>
<p>Put things in the header</p>
<div>
<a href="http://www.nicholasgot.com", target="_blank">A link to my website</a>
</div>
<a href='me.html'>Me</a>
<p><a href='http://linkedin.com', target='_blank'>A link to linked-in</a></p>
</p>
<hr />
<div>
<p>The time now is 2012-09-04 06:40:18 +0300</p>

<div>My name is Nicholas Got</div>
<div>

<p>I clearly love art</p>

</div>
<ul>

<li>I like Mbuzi</li>

<li>I like Ngombe</li>

<li>I like Cat</li>

<li>I like Dog</li>

</ul>

</div>
<hr />
<div>
<h3> I'm a footer</h3>
<p>Put things in the footer</p>
<a href="http://www.twitter.com/", target="_blank">And here my twitter feed</a>
</div>
</body>
</html>
6 changes: 5 additions & 1 deletion server_simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
## Capture control+c to shut down the server
trap 'INT' do server.shutdown end

server.mount_proc '/' do |req, res|
res.body = 'Hello, yay!'
end

## Start the server
server.start
server.start
2 changes: 1 addition & 1 deletion views/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1> Hello</h1>
<p>
The time is now:
The system time is now:
<%= Time.now %>
</p>

Expand Down
41 changes: 39 additions & 2 deletions views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,57 @@
<%
def link_to(name, url)
"<a href='#{url}', target='_blank'>#{name}</a>"
end
%>

<html>
<body>
<h1>You're using a layout</h1>
<p>
<h3> I'm a header</h3>
<p>Put things in the header</p>
<div>
<a href="http://www.nicholasgot.com", target="_blank">A link to my website</a>
</div>
<a href='me.html'>Me</a>

<p><%= link_to('A link to linked-in', 'http://linkedin.com') %></p>
</p>
<hr />
<p>
<% if @request.query['first_name'] && [email protected]['first_name'].empty? %>
Hello there <%= @request.query['first_name'] %>
<% else %>
Please enter your name
<% end %>
</p>

<form method='post' action="<% @request.path %>">
First name: <input type="text" name="first_name" placeholder='fist name'/><br />
<p>Gender: Male <input type="radio" name="gender" value="Male"/>
Female<input type="radio" name="gender" value="Female"/>
</p>
<div>
Hobbies <br />
Soccer <input type="checkbox" name="hobbies" value="soccer" /><br />
Reading <input type="checkbox" name="hobbies" value="reading" /></br />
Programming <input type="checkbox" name="hobbies" value="programming" /><br />
</div>
<br />

Password <input type="password" name="password" /><br />
<input type="submit" value="Submit" />
</form>

<div>
<%= yield %>
</div>


<hr />
<div>
<h3> I'm a footer</h3>
<p>Put things in the footer</p>
<a href="http://www.twitter.com/", target="_blank">And here my twitter feed</a>
</div>
</body>
</html>
</html>
13 changes: 13 additions & 0 deletions views/nick.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<p>The time now is <%= Time.now %></p>
<% me = {name: "Nicholas Got", art: "yes", number: 78} %>
<div>My name is <%= me[:name] %></div>
<div>
<% if me[:art] == "yes" %>
<p>I clearly love art</p>
<% end %>
</div>
<ul>
<% ['mbuzi', 'ngombe', 'cat', 'dog'].each do |pet| %>
<li>I like <%= pet.capitalize %></li>
<% end %>
</ul>