Restructured Blog Module

All blog handlers and storage classes are detached from the nodes module. All files of the blog module are in the modules/blog folder
This commit is contained in:
Dario Bösch
2015-05-21 16:04:58 +02:00
parent 57c2a7bccd
commit 470b1b2e05
12 changed files with 207 additions and 63 deletions

View File

@@ -0,0 +1,52 @@
note
description: "API to handle nodes of type blog"
author: "Dario B<>sch <daboesch@student.ethz.ch"
date: "$Date: 2015-05-21 14:46:00 +0100$"
revision: "$Revision: 96616 $"
class
CMS_BLOG_API
inherit
CMS_NODE_API
redefine
initialize,
node_storage
end
create
make
feature {NONE} -- Implementation
initialize
-- <Precursor>
do
Precursor
if attached {CMS_STORAGE_SQL_I} storage as l_storage_sql then
create {CMS_BLOG_STORAGE_SQL} node_storage.make (l_storage_sql)
else
create {CMS_BLOG_STORAGE_NULL} node_storage.make
end
initialize_node_types
end
feature {CMS_MODULE} -- Access nodes storage.
node_storage: CMS_BLOG_STORAGE_I
feature -- Access node
blogs_count: INTEGER_64
-- Number of nodes of type blog
do
Result := node_storage.blogs_count
end
blogs_order_created_desc: LIST[CMS_NODE]
-- List of nodes ordered by creation date (descending)
do
Result := node_storage.blogs
end
end

View File

@@ -20,6 +20,7 @@
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
<library name="wsf_html" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf_html\wsf_html-safe.ecf"/>
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/>
<library name="wsf_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
<cluster name="src" location=".\" recursive="true"/>
</target>

View File

