Merged Old CMS code with new CMS code.

Pending: Update code to use the new theme
This commit is contained in:
jvelilla
2014-11-07 18:23:25 -03:00
parent 2c130cf882
commit 75d34870fa
8 changed files with 405 additions and 178 deletions

View File

@@ -39,7 +39,7 @@ feature -- Access
content: READABLE_STRING_8
format: CONTENT_FORMAT
format: detachable CONTENT_FORMAT
feature -- Status report
@@ -58,9 +58,14 @@ feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
do
Result := content
end
-- Why in this particular case theme is not used to generate the content?
if attached format as f then
Result := f.formatted_output (content)
else
Result := content
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)"

View File

@@ -1,5 +1,5 @@
note
description: "Generic CMS Response, place to add HOOKS features as collaborators."
description: "Generic CMS Response.It builds the content to get process to render the output"
date: "$Date$"
revision: "$Revision$"
@@ -34,13 +34,11 @@ feature {NONE} -- Initialization
register_hooks
end
register_hooks
local
l_module: CMS_MODULE
l_available_modules: CMS_MODULE_COLLECTION
do
-- log.write_debug (generator + ".register_hooks")
l_available_modules := setup.modules
across
l_available_modules as ic
@@ -52,7 +50,6 @@ feature {NONE} -- Initialization
end
end
feature -- Access
request: WSF_REQUEST
@@ -73,9 +70,75 @@ feature -- Access
main_content: detachable STRING_8
additional_page_head_lines: detachable LIST [READABLE_STRING_8]
-- HTML>head>...extra lines
feature -- Access: CMS
site_name: STRING_32
do
Result := setup.site_name
end
front_page_url: READABLE_STRING_8
do
Result := request.absolute_script_url ("/")
end
values: CMS_VALUE_TABLE
-- Associated values indexed by string name.
feature -- Permission
-- FIXME: to be implemented has_permissions and has_permission.
feature -- Status
-- FIXME: to be implemented
-- is_from, is_module, has_js.
feature -- Head customization
add_additional_head_line (s: READABLE_STRING_8; a_allow_duplication: BOOLEAN)
local
lst: like additional_page_head_lines
do
lst := additional_page_head_lines
if lst = Void then
create {ARRAYED_LIST [like additional_page_head_lines.item]} lst.make (1)
additional_page_head_lines := lst
end
if a_allow_duplication or else across lst as c all not c.item.same_string (s) end then
lst.extend (s)
end
end
add_style (a_href: STRING; a_media: detachable STRING)
local
s: STRING_8
do
s := "<link rel=%"stylesheet%" href=%""+ a_href + "%" type=%"text/css%""
if a_media /= Void then
s.append (" media=%""+ a_media + "%"")
end
s.append ("/>")
add_additional_head_line (s, False)
end
add_javascript_url (a_src: STRING)
local
s: STRING_8
do
s := "<script type=%"text/javascript%" src=%"" + a_src + "%"></script>"
add_additional_head_line (s, False)
end
add_javascript_content (a_script: STRING)
local
s: STRING_8
do
s := "<script type=%"text/javascript%">%N" + a_script + "%N</script>"
add_additional_head_line (s, True)
end
feature -- Element change
@@ -95,6 +158,35 @@ feature -- Element change
main_content := s
end
set_value (v: detachable ANY; k: READABLE_STRING_GENERAL)
-- Set value `v' associated with name `k'.
do
values.force (v, k)
end
unset_value (k: READABLE_STRING_GENERAL)
-- Unset value associated with name `k'.
do
values.remove (k)
end
feature -- Logging
log (a_category: READABLE_STRING_8; a_message: READABLE_STRING_8; a_level: INTEGER; a_link: detachable CMS_LINK)
local
-- l_log: CMS_LOG
do
debug
to_implement ("Add implemenatation")
end
-- create l_log.make (a_category, a_message, a_level, Void)
-- if a_link /= Void then
-- l_log.set_link (a_link)
-- end
-- l_log.set_info (request.http_user_agent)
-- service.storage.save_log (l_log)
end
feature -- Formats
@@ -202,28 +294,6 @@ feature -- Blocks
end
set_blocks (a_page: CMS_HTML_PAGE)
-- Set blocks to the current `a_page'
do
debug
fixme ("Experimental code")
end
-- top_header_block
set_header_block (a_page)
end
set_header_block (a_page: CMS_HTML_PAGE)
do
if not main_menu.is_empty then
a_page.register_variable (theme.menu_html (main_menu, False), "primary_nav")
end
if not navigation_menu.is_empty then
a_page.register_variable (theme.menu_html (navigation_menu, False), "secondary_nav")
end
end
get_blocks
do
fixme ("find a way to have this in configuration or database, and allow different order")
@@ -318,6 +388,21 @@ feature -- Blocks
Result.set_is_raw (True)
end
horizontal_main_menu_html: STRING
do
create Result.make_empty
Result.append ("<div id=%"menu-bar%">")
Result.append (theme.menu_html (main_menu, True))
Result.append ("</div>")
end
message_html: detachable STRING
do
if attached message as m and then not m.is_empty then
Result := "<div id=%"message%">" + m + "</div>"
end
end
message_block: detachable CMS_CONTENT_BLOCK
do
if attached message as m and then not m.is_empty then
@@ -342,13 +427,15 @@ feature -- Blocks
Result.set_is_raw (True)
end
footer_block: CMS_CONTENT_BLOCK
local
s: STRING
made_with_html: STRING
do
create s.make_empty
s.append ("Made with <a href=%"http://www.eiffel.com/%">EWF</a>")
create Result.make ("made_with", Void, s, formats.full_html)
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 -- Hook: value alter
@@ -595,58 +682,78 @@ feature -- Generation
common_prepare (page)
custom_prepare (page)
-- Cms values
call_value_alter_hooks (values)
-- Menu
add_to_main_menu (create {CMS_LOCAL_LINK}.make ("Home", "/"))
call_menu_alter_hooks (menu_system)
prepare_menu_system (menu_system)
-- Blocks
get_blocks
across
regions as reg_ic
loop
across
reg_ic.item.blocks as ic
loop
if attached {CMS_MENU_BLOCK} ic.item as l_menu_block then
recursive_get_active (l_menu_block.menu, request)
end
end
end
-- Values
if attached current_user_name (request) as l_user then
page.register_variable (l_user, "user")
end
-- Cms values
call_value_alter_hooks (values)
-- Predefined values
if attached title as l_title then
page.set_title (l_title)
else
page.set_title ("CMS::" + request.path_info)
end
page.register_variable (page, "page")
-- page.register_variable (is_front, "is_front")
page.register_variable (request.absolute_script_url (""), "site_url")
page.register_variable (title, "site_title")
-- page.register_variable (site_name_and_slogan, "site_name_and_slogan")
-- if attached logo_location as l_logo then
-- page.register_variable (l_logo, "logo")
-- end
page.register_variable (horizontal_main_menu_html, "primary_nav")
-- Values Associated with current Execution object.
across
values as ic
loop
page.register_variable (ic.item, ic.key)
end
-- Specific values
page.register_variable (request.absolute_script_url (""), "site_url")
-- 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)
if attached theme.navigation_template as l_navigation_template then
page.register_variable (l_navigation_template, l_navigation_template)
end
set_blocks (page)
-- get_blocks
-- across
-- regions as reg_ic
-- loop
-- across
-- reg_ic.item.blocks as ic
-- loop
-- if attached {CMS_MENU_BLOCK} ic.item as l_menu_block then
-- recursive_get_active (l_menu_block.menu, request)
-- end
-- end
-- end
if attached title as l_title then
page.set_title (l_title)
else
page.set_title ("CMS::" + request.path_info)
end
-- blocks
across
regions as reg_ic
loop
across
reg_ic.item.blocks as ic
values as ic
loop
page.add_to_region (theme.block_html (ic.item), reg_ic.item.name)
page.register_variable (ic.item, ic.key)
end
end
-- Block rendering
across
regions as reg_ic
loop
across
reg_ic.item.blocks as ic
loop
page.add_to_region (theme.block_html (ic.item), reg_ic.item.name)
end
end
-- Additional lines in <head ../>
if attached additional_page_head_lines as l_head_lines then
across
l_head_lines as hl
loop
page.head_lines.force (hl.item)
end
end
end
common_prepare (page: CMS_HTML_PAGE)

