From ec9aa032f086e06d94382b0cf1f4176b9fb8dc5f Mon Sep 17 00:00:00 2001 From: Joan Arnaldich Bernal Date: Sun, 30 Jan 2011 22:57:08 +0100 Subject: [PATCH] Modifyied blog content type --- sputnik/actions/blog.lua | 99 +++++++++++++++++++++--------------- sputnik/node_defaults/@BlogEntry.lua | 1 + sputnik/node_defaults/blog.lua | 1 + 3 files changed, 59 insertions(+), 42 deletions(-) rewrite sputnik/actions/blog.lua (76%) diff --git a/sputnik/actions/blog.lua b/sputnik/actions/blog.lua dissimilarity index 76% index 5084fe0..03990e5 100644 --- a/sputnik/actions/blog.lua +++ b/sputnik/actions/blog.lua @@ -1,42 +1,57 @@ --- --- Blog actions --- -module(..., package.seeall) - -actions = {} - -local template = [=[ -

Blog page $test

- -
    - $do_entries[[
  1. $name
  2. ]] -
-]=] - - -local function pages_in_order(sputnik) - local pages = sputnik.saci:get_nodes_by_prefix'blog' - local res = {} - for id,page in pairs(pages) do - res[#res+1] = page - end - table.sort(res,function(p1,p2) return (p1.creation_time or '') < (p2.creation_time or '') end) - return res -end - - -function actions.show_blog(node, request, sputnik) - node.inner_html = cosmo.f(template) { - test = "Prova", - do_entries = function() - local pages = pages_in_order(sputnik) - for _, page in ipairs(pages) do - cosmo.yield{ - name = page.title:gsub('blog/',''), - } - end - end - } - - return node.wrappers.default(node, request, sputnik) -end +-- +-- Blog actions +-- +module(..., package.seeall) + +actions = {} + +local template = [=[ + $most_recent +

Older posts

+
    + $do_entries[[
  1. $name
  2. ]] +
+]=] + +local function pages_in_order(sputnik) + local pages = sputnik.saci:get_nodes_by_prefix'blog' + local res = {} + for id,page in pairs(pages) do + res[#res+1] = page + end + table.sort(res,function(p1,p2) return (p1.creation_time or '') < (p2.creation_time or '') end) + return res +end + +local wiki = require("sputnik.actions.wiki") +function actions.show_blog(node, request, sputnik) + -- XXX: Falta el cas on no hi ha cap subpàgina... + -- i documentar una mica això + local pages = pages_in_order(sputnik) + local most_recent = sputnik:get_node(table.remove(pages, 1).id) + + most_recent = sputnik:decorate_node(most_recent) + most_recent = sputnik:activate_node(most_recent) + + node.title = most_recent.title:gsub('blog/','') + node.inner_html = cosmo.f(template) { + test = "Prova", + most_recent = most_recent.actions.show_content(most_recent, request, sputnik), + do_entries = function() + for _, page in ipairs(pages) do + cosmo.yield{ + id = page.id, + name = page.title:gsub('blog/',''), + } + end + end + } + + return node.wrappers.default(node, request, sputnik) +end + + +function actions.show_blog_entry(node, request, sputnik) + node.title = node.title:gsub('blog/', '') + return wiki.actions.show(node, request, sputnik) +end \ No newline at end of file diff --git a/sputnik/node_defaults/@BlogEntry.lua b/sputnik/node_defaults/@BlogEntry.lua index 28d83cc..18effee 100644 --- a/sputnik/node_defaults/@BlogEntry.lua +++ b/sputnik/node_defaults/@BlogEntry.lua @@ -5,6 +5,7 @@ NODE = { category = "prototypes", actions= [[ edit = "wiki.edit" + show = "blog.show_blog_entry" ]], permissions = [[ deny(Anonymous, edit_and_save) diff --git a/sputnik/node_defaults/blog.lua b/sputnik/node_defaults/blog.lua index 94d5c67..62882ed 100644 --- a/sputnik/node_defaults/blog.lua +++ b/sputnik/node_defaults/blog.lua @@ -8,6 +8,7 @@ NODE = { ]], actions = [[ show = "blog.show_blog" + reload = "wiki.reload" ]], } -- 2.11.4.GIT