-
Notifications
You must be signed in to change notification settings - Fork 19
/
notify_me.rb
98 lines (88 loc) · 2.86 KB
/
notify_me.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
configure :development do
set :database, 'sqlite://notify-me.db'
set :show_exceptions, true
end
configure :production do
set :database, ENV['HEROKU_POSTGRESQL_BROWN_URL']
end
set :product_name, 'Acme Widget'
set :product_keywords, 'widget, acme, awesome, cool'
set :placeholder_email, '[email protected]'
set :analytics_id, 'UA-XXXXX-X' #Just keep UA-XXXXX-X to not load analytics
enable :inline_templates
migration "create subscriptions" do
database.create_table :subscriptions do
primary_key :id
String :email, :null => false
DateTime :created_at, :null => false
end
end
class Subscription < Sequel::Model
end
get '/' do
erb :index
end
post '/subscribe' do
if params[:email].nil?
halt 200, 'Email is required to subscribe!'
end
@email = params[:email]
Subscription.insert(:email => @email, :created_at => DateTime.now) unless Subscription.find(:email => @email)
erb :success
end
__END__
@@ layout
<!DOCTYPE html>
<html>
<head>
<meta content='<%= settings.product_name %>' name='description' />
<meta content='<%= settings.product_keywords %>' name='keywords' />
<title><%= "Notify me when #{settings.product_name} launches!" %></title>
<link href='/reset.css' rel='stylesheet' />
<link href='/notify-me.css' rel='stylesheet' />
</head>
<body>
<div id='container'>
<%= yield %>
</div>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script>
<script src='/notify-me.js'></script>
<% if settings.analytics_id != 'UA-XXXXX-X' && settings.environment == :production %>
<!-- mathiasbynens.be/notes/async-analytics-snippet -->
<script>
var _gaq=[['_setAccount','<%= settings.analytics_id %>'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
<% end %>
</body>
</html>
@@ index
<div id='boxtop'></div>
<div id='banner'>
<h1><%= "#{settings.product_name} will be launching soon!" %></h1>
</div>
<div id='boxmain'>
<p>Enter your email address below and we'll notify you when it has launched.</p>
<div id='subscribe'>
<form action='/subscribe' method='post'>
<label for='email'>Email</label>
<input type='text' name='email' placeholder='<%= settings.placeholder_email %>'></input>
<div class='button-container'>
<button value='submit' class='awesome'>Notify Me!</button>
</div>
</form>
</div>
</div>
@@ success
<div id='boxtop'></div>
<div id='banner'>
<h1>Thanks for your submission!</h1>
</div>
<div id='boxmain'>
<h3><%= "We'll notify #{@email} when #{settings.product_name} launches!" %></h3>
<div class='button-container'>
<a href='/' class='awesome enabled'>Return Home</a>
</div>
</div>