This repository has been archived by the owner on May 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
49 lines (42 loc) · 1.42 KB
/
app.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
require 'sinatra'
require 'sass'
require 'gibbon'
require './helpers/helpers.rb'
# require_relative does not exist in ruby 1.8.7
# This is a fallback -- http://stackoverflow.com/a/4718414/951432
unless Kernel.respond_to?(:require_relative)
module Kernel
def require_relative(path)
require File.join(File.dirname(caller[0]), path.to_str)
end
end
end
configure do
set :sass, :style => :compressed
if ENV['RACK_ENV'] == "development"
KEYS = YAML.load_file("#{settings.root}/config/api_keys.yml")
set :gb, Gibbon.new(KEYS["mailchimp"])
set :newsletter, KEYS["newsletter"]
else
set :gb, Gibbon.new(ENV['mailchimp'])
set :newsletter, ENV['newsletter']
end
end
get '/stylesheets/:filename.css' do
content_type 'text/css', :charset => 'utf-8'
filename = "#{params[:filename]}"
render :scss, filename.to_sym, :views => './views/stylesheets'
end
get '/' do
@javascripts = ['/javascripts/jquery.js', '/javascripts/bootstrap-modal.js', '/javascripts/verimail.jquery.min.js',
'/javascripts/verimail.min.js', '/javascripts/app.js', '/javascripts/jquery.scrollTo-min.js']
erb :index
end
# tem de se verificar se é realmente um email e se não vai repetido
post '/newsletter' do
email_regex = /^[a-zA-Z0-9_.+\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/
if params[:email] =~ email_regex
settings.gb.listSubscribe(:id => settings.newsletter, :email_address => params[:email])
end
redirect to('/') unless request.xhr?
end