From bfe781ff877e830ce8b61022b79f736a978913f8 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 10 Oct 2017 11:52:27 -0300 Subject: [PATCH] parsear la fecha / mostrar mensajes --- lib/sutty/post.rb | 10 ++++++---- views/_flash.haml | 9 +++++++++ views/layout.haml | 1 + views/posts/_form.haml | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 views/_flash.haml diff --git a/lib/sutty/post.rb b/lib/sutty/post.rb index e797c25f..f5f2842f 100644 --- a/lib/sutty/post.rb +++ b/lib/sutty/post.rb @@ -51,18 +51,20 @@ module Sutty tags: params[:post][:tags].split(',').map(&:strip), categories: params[:post][:categories].split(',').map(&:strip), title: params[:post][:title], - date: Time.new(params[:post][:date]) + date: Time.parse(params[:post][:date]) } post = Sutty::Models::Post.new(@site, @post, front_matter) post.content = params[:post][:content] if post.save + @post = post.post flash[:success] = 'Artículo guardado con éxito' - redirect to("/sites/#{@site.name}/posts/#{post.post.basename}") + # XXX por alguna razon el flash no sobrevive la redirección + haml :'posts/show' else - flash[:error] = 'Hubo un error al guardar el artículo' - redirect back + flash[:warning] = post.errors + haml :'posts/edit' end end end diff --git a/views/_flash.haml b/views/_flash.haml new file mode 100644 index 00000000..23eee97b --- /dev/null +++ b/views/_flash.haml @@ -0,0 +1,9 @@ +- [ :warning, :success ].each do |type| + - if flash[type] + .alert{class: "alert-#{type.to_s}", role: 'alert'} + - if flash[type].respond_to? :each + %ul + - flash[type].each do |msg| + %li= msg + - else + = flash[type] diff --git a/views/layout.haml b/views/layout.haml index 820927c5..d9b18b24 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -7,6 +7,7 @@ %link{rel: 'stylesheet', type: 'text/css', href: '/stylesheets/sutty.css'} %body{class: @has_cover ? 'background-cover' : ''} .container-fluid + = haml :_flash = yield %footer.footer %p{style: @has_cover ? 'color: white' : ''} diff --git a/views/posts/_form.haml b/views/posts/_form.haml index 5dcca2b3..99a9b707 100644 --- a/views/posts/_form.haml +++ b/views/posts/_form.haml @@ -6,7 +6,7 @@ = @post.content .form-group %label{for: 'date'} Fecha de publicación - %input.form-control{type: 'text', name: 'post[date]', id: 'date', value: @post.data['date']} + %input.form-control{type: 'text', name: 'post[date]', id: 'date', value: @post.data['date'].strftime('%F')} .form-group %label{for: 'title'} Título %input.form-control{type: 'text', name: 'post[title]', id: 'title', value: @post.data['title']}