Added weight into to the CMS_LINK and provide a `sort' feature for CMS_MENU and related.

Protected cms service from registering many time the same module type.
Moved library/persistence/implementation/* under library/persistence/.
Moved site/www/themes to site/themes
For SQLite storage driver, auto create sqlite db file using associated sql script (to be completed).
Added code in demo module to reuse storage for module purpose.
Always call sql_post_execution in sql_query and sql_change, and not anymore by the callers.
Removed is_web and is_html from {CMS_SETUP}, it was not used.
Reused SHARED_*_ENCODER in CMS_ENCODERS
Added CMS_API.logger rather than using directly the SHARED_LOGGER.log ...
Centralize the implementation of current_user in CMS_REQUEST_UTIL
Removed the inheritance on WSF_FILTER for node handlers, since it is useless and unused.
Added CMS_NODE_API and CMS_USER_API
Prefix html id for block generated html items with "block-", to avoid css name conflict on "main", "content" or similar.
Code cleaning
This commit is contained in:
2015-02-16 13:01:06 +01:00
parent a810b1176c
commit 8d59d25ace
165 changed files with 1430 additions and 2206 deletions

View File

@@ -1,7 +1,7 @@
note
description: "API for a CMS"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
class
CMS_API
@@ -11,35 +11,25 @@ inherit
REFACTORING_HELPER
SHARED_HTML_ENCODER
export
{NONE} all
end
SHARED_WSF_PERCENT_ENCODER
export
{NONE} all
end
CMS_ENCODERS
create
make
feature -- Initialize
feature {NONE} -- Initialize
make (a_setup: CMS_SETUP)
-- Create the API service with a setup `a_setup'
do
setup := a_setup
create error_handler.make
create {CMS_ENV_LOGGER} logger.make
initialize
ensure
setup_set: setup = a_setup
error_handler_set: not error_handler.has_error
end
setup: CMS_SETUP
-- CMS setup.
initialize
-- Initialize the persitent layer.
do
@@ -51,7 +41,18 @@ feature -- Initialize
end
end
feature -- Access: Error
feature -- Access
setup: CMS_SETUP
-- CMS setup.
logger: CMS_LOGGER
-- Logger
storage: CMS_STORAGE
-- Persistence storage.
feature -- Status Report
has_error: BOOLEAN
-- Has error?
@@ -59,162 +60,82 @@ feature -- Access: Error
Result := error_handler.has_error
end
as_string_representation: STRING_32
string_representation_of_errors: STRING_32
-- String representation of all error(s).
do
Result := error_handler.as_string_representation
end
feature -- Query: module
module (a_type: TYPE [CMS_MODULE]): detachable CMS_MODULE
-- Enabled module typed `a_type', if any.
--| usage: if attached module ({FOO_MODULE}) as mod then ...
do
across
setup.modules as ic
until
Result /= Void
loop
Result := ic.item
if
not Result.is_enabled
or else Result.generating_type /~ a_type
then
Result := Void
end
end
end
module_by_name (a_name: READABLE_STRING_GENERAL): detachable CMS_MODULE
-- Enabled module named `a_name', if any.
do
across
setup.modules as ic
until
Result /= Void
loop
Result := ic.item
if
not Result.is_enabled
or else not Result.name.is_case_insensitive_equal_general (a_name)
then
Result := Void
end
end
ensure
Result /= Void implies Result.name.is_case_insensitive_equal_general (a_name)
end
feature -- Query: API
user_api: CMS_USER_API
local
l_api: like internal_user_api
do
l_api := internal_user_api
if l_api = Void then
create l_api.make (Current)
internal_user_api := l_api
end
Result := l_api
end
feature -- Element Change: Error
reset
reset_error
-- Reset error handler.
do
error_handler.reset
end
feature {NONE}-- Error handler implemenations
feature {NONE}-- Implemenation
error_handler: ERROR_HANDLER
-- Error handler.
feature -- Status Report
is_valid_credential (a_auth_login, a_auth_password: READABLE_STRING_32): BOOLEAN
-- Is the credentials `a_auth_login' and `a_auth_password' valid?
do
Result := storage.is_valid_credential (a_auth_login, a_auth_password)
end
feature -- Access: Node
nodes_count: INTEGER_64
do
Result := storage.nodes_count
end
nodes: LIST [CMS_NODE]
-- List of nodes.
do
Result := storage.nodes
end
recent_nodes (a_offset, a_rows: INTEGER): LIST [CMS_NODE]
-- List of the `a_rows' most recent nodes starting from `a_offset'.
do
Result := storage.recent_nodes (a_offset, a_rows)
end
node (a_id: INTEGER_64): detachable CMS_NODE
-- Node by ID.
do
debug ("refactor_fixme")
fixme ("Check preconditions")
end
Result := storage.node_by_id (a_id)
end
feature -- Change: Node
new_node (a_node: CMS_NODE)
-- Add a new node `a_node'
require
no_id: not a_node.has_id
do
storage.new_node (a_node)
end
delete_node (a_node: CMS_NODE)
-- Delete `a_node'.
do
if a_node.has_id then
storage.delete_node (a_node)
end
end
update_node (a_node: CMS_NODE)
-- Update node `a_node' data.
do
storage.update_node (a_node)
end
update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- Update node title, with user identified by `a_id', with node id `a_node_id' and a new title `a_title'.
do
debug ("refactor_fixme")
fixme ("Check preconditions")
end
storage.update_node_title (a_user_id, a_node_id, a_title)
end
update_node_summary (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- Update node summary, with user identified by `a_user_id', with node id `a_node_id' and a new summary `a_summary'.
do
debug ("refactor_fixme")
fixme ("Check preconditions")
end
storage.update_node_summary (a_user_id, a_node_id, a_summary)
end
update_node_content (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- Update node content, with user identified by `a_user_id', with node id `a_node_id' and a new content `a_content'.
do
debug ("refactor_fixme")
fixme ("Check preconditions")
end
storage.update_node_content (a_user_id, a_node_id, a_content)
end
feature -- Access: User
user_by_name (a_username: READABLE_STRING_32): detachable CMS_USER
-- User by name `a_user_name', if any.
do
Result := storage.user_by_name (a_username)
end
feature -- Change User
new_user (a_user: CMS_USER)
-- Add a new user `a_user'.
require
no_id: not a_user.has_id
no_hashed_password: a_user.hashed_password = Void
do
if
attached a_user.password as l_password and then
attached a_user.email as l_email
then
storage.new_user (a_user)
else
debug ("refactor_fixme")
fixme ("Add error")
end
end
end
update_user (a_user: CMS_USER)
-- Update user `a_user'.
require
has_id: a_user.has_id
do
storage.update_user (a_user)
end
feature -- Helpers
html_encoded (a_string: READABLE_STRING_GENERAL): STRING_8
-- `a_string' encoded for html output.
do
Result := html_encoder.general_encoded_string (a_string)
end
percent_encoded (a_string: READABLE_STRING_GENERAL): STRING_8
-- `a_string' encoded with percent encoding, mainly used for url.
do
Result := percent_encoder.percent_encoded_string (a_string)
end
internal_user_api: detachable like user_api
-- Cached value for `user_api'.
feature -- Layout
@@ -249,10 +170,5 @@ feature -- Layout
end
end
feature {NONE} -- Implemenataion
storage: CMS_STORAGE
-- Persistence storage.
end

View File

@@ -0,0 +1,26 @@
note
description: "Summary description for {CMS_MODULE_API}."
author: ""
date: "$Date: 2015-02-13 14:54:27 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96620 $"
deferred class
CMS_MODULE_API
feature {NONE} -- Implementation
make (a_api: CMS_API)
do
api := a_api
end
feature {CMS_MODULE, CMS_API} -- Restricted access
api: CMS_API
storage: CMS_STORAGE
do
Result := api.storage
end
end

View File

@@ -97,7 +97,7 @@ feature -- Settings: router
l_api: like api
l_router: like router
do
log.write_debug (generator + ".setup_router")
api.logger.put_debug (generator + ".setup_router", Void)
-- Configure root of api handler.
l_router := router
@@ -120,7 +120,7 @@ feature -- Settings: router
l_root_handler: CMS_ROOT_HANDLER
l_methods: WSF_REQUEST_METHODS
do
log.write_debug (generator + ".configure_api_root")
api.logger.put_debug (generator + ".configure_api_root", Void)
create l_root_handler.make (api)
create l_methods
l_methods.enable_get
@@ -133,7 +133,7 @@ feature -- Settings: router
local
fhdl: WSF_FILE_SYSTEM_HANDLER
do
log.write_debug (generator + ".configure_api_file_handler")
api.logger.put_information (generator + ".configure_api_file_handler", Void)
create fhdl.make_hidden_with_path (setup.theme_assets_location)
fhdl.disable_index
@@ -172,7 +172,7 @@ feature -- Filters
l_module: CMS_MODULE
l_api: like api
do
log.write_debug (generator + ".create_filter")
api.logger.put_debug (generator + ".create_filter", Void)
l_filter := Void
-- Maintenance
@@ -211,7 +211,7 @@ feature -- Filters
local
f: WSF_FILTER
do
log.write_debug (generator + ".setup_filter")
api.logger.put_debug (generator + ".setup_filter", Void)
from
f := filter

View File

@@ -1,7 +1,7 @@
note
description: "Summary description for {CMS_ERROR_FILTER}."
date: "$Date: 2014-12-19 14:17:32 +0100 (ven., 19 déc. 2014) $"
revision: "$Revision: 96402 $"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
class
CMS_ERROR_FILTER
@@ -22,18 +22,18 @@ feature -- Basic operations
do
fixme ("Check if it's ok to add new fetures CMS_API.has_error:BOOLEAN and CMS_API.error_description.")
if not api.has_error then
log.write_information (generator + ".execute with req: " + req.debug_output)
api.logger.put_information (generator + ".execute with req: " + req.debug_output, Void)
if attached req.raw_header_data as l_header_data then
log.write_debug (generator + ".execute with req header: " + l_header_data)
api.logger.put_debug (generator + ".execute with req header: " + l_header_data, Void)
end
if attached req.raw_input_data as l_input_data then
log.write_debug (generator + ".execute with req input: " + l_input_data)
api.logger.put_debug (generator + ".execute with req input: " + l_input_data, Void)
end
execute_next (req, res)
else
log.write_critical (generator + ".execute" + api.as_string_representation )
api.logger.put_critical (generator + ".execute" + api.string_representation_of_errors, Void)
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
api.reset
api.reset_error
end
end

View File

@@ -1,36 +1,27 @@
note
description: "Summary description for {CMS_HANDLER}."
author: ""
date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
deferred class
CMS_HANDLER
inherit
WSF_HANDLER
CMS_REQUEST_UTIL
SHARED_LOGGER
REFACTORING_HELPER
feature {NONE} -- Initialization
make (a_api: CMS_API)
-- Initialize Current handler with `a_api'.
do
api := a_api
end
feature -- Setup
setup: CMS_SETUP
do
Result := api.setup
end
feature -- API Service
api: CMS_API