@@ -42,7 +42,7 @@ feature {CMS_API} -- Module Initialization
do
Precursor (api)
if attached {CMS_NODE_API} api.module_api ({NODE_MODULE}) as l_node_api then
if attached {CMS_BLOG_API} api.module_api ({NODE_MODULE}) as l_node_api then
create ct
l_node_api.add_content_type (ct)
l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
@@ -87,7 +87,7 @@ CREATE TABLE "blog_post_nodes"(
feature {CMS_API} -- Access: API
node_api: detachable CMS_NODE_API
node_api: detachable CMS_BLOG_API
-- <Precursor>
feature -- Access: router
@@ -114,10 +114,9 @@ feature -- Access: router
-- a_router.handle_with_request_methods ("/blogs/", create {WSF_URI_AGENT_HANDLER}.make (agent handle_blogs (?,?, a_api)), a_router.methods_get)
-- end
configure_web (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
configure_web (a_api: CMS_API; a_node_api: CMS_BLOG_API; a_router: WSF_ROUTER)
local
l_blog_handler: BLOG_HANDLER
l_node_handler: NODE_HANDLER
l_uri_mapping: WSF_URI_MAPPING
do
-- TODO: for now, focused only on web interface, add REST api later. [2015-May-18]
@@ -140,16 +139,4 @@ feature -- Hooks
create lnk.make ("Blogs", "/blogs/")
a_menu_system.primary_menu.extend (lnk)
end
feature -- Handler
handle_blogs (req: WSF_REQUEST; res: WSF_RESPONSE; a_api: CMS_API)
local
r: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE
do
create r.make (req, res, a_api)
r.set_main_content ("Blog module is in development ...")
r.execute
end
end

View File

@@ -0,0 +1,117 @@
note
description: "Request handler related to /blogs."
author: "Dario B<>sch <daboesch@student.ethz.ch>"
date: "$Date: 2015-05-18 13:49:99 +0100 (lun., 18 mai 2015) $"
revision: "$966167$"
class
BLOG_HANDLER
inherit
CMS_BLOG_HANDLER
WSF_URI_HANDLER
rename
new_mapping as new_uri_mapping
end
WSF_RESOURCE_HANDLER_HELPER
redefine
do_get
end
REFACTORING_HELPER
create
make
feature -- execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
feature -- Settings
entries_per_page : INTEGER
-- The numbers of posts that are shown on one page. If there are more post a pagination is generated
do
-- For test reasons this is 2, so we don't have to create a lot of blog entries.
-- TODO: Set to bigger constant or load from global configuration file.
Result := 2
end
feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
l_page: CMS_RESPONSE
s: STRING
n: CMS_NODE
lnk: CMS_LOCAL_LINK
hdate: HTTP_DATE
do
-- At the moment the template is hardcoded, but we can
-- get them from the configuration file and load them into
-- the setup class.
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
l_page.add_variable (node_api.nodes, "nodes")
-- NOTE: for development purposes we have the following hardcode output.
create s.make_from_string ("<h2>Blog</h2>")
if attached node_api.blogs_order_created_desc as lst then
-- Filter out blog entries from all nodes
--if n.content_type.is_equal ("blog") then
s.append ("<ul class=%"cms-blog-nodes%">%N")
across
lst as ic
loop
n := ic.item
lnk := node_api.node_link (n)
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
-- Post date (creation)
if attached n.creation_date as l_modified then
create hdate.make_from_date_time (l_modified)
s.append (hdate.yyyy_mmm_dd_string)
s.append (" ")
end
-- Author
if attached n.author as l_author then
s.append ("by ")
s.append (l_author.name)
end
-- Title with link
s.append (l_page.link (lnk.title, lnk.location, Void))
-- Summary
if attached n.summary as l_summary then
s.append ("<p class=%"blog_list_summary%">")
if attached api.format (n.format) as f then
s.append (f.formatted_output (l_summary))
else
s.append (l_page.formats.default_format.formatted_output (l_summary))
end
s.append ("<br />")
s.append (l_page.link ("See more...", lnk.location, Void))
s.append ("</p>")
end
s.append ("</li>%N")
end
s.append ("</ul>%N")
--end
end
l_page.set_main_content (s)
l_page.add_block (create {CMS_CONTENT_BLOCK}.make ("nodes_warning", Void, "/blogs/ is not yet fully implemented<br/>", Void), "highlighted")
l_page.execute
end
end

View File

@@ -0,0 +1,16 @@
note
description: "Summary description for {CMS_NODE_HANDLER}."
author: ""
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
deferred class
CMS_BLOG_HANDLER
inherit
CMS_MODULE_HANDLER [CMS_BLOG_API]
rename
module_api as node_api
end
end

View File

@@ -0,0 +1,24 @@
note
description: "Interface for accessing blog contents from the database."
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
deferred class
CMS_BLOG_STORAGE_I
inherit
CMS_NODE_STORAGE_I
feature -- Access
blogs_count: INTEGER_64
-- Count of blog nodes
deferred
end
blogs: LIST [CMS_NODE]
-- List of nodes ordered by creation date (descending).
deferred
end
end

View File

@@ -0,0 +1,31 @@
note
description: "Summary description for {CMS_BLOG_STORAGE_NULL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_BLOG_STORAGE_NULL
inherit
CMS_NODE_STORAGE_NULL
CMS_BLOG_STORAGE_I
create
make
feature -- Access
blogs_count: INTEGER_64
-- Count of nodes.
do
end
blogs: LIST[CMS_NODE]
-- List of nodes.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
end

View File

@@ -0,0 +1,61 @@
note
description: "Summary description for {CMS_BLOG_STORAGE_SQL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_BLOG_STORAGE_SQL
inherit
CMS_NODE_STORAGE_SQL
CMS_BLOG_STORAGE_I
create
make
feature -- Access
blogs_count: INTEGER_64
-- Count of blog nodes
do
error_handler.reset
write_information_log (generator + ".nodes_count")
sql_query (sql_select_blog_count, Void)
if sql_rows_count = 1 then
Result := sql_read_integer_64 (1)
end
end
blogs: LIST [CMS_NODE]
-- List of nodes ordered by creation date (descending).
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
error_handler.reset
write_information_log (generator + ".nodes")
from
sql_query (sql_select_blogs_order_created_desc, Void)
sql_start
until
sql_after
loop
if attached fetch_node as l_node then
Result.force (l_node)
end
sql_forth
end
end
feature {NONE} -- Queries
sql_select_blog_count: STRING = "SELECT count(*) FROM Nodes WHERE status != -1 AND type = %"blog%";"
-- Nodes count (Published and not Published)
--| note: {CMS_NODE_API}.trashed = -1
sql_select_blogs_order_created_desc: STRING = "SELECT * FROM Nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC;"
-- SQL Query to retrieve all nodes that are from the type "blog" ordered by descending creation date.
end