Updated CMS code.

Separated code to have a lib and an example.
Improved design, fixed a few issues related to folder location.

This is still experimental and require more work to be really friendly to use.
This commit is contained in:
Jocelyn Fiat
2013-01-31 15:33:24 +01:00
parent 40ea982293
commit ce469b6ede
136 changed files with 1841 additions and 299 deletions

View File

@@ -0,0 +1,75 @@
note
description: "Summary description for {CMS_PAGE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_PAGE
inherit
CMS_NODE
create
make_new,
make
feature {NONE} -- Initialization
make (a_id: like id; a_title: like title; dt: like creation_date)
require
a_id > 0
do
set_id (a_id)
creation_date := dt
modification_date := dt
title := a_title
initialize
end
make_new (a_title: like title)
do
title := a_title
create creation_date.make_now_utc
modification_date := creation_date
initialize
end
initialize
do
format := formats.default_format
end
feature -- Access
title: detachable READABLE_STRING_32
body: detachable READABLE_STRING_8
format: CMS_FORMAT
content_type_name: STRING = "page"
feature -- Change
set_title (a_title: like title)
-- Set `title' to `a_title'
do
title := a_title
end
set_body (a_body: like body; a_format: like format)
-- Set `body' and associated `format'
do
body := a_body
format := a_format
end
feature -- Conversion
-- to_html (a_theme: CMS_THEME): STRING_8
-- do
-- Result := Precursor (a_theme)
-- end
end

View File

@@ -0,0 +1,177 @@
note
description: "Summary description for {CMS_PAGE_CONTENT_TYPE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_PAGE_CONTENT_TYPE
inherit
CMS_CONTENT_TYPE
create
make
feature {NONE} -- Initialization
make
do
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (1)
available_formats.extend (formats.plain_text)
available_formats.extend (formats.filtered_html)
available_formats.extend (formats.full_html)
end
feature -- Access
name: STRING = "page"
title: STRING = "basic page"
description: detachable READABLE_STRING_8
-- Optional description
do
Result := "Use <em>basic pages</em> for your static content, such as an 'About us' page."
end
available_formats: LIST [CMS_FORMAT]
feature -- Factory
fill_edit_form (f: CMS_FORM; a_node: detachable CMS_NODE)
local
ti: CMS_FORM_TEXT_INPUT
fset: CMS_FORM_FIELD_SET
ta: CMS_FORM_TEXTAREA
tselect: CMS_FORM_SELECT
opt: CMS_FORM_SELECT_OPTION
do
create ti.make ("title")
ti.set_label ("Title")
ti.set_size (70)
if a_node /= Void then
ti.set_text_value (a_node.title)
end
ti.set_is_required (True)
f.extend (ti)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
create ta.make ("body")
ta.set_rows (10)
ta.set_cols (70)
if a_node /= Void then
ta.set_text_value (a_node.body)
end
-- ta.set_label ("Body")
ta.set_description ("This is the main content")
ta.set_is_required (False)
create fset.make
fset.set_legend ("Body")
fset.extend (ta)
fset.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
create tselect.make ("format")
tselect.set_label ("Body's format")
tselect.set_is_required (True)
across
available_formats as c
loop
create opt.make (c.item.name, c.item.title)
if attached c.item.help as f_help then
opt.set_description ("<ul>" + f_help + "</ul>")
end
tselect.add_option (opt)
end
if a_node /= Void then
tselect.set_text_by_value (a_node.format.name)
end
fset.extend (tselect)
f.extend (fset)
end
change_node (a_execution: CMS_EXECUTION; fd: CMS_FORM_DATA; a_node: like new_node)
local
b: detachable READABLE_STRING_8
f: detachable CMS_FORMAT
do
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
check a_node.id = l_id end
end
if attached fd.string_item ("title") as l_title then
a_node.set_title (l_title)
end
if attached fd.string_item ("body") as l_body then
b := l_body
end
if attached fd.string_item ("format") as s_format and then attached formats.format (s_format) as f_format then
f := f_format
elseif a_node /= Void then
f := a_node.format
else
f := formats.default_format
end
if b /= Void then
a_node.set_body (b, f)
end
end
new_node (a_execution: CMS_EXECUTION; fd: CMS_FORM_DATA; a_node: detachable like new_node): CMS_PAGE
-- <Precursor>
local
b: detachable READABLE_STRING_8
f: detachable CMS_FORMAT
l_node: detachable like new_node
do
l_node := a_node
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
if l_node /= Void then
check l_node.id = l_id end
else
if attached {like new_node} a_execution.service.storage.node (l_id) as n then
l_node := n
else
-- FIXME: Error
end
end
end
if attached fd.string_item ("title") as l_title then
if l_node = Void then
create l_node.make_new (l_title)
else
l_node.set_title (l_title)
end
else
if l_node = Void then
create l_node.make_new ("...")
end
end
l_node.set_author (a_execution.user)
if attached fd.string_item ("body") as l_body then
b := l_body
end
if attached fd.string_item ("format") as s_format and then attached formats.format (s_format) as f_format then
f := f_format
elseif a_node /= Void then
f := a_node.format
else
f := formats.default_format
end
if b /= Void then
l_node.set_body (b, f)
end
Result := l_node
end
invariant
end

