Skip to content

Instantly share code, notes, and snippets.

@allomov
Last active January 15, 2019 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allomov/4694bf4730f58bd2059621b6f3b428a3 to your computer and use it in GitHub Desktop.
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.
curl -X GET http://localhost:4567
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