Created
August 12, 2015 15:49
-
-
Save alxjrvs/1ce4dbaf2a68f463618c to your computer and use it in GitHub Desktop.
Helper Methods & cutting hair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
li { | |
font-size: 24px; | |
} | |
.complete { | |
text-decoration: line-through; | |
} | |
.high { | |
color: red; | |
} | |
.medium { | |
color: yellow; | |
} | |
.low { | |
color: green; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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