Updated CMS_HOOK_BLOCK, to provide a better block_identifiers (CMS_RESPONSE): detachable ITERABLE [READABLE_STRING_8] query, to be implemented by CMS_HOOK_RESPONSE_BLOCK descendants.
Added CONFIG_READER.table_keys: detachable LIST [READABLE_STRING_32].
This commit is contained in:
165
modules/custom_block/cms_custom_block_module.e
Normal file
165
modules/custom_block/cms_custom_block_module.e
Normal file
@@ -0,0 +1,165 @@
|
||||
note
|
||||
description: "[
|
||||
Module that provide custom block factory.
|
||||
]"
|
||||
author: "$Author: jfiat $"
|
||||
date: "$Date: 2016-01-08 22:43:12 +0100 (ven., 08 janv. 2016) $"
|
||||
revision: "$Revision: 98369 $"
|
||||
|
||||
class
|
||||
CMS_CUSTOM_BLOCK_MODULE
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
rename
|
||||
module_api as custom_block_api
|
||||
redefine
|
||||
initialize,
|
||||
setup_hooks,
|
||||
custom_block_api
|
||||
end
|
||||
|
||||
CMS_HOOK_RESPONSE_BLOCK
|
||||
|
||||
CMS_HOOK_BLOCK_HELPER
|
||||
|
||||
CMS_HOOK_AUTO_REGISTER
|
||||
|
||||
SHARED_EXECUTION_ENVIRONMENT
|
||||
export
|
||||
{NONE} all
|
||||
end
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Create current module
|
||||
do
|
||||
version := "1.0"
|
||||
description := "Custom Block"
|
||||
package := "layout"
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING = "custom_block"
|
||||
-- <Precursor>
|
||||
|
||||
feature {CMS_API} -- Module Initialization
|
||||
|
||||
initialize (api: CMS_API)
|
||||
-- Initialize Current module with `api'.
|
||||
do
|
||||
create custom_block_api.make (api)
|
||||
Precursor (api)
|
||||
end
|
||||
|
||||
custom_block_api: detachable CMS_MODULE_API
|
||||
-- <Precursor>.
|
||||
|
||||
feature -- Router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- Router configuration.
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Hooks configuration
|
||||
|
||||
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
||||
-- Module hooks configuration.
|
||||
do
|
||||
auto_subscribe_to_hooks (a_hooks)
|
||||
a_hooks.subscribe_to_block_hook (Current)
|
||||
end
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
block_identifiers (a_response: detachable CMS_RESPONSE): detachable ARRAYED_LIST [READABLE_STRING_8]
|
||||
-- <Precursor>
|
||||
local
|
||||
api: CMS_API
|
||||
l_name: READABLE_STRING_32
|
||||
l_block_id: READABLE_STRING_8
|
||||
l_conds: detachable ARRAYED_LIST [CMS_BLOCK_CONDITION]
|
||||
do
|
||||
if attached custom_block_api as l_mod_api then
|
||||
api := l_mod_api.cms_api
|
||||
if
|
||||
attached api.module_configuration (Current, name) as cfg and then
|
||||
attached cfg.table_keys ("blocks") as lst
|
||||
then
|
||||
create Result.make (0)
|
||||
across
|
||||
lst as ic
|
||||
loop
|
||||
l_name := ic.item
|
||||
if l_name.is_valid_as_string_8 then
|
||||
l_block_id := l_name.to_string_8
|
||||
if a_response /= Void then
|
||||
if attached cfg.text_list_item ("blocks." + l_block_id + ".conditions") as l_cond_expressions then
|
||||
if l_conds = Void then
|
||||
create l_conds.make (l_cond_expressions.count)
|
||||
end
|
||||
across
|
||||
l_cond_expressions as exp_ic
|
||||
loop
|
||||
l_conds.force (create {CMS_BLOCK_EXPRESSION_CONDITION}.make (exp_ic.item))
|
||||
end
|
||||
end
|
||||
if l_conds = Void or else l_conds.is_empty then
|
||||
Result.force ("?" + l_block_id)
|
||||
elseif are_conditions_satisfied (l_conds, a_response) then
|
||||
Result.force (l_block_id)
|
||||
end
|
||||
else
|
||||
Result.force ("?" + l_block_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
are_conditions_satisfied (a_conditions: LIST [CMS_BLOCK_CONDITION]; a_response: CMS_RESPONSE): BOOLEAN
|
||||
-- Are `a_conditions' satisfied for `a_response'?
|
||||
do
|
||||
Result := across a_conditions as ic some ic.item.satisfied_for_response (a_response) end
|
||||
end
|
||||
|
||||
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||
local
|
||||
l_region: detachable READABLE_STRING_8
|
||||
l_cond: CMS_BLOCK_EXPRESSION_CONDITION
|
||||
do
|
||||
if attached smarty_template_block (Current, a_block_id, a_response.api) as bk then
|
||||
if attached a_response.api.module_configuration (Current, name) as cfg then
|
||||
if
|
||||
attached cfg.text_item ("blocks." + a_block_id + ".region") as s and then
|
||||
s.is_valid_as_string_8
|
||||
then
|
||||
l_region := s.to_string_8
|
||||
end
|
||||
bk.set_weight (cfg.integer_item ("blocks." + a_block_id + ".weight"))
|
||||
bk.set_title (cfg.text_item ("blocks." + a_block_id + ".title"))
|
||||
if attached cfg.text_list_item ("blocks." + a_block_id + ".conditions") as l_cond_exp_list then
|
||||
across
|
||||
l_cond_exp_list as ic
|
||||
loop
|
||||
create l_cond.make (ic.item)
|
||||
bk.add_condition (l_cond)
|
||||
end
|
||||
end
|
||||
end
|
||||
a_response.add_block (bk, l_region)
|
||||
else
|
||||
a_response.add_debug_message ("Missing template for custom block %"" + a_block_id + "%"!")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
21
modules/custom_block/custom_block-safe.ecf
Normal file
21
modules/custom_block/custom_block-safe.ecf
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="custom_block_module" uuid="F9B7C390-04F2-4E59-9040-00DD68A5BDBC" library_target="custom_block_module">
|
||||
<target name="custom_block_module">
|
||||
<root all_classes="true" />
|
||||
<file_rule>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="cms" location="..\..\cms-safe.ecf"/>
|
||||
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf"/>
|
||||
<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"/>
|
||||
<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_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
|
||||
<cluster name="src" location=".\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
22
modules/custom_block/custom_block.ecf
Normal file
22
modules/custom_block/custom_block.ecf
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="custom_block_module" uuid="F9B7C390-04F2-4E59-9040-00DD68A5BDBC" library_target="custom_block_module">
|
||||
<target name="custom_block_module">
|
||||
<root all_classes="true"/>
|
||||
<file_rule>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" full_class_checking="true" void_safety="none" syntax="standard">
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="cms" location="..\..\cms.ecf"/>
|
||||
<library name="cms_model" location="..\..\library\model\cms_model.ecf"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
|
||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf.ecf"/>
|
||||
<library name="wsf_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder.ecf"/>
|
||||
<cluster name="src" location=".\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
10
modules/custom_block/site/config/custom_block.json.example
Normal file
10
modules/custom_block/site/config/custom_block.json.example
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"blocks": {
|
||||
"test": {
|
||||
"title": "Custom block test",
|
||||
"region": "footer",
|
||||
"weight": 100,
|
||||
"conditions": ["path:demo/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<div>
|
||||
This is a nice custom block test for site {$sitename/}.
|
||||
</div>
|
||||
Reference in New Issue
Block a user