View File

@@ -0,0 +1,143 @@
note
description: "[
]"
class
NODE_ADD_CMS_EXECUTION
inherit
CMS_EXECUTION
create
make
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
f: like edit_form
fd: detachable CMS_FORM_DATA
l_preview: BOOLEAN
l_format: detachable CMS_FORMAT
do
create b.make_empty
if attached non_empty_string_path_parameter ("type") as s_type then
if attached service.content_type (s_type) as l_type then
f := edit_form (Void, request.path_info, "add-" + l_type.name, l_type)
if request.is_post_request_method then
create fd.make (request, f)
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
end
set_title ("Create " + l_type.title)
if has_permission ("create " + l_type.name) then
if fd /= Void and l_preview then
b.append ("<strong>Preview</strong><div class=%"preview%">")
if attached fd.string_item ("format") as s_format and then attached formats.format (s_format) as f_format then
l_format := f_format
end
if attached fd.string_item ("title") as l_title then
b.append ("<strong>Title:</strong><div class=%"title%">" + html_encoded (l_title) + "</div>")
end
if attached fd.string_item ("body") as l_body then
b.append ("<strong>Body:</strong><div class=%"body%">")
if l_format /= Void then
b.append (l_format.to_html (l_body))
else
b.append (html_encoded (l_body))
end
b.append ("</div>")
end
b.append ("</div>")
end
if fd /= Void and then fd.is_valid and not l_preview then
across
fd as c
loop
b.append ("<li>" + html_encoded (c.key) + "=")
if attached c.item as v then
b.append (html_encoded (v.string_representation))
end
b.append ("</li>")
end
if attached l_type.new_node (Current, fd, Void) as l_node then
service.storage.save_node (l_node)
if attached user as u then
service.log ("node", "User %"" + user_link (u) + "%" created node " + link (l_type.name +" #" + l_node.id.out, "/node/" + l_node.id.out , Void), 0, node_local_link (l_node))
else
service.log ("node", "Anonymous created node "+ l_type.name +" #" + l_node.id.out, 0, node_local_link (l_node))
end
add_success_message ("Node #" + l_node.id.out + " saved.")
set_redirection (node_url (l_node))
end
-- Creation ...
else
if fd /= Void then
if not fd.is_valid then
report_form_errors (fd)
end
fd.apply_to_associated_form
end
b.append (f.to_html (theme))
end
else
set_title ("Access denied")
end
else
set_title ("Unknown content type [" + s_type + "]")
end
else
set_title ("Create new content ...")
b.append ("<ul id=%"content-types%">")
across
service.content_types as c
loop
if has_permission ("create " + c.item.name) then
b.append ("<li>" + link (c.item.name, "/node/add/" + c.item.name, Void))
if attached c.item.description as d then
b.append ("<div class=%"description%">" + d + "</div>")
end
b.append ("</li>")
end
end
b.append ("</ul>")
end
set_main_content (b)
end
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_CONTENT_TYPE): CMS_FORM
local
f: CMS_FORM
ts: CMS_FORM_SUBMIT_INPUT
th: CMS_FORM_HIDDEN_INPUT
do
create f.make (a_url, a_name)
create th.make ("node-id")
if a_node /= Void then
th.set_text_value (a_node.id.out)
else
th.set_text_value ("0")
end
f.extend (th)
a_type.fill_edit_form (f, a_node)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
create ts.make ("op")
ts.set_default_value ("Save")
f.extend (ts)
create ts.make ("op")
ts.set_default_value ("Preview")
f.extend (ts)
Result := f
end
end

View File

@@ -0,0 +1,148 @@
note
description: "[
]"
class
NODE_EDIT_CMS_EXECUTION
inherit
CMS_EXECUTION
create
make
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
f: like edit_form
fd: detachable CMS_FORM_DATA
l_preview: BOOLEAN
l_format: detachable CMS_FORMAT
do
create b.make_empty
if
attached {WSF_STRING} request.path_parameter ("nid") as p_nid and then
p_nid.is_integer and then
attached service.storage.node (p_nid.integer_value) as l_node
then
if attached service.content_type (l_node.content_type_name) as l_type then
if has_permission ("edit " + l_type.name) then
f := edit_form (l_node, request.path_info, "edit-" + l_type.name, l_type)
if request.is_post_request_method then
create fd.make (request, f)
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
end
set_title ("Edit #" + l_node.id.out)
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
if fd /= Void and l_preview then
b.append ("<strong>Preview</strong><div class=%"preview%">")
if attached fd.string_item ("format") as s_format and then attached formats.format (s_format) as f_format then
l_format := f_format
end
if attached fd.string_item ("title") as l_title then
b.append ("<strong>Title:</strong><div class=%"title%">" + html_encoded (l_title) + "</div>")
end
if attached fd.string_item ("body") as l_body then
b.append ("<strong>Body:</strong><div class=%"body%">")
if l_format /= Void then
b.append (l_format.to_html (l_body))
else
b.append (html_encoded (l_body))
end
b.append ("</div>")
end
b.append ("</div>")
end
if fd /= Void and then fd.is_valid and not l_preview then
across
fd as c
loop
b.append ("<li>" + html_encoded (c.key) + "=")
if attached c.item as v then
b.append (html_encoded (v.string_representation))
end
b.append ("</li>")
end
l_type.change_node (Current, fd, l_node)
service.storage.save_node (l_node)
if attached user as u then
service.log ("node", "User %"" + user_link (u) + "%" modified node " + link (l_type.name +" #" + l_node.id.out, "/node/" + l_node.id.out , Void), 0, node_local_link (l_node))
else
service.log ("node", "Anonymous modified node "+ l_type.name +" #" + l_node.id.out, 0, node_local_link (l_node))
end
add_success_message ("Node #" + l_node.id.out + " saved.")
set_redirection (node_url (l_node))
else
if fd /= Void then
if not fd.is_valid then
report_form_errors (fd)
end
fd.apply_to_associated_form
end
b.append (f.to_html (theme))
end
else
b.append ("<h1>Access denied</h1>")
end
else
set_title ("Unknown node")
end
else
set_title ("Create new content ...")
b.append ("<ul id=%"content-types%">")
across
service.content_types as c
loop
if has_permission ("create " + c.item.name) then
b.append ("<li>" + link (c.item.name, "/node/add/" + c.item.name, Void))
if attached c.item.description as d then
b.append ("<div class=%"description%">" + d + "</div>")
end
b.append ("</li>")
end
end
b.append ("</ul>")
end
set_main_content (b)
end
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_CONTENT_TYPE): CMS_FORM
local
f: CMS_FORM
ts: CMS_FORM_SUBMIT_INPUT
th: CMS_FORM_HIDDEN_INPUT
do
create f.make (a_url, a_name)
create th.make ("node-id")
if a_node /= Void then
th.set_text_value (a_node.id.out)
else
th.set_text_value ("0")
end
f.extend (th)
a_type.fill_edit_form (f, a_node)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
create ts.make ("op")
ts.set_default_value ("Save")
f.extend (ts)
create ts.make ("op")
ts.set_default_value ("Preview")
f.extend (ts)
Result := f
end
end

