Skip to content

Instantly share code, notes, and snippets.

@alxjrvs
Created August 12, 2015 15:49
Show Gist options
  • Save alxjrvs/1ce4dbaf2a68f463618c to your computer and use it in GitHub Desktop.
Save alxjrvs/1ce4dbaf2a68f463618c to your computer and use it in GitHub Desktop.
Helper Methods & cutting hair
li {
font-size: 24px;
}
.complete {
text-decoration: line-through;
}
.high {
color: red;
}
.medium {
color: yellow;
}
.low {
color: green;
}
<!DOCTYPE html>
<html>
<head>
<title>Basic HTML Page</title>
<link rel="stylesheet" href="home.css">
</head>
<body>
<h1>TODO list</h1>
<ul>
<% tasks.each do |task| %>
<li <%= "class='#{priority_css(task.priority)} #{complete_css(task.complete)}'" %> > <%= task.name %> </li>
<% end %>
</ul>
</body>
</html>
require 'sinatra'
get '/tasks' do
tasks = [
Task.new("Get Haircut", 10, true),
Task.new("Build a City for Ants"),
Task.new("Contemplate Navel", 2),
]
erb :index, locals: { tasks: tasks }
end
helpers do
def complete_css(complete)
if complete
"complete"
else
""
end
end
def priority_css(priority)
return "high" if (8..10).include? priority
return "medium" if (5..7).include? priority
return "low" if (0..4).include? priority
end
end
class Task
attr_reader :name, :priority, :complete
def initialize(name, priority = 0, complete = false)
@name = name
@priority = priority
@complete = complete
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment