From 59828b3f6a735de6d6e82b0e279ae190e943d240 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Oct 2023 10:13:32 -0300 Subject: [PATCH] feat: generar un post nuevo --- app/models/post.rb | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index fab9ab06..fff9e17f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -31,14 +31,34 @@ class Post def find_layout(path) File.foreach(path).lazy.grep(/^layout: /).take(1).first&.split(' ')&.last&.tr('\'', '')&.tr('"', '')&.to_sym end + + # Genera un Post nuevo + # + # @params :site [Site] + # @params :locale [String, Symbol] + # @params :document [Jekyll::Document] + # @params :layout [String,Symbol] + # @return [Post] + def build(**args) + args[:document] ||= + begin + site = args[:site] + collection = site.collections[args[:locale].to_s] + + Jekyll::Document.new('', site: site.jekyll, collection: collection).tap do |doc| + doc.data['date'] = Date.today.to_time + end + end + + Post.new(**args) + end end # Redefinir el inicializador de OpenStruct # - # @param site: [Site] el sitio en Sutty - # @param document: [Jekyll::Document] el documento leído por Jekyll - # @param layout: [Layout] la plantilla - # + # @param :site [Site] el sitio en Sutty + # @param :document [Jekyll::Document] el documento leído por Jekyll + # @param :layout [Layout] la plantilla def initialize(**args) default_attributes_missing(**args)