View File

@@ -0,0 +1,113 @@
note
description: "Summary description for {NODE_MODULE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
NODE_MODULE
inherit
CMS_MODULE
CMS_HOOK_MENU_ALTER
CMS_HOOK_BLOCK
create
make
feature {NONE} -- Initialization
make (a_service: like service)
do
service := a_service
name := "node"
version := "1.0"
description := "Service to manage content based on 'node'"
package := "core"
enable
end
feature {CMS_SERVICE} -- Registration
service: CMS_SERVICE
register (a_service: CMS_SERVICE)
local
h: CMS_HANDLER
do
a_service.map_uri ("/node/add", agent handle_node_add)
a_service.map_uri_template ("/node/add/{type}", agent handle_node_add)
create {CMS_HANDLER} h.make (agent handle_node_view)
a_service.router.map (create {WSF_URI_TEMPLATE_MAPPING}.make ("/node/{nid}", h))
a_service.router.map (create {WSF_URI_TEMPLATE_MAPPING}.make ("/node/{nid}/view", h))
a_service.map_uri_template ("/node/{nid}/edit", agent handle_node_edit)
a_service.add_content_type (create {CMS_PAGE_CONTENT_TYPE}.make)
a_service.add_menu_alter_hook (Current)
a_service.add_block_hook (Current)
end
feature -- Hooks
block_list: ITERABLE [like {CMS_BLOCK}.name]
do
Result := <<"node-info">>
end
get_block_view (a_block_id: detachable READABLE_STRING_8; a_execution: CMS_EXECUTION)
-- local
-- b: CMS_CONTENT_BLOCK
do
-- if
-- a_execution.is_front and then
-- attached a_execution.user as u
-- then
-- create b.make ("node-info", "Node", "Node ...", a_execution.formats.plain_text)
-- a_execution.add_block (b, Void)
-- end
end
menu_alter (a_menu_system: CMS_MENU_SYSTEM; a_execution: CMS_EXECUTION)
local
lnk: CMS_LOCAL_LINK
do
if a_execution.authenticated then
create lnk.make ("Add content", "/node/add/")
lnk.set_permission_arguments (<<"authenticated">>)
a_menu_system.navigation_menu.extend (lnk)
end
end
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
-- Link indexed by path
local
-- lnk: CMS_MODULE_LINK
do
create Result.make (3)
-- create lnk.make ("Date/time demo")
-- lnk.set_callback (agent process_date_time_demo, <<"arg">>)
-- Result["/demo/date/{arg}"] := lnk
end
handle_node_view (req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {NODE_VIEW_CMS_EXECUTION}.make (req, res, service)).execute
end
handle_node_edit (req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {NODE_EDIT_CMS_EXECUTION}.make (req, res, service)).execute
end
handle_node_add (req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {NODE_ADD_CMS_EXECUTION}.make (req, res, service)).execute
end
end

View File

@@ -0,0 +1,41 @@
note
description: "[
]"
class
NODE_VIEW_CMS_EXECUTION
inherit
CMS_EXECUTION
create
make
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
do
if attached {WSF_STRING} request.path_parameter ("nid") as p_nid and then p_nid.is_integer then
create b.make_empty
if attached storage.node (p_nid.integer_value) as l_node then
set_title ("Node [" + l_node.id.out + "]")
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
b.append (l_node.to_html (theme))
else
set_title ("Node [" + p_nid.value + "] does not exists!")
end
set_main_content (b)
else
set_title ("Node ...")
create b.make_empty
set_main_content (b)
end
end
end