Last active
January 15, 2019 20:39
-
-
Save allomov/4694bf4730f58bd2059621b6f3b428a3 to your computer and use it in GitHub Desktop.
An example that demonstrates a simple app with Sinatra, html templates and jQuery.
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
curl -X GET http://localhost:4567 |
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' | |
require 'erb' | |
require 'ostruct' | |
a = :a_symbol_of_good_will | |
get '/' do | |
time_to_show = DateTime.now.to_s | |
h = { title: "title", | |
subtitle: "subtitle", | |
content: "content" } | |
post = OpenStruct.new(h) | |
template = ERB.new <<-HTML | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Sample app</title> | |
</head> | |
<body> | |
<section class="container"> | |
<h1><%= post.title %></h1> | |
<h2><%= post.subtitle %></h2> | |
<div class="content"> | |
<%= post.content %> | |
</div> | |
<% (1..6).to_a.each do |v| %> | |
<div><%= v %></div> | |
<% end %> | |
</section> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
console.log("hello world"); | |
</script> | |
</body> | |
</html> | |
HTML | |
template.result(binding) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment