From: Ben Beltran Date: Wed, 1 Dec 2010 19:17:32 +0000 (-0700) Subject: Muchas cosas. X-Git-Url: https://git.r.bdr.sh/rbdr/grita/commitdiff_plain/0e0a67f4f172e61592d259386aa52f0635249f64?ds=inline;hp=5573b3c2672a04d58a91ce1c74f9c543e14fb423 Muchas cosas. Sería la primera copia funcional de la aplicación... Falta por supuesto estilizar las páginas individuales. --- diff --git a/Gemfile b/Gemfile index 7043675..c5e2123 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,8 @@ gem 'haml', ">=3.0.0" gem 'less', ">=1.2.0" gem 'rdiscount', ">=1.6.5" gem 'dm-core', ">=1.0" +gem 'dm-validations', ">=1.0" +gem 'dm-migrations', ">=1.0" gem 'dm-timestamps', ">=1.0" -gem 'dm-mysql-adapter', ">=1.0" \ No newline at end of file +gem 'dm-postgres-adapter', ">=1.0" +gem 'rqr', ">=0.2.2" \ No newline at end of file diff --git a/grita.rb b/grita.rb index eaf59a7..28d903a 100644 --- a/grita.rb +++ b/grita.rb @@ -2,7 +2,10 @@ require 'sinatra' require 'haml' require 'less' require 'dm-core' +require 'dm-validations' require 'dm-timestamps' +require 'dm-migrations' +require 'rqr' #config set :haml, :format => :html5 @@ -13,15 +16,37 @@ get '/' do end post '/' do - @grito = Grito.first_or_create(:title => params[:title], :text => params[:text]) + @grito = Grito.new(:title => params[:title], :text => params[:text]) + @grito.save haml :index end +get '/qr/:grito.png' do + tmpfile = Tempfile.new('tmp') + tmpfile.close + rpr_filepath = tmpfile.path + '.png' + + RQR::QRCode.create do |qr| + qr.save('http://grita.heroku.com/'+params[:grito], rpr_filepath) + end + + buffer = File.open(rpr_filepath).read + + content_type 'image/png' + buffer +end + get '/style.css' do less :style end -not_found do +get '/:grito' do + @grito = Grito.first(:id => params[:grito].to_i(36)) + raise "Invalid Post" if @grito.nil? + haml :grito +end + +error do haml :error end @@ -29,11 +54,14 @@ DataMapper.setup(:default, ENV['DATABASE_URL'] || 'mysql://root:root@localhost/g class Grito include DataMapper::Resource property :id, Serial - property :title, String, :required => true - property :text, Text, :required => true + property :title, String + property :text, Text property :created_at, DateTime - def geturl() + validates_presence_of :title, :message => "· Debes incluír un título." + validates_presence_of :text, :message => "· ¡No escribiste contenido!" + + def gethash() self.id.to_s(36) end end \ No newline at end of file diff --git a/views/grito.haml b/views/grito.haml index a8e5eb5..1a3bbc2 100644 --- a/views/grito.haml +++ b/views/grito.haml @@ -1,8 +1,5 @@ -%h1 The Sorrows of Young Werther -%p - :markdown - A **wonderful serenity** has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. - - I am so happy, *my dear friend*, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now. - - When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream; and, as I lie close to the earth, a thousand unknown plants are noticed by me: when I hear the buzz of the little world among the stalks, and grow familiar with the countless indescribable forms of the insects and flies, then I feel the presence of the Almighty, who formed us in his own image, \ No newline at end of file +%h1= @grito.title +%p= @grito.text +%h2 Share +%p= "http://grita.heroku.com/#{@grito.gethash}" +%img#qrcode{:alt=>"Código QR", :src=>"/qr/#{@grito.gethash}.png"} \ No newline at end of file diff --git a/views/index.haml b/views/index.haml index 742418d..2b40431 100644 --- a/views/index.haml +++ b/views/index.haml @@ -1,8 +1,18 @@ %form{:method => 'post', :action => '/'} + -unless @grito.nil? + -unless @grito.errors.empty? + #errors + -@grito.errors.each do |e| + %span= e + %br + -else + #success + Su texto ha sido guardado! + %a{:href=>"/#{@grito.gethash}"} De click aquí para verlo. %h1 Título - %input{:type => 'text', :name => 'title', :class => 'title'} + %input.title{:type => 'text', :name => 'title'} %br %h1 Texto - %textarea{:name => 'text', :class => 'text', :cols => '100'} + %textarea.text{:name => 'text', :cols => '76', :rows => '20'} %br - %input{:type => 'submit', :value => 'Gritalo!'} \ No newline at end of file + %input.submit{:type => 'submit', :value => 'Gritalo!'} \ No newline at end of file diff --git a/views/style.css b/views/style.css index 35f810c..c082c52 100644 --- a/views/style.css +++ b/views/style.css @@ -47,3 +47,47 @@ hr { border: 0; border-bottom: 1px solid #eeeeee; } +#body #qrcode { + display: block; + margin: 10px 250px; +} +#body input.title { + border: 1px solid #eeeeee; + font-size: 1.6em; + padding: 5px; + margin: 0 90px; + width: 770px; +} +#body textarea.text { + border: 1px solid #eeeeee; + font-size: 1.6em; + padding: 5px; + margin: 0 90px; + resize: vertical; +} +#body input.submit { + width: 150px; + font-size: 4.8em; + margin: 10px 410px; + padding: 20px; +} +#body #errors { + -moz-border-radius: 5px; + border-radius: 5px; + -webkit-border-radius: 5px; + padding: 10px; + font-size: 1.4em; + margin: 0 90px; + width: 760px; + background-color: #ffebe8; +} +#body #success { + -moz-border-radius: 5px; + border-radius: 5px; + -webkit-border-radius: 5px; + padding: 10px; + font-size: 1.4em; + margin: 0 90px; + width: 760px; + background-color: #f0fff0; +} diff --git a/views/style.less b/views/style.less index 0963093..6052c10 100644 --- a/views/style.less +++ b/views/style.less @@ -3,6 +3,10 @@ @emphasis_color: #222; @light_color: #999; @border_color: #eee; +@error_color: #ffebe8; +@success_color: #f0fff0; + +@font_stack: "Helvetica Neue", Helvetica, Arial, sans-serif; *{ margin: 0; @@ -14,7 +18,7 @@ body{ background-color: @background_color; text-align: center; font-size: .625em; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + font-family: @font_stack; } #wrapper{ @@ -62,4 +66,54 @@ hr{ margin: 10px; border: 0; border-bottom: 1px solid @border_color; +} + +#body #qrcode{ + display: block; + margin: 10px 250px; +} + +#body input.title{ + border: 1px solid @border_color; + font-size: 1.6em; + padding: 5px; + margin: 0 90px; + width: 770px; +} + +#body textarea.text{ + border: 1px solid @border_color; + font-size: 1.6em; + padding: 5px; + margin: 0 90px; + resize: vertical; +} + +#body input.submit{ + width: 150px; + font-size: 4.8em; + margin: 10px 410px; + padding: 20px; +} + +#body #errors{ + -moz-border-radius: 5px; + border-radius: 5px; + -webkit-border-radius: 5px; + padding: 10px; + font-size: 1.4em; + margin: 0 90px; + width: 760px; + background-color: @error_color; +} + +#body #success{ + -moz-border-radius: 5px; + border-radius: 5px; + -webkit-border-radius: 5px; + padding: 10px; + font-size: 1.4em; + margin: 0 90px; + width: 760px; + background-color: @success_color; } \ No newline at end of file