Added cms_smarty_template_block

Added CMS_RESPONSE.module_assets_location and CMS_RESPONSE.module_assets_theme_location
    that help locating module related assets.
Added CMS_BLOCK.is_raw to abstract CMS_CONTENT_BLOCK.is_raw
This commit is contained in:
2014-11-14 19:31:40 +01:00
parent 6aad460b11
commit 8bfb66af30
6 changed files with 242 additions and 19 deletions

View File

@@ -8,20 +8,30 @@ deferred class
feature -- Access
name: READABLE_STRING_8
-- Name identifying Current block.
deferred
end
title: detachable READABLE_STRING_32
-- Optional title.
deferred
end
feature -- status report
is_enabled: BOOLEAN
-- Is current block enabled?
is_raw: BOOLEAN
-- Is raw?
-- If True, do not get wrapped it with block specific div
deferred
end
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
-- HTML representation of Current block.
deferred
end

View File

@@ -17,6 +17,8 @@ create
feature {NONE} -- Initialization
make (a_name: like name; a_title: like title; a_content: like content; a_format: like format)
require
a_name_not_blank: not a_name.is_whitespace
do
is_enabled := True
name := a_name
@@ -26,6 +28,8 @@ feature {NONE} -- Initialization
end
make_raw (a_name: like name; a_title: like title; a_content: like content; a_format: like format)
require
a_name_not_blank: not a_name.is_whitespace
do
make (a_name, a_title, a_content, a_format)
set_is_raw (True)
@@ -54,6 +58,20 @@ feature -- Element change
is_raw := b
end
set_name (n: like name)
-- Set `name' to `n'.
require
not n.is_whitespace
do
name := n
end
set_title (a_title: like title)
-- Set `title' to `a_title'.
do
title := a_title
end
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8

View File

@@ -29,8 +29,29 @@ feature -- Access
title: detachable READABLE_STRING_32
feature -- Status report
is_horizontal: BOOLEAN
is_raw: BOOLEAN = False
-- <Precursor>
feature -- Element change
set_name (n: like name)
-- Set `name' to `n'.
require
not n.is_whitespace
do
name := n
end
set_title (a_title: like title)
-- Set `title' to `a_title'.
do
title := a_title
end
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8

View File

