From 24b0d74221b32d6a1a209ae20a5feae7bdb6940f Mon Sep 17 00:00:00 2001 From: f Date: Tue, 30 Jan 2018 12:20:19 -0300 Subject: [PATCH] ver un articulo --- app/controllers/application_controller.rb | 8 ++++++++ app/controllers/posts_controller.rb | 5 +++++ app/models/post.rb | 8 ++++++++ app/views/posts/index.haml | 2 +- app/views/posts/show.haml | 24 +++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 app/views/posts/show.haml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bf8e25d4..f301ae8e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,4 +19,12 @@ class ApplicationController < ActionController::Base s.id == id end end + + def find_post(site) + id = params[:post_id] || params[:id] + + site.posts.find do |p| + p.id == id + end + end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 782d5099..3a98367a 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -4,4 +4,9 @@ class PostsController < ApplicationController def index @site = find_site end + + def show + @site = find_site + @post = find_post(@site) + end end diff --git a/app/models/post.rb b/app/models/post.rb index 5ab63ca8..9e7af91c 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -72,6 +72,14 @@ class Post @post.basename != basename_from_front_matter end + def data + @post.data + end + + def content + @post.content + end + private def new_post diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 6c0942c5..48492ccb 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -5,4 +5,4 @@ - @site.posts.each do |post| %tr %td= link_to post.title, site_post_path(@site, post) - %td= post.date + %td= post.date.strftime('%F') diff --git a/app/views/posts/show.haml b/app/views/posts/show.haml new file mode 100644 index 00000000..7df0997b --- /dev/null +++ b/app/views/posts/show.haml @@ -0,0 +1,24 @@ +.row + + %h1= @post.title + + .content + :markdown + #{@post.content} + + %table.table.table-condensed.table-striped + %tbody + - @post.data.each do |key, data| + %tr + %th= key + %td + - if data.respond_to? :each + - data.each do |d| + %span.badge.badge-success= d + - elsif data.respond_to? :content + :markdown + #{data.content} + - elsif data.respond_to? :strftime + = data.strftime('%F') + - else + = data