Added a CMS_ENCODER utility class.
Added a block header template: smarty engine. Added a menu template: smarty engine.
This commit is contained in:
35
cms/src/kernel/content/cms_encoders.e
Normal file
35
cms/src/kernel/content/cms_encoders.e
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {CMS_ENCODERS}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
CMS_ENCODERS
|
||||||
|
|
||||||
|
feature -- Encoders
|
||||||
|
|
||||||
|
url_encoded (s: detachable READABLE_STRING_GENERAL): STRING_8
|
||||||
|
local
|
||||||
|
enc: URL_ENCODER
|
||||||
|
do
|
||||||
|
create enc
|
||||||
|
if s /= Void then
|
||||||
|
Result := enc.general_encoded_string (s)
|
||||||
|
else
|
||||||
|
create Result.make_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
html_encoded (s: detachable READABLE_STRING_GENERAL): STRING_8
|
||||||
|
local
|
||||||
|
enc: HTML_ENCODER
|
||||||
|
do
|
||||||
|
create enc
|
||||||
|
if s /= Void then
|
||||||
|
Result := enc.general_encoded_string (s)
|
||||||
|
else
|
||||||
|
create Result.make_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -152,8 +152,8 @@ feature -- Hooks
|
|||||||
lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
perms: detachable ARRAYED_LIST [READABLE_STRING_8]
|
perms: detachable ARRAYED_LIST [READABLE_STRING_8]
|
||||||
do
|
do
|
||||||
create lnk.make ("node", "/node")
|
create lnk.make ("List of nodes", "/nodes")
|
||||||
a_menu_system.navigation_menu.extend (lnk)
|
a_menu_system.main_menu.extend (lnk)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ deferred class
|
|||||||
CMS_RESPONSE
|
CMS_RESPONSE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
CMS_ENCODERS
|
||||||
|
|
||||||
CMS_REQUEST_UTIL
|
CMS_REQUEST_UTIL
|
||||||
|
|
||||||
@@ -139,9 +140,10 @@ feature -- Blocks initialization
|
|||||||
local
|
local
|
||||||
l_table: like block_region_settings
|
l_table: like block_region_settings
|
||||||
do
|
do
|
||||||
|
fixme ("CHECK:Can we use the same structure as in theme.info?")
|
||||||
create regions.make_caseless (5)
|
create regions.make_caseless (5)
|
||||||
|
|
||||||
-- FIXME: let the user choose ...
|
fixme ("let the user choose ...")
|
||||||
create l_table.make_caseless (10)
|
create l_table.make_caseless (10)
|
||||||
l_table["top"] := "top"
|
l_table["top"] := "top"
|
||||||
l_table["header"] := "header"
|
l_table["header"] := "header"
|
||||||
@@ -202,7 +204,7 @@ feature -- Blocks
|
|||||||
get_blocks
|
get_blocks
|
||||||
do
|
do
|
||||||
fixme ("find a way to have this in configuration or database, and allow different order")
|
fixme ("find a way to have this in configuration or database, and allow different order")
|
||||||
add_block (top_header_block, "header")
|
add_block (top_header_block, "top")
|
||||||
add_block (header_block, "header")
|
add_block (header_block, "header")
|
||||||
if attached message_block as m then
|
if attached message_block as m then
|
||||||
add_block (m, "content")
|
add_block (m, "content")
|
||||||
@@ -275,22 +277,46 @@ feature -- Blocks
|
|||||||
local
|
local
|
||||||
s: STRING
|
s: STRING
|
||||||
do
|
do
|
||||||
fixme ("Avoid Hardcoded HTML!!!")
|
|
||||||
-- create s.make_from_string ("<a href=%""+ url ("/", Void) +"%"><img id=%"logo%" src=%"" + logo_location + "%"/></a><div id=%"title%">" + html_encoded (site_name) + "</div>")
|
|
||||||
create s.make_empty
|
create s.make_empty
|
||||||
s.append ("<div id=%"menu-bar%">")
|
create Result.make ("page_top", Void, s, formats.full_html)
|
||||||
s.append (theme.menu_html (main_menu, True))
|
|
||||||
s.append ("</div>")
|
|
||||||
create Result.make ("header", Void, s, formats.full_html)
|
|
||||||
Result.set_is_raw (True)
|
Result.set_is_raw (True)
|
||||||
end
|
end
|
||||||
|
|
||||||
header_block: CMS_CONTENT_BLOCK
|
header_block: CMS_CONTENT_BLOCK
|
||||||
local
|
local
|
||||||
s: STRING
|
s: STRING
|
||||||
|
tpl: SMARTY_CMS_PAGE_TEMPLATE
|
||||||
|
l_page: CMS_HTML_PAGE
|
||||||
|
l_hb: STRING
|
||||||
do
|
do
|
||||||
create s.make_empty
|
create s.make_from_string (theme.menu_html (main_menu, True))
|
||||||
create Result.make ("header", Void, s, formats.full_html)
|
create l_hb.make_empty
|
||||||
|
to_implement ("Check if the tpl does not exist, provide a default implementation")
|
||||||
|
if attached {SMARTY_CMS_THEME} theme as l_theme then
|
||||||
|
create tpl.make ("block/header_test", l_theme)
|
||||||
|
-- Change to "block/header_block" to use the template code.
|
||||||
|
create l_page.make
|
||||||
|
l_page.register_variable (s, "header_block")
|
||||||
|
tpl.prepare (l_page)
|
||||||
|
l_hb := tpl.to_html (l_page)
|
||||||
|
end
|
||||||
|
if l_hb.starts_with ("ERROR") then
|
||||||
|
l_hb.wipe_out
|
||||||
|
to_implement ("Hardcoded HTML with CSS, find a better way to define defaults!!!.")
|
||||||
|
l_hb := "[
|
||||||
|
<div class='navbar navbar-inverse'>
|
||||||
|
<div class='navbar-inner nav-collapse' style='height: auto;'>
|
||||||
|
<ul class='nav'>
|
||||||
|
]"
|
||||||
|
l_hb.append (s)
|
||||||
|
l_hb.append ("[
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
]")
|
||||||
|
|
||||||
|
end
|
||||||
|
create Result.make ("header", Void, l_hb, formats.full_html)
|
||||||
Result.set_is_raw (True)
|
Result.set_is_raw (True)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -447,6 +473,25 @@ feature -- Hook: block
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
feature -- Menu: change
|
||||||
|
|
||||||
|
add_to_main_menu (lnk: CMS_LINK)
|
||||||
|
do
|
||||||
|
-- if attached {CMS_LOCAL_LINK} lnk as l_local then
|
||||||
|
-- l_local.get_is_active (request)
|
||||||
|
-- end
|
||||||
|
main_menu.extend (lnk)
|
||||||
|
end
|
||||||
|
|
||||||
|
add_to_menu (lnk: CMS_LINK; m: CMS_MENU)
|
||||||
|
do
|
||||||
|
-- if attached {CMS_LOCAL_LINK} lnk as l_local then
|
||||||
|
-- l_local.get_is_active (request)
|
||||||
|
-- end
|
||||||
|
m.extend (lnk)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Message
|
feature -- Message
|
||||||
|
|
||||||
add_message (a_msg: READABLE_STRING_8; a_category: detachable READABLE_STRING_8)
|
add_message (a_msg: READABLE_STRING_8; a_category: detachable READABLE_STRING_8)
|
||||||
@@ -567,6 +612,7 @@ feature -- Generation
|
|||||||
|
|
||||||
-- Additional lines in <head ../>
|
-- Additional lines in <head ../>
|
||||||
|
|
||||||
|
add_to_main_menu (create {CMS_LOCAL_LINK}.make ("Home", "/"))
|
||||||
call_menu_alter_hooks (menu_system)
|
call_menu_alter_hooks (menu_system)
|
||||||
prepare_menu_system (menu_system)
|
prepare_menu_system (menu_system)
|
||||||
|
|
||||||
@@ -619,11 +665,11 @@ feature -- Generation
|
|||||||
|
|
||||||
prepare_menu_system (a_menu_system: CMS_MENU_SYSTEM)
|
prepare_menu_system (a_menu_system: CMS_MENU_SYSTEM)
|
||||||
do
|
do
|
||||||
across
|
-- across
|
||||||
a_menu_system as c
|
-- a_menu_system as c
|
||||||
loop
|
-- loop
|
||||||
prepare_links (c.item)
|
-- prepare_links (c.item)
|
||||||
end
|
-- end
|
||||||
end
|
end
|
||||||
|
|
||||||
prepare_links (a_menu: CMS_LINK_COMPOSITE)
|
prepare_links (a_menu: CMS_LINK_COMPOSITE)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ deferred class
|
|||||||
CMS_THEME
|
CMS_THEME
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
CMS_ENCODERS
|
||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
@@ -88,33 +89,6 @@ feature {NONE} -- Implementation
|
|||||||
s.append ("</li>")
|
s.append ("</li>")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Encoders
|
|
||||||
|
|
||||||
url_encoded (s: detachable READABLE_STRING_GENERAL): STRING_8
|
|
||||||
local
|
|
||||||
enc: URL_ENCODER
|
|
||||||
do
|
|
||||||
create enc
|
|
||||||
if s /= Void then
|
|
||||||
Result := enc.general_encoded_string (s)
|
|
||||||
else
|
|
||||||
create Result.make_empty
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
html_encoded (s: detachable READABLE_STRING_GENERAL): STRING_8
|
|
||||||
local
|
|
||||||
enc: HTML_ENCODER
|
|
||||||
do
|
|
||||||
create enc
|
|
||||||
if s /= Void then
|
|
||||||
Result := enc.general_encoded_string (s)
|
|
||||||
else
|
|
||||||
create Result.make_empty
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
|
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
|
|||||||
@@ -79,20 +79,21 @@ feature -- Conversion
|
|||||||
menu_html (a_menu: CMS_MENU; is_horizontal: BOOLEAN): STRING_8
|
menu_html (a_menu: CMS_MENU; is_horizontal: BOOLEAN): STRING_8
|
||||||
-- Render Menu as HTML.
|
-- Render Menu as HTML.
|
||||||
-- A theme will define a menu.tpl
|
-- A theme will define a menu.tpl
|
||||||
|
local
|
||||||
|
tpl: SMARTY_CMS_PAGE_TEMPLATE
|
||||||
|
l_page: CMS_HTML_PAGE
|
||||||
do
|
do
|
||||||
create Result.make_from_string ("<div id=%""+ a_menu.name +"%" class=%"menu%">")
|
to_implement ("Proof of concept to load a Menu from a tpl/menu.tpl.")
|
||||||
if is_horizontal then
|
to_implement ("In this case the template only take care of links.")
|
||||||
Result.append ("<ul class=%"horizontal%" >%N")
|
to_implement ("Maybe we need a SMARTY_CMS_REGION_TEMPLATE")
|
||||||
else
|
to_implement ("Provide a default Menu using HTML hardcoded, maybe using the Default or providing a default implementation in CMS_THEME.menu_html")
|
||||||
Result.append ("<ul class=%"vertical%" >%N")
|
-- Use the similar pattern to SMARTY_CMS_PAGE_TEMPLATE, with a different prepare
|
||||||
end
|
-- feature.
|
||||||
across
|
create tpl.make ("tpl/menu", Current)
|
||||||
a_menu as c
|
create l_page.make
|
||||||
loop
|
l_page.register_variable (a_menu, "menu")
|
||||||
append_cms_link_to (c.item, Result)
|
tpl.prepare (l_page)
|
||||||
end
|
Result := tpl.to_html (l_page)
|
||||||
Result.append ("</ul>%N")
|
|
||||||
Result.append ("</div>")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<div class='navbar navbar-inverse'>
|
||||||
|
<div class='navbar-inner nav-collapse' style="height: auto;">
|
||||||
|
<ul class="nav">
|
||||||
|
{$header_block/}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<div class='container-fluid'>
|
<div class='container-fluid'>
|
||||||
|
|
||||||
<!-- Page Header -->
|
<!-- Page Header -->
|
||||||
{$region_header/}
|
{$region_header/}
|
||||||
|
|
||||||
<!-- General Page Content -->
|
<!-- General Page Content -->
|
||||||
<div id='content' class='row-fluid'>
|
<div id='content' class='row-fluid'>
|
||||||
|
|||||||
3
examples/roc_api/site/www/themes/bootstrap/tpl/menu.tpl
Normal file
3
examples/roc_api/site/www/themes/bootstrap/tpl/menu.tpl
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{foreach item="item" from="$menu.items"}
|
||||||
|
<li class="active"><a href="{$item.location/}">{$item.title/}</a></li>
|
||||||
|
{/foreach}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<h1>ROC Layout with Default Regions</h1>
|
<h1>{$page_title/}</h1>
|
||||||
<div class='navbar navbar-inverse'>
|
<div class='navbar navbar-inverse'>
|
||||||
<div class='navbar-inner nav-collapse' style="height: auto;">
|
<div class='navbar-inner nav-collapse' style="height: auto;">
|
||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
|
|||||||
Reference in New Issue
Block a user