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
|
||||
perms: detachable ARRAYED_LIST [READABLE_STRING_8]
|
||||
do
|
||||
create lnk.make ("node", "/node")
|
||||
a_menu_system.navigation_menu.extend (lnk)
|
||||
create lnk.make ("List of nodes", "/nodes")
|
||||
a_menu_system.main_menu.extend (lnk)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ deferred class
|
||||
CMS_RESPONSE
|
||||
|
||||
inherit
|
||||
CMS_ENCODERS
|
||||
|
||||
CMS_REQUEST_UTIL
|
||||
|
||||
@@ -139,9 +140,10 @@ feature -- Blocks initialization
|
||||
local
|
||||
l_table: like block_region_settings
|
||||
do
|
||||
fixme ("CHECK:Can we use the same structure as in theme.info?")
|
||||
create regions.make_caseless (5)
|
||||
|
||||
-- FIXME: let the user choose ...
|
||||
fixme ("let the user choose ...")
|
||||
create l_table.make_caseless (10)
|
||||
l_table["top"] := "top"
|
||||
l_table["header"] := "header"
|
||||
@@ -202,7 +204,7 @@ feature -- Blocks
|
||||
get_blocks
|
||||
do
|
||||
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")
|
||||
if attached message_block as m then
|
||||
add_block (m, "content")
|
||||
@@ -275,22 +277,46 @@ feature -- Blocks
|
||||
local
|
||||
s: STRING
|
||||
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
|
||||
s.append ("<div id=%"menu-bar%">")
|
||||
s.append (theme.menu_html (main_menu, True))
|
||||
s.append ("</div>")
|
||||
create Result.make ("header", Void, s, formats.full_html)
|
||||
create Result.make ("page_top", Void, s, formats.full_html)
|
||||
Result.set_is_raw (True)
|
||||
end
|
||||
|
||||
header_block: CMS_CONTENT_BLOCK
|
||||
local
|
||||
s: STRING
|
||||
tpl: SMARTY_CMS_PAGE_TEMPLATE
|
||||
l_page: CMS_HTML_PAGE
|
||||
l_hb: STRING
|
||||
do
|
||||
create s.make_empty
|
||||
create Result.make ("header", Void, s, formats.full_html)
|
||||
create s.make_from_string (theme.menu_html (main_menu, True))
|
||||
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)
|
||||
end
|
||||
|
||||
@@ -447,6 +473,25 @@ feature -- Hook: block
|
||||
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
|
||||
|
||||
add_message (a_msg: READABLE_STRING_8; a_category: detachable READABLE_STRING_8)
|
||||
@@ -567,6 +612,7 @@ feature -- Generation
|
||||
|
||||
-- Additional lines in <head ../>
|
||||
|
||||
add_to_main_menu (create {CMS_LOCAL_LINK}.make ("Home", "/"))
|
||||
call_menu_alter_hooks (menu_system)
|
||||
prepare_menu_system (menu_system)
|
||||
|
||||
@@ -619,11 +665,11 @@ feature -- Generation
|
||||
|
||||
prepare_menu_system (a_menu_system: CMS_MENU_SYSTEM)
|
||||
do
|
||||
across
|
||||
a_menu_system as c
|
||||
loop
|
||||
prepare_links (c.item)
|
||||
end
|
||||
-- across
|
||||
-- a_menu_system as c
|
||||
-- loop
|
||||
-- prepare_links (c.item)
|
||||
-- end
|
||||
end
|
||||
|
||||
prepare_links (a_menu: CMS_LINK_COMPOSITE)
|
||||
|
||||
@@ -7,6 +7,7 @@ deferred class
|
||||
CMS_THEME
|
||||
|
||||
inherit
|
||||
CMS_ENCODERS
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
@@ -88,33 +89,6 @@ feature {NONE} -- Implementation
|
||||
s.append ("</li>")
|
||||
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
|
||||
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
|
||||
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
|
||||
-- Render Menu as HTML.
|
||||
-- A theme will define a menu.tpl
|
||||
local
|
||||
tpl: SMARTY_CMS_PAGE_TEMPLATE
|
||||
l_page: CMS_HTML_PAGE
|
||||
do
|
||||
create Result.make_from_string ("<div id=%""+ a_menu.name +"%" class=%"menu%">")
|
||||
if is_horizontal then
|
||||
Result.append ("<ul class=%"horizontal%" >%N")
|
||||
else
|
||||
Result.append ("<ul class=%"vertical%" >%N")
|
||||
end
|
||||
across
|
||||
a_menu as c
|
||||
loop
|
||||
append_cms_link_to (c.item, Result)
|
||||
end
|
||||
Result.append ("</ul>%N")
|
||||
Result.append ("</div>")
|
||||
to_implement ("Proof of concept to load a Menu from a tpl/menu.tpl.")
|
||||
to_implement ("In this case the template only take care of links.")
|
||||
to_implement ("Maybe we need a SMARTY_CMS_REGION_TEMPLATE")
|
||||
to_implement ("Provide a default Menu using HTML hardcoded, maybe using the Default or providing a default implementation in CMS_THEME.menu_html")
|
||||
-- Use the similar pattern to SMARTY_CMS_PAGE_TEMPLATE, with a different prepare
|
||||
-- feature.
|
||||
create tpl.make ("tpl/menu", Current)
|
||||
create l_page.make
|
||||
l_page.register_variable (a_menu, "menu")
|
||||
tpl.prepare (l_page)
|
||||
Result := tpl.to_html (l_page)
|
||||
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'>
|
||||
|
||||
<!-- Page Header -->
|
||||
{$region_header/}
|
||||
{$region_header/}
|
||||
|
||||
<!-- General Page Content -->
|
||||
<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-inner nav-collapse' style="height: auto;">
|
||||
<ul class="nav">
|
||||
|
||||
Reference in New Issue
Block a user