Added blog module as example, this is far from being a real blog module.
but this is an example about on to add a new content type, and support it. Fixed new node form workflow. The current state is not final, it requires many changes, but for now, it implements a node editing workflow.
This commit is contained in:
103
examples/demo/modules/blog/cms_blog.e
Normal file
103
examples/demo/modules/blog/cms_blog.e
Normal file
@@ -0,0 +1,103 @@
|
||||
note
|
||||
description: "Summary description for {CMS_BLOG}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_BLOG
|
||||
|
||||
inherit
|
||||
CMS_NODE
|
||||
redefine
|
||||
make_empty,
|
||||
import_node
|
||||
end
|
||||
|
||||
create
|
||||
make_empty,
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_empty
|
||||
do
|
||||
Precursor
|
||||
end
|
||||
|
||||
feature {CMS_CONTENT_TYPE} -- Conversion
|
||||
|
||||
import_node (a_node: CMS_NODE)
|
||||
-- <Precursor>
|
||||
do
|
||||
Precursor (a_node)
|
||||
if attached {CMS_BLOG} a_node as l_blog then
|
||||
-- l_blog
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
content_type: READABLE_STRING_8
|
||||
once
|
||||
Result := {CMS_BLOG_CONTENT_TYPE}.name
|
||||
end
|
||||
|
||||
feature -- Access: content
|
||||
|
||||
summary: detachable READABLE_STRING_8
|
||||
-- A short summary of the node.
|
||||
|
||||
content: detachable READABLE_STRING_8
|
||||
-- Content of the node.
|
||||
|
||||
format: detachable READABLE_STRING_8
|
||||
-- Format associated with `content' and `summary'.
|
||||
-- For example: text, mediawiki, html, etc
|
||||
|
||||
tags: detachable ARRAYED_LIST [READABLE_STRING_32]
|
||||
-- Optional tags
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_content (a_content: like content; a_summary: like summary; a_format: like format)
|
||||
do
|
||||
content := a_content
|
||||
summary := a_summary
|
||||
format := a_format
|
||||
end
|
||||
|
||||
add_tag (a_tag: READABLE_STRING_32)
|
||||
-- Set `parent' to `a_page'
|
||||
require
|
||||
not a_tag.is_whitespace
|
||||
local
|
||||
l_tags: like tags
|
||||
do
|
||||
l_tags := tags
|
||||
if l_tags = Void then
|
||||
create l_tags.make (1)
|
||||
tags := l_tags
|
||||
end
|
||||
l_tags.force (a_tag)
|
||||
end
|
||||
|
||||
set_tags_from_string (a_tags: READABLE_STRING_32)
|
||||
local
|
||||
t: STRING_32
|
||||
do
|
||||
tags := Void
|
||||
across
|
||||
a_tags.split (',') as ic
|
||||
loop
|
||||
t := ic.item
|
||||
t.left_adjust
|
||||
t.right_adjust
|
||||
if not t.is_whitespace then
|
||||
add_tag (t)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
65
examples/demo/modules/blog/cms_blog_content_type.e
Normal file
65
examples/demo/modules/blog/cms_blog_content_type.e
Normal file
@@ -0,0 +1,65 @@
|
||||
note
|
||||
description: "Summary description for {CMS_BLOG_CONTENT_TYPE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_BLOG_CONTENT_TYPE
|
||||
|
||||
inherit
|
||||
CMS_CONTENT_TYPE
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (3)
|
||||
available_formats.extend (create {PLAIN_TEXT_CONTENT_FORMAT})
|
||||
available_formats.extend (create {FILTERED_HTML_CONTENT_FORMAT})
|
||||
available_formats.extend (create {FULL_HTML_CONTENT_FORMAT})
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING = "blog"
|
||||
-- Internal name.
|
||||
|
||||
title: STRING_32 = "Blog"
|
||||
-- Human readable name.
|
||||
|
||||
description: STRING_32 = "Content published as a blog post."
|
||||
-- Optional description
|
||||
|
||||
feature -- Access
|
||||
|
||||
available_formats: LIST [CONTENT_FORMAT]
|
||||
-- Available formats for Current type.
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node
|
||||
-- New node with `a_title' and fill from partial `a_partial_node' if set.
|
||||
do
|
||||
create Result.make (a_title)
|
||||
if a_partial_node /= Void then
|
||||
Result.import_node (a_partial_node)
|
||||
Result.set_title (a_title)
|
||||
end
|
||||
end
|
||||
|
||||
new_node (a_partial_node: detachable CMS_NODE): CMS_BLOG
|
||||
-- New node based on partial `a_partial_node', or from none.
|
||||
do
|
||||
create Result.make_empty
|
||||
if a_partial_node /= Void then
|
||||
Result.import_node (a_partial_node)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,75 @@
|
||||
note
|
||||
description: "Summary description for {CMS_BLOG_CONTENT_TYPE_WEBFORM_MANAGER}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_BLOG_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
|
||||
inherit
|
||||
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER [CMS_BLOG]
|
||||
redefine
|
||||
content_type,
|
||||
fill_edit_form,
|
||||
change_node,
|
||||
new_node
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Access
|
||||
|
||||
content_type: CMS_BLOG_CONTENT_TYPE
|
||||
-- Associated content type.
|
||||
|
||||
feature -- form
|
||||
|
||||
fill_edit_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable like new_node)
|
||||
local
|
||||
ti: WSF_FORM_TEXT_INPUT
|
||||
fset: WSF_FORM_FIELD_SET
|
||||
ta: WSF_FORM_TEXTAREA
|
||||
tselect: WSF_FORM_SELECT
|
||||
opt: WSF_FORM_SELECT_OPTION
|
||||
s: STRING_32
|
||||
do
|
||||
Precursor (response, f, a_node)
|
||||
create ti.make ("tags")
|
||||
ti.set_label ("Tags")
|
||||
ti.set_size (70)
|
||||
if a_node /= Void and then attached a_node.tags as l_tags then
|
||||
create s.make_empty
|
||||
across
|
||||
l_tags as ic
|
||||
loop
|
||||
if not s.is_empty then
|
||||
s.append_character (',')
|
||||
end
|
||||
s.append (ic.item)
|
||||
end
|
||||
ti.set_text_value (s)
|
||||
end
|
||||
ti.set_is_required (False)
|
||||
f.extend (ti)
|
||||
end
|
||||
|
||||
change_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: like new_node)
|
||||
do
|
||||
Precursor (response, fd, a_node)
|
||||
if attached fd.string_item ("tags") as l_tags then
|
||||
a_node.set_tags_from_string (l_tags)
|
||||
end
|
||||
end
|
||||
|
||||
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable like new_node): like content_type.new_node
|
||||
-- <Precursor>
|
||||
do
|
||||
Result := Precursor (response, fd, a_node)
|
||||
if attached fd.string_item ("tags") as l_tags then
|
||||
Result.set_tags_from_string (l_tags)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
26
examples/demo/modules/blog/cms_blog_module-safe.ecf
Normal file
26
examples/demo/modules/blog/cms_blog_module-safe.ecf
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="cms_blog_module" uuid="C92F6E1E-2222-4414-9B6E-AA680E324D42" library_target="cms_blog_module">
|
||||
<target name="cms_blog_module">
|
||||
<root all_classes="true"/>
|
||||
<file_rule>
|
||||
<exclude>/.git$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="transitional" syntax="standard">
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="base_extension" location="$ISE_LIBRARY\library\base_extension\base_extension-safe.ecf"/>
|
||||
<library name="cms" location="..\..\..\..\cms-safe.ecf" readonly="false"/>
|
||||
<library name="cms_model" location="..\..\..\..\library\model\cms_model-safe.ecf" readonly="false"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf" readonly="false"/>
|
||||
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter-safe.ecf"/>
|
||||
<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_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
|
||||
<cluster name="src" location=".\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
|
||||
121
examples/demo/modules/blog/cms_blog_module.e
Normal file
121
examples/demo/modules/blog/cms_blog_module.e
Normal file
@@ -0,0 +1,121 @@
|
||||
note
|
||||
description: "Summary description for {CMS_BLOG_MODULE}."
|
||||
author: ""
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
class
|
||||
CMS_BLOG_MODULE
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
redefine
|
||||
register_hooks,
|
||||
initialize,
|
||||
is_installed,
|
||||
install
|
||||
end
|
||||
|
||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
name := "Blog demo module"
|
||||
version := "1.0"
|
||||
description := "Service to demonstrate new node for blog"
|
||||
package := "demo"
|
||||
end
|
||||
|
||||
feature {CMS_API} -- Module Initialization
|
||||
|
||||
initialize (api: CMS_API)
|
||||
-- <Precursor>
|
||||
local
|
||||
ct: CMS_BLOG_CONTENT_TYPE
|
||||
do
|
||||
Precursor (api)
|
||||
|
||||
if attached {CMS_NODE_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_CONTENT_TYPE_WEBFORM_MANAGER}.make (ct))
|
||||
-- Add support for CMS_BLOG, which requires a storage extension to store the optional "tags" value
|
||||
-- For now, we only have extension based on SQL statement.
|
||||
if attached {CMS_NODE_STORAGE_SQL} l_node_api.node_storage as l_sql_node_storage then
|
||||
l_sql_node_storage.register_node_storage_extension (create {CMS_NODE_STORAGE_SQL_BLOG_EXTENSION}.make (l_sql_node_storage))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature {CMS_API} -- Module management
|
||||
|
||||
is_installed (api: CMS_API): BOOLEAN
|
||||
-- Is Current module installed?
|
||||
do
|
||||
Result := attached api.storage.custom_value ("is_initialized", "module-" + name) as v and then v.is_case_insensitive_equal_general ("yes")
|
||||
end
|
||||
|
||||
install (api: CMS_API)
|
||||
local
|
||||
sql: STRING
|
||||
do
|
||||
-- Schema
|
||||
if attached {CMS_STORAGE_SQL_I} api.storage as l_sql_storage then
|
||||
if not l_sql_storage.sql_table_exists ("blog_post_nodes") then
|
||||
sql := "[
|
||||
CREATE TABLE "blog_post_nodes"(
|
||||
"nid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("nid">=0),
|
||||
"revision" INTEGER,
|
||||
"tags" VARCHAR(255)
|
||||
);
|
||||
]"
|
||||
l_sql_storage.sql_execute_script (sql)
|
||||
if l_sql_storage.has_error then
|
||||
api.logger.put_error ("Could not initialize database for blog module", generating_type)
|
||||
end
|
||||
end
|
||||
api.storage.set_custom_value ("is_initialized", "module-" + name, "yes")
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Node router.
|
||||
do
|
||||
create Result.make (1)
|
||||
Result.handle_with_request_methods ("/blogs/", create {WSF_URI_AGENT_HANDLER}.make (agent handle_blogs (?,?, a_api)), Result.methods_get)
|
||||
end
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
register_hooks (a_response: CMS_RESPONSE)
|
||||
do
|
||||
a_response.subscribe_to_menu_system_alter_hook (Current)
|
||||
end
|
||||
|
||||
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
do
|
||||
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
|
||||
116
examples/demo/modules/blog/cms_node_storage_sql_blog_extension.e
Normal file
116
examples/demo/modules/blog/cms_node_storage_sql_blog_extension.e
Normal file
@@ -0,0 +1,116 @@
|
||||
note
|
||||
description: "Storage extension for Blog nodes."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_NODE_STORAGE_SQL_BLOG_EXTENSION
|
||||
|
||||
inherit
|
||||
CMS_NODE_STORAGE_EXTENSION [CMS_BLOG]
|
||||
|
||||
CMS_PROXY_STORAGE_SQL
|
||||
rename
|
||||
sql_storage as node_storage
|
||||
redefine
|
||||
node_storage
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
node_storage: CMS_NODE_STORAGE_SQL
|
||||
-- <Precursor>
|
||||
|
||||
feature -- Access
|
||||
|
||||
content_type: STRING
|
||||
once
|
||||
Result := {CMS_BLOG_CONTENT_TYPE}.name
|
||||
end
|
||||
|
||||
feature -- Persistence
|
||||
|
||||
store (a_node: CMS_BLOG)
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
l_new_tags: detachable STRING_32
|
||||
l_previous_tags: detachable STRING_32
|
||||
l_update: BOOLEAN
|
||||
do
|
||||
error_handler.reset
|
||||
if attached api as l_api then
|
||||
l_api.logger.put_information (generator + ".store", Void)
|
||||
end
|
||||
|
||||
create l_parameters.make (2)
|
||||
l_parameters.put (a_node.id, "nid")
|
||||
l_parameters.put (a_node.revision, "revision")
|
||||
|
||||
sql_query (sql_select_blog_data, l_parameters)
|
||||
if not has_error then
|
||||
if sql_rows_count = 1 then
|
||||
l_previous_tags := sql_read_string_32 (3)
|
||||
l_update := True
|
||||
end
|
||||
if attached a_node.tags as l_tags and then not l_tags.is_empty then
|
||||
create l_new_tags.make (0)
|
||||
across
|
||||
l_tags as ic
|
||||
loop
|
||||
if not l_new_tags.is_empty then
|
||||
l_new_tags.append_character (',')
|
||||
end
|
||||
l_new_tags.append (ic.item)
|
||||
end
|
||||
else
|
||||
l_new_tags := Void
|
||||
end
|
||||
l_parameters.put (l_new_tags, "tags")
|
||||
if l_update and l_new_tags /~ l_previous_tags then
|
||||
sql_change (sql_update_blog_data, l_parameters)
|
||||
elseif l_new_tags /= Void then
|
||||
sql_change (sql_insert_blog_data, l_parameters)
|
||||
else
|
||||
-- no blog data, means everything is empty.
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
load (a_node: CMS_BLOG)
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
n: INTEGER
|
||||
ct: CMS_BLOG_CONTENT_TYPE
|
||||
do
|
||||
error_handler.reset
|
||||
create l_parameters.make (2)
|
||||
l_parameters.put (a_node.id, "nid")
|
||||
l_parameters.put (a_node.revision, "revision")
|
||||
sql_query (sql_select_blog_data, l_parameters)
|
||||
if not has_error then
|
||||
n := sql_rows_count
|
||||
if n = 1 then
|
||||
-- nid, revision, parent
|
||||
if
|
||||
attached sql_read_string_32 (3) as l_tags and then
|
||||
not l_tags.is_whitespace
|
||||
then
|
||||
-- FIXME: find a simple way to access the declared content types.
|
||||
a_node.set_tags_from_string (l_tags)
|
||||
end
|
||||
else
|
||||
check unique_data: n = 0 end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- SQL
|
||||
|
||||
sql_select_blog_data: STRING = "SELECT nid, revision, tags FROM blog_post_nodes WHERE nid =:nid AND revision=:revision;"
|
||||
sql_insert_blog_data: STRING = "INSERT INTO blog_post_nodes (nid, revision, tags) VALUES (:nid, :revision, :tags);"
|
||||
sql_update_blog_data: STRING = "UPDATE blog_post_nodes SET nid=:nid, revision=:revision, tags=:tags WHERE nid=:nid AND revision=:revision;"
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user