Redesigned hooks system (moving from CMS_RESPONSE to CMS_API).

Indeed, hooks does not require RESPONSE interface,
   and should be setup before, at the system level (i.e CMS_API)
Added exportation solution via CMS_HOOK_EXPORT.
Updated blocks settings for demo example project.
This commit is contained in:
2015-11-09 21:07:02 +01:00
parent 6b3ff6f980
commit 420051cd14
30 changed files with 609 additions and 100 deletions

View File

@@ -16,11 +16,11 @@ inherit
feature -- Hook
auto_subscribe_to_hooks (a_response: CMS_RESPONSE)
auto_subscribe_to_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
local
l_manager: CMS_HOOK_CORE_MANAGER
do
l_manager := a_response.hooks
l_manager := a_hooks
if attached {CMS_HOOK_MENU_SYSTEM_ALTER} Current as h_menu_system_alter then
l_manager.subscribe_to_menu_system_alter_hook (h_menu_system_alter)
end

View File

@@ -223,6 +223,34 @@ feature -- Hook: cache
end
end
feature -- Hook: export
subscribe_to_export_hook (h: CMS_HOOK_EXPORT)
-- Add `h' as subscriber of export hooks CMS_HOOK_EXPORT.
do
subscribe_to_hook (h, {CMS_HOOK_EXPORT})
end
invoke_export_to (a_export_id_list: detachable ITERABLE [READABLE_STRING_GENERAL]; a_export_parameters: CMS_EXPORT_PARAMETERS; a_response: CMS_RESPONSE)
-- Invoke response alter hook for response `a_response'.
local
d: DIRECTORY
do
if attached subscribers ({CMS_HOOK_EXPORT}) as lst then
create d.make_with_path (a_export_parameters.location)
if not d.exists then
d.recursive_create_dir
end
across
lst as ic
loop
if attached {CMS_HOOK_EXPORT} ic.item as h then
h.export_to (a_export_id_list, a_export_parameters, a_response)
end
end
end
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -0,0 +1,35 @@
note
description: "[
Usefull routines to export to JSON.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_EXPORT_JSON_UTILITIES
feature -- Access
put_date_into_json (dt: detachable DATE_TIME; a_key: JSON_STRING; j: JSON_OBJECT)
local
hd: HTTP_DATE
do
if dt /= Void then
create hd.make_from_date_time (dt)
j.put_integer (hd.timestamp, a_key)
end
end
json_to_string (j: JSON_OBJECT): STRING
local
pp: JSON_PRETTY_STRING_VISITOR
do
create Result.make_empty
create pp.make (Result)
j.accept (pp)
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -0,0 +1,43 @@
note
description: "[
Parameters used by CMS_HOOK_EXPORT subscribers.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_EXPORT_PARAMETERS
create
make
feature {NONE} -- Initialization
make (a_location: PATH)
do
location := a_location
create logs.make (10)
end
feature -- Access
location: PATH
-- Location of export folder.
feature -- Logs
logs: ARRAYED_LIST [READABLE_STRING_8]
-- Associated exportation logs.
log (m: READABLE_STRING_8)
-- Add message `m' into `logs'.
do
logs.force (m)
end
invariant
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -0,0 +1,31 @@
note
description: "[
CMS HOOK providing a way to export module data according to specific export parameters.
]"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_HOOK_EXPORT
inherit
CMS_HOOK
feature -- Hook
export_to (a_export_id_list: detachable ITERABLE [READABLE_STRING_GENERAL]; a_export_parameters: CMS_EXPORT_PARAMETERS; a_response: CMS_RESPONSE)
-- Export data identified by `a_export_id_list',
-- or export all data if `a_export_id_list' is Void.
deferred
end
-- export_identifiers: detachable ITERABLE [READABLE_STRING_32]
-- -- Optional list of exportation ids, if any.
-- do
-- -- To redefine if needed.
-- end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -9,7 +9,7 @@ class
inherit
CMS_MODULE
redefine
register_hooks
setup_hooks
end
CMS_HOOK_BLOCK
@@ -47,11 +47,11 @@ feature -- Router
feature -- Hooks configuration
register_hooks (a_response: CMS_RESPONSE)
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
-- Module hooks configuration.
do
auto_subscribe_to_hooks (a_response)
a_response.hooks.subscribe_to_block_hook (Current)
auto_subscribe_to_hooks (a_hooks)
a_hooks.subscribe_to_block_hook (Current)
end
feature -- Hooks

View File

@@ -24,6 +24,7 @@ feature {NONE} -- Initialize
setup := a_setup
create error_handler.make
create {CMS_ENV_LOGGER} logger.make
create hooks.make
initialize
ensure
setup_set: setup = a_setup
@@ -51,6 +52,7 @@ feature {NONE} -- Initialize
l_enabled_modules := setup.enabled_modules
enabled_modules := l_enabled_modules
-- Complete storage setup.
storage.set_api (Current)
@@ -82,6 +84,9 @@ feature {NONE} -- Initialize
l_enabled_modules.remove (ic.item)
end
end
-- Initialize hooks system
setup_hooks
end
initialize_formats
@@ -302,6 +307,32 @@ feature -- Query: module
end
end
feature -- Hooks
hooks: CMS_HOOK_CORE_MANAGER
-- Manager handling hook subscriptions.
feature {NONE} -- Hooks
setup_hooks
local
l_module: CMS_MODULE
l_enabled_modules: CMS_MODULE_COLLECTION
l_hooks: like hooks
do
l_hooks := hooks
l_enabled_modules := enabled_modules
across
l_enabled_modules as ic
loop
l_module := ic.item
if attached {CMS_HOOK_AUTO_REGISTER} l_module as l_auto then
l_auto.auto_subscribe_to_hooks (l_hooks)
end
l_module.setup_hooks (l_hooks)
end
end
feature -- Query: API
user_api: CMS_USER_API

View File

@@ -129,7 +129,7 @@ feature -- Router
feature -- Hooks configuration
register_hooks (a_response: CMS_RESPONSE)
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
-- Module hooks configuration.
require
is_enabled: is_enabled

View File

@@ -33,8 +33,6 @@ feature {NONE} -- Initialization
get_theme
create menu_system.make
initialize_block_region_settings
create hooks.make
register_hooks
end
initialize_site_url
@@ -66,23 +64,6 @@ feature {NONE} -- Initialization
site_url_ends_with_slash: site_url.ends_with_general ("/")
end
register_hooks
local
l_module: CMS_MODULE
l_enabled_modules: CMS_MODULE_COLLECTION
do
l_enabled_modules := api.enabled_modules
across
l_enabled_modules as ic
loop
l_module := ic.item
if attached {CMS_HOOK_AUTO_REGISTER} l_module as l_auto then
l_auto.auto_subscribe_to_hooks (Current)
end
l_module.register_hooks (Current)
end
end
feature -- Access
request: WSF_REQUEST
@@ -868,6 +849,9 @@ feature -- Hooks
hooks: CMS_HOOK_CORE_MANAGER
-- Manager handling hook subscriptions.
do
Result := api.hooks
end
feature -- Menu: change