View File

@@ -33,25 +33,49 @@ feature -- Access
deferred
end
navigation_template: detachable READABLE_STRING_GENERAL
-- navigation template name, if any.
deferred
end
feature -- Conversion
menu_html (a_menu: CMS_MENU; is_horizontal: BOOLEAN): STRING_8
-- Render Menu as HTML.
-- A theme will define a menu.tpl
deferred
do
fixme ("Refactor HTML code to use the new Bootstrap theme template")
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>")
end
block_html (a_block: CMS_BLOCK): STRING_8
-- Render a block as HTML.
deferred
local
s: STRING
do
fixme ("Refactor HTML code to use the new Bootstrap theme template")
if attached {CMS_CONTENT_BLOCK} a_block as l_content_block and then l_content_block.is_raw then
create s.make_empty
if attached l_content_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))
else
create s.make_from_string ("<div class=%"block%" id=%"" + a_block.name + "%">")
if attached a_block.title as l_title then
s.append ("<div class=%"title%">" + html_encoded (l_title) + "</div>")
end
s.append ("<div class=%"inside%">")
s.append (a_block.to_html (Current))
s.append ("</div>")
s.append ("</div>")
end
Result := s
end
page_html (page: CMS_HTML_PAGE): STRING_8
-- Render `page' as html.
deferred

View File

@@ -62,46 +62,6 @@ feature -- Conversion
do
end
menu_html (a_menu: CMS_MENU; is_horizontal: BOOLEAN): STRING_8
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>")
end
block_html (a_block: CMS_BLOCK): STRING_8
local
s: STRING
do
if attached {CMS_CONTENT_BLOCK} a_block as l_content_block and then l_content_block.is_raw then
create s.make_empty
if attached l_content_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))
else
create s.make_from_string ("<div class=%"block%" id=%"" + a_block.name + "%">")
if attached a_block.title as l_title then
s.append ("<div class=%"title%">" + html_encoded (l_title) + "</div>")
end
s.append ("<div class=%"inside%">")
s.append (a_block.to_html (Current))
s.append ("</div>")
s.append ("</div>")
end
Result := s
end
page_html (page: CMS_HTML_PAGE): STRING_8
local
l_content: STRING_8

View File

@@ -0,0 +1,52 @@
note
description: "Summary description for {SMARTY_CMS_HTML_PAGE_INSPECTOR}."
author: ""
date: "$Date: 2014-11-07 04:58:41 -0300 (vi. 07 de nov. de 2014) $"
revision: "$Revision: 96042 $"
class
SMARTY_CMS_HTML_PAGE_INSPECTOR
inherit
TEMPLATE_INSPECTOR
redefine
internal_data
end
create
register
feature {TEMPLATE_ROUTINES}
internal_data (field_name: STRING; obj: detachable ANY): detachable CELL [detachable ANY]
-- Return object in a cell
-- If not handled by this inspector, return Void
local
l_fn: STRING
do
if attached {CMS_HTML_PAGE} obj as l_page then
l_fn := field_name.as_lower
if attached l_page.variables.item (l_fn) as v then
Result := cell_of (v)
elseif l_fn.is_case_insensitive_equal ("title") then
Result := cell_of (l_page.title)
elseif l_fn.starts_with_general ("region_") then
l_fn.remove_head (7) -- remove "region_"
Result := cell_of (l_page.region (l_fn))
elseif l_fn.is_case_insensitive_equal ("regions") then
Result := cell_of (l_page.regions)
end
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)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,47 @@
note
description: "Summary description for {SMARTY_CMS_REGIONS_INSPECTOR}."
author: ""
date: "$Date: 2014-11-06 17:59:12 -0300 (ju. 06 de nov. de 2014) $"
revision: "$Revision: 96040 $"
class
SMARTY_CMS_REGIONS_INSPECTOR
inherit
TEMPLATE_INSPECTOR
redefine
internal_data
end
create
register
feature {TEMPLATE_ROUTINES}
internal_data (field_name: STRING; obj: detachable ANY): detachable CELL [detachable ANY]
-- Return object in a cell
-- If not handled by this inspector, return Void
local
l_fn: STRING
do
if attached {like {CMS_RESPONSE}.regions} obj as l_regions then
l_fn := field_name.as_lower
if l_fn.is_case_insensitive_equal ("count") then
Result := cell_of (l_regions.count)
elseif l_regions.has (l_fn) then
Result := cell_of (l_regions.item (l_fn))
end
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)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -74,61 +74,46 @@ feature -- Access
Result := tpl
end
navigation_template: detachable READABLE_STRING_GENERAL
-- navigation template name, if any.
do
Result := information.item ("navigation")
end
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 tpl.make ("tpl/" + a_menu.name, Current)
create l_page.make
l_page.register_variable (a_menu, "menu")
tpl.prepare (l_page)
Result := tpl.to_html (l_page)
end
block_html (a_block: CMS_BLOCK): STRING_8
local
s: STRING
do
if attached {CMS_CONTENT_BLOCK} a_block as l_content_block and then l_content_block.is_raw then
create s.make_empty
if attached l_content_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))
else
create s.make_from_string ("<div class=%"block%" id=%"" + a_block.name + "%">")
if attached a_block.title as l_title then
s.append ("<div class=%"title%">" + html_encoded (l_title) + "</div>")
end
s.append ("<div class=%"inside%">")
s.append (a_block.to_html (Current))
s.append ("</div>")
s.append ("</div>")
end
Result := s
end
prepare (page: CMS_HTML_PAGE)
do
page.register_variable (page, "page")
page.register_variable (page.regions, "regions")
across
page.regions as ic
loop
page.register_variable (ic.item, "region_" + ic.key)
end
end
page_html (page: CMS_HTML_PAGE): STRING_8
local
l_page_inspector: detachable SMARTY_CMS_HTML_PAGE_INSPECTOR
l_regions_inspector: detachable SMARTY_CMS_REGIONS_INSPECTOR
l_table_inspector: detachable STRING_TABLE_OF_STRING_INSPECTOR
do
prepare (page)
create l_page_inspector.register (page.generating_type)
if attached {CMS_RESPONSE} page.variables.item ("cms") as l_cms then
if attached l_cms.regions as l_regions then
create l_regions_inspector.register (l_regions.generating_type)
end
end
create l_table_inspector.register (({detachable STRING_TABLE [STRING]}).name)
page_template.prepare (page)
Result := page_template.to_html (page)
-- Clean template inspector.
if l_regions_inspector /= Void then
l_regions_inspector.unregister
end
if l_page_inspector /= Void then
l_page_inspector.unregister
end
l_table_inspector.unregister
end
feature {NONE} -- Internal

View File

@@ -0,0 +1,47 @@
note
description: "Summary description for {STRING_TABLE_OF_STRING_INSPECTOR}."
author: ""
date: "$Date: 2014-11-06 17:59:12 -0300 (ju. 06 de nov. de 2014) $"
revision: "$Revision: 96040 $"
class
STRING_TABLE_OF_STRING_INSPECTOR
inherit
TEMPLATE_INSPECTOR
redefine
internal_data
end
create
register
feature {TEMPLATE_ROUTINES}
internal_data (field_name: STRING; obj: detachable ANY): detachable CELL [detachable ANY]
-- Return object in a cell
-- If not handled by this inspector, return Void
local
l_fn: STRING
do
if attached {STRING_TABLE [STRING]} obj as l_regions then
l_fn := field_name.as_lower
if l_fn.is_case_insensitive_equal ("count") then
Result := cell_of (l_regions.count)
elseif attached l_regions.item (l_fn) as v then
Result := cell_of (v)
end
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)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end