View File

@@ -0,0 +1,27 @@
note
description: "Summary description for {CMS_MODULE_HANDLER}."
author: ""
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
deferred class
CMS_MODULE_HANDLER [G -> CMS_MODULE_API]
inherit
CMS_HANDLER
rename
make as cms_make
end
feature {NONE} -- Initialization
make (a_api: CMS_API; a_module_api: G)
do
cms_make (a_api)
module_api := a_module_api
end
module_api: G
-- Node api
end

View File

@@ -1,20 +1,16 @@
note
description: "Summary description for {CMS_ROOT_HANDLER}."
date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
class
CMS_ROOT_HANDLER
inherit
CMS_HANDLER
WSF_FILTER
WSF_URI_HANDLER
rename
execute as uri_execute,
new_mapping as new_uri_mapping
end
@@ -32,13 +28,6 @@ feature -- execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
execute_next (req, res)
end
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end

View File

@@ -0,0 +1,60 @@
note
description : "Objects that ..."
author : "$Author: jfiat $"
date : "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision : "$Revision: 96616 $"
class
CMS_ENV_LOGGER
inherit
CMS_LOGGER
SHARED_LOGGER
rename
log as log_facility
end
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
end
feature -- Logging
put_information (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
log_facility.write_information (log_message (a_message, a_data))
end
put_error (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
log_facility.write_error (log_message (a_message, a_data))
end
put_warning (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
log_facility.write_warning (log_message (a_message, a_data))
end
put_critical (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
log_facility.write_critical (log_message (a_message, a_data))
end
put_alert (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
log_facility.write_alert (log_message (a_message, a_data))
end
put_debug (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
log_facility.write_debug (log_message (a_message, a_data))
end
end

View File

@@ -0,0 +1,55 @@
note
description : "Objects that ..."
author : "$Author: jfiat $"
date : "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision : "$Revision: 96616 $"
deferred class
CMS_LOGGER
feature -- Logging
put_information (a_message: READABLE_STRING_8; a_data: detachable ANY)
deferred
end
put_error (a_message: READABLE_STRING_8; a_data: detachable ANY)
deferred
end
put_warning (a_message: READABLE_STRING_8; a_data: detachable ANY)
deferred
end
put_critical (a_message: READABLE_STRING_8; a_data: detachable ANY)
deferred
end
put_alert (a_message: READABLE_STRING_8; a_data: detachable ANY)
deferred
end
put_debug (a_message: READABLE_STRING_8; a_data: detachable ANY)
deferred
end
feature {NONE} -- Logging
log_message (a_message: READABLE_STRING_8; a_data: detachable ANY): STRING
do
create Result.make (a_message.count)
if attached {CMS_MODULE} a_data as a_module then
Result.append_character ('[')
Result.append (a_module.name)
Result.append_character (']')
Result.append_character (' ')
elseif attached {TYPE [detachable ANY]} a_data as a_type then
Result.append_character ('{')
Result.append (a_type.out)
Result.append_character ('}')
Result.append_character (' ')
end
Result.append (a_message)
end
end

View File

@@ -0,0 +1,39 @@
note
description : "Objects that ..."
author : "$Author: jfiat $"
date : "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision : "$Revision: 96616 $"
class
CMS_NULL_LOGGER
inherit
CMS_LOGGER
feature -- Logging
put_information (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
end
put_error (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
end
put_warning (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
end
put_critical (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
end
put_alert (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
end
put_debug (a_message: READABLE_STRING_8; a_data: detachable ANY)
do
end
end

View File

@@ -1,14 +1,13 @@
note
description: "Summary description for {CMS_REQUEST_UTIL}."
author: ""
date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
deferred class
CMS_REQUEST_UTIL
inherit
CMS_ENCODERS
REFACTORING_HELPER
@@ -30,11 +29,25 @@ feature -- User
note
EIS: "eiffel:?class=AUTHENTICATION_FILTER&feature=execute"
do
if attached {CMS_USER} req.execution_variable ("user") as l_user then
if attached {CMS_USER} req.execution_variable ("_cms_active_user_") as l_user then
Result := l_user
end
end
feature -- Change
set_current_user (req: WSF_REQUEST; a_user: detachable CMS_USER)
-- Set `a_user' as `current_user'.
do
if a_user = Void then
req.unset_execution_variable ("_cms_active_user_")
else
req.set_execution_variable ("_cms_active_user_", a_user)
end
ensure
user_set: current_user (req) ~ a_user
end
feature -- Media Type
current_media_type (req: WSF_REQUEST): detachable READABLE_STRING_32

View File

@@ -1,8 +1,8 @@
note
description: "Summary description for {CMS_URL_UTILITIES}."
author: ""
date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
deferred class
CMS_URL_UTILITIES

View File

@@ -1,7 +1,7 @@
note
description: "Generic CMS Response.It builds the content to get process to render the output"
date: "$Date: 2014-12-15 21:43:38 +0100 (lun., 15 déc. 2014) $"
revision: "$Revision: 96346 $"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
deferred class
CMS_RESPONSE
@@ -357,7 +357,6 @@ feature -- Blocks regions
end
end
feature -- Blocks
add_block (b: CMS_BLOCK; a_default_region: detachable READABLE_STRING_8)
@@ -369,7 +368,6 @@ feature -- Blocks
l_region.extend (b)
end
get_blocks
do
debug ("refactor_fixme")
@@ -754,9 +752,13 @@ feature -- Element Change
feature -- Generation
prepare (page: CMS_HTML_PAGE)
local
lnk: CMS_LINK
do
-- Menu
add_to_primary_menu (create {CMS_LOCAL_LINK}.make ("Home", "/"))
create {CMS_LOCAL_LINK} lnk.make ("Home", "/")
lnk.set_weight (-10)
add_to_primary_menu (lnk)
invoke_menu_system_alter (menu_system)
prepare_menu_system (menu_system)
@@ -774,6 +776,11 @@ feature -- Generation
end
end
-- Sort items
across menu_system as ic loop
ic.item.sort
end
-- Values
common_prepare (page)
custom_prepare (page)
@@ -843,10 +850,6 @@ feature -- Generation
page.register_variable (title, "site_title")
page.set_is_front (is_front)
-- Variables/Setup
page.register_variable (setup.is_web, "web")
page.register_variable (setup.is_html, "html")
-- Variables/Misc
-- FIXME: logo .. could be a settings of theme, managed by admin front-end/database.

View File

@@ -0,0 +1,62 @@
note
description: "Summary description for {CMS_USER_API}."
author: ""
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
class
CMS_USER_API
inherit
CMS_MODULE_API
REFACTORING_HELPER
create
make
feature -- Access
user_by_name (a_username: READABLE_STRING_32): detachable CMS_USER
-- User by name `a_user_name', if any.
do
Result := storage.user_by_name (a_username)
end
feature -- Status report
is_valid_credential (a_auth_login, a_auth_password: READABLE_STRING_32): BOOLEAN
-- Is the credentials `a_auth_login' and `a_auth_password' valid?
do
Result := storage.is_valid_credential (a_auth_login, a_auth_password)
end
feature -- Change User
new_user (a_user: CMS_USER)
-- Add a new user `a_user'.
require
no_id: not a_user.has_id
no_hashed_password: a_user.hashed_password = Void
do
if
attached a_user.password as l_password and then
attached a_user.email as l_email
then
storage.new_user (a_user)
else
debug ("refactor_fixme")
fixme ("Add error")
end
end
end
update_user (a_user: CMS_USER)
-- Update user `a_user'.
require
has_id: a_user.has_id
do
storage.update_user (a_user)
end
end