@@ -0,0 +1,148 @@
note
description: "[
CMS block with smarty template file content.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_SMARTY_TEMPLATE_BLOCK
inherit
CMS_BLOCK
SHARED_TEMPLATE_CONTEXT
create
make,
make_raw
feature {NONE} -- Initialization
make (a_name: like name; a_title: like title; a_template_root_path: PATH; a_template_location: PATH)
-- Create Current with `a_name', `a_title', `a_template_location'
-- inside root directory `a_template_root_path' for the templates.
require
a_name_not_blank: not a_name.is_whitespace
do
is_enabled := True
name := a_name
title := a_title
location := a_template_location
template_root_path := a_template_root_path
create values.make (0)
end
make_raw (a_name: like name; a_title: like title; a_template_root_path: PATH; a_template_location: PATH)
-- Create Current with `a_name', `a_title', `a_template_location'
-- inside root directory `a_template_root_path' for the templates.
require
a_name_not_blank: not a_name.is_whitespace
do
make (a_name, a_title, a_template_root_path, a_template_location)
set_is_raw (True)
end
feature -- Access
name: READABLE_STRING_8
-- <Precursor>
title: detachable READABLE_STRING_32
-- <Precursor>
location: PATH
-- Location of template file.
template_root_path: PATH
-- Root location for templates universe.
values: STRING_TABLE [detachable ANY]
-- Additional value used during template output processing.
feature -- Status report
is_raw: BOOLEAN
-- Is raw?
-- If True, do not get wrapped it with block specific div
feature -- Element change
set_is_raw (b: BOOLEAN)
do
is_raw := b
end
set_name (n: like name)
-- Set `name' to `n'.
require
not n.is_whitespace
do
name := n
end
set_title (a_title: like title)
-- Set `title' to `a_title'.
do
title := a_title
end
set_value (v: detachable ANY; k: READABLE_STRING_GENERAL)
-- Associate value `v' with key `k'.
do
values.force (v, k)
end
unset_value (k: READABLE_STRING_GENERAL)
-- Remove value indexed by key `k'.
do
values.remove (k)
end
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
-- <Precursor>
local
p: detachable PATH
tpl: detachable TEMPLATE_FILE
ut: FILE_UTILITIES
n: STRING_32
do
-- Process html generation
p := location
if ut.file_path_exists (template_root_path.extended_path (p)) then
n := p.name
template_context.set_template_folder (template_root_path)
template_context.disable_verbose
debug ("cms")
template_context.enable_verbose
end
create tpl.make_from_file (n)
across
values as ic
loop
tpl.add_value (ic.item, ic.key)
end
tpl.analyze
tpl.get_output
if attached tpl.output as l_output then
Result := l_output
else
Result := ""
debug ("cms")
Result := "Template block #" + name
end
end
else
Result := ""
debug ("cms")
Result := "Template block #" + name
end
end
end
end

View File

@@ -81,6 +81,37 @@ feature -- Access
additional_page_head_lines: detachable LIST [READABLE_STRING_8]
-- HTML>head>...extra lines
feature -- Module
module_resource_path (a_module: CMS_MODULE; a_resource: PATH): detachable PATH
-- Resource path of `a_resource' for module `a_module', if resource exists.
local
rp: PATH
ut: FILE_UTILITIES
do
rp := module_assets_theme_location (a_module)
Result := rp.extended_path (a_resource)
if not ut.file_path_exists (Result) then
rp := module_assets_location (a_module)
Result := rp.extended_path (a_resource)
if not ut.file_path_exists (Result) then
Result := Void
end
end
end
module_assets_location (a_module: CMS_MODULE): PATH
-- Location for the assets associated with `a_module'.
do
Result := setup.layout.path.extended ("modules").extended (a_module.name)
end
module_assets_theme_location (a_module: CMS_MODULE): PATH
-- Location for the assets associated with `a_module'.
do
Result := setup.theme_location.extended ("modules").extended (a_module.name)
end
feature -- URL utilities
is_front: BOOLEAN
@@ -372,11 +403,10 @@ feature -- Blocks
add_block (l_block, "first_sidebar")
end
if attached footer_block as l_block then
add_block (l_block, "footer")
end
invoke_block
debug ("cms")
add_block (create {CMS_CONTENT_BLOCK}.make ("made_with", Void, "Made with <a href=%"http://www.eiffel.com/%">EWF</a>", Void), "footer")
end
end
primary_menu_block: detachable CMS_MENU_BLOCK
@@ -473,18 +503,6 @@ feature -- Blocks
Result.set_is_raw (True)
end
made_with_html: STRING
do
create Result.make_empty
Result.append ("Made with <a href=%"http://www.eiffel.com/%">EWF</a>")
end
footer_block: CMS_CONTENT_BLOCK
do
create Result.make ("made_with", Void, made_with_html, Void)
end
feature -- Hooks
hook_subscribers: HASH_TABLE [LIST [CMS_HOOK], TYPE [CMS_HOOK]]
@@ -786,6 +804,13 @@ feature -- Generation
across
reg_ic.item.blocks as ic
loop
-- if attached {CMS_SMARTY_CONTENT_BLOCK} ic.item as l_tpl_block then
-- across
-- page.variables as var_ic
-- loop
-- l_tpl_block.set_value (var_ic.item, var_ic.key)
-- end
-- end
page.add_to_region (theme.block_html (ic.item), reg_ic.item.name)
end
end

View File

@@ -62,12 +62,12 @@ feature -- Conversion
debug ("refactor_fixme")
fixme ("Refactor HTML code to use the new Bootstrap theme template")
end
if attached {CMS_CONTENT_BLOCK} a_block as l_content_block and then l_content_block.is_raw then
if attached a_block.is_raw then
create s.make_empty
if attached l_content_block.title as l_title then
if attached a_block.title as l_title then
s.append ("<div class=%"title%">" + html_encoded (l_title) + "</div>")
end
s.append (l_content_block.to_html (Current))
s.append (a_block.to_html (Current))
else
create s.make_from_string ("<div class=%"block%" id=%"" + a_block.name + "%">")
if attached a_block.title as l_title then
@@ -80,6 +80,7 @@ feature -- Conversion
end
Result := s
end
page_html (page: CMS_HTML_PAGE): STRING_8
-- Render `page' as html.
deferred