]>
Commit | Line | Data |
---|---|---|
3e43ab35 BB |
1 | require 'sinatra' |
2 | require 'haml' | |
3 | require 'less' | |
5573b3c2 | 4 | require 'dm-core' |
0e0a67f4 | 5 | require 'dm-validations' |
5573b3c2 | 6 | require 'dm-timestamps' |
0e0a67f4 BB |
7 | require 'dm-migrations' |
8 | require 'rqr' | |
b7be4f63 | 9 | require 'rdiscount' |
3e43ab35 BB |
10 | |
11 | #config | |
12 | set :haml, :format => :html5 | |
13 | ||
14 | #app | |
15 | get '/' do | |
16 | haml :index | |
17 | end | |
18 | ||
5573b3c2 | 19 | post '/' do |
9316ecf2 | 20 | @grito = Grito.create(:title => params[:title], :text => params[:text]) |
5573b3c2 BB |
21 | haml :index |
22 | end | |
23 | ||
0e0a67f4 BB |
24 | get '/qr/:grito.png' do |
25 | tmpfile = Tempfile.new('tmp') | |
26 | tmpfile.close | |
27 | rpr_filepath = tmpfile.path + '.png' | |
28 | ||
29 | RQR::QRCode.create do |qr| | |
8aee5d71 | 30 | qr.save("http://#{request.host}/"+params[:grito], rpr_filepath) |
0e0a67f4 BB |
31 | end |
32 | ||
33 | buffer = File.open(rpr_filepath).read | |
34 | ||
35 | content_type 'image/png' | |
36 | buffer | |
37 | end | |
38 | ||
3e43ab35 BB |
39 | get '/style.css' do |
40 | less :style | |
41 | end | |
42 | ||
0e0a67f4 BB |
43 | get '/:grito' do |
44 | @grito = Grito.first(:id => params[:grito].to_i(36)) | |
45 | raise "Invalid Post" if @grito.nil? | |
b7be4f63 BB |
46 | |
47 | @markdown = RDiscount.new(@grito.text) | |
48 | ||
396b06b8 | 49 | haml :grito, :layout => :layoutmini |
0e0a67f4 BB |
50 | end |
51 | ||
52 | error do | |
5573b3c2 BB |
53 | haml :error |
54 | end | |
55 | ||
56 | DataMapper.setup(:default, ENV['DATABASE_URL'] || 'mysql://root:root@localhost/grita') | |
57 | class Grito | |
58 | include DataMapper::Resource | |
59 | property :id, Serial | |
0e0a67f4 BB |
60 | property :title, String |
61 | property :text, Text | |
5573b3c2 BB |
62 | property :created_at, DateTime |
63 | ||
0e0a67f4 BB |
64 | validates_presence_of :title, :message => "· Debes incluír un título." |
65 | validates_presence_of :text, :message => "· ¡No escribiste contenido!" | |
66 | ||
67 | def gethash() | |
5573b3c2 BB |
68 | self.id.to_s(36) |
69 | end | |
3e43ab35 | 70 | end |