]>
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 |
0e0a67f4 BB |
20 | @grito = Grito.new(:title => params[:title], :text => params[:text]) |
21 | @grito.save | |
5573b3c2 BB |
22 | haml :index |
23 | end | |
24 | ||
0e0a67f4 BB |
25 | get '/qr/:grito.png' do |
26 | tmpfile = Tempfile.new('tmp') | |
27 | tmpfile.close | |
28 | rpr_filepath = tmpfile.path + '.png' | |
29 | ||
30 | RQR::QRCode.create do |qr| | |
c194753d | 31 | qr.save('http://#{request.host}/'+params[:grito], rpr_filepath) |
0e0a67f4 BB |
32 | end |
33 | ||
34 | buffer = File.open(rpr_filepath).read | |
35 | ||
36 | content_type 'image/png' | |
37 | buffer | |
38 | end | |
39 | ||
3e43ab35 BB |
40 | get '/style.css' do |
41 | less :style | |
42 | end | |
43 | ||
0e0a67f4 BB |
44 | get '/:grito' do |
45 | @grito = Grito.first(:id => params[:grito].to_i(36)) | |
46 | raise "Invalid Post" if @grito.nil? | |
b7be4f63 BB |
47 | |
48 | @markdown = RDiscount.new(@grito.text) | |
49 | ||
396b06b8 | 50 | haml :grito, :layout => :layoutmini |
0e0a67f4 BB |
51 | end |
52 | ||
53 | error do | |
5573b3c2 BB |
54 | haml :error |
55 | end | |
56 | ||
57 | DataMapper.setup(:default, ENV['DATABASE_URL'] || 'mysql://root:root@localhost/grita') | |
58 | class Grito | |
59 | include DataMapper::Resource | |
60 | property :id, Serial | |
0e0a67f4 BB |
61 | property :title, String |
62 | property :text, Text | |
5573b3c2 BB |
63 | property :created_at, DateTime |
64 | ||
0e0a67f4 BB |
65 | validates_presence_of :title, :message => "· Debes incluír un título." |
66 | validates_presence_of :text, :message => "· ¡No escribiste contenido!" | |
67 | ||
68 | def gethash() | |
5573b3c2 BB |
69 | self.id.to_s(36) |
70 | end | |
3e43ab35 | 71 | end |