Updated CMS code.

Separated code to have a lib and an example.
Improved design, fixed a few issues related to folder location.

This is still experimental and require more work to be really friendly to use.
This commit is contained in:
Jocelyn Fiat
2013-01-31 15:33:24 +01:00
parent 40ea982293
commit ce469b6ede
136 changed files with 1841 additions and 299 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="cms" uuid="0D24AE3C-61DA-4E81-8DCF-90C2E65FB669"> <system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="cms" library_target="cms" uuid="0D24AE3C-61DA-4E81-8DCF-90C2E65FB669">
<target name="cms"> <target name="cms">
<root class="WEB_CMS" feature="make_and_launch"/> <root class="WEB_CMS" feature="make_and_launch"/>
<file_rule> <file_rule>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="cms" library_target="cms" uuid="0D24AE3C-61DA-4E81-8DCF-90C2E65FB669">
<target name="cms">
<root class="WEB_CMS" feature="make_and_launch"/>
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="concurrency" value="thread"/>
<setting name="exception_trace" value="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="default_nino" location="..\..\..\library\server\wsf\default\nino.ecf"/>
<library name="encoder" location="..\..\..\library\text\encoder\encoder.ecf" readonly="false"/>
<library name="http" location="..\..\..\library\network\protocol\http\http.ecf" readonly="false"/>
<library name="nino" location="..\..\..\library\server\ewsgi\connectors\nino\nino.ecf"/>
<library name="process" location="$ISE_LIBRARY\library\process\process.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
<library name="uri_template" location="..\..\..\library\text\parser\uri_template\uri_template.ecf" readonly="false"/>
<library name="uuid" location="$ISE_LIBRARY\library\uuid\uuid.ecf"/>
<library name="wsf" location="..\..\..\library\server\wsf\wsf.ecf" readonly="false"/>
<library name="wsf_session" location="..\..\..\library\server\wsf\wsf_session.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true">
</cluster>
</target>
</system>

View File

@@ -1,3 +0,0 @@
site.name=EWF Web CMS
#site.base_url=/demo
site.email=your@email.com

View File

@@ -0,0 +1,8 @@
site.name=EWF Web CMS
#site.base_url=/demo
site.email=your@email.com
root-dir=../www
var-dir=var
files-dir=../www/files
themes-dir=../www/themes
theme=test

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="demo" uuid="402ED70E-9A85-4501-8730-7B211EB32E6B">
<target name="demo">
<root class="WEB_CMS" feature="make_and_launch"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
</option>
<setting name="concurrency" value="none"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="..\cms-safe.ecf" readonly="false"/>
<library name="default_nino" location="..\..\..\..\library\server\wsf\default\nino-safe.ecf"/>
<library name="http" location="..\..\..\..\library\network\protocol\http\http-safe.ecf" readonly="false"/>
<library name="nino" location="..\..\..\..\library\server\ewsgi\connectors\nino\nino-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<library name="wsf" location="..\..\..\..\library\server\wsf\wsf-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
</system>

View File

@@ -25,6 +25,13 @@ feature -- Initialization
base_url: detachable READABLE_STRING_8 base_url: detachable READABLE_STRING_8
server_base_url: detachable READABLE_STRING_8
-- Base url (related to absolute path).
--| Mainly pertinent when run from a standalone server.
do
Result := base_url
end
modules: ARRAYED_LIST [CMS_MODULE] modules: ARRAYED_LIST [CMS_MODULE]
local local
m: CMS_MODULE m: CMS_MODULE
@@ -83,14 +90,14 @@ feature {NONE} -- Initialization
create cms_config.make create cms_config.make
end end
--| The following line is to be able to load options from the file ewf.ini --| EWF settings
create opts.make_from_file ("ewf.ini") create opts.make_from_file ("ewf.ini")
service_options := opts service_options := opts
--| If you don't need any custom options, you are not obliged to redefine `initialize'
Precursor Precursor
--| CMS settings
base_url := cms_config.site_base_url (base_url) base_url := cms_config.site_base_url (base_url)
initialize_cms initialize_cms (cms_config)
site_email := cms_config.site_email (site_email) site_email := cms_config.site_email (site_email)
site_name := cms_config.site_name (site_name) site_name := cms_config.site_name (site_name)

View File

@@ -7,6 +7,9 @@ note
class class
CMS_CONFIGURATION CMS_CONFIGURATION
--inherit
-- SHARED_EXECUTION_ENVIRONMENT
create create
make, make,
make_from_file make_from_file
@@ -16,6 +19,7 @@ feature {NONE} -- Initialization
make make
do do
create options.make (10) create options.make (10)
analyze
end end
make_from_file (a_filename: READABLE_STRING_32) make_from_file (a_filename: READABLE_STRING_32)
@@ -23,6 +27,15 @@ feature {NONE} -- Initialization
do do
make make
import (a_filename) import (a_filename)
analyze
end
analyze
do
get_root_location
get_var_location
get_themes_location
get_files_location
end end
feature -- Access feature -- Access
@@ -43,24 +56,74 @@ feature -- Element change
feature -- Access feature -- Access
root_location: STRING var_location: READABLE_STRING_8
get_var_location
local
res: STRING_32
do do
if attached options.item ("root.location") as s then if attached options.item ("var-dir") as s then
Result := s res := s
else else
Result := execution_environment.current_working_directory res := execution_environment.current_working_directory
end end
if not Result.ends_with ("/") then if res.ends_with ("/") then
Result.append_character ('/') res.remove_tail (1)
end
var_location := res
end
root_location: READABLE_STRING_8
get_root_location
local
res: STRING_32
do
if attached options.item ("root-dir") as s then
res := s
else
res := execution_environment.current_working_directory
end
if res.ends_with ("/") then
res.remove_tail (1)
end
root_location := res
end
files_location: STRING
get_files_location
do
if attached options.item ("files-dir") as s then
files_location := s
else
files_location := "files"
end end
end end
themes_location: STRING themes_location: STRING
get_themes_location
local
dn: DIRECTORY_NAME
do do
if attached options.item ("themes.location") as s then if attached options.item ("themes-dir") as s then
Result := s themes_location := s
else else
Result := root_location + "theme/default/" create dn.make_from_string (root_location)
dn.extend ("theme")
themes_location := dn.string
end
end
theme_name (dft: detachable like theme_name): READABLE_STRING_8
do
if attached options.item ("theme") as s then
Result := s
elseif dft /= Void then
Result := dft
else
Result := "default"
end end
end end
@@ -103,11 +166,6 @@ feature -- Access
feature {NONE} -- Implementation feature {NONE} -- Implementation
execution_environment: EXECUTION_ENVIRONMENT
once
create Result
end
import (a_filename: READABLE_STRING_32) import (a_filename: READABLE_STRING_32)
-- Import ini file content -- Import ini file content
local local
@@ -143,4 +201,11 @@ feature {NONE} -- Implementation
end end
end end
feature {NONE} -- Environment
Execution_environment: EXECUTION_ENVIRONMENT
once
create Result
end
end end

View File

@@ -24,7 +24,7 @@ feature {NONE} -- Initialization
initialize initialize
do do
is_front := request.path_info.same_string (service.front_path) is_front := service.is_front_page (request)
has_js := True -- by default it is true, check cookie to see if this is not supported. has_js := True -- by default it is true, check cookie to see if this is not supported.
if attached request.cookie ("has_js") as c_has_js then if attached request.cookie ("has_js") as c_has_js then
has_js := c_has_js.same_string ("0") has_js := c_has_js.same_string ("0")
@@ -53,7 +53,7 @@ feature {CMS_SESSION_CONTROLER} -- Access: restricted
base_url: detachable READABLE_STRING_8 base_url: detachable READABLE_STRING_8
do do
Result := service.base_url Result := service.server_base_url
end end
pending_messages_session_item_name: STRING = "cms.pending_messages" pending_messages_session_item_name: STRING = "cms.pending_messages"
@@ -349,10 +349,10 @@ feature -- Blocks
add_block (create {CMS_MENU_BLOCK}.make (m), Void) add_block (create {CMS_MENU_BLOCK}.make (m), Void)
end end
create s.make_empty -- create s.make_empty
s.append ("This site demonstrates a first implementation of CMS using EWF.%N") -- s.append ("This site demonstrates a first implementation of CMS using EWF.%N")
create b.make ("about", "About", s, formats.plain_text) -- create b.make ("about", "About", s, formats.plain_text)
add_block (b, "second_sidebar") -- add_block (b, "second_sidebar")
create s.make_empty create s.make_empty
s.append ("Made with <a href=%"http://www.eiffel.com/%">EWF</a>") s.append ("Made with <a href=%"http://www.eiffel.com/%">EWF</a>")
@@ -374,6 +374,9 @@ feature -- Access
page_title: detachable READABLE_STRING_32 page_title: detachable READABLE_STRING_32
-- Page title -- Page title
additional_page_head_lines: detachable LIST [READABLE_STRING_8]
-- HTML>head>...extra lines
main_content: detachable STRING_8 main_content: detachable STRING_8
redirection: detachable READABLE_STRING_8 redirection: detachable READABLE_STRING_8
@@ -416,6 +419,14 @@ feature -- Generation
local local
s: STRING_8 s: STRING_8
do do
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
add_to_main_menu (create {CMS_LOCAL_LINK}.make ("Home", "/")) add_to_main_menu (create {CMS_LOCAL_LINK}.make ("Home", "/"))
service.call_menu_alter_hooks (menu_system, Current) service.call_menu_alter_hooks (menu_system, Current)
@@ -491,6 +502,50 @@ feature -- Generation
end end
end end
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 feature -- Element change
set_title (t: like title) set_title (t: like title)
@@ -558,6 +613,12 @@ feature {NONE} -- Execution
controller.session_commit (page, Current) controller.session_commit (page, Current)
response.send (page) response.send (page)
on_terminated
end
on_terminated
do
end end
feature {NONE} -- Implementation feature {NONE} -- Implementation

View File

@@ -11,11 +11,27 @@ deferred class
feature -- Initialization feature -- Initialization
initialize_cms initialize_cms (a_cfg: detachable CMS_CONFIGURATION)
local
cfg: detachable CMS_CONFIGURATION
do do
site_name := "EWF::CMS" cfg := a_cfg
site_email := "webmaster" if cfg = Void then
site_url := "" -- FIXME create cfg.make
end
site_url := "" -- Fixme
site_name := cfg.site_name ("EWF::CMS")
site_email := cfg.site_email ("webmaster")
site_dir := cfg.root_location
site_var_dir := cfg.var_location
files_location := cfg.files_location
themes_location := cfg.themes_location
theme_name := cfg.theme_name ("default")
compute_theme_resource_location
create content_types.make (3) create content_types.make (3)
initialize_storage initialize_storage
initialize_auth_engine initialize_auth_engine
@@ -29,7 +45,7 @@ feature -- Initialization
local local
dn: DIRECTORY_NAME dn: DIRECTORY_NAME
do do
create dn.make_from_string ((create {EXECUTION_ENVIRONMENT}).current_working_directory) create dn.make_from_string (site_var_dir)
dn.extend ("_storage_") dn.extend ("_storage_")
dn.extend ("_sessions_") dn.extend ("_sessions_")
create {WSF_FS_SESSION_MANAGER} session_manager.make_with_folder (dn.string) create {WSF_FS_SESSION_MANAGER} session_manager.make_with_folder (dn.string)
@@ -37,26 +53,25 @@ feature -- Initialization
initialize_storage initialize_storage
local local
e: EXECUTION_ENVIRONMENT
dn: DIRECTORY_NAME dn: DIRECTORY_NAME
-- u: CMS_USER
do do
create e create dn.make_from_string (site_var_dir)
create dn.make_from_string (e.current_working_directory)
dn.extend ("_storage_") dn.extend ("_storage_")
create {CMS_SED_STORAGE} storage.make (dn.string) create {CMS_SED_STORAGE} storage.make (dn.string)
if storage.users_count = 0 then if not storage.has_user then
initialize_users initialize_users
end end
end end
initialize_users initialize_users
require require
has_no_user: storage.users_count = 0 has_no_user: not storage.has_user
local local
u: CMS_USER u: CMS_USER
do do
create u.make_new ("admin") create u.make_new ("admin")
u.set_encoded_password (storage.encoded_password ("istrator")) u.set_password ("istrator")
storage.save_user (u) storage.save_user (u)
end end
@@ -75,6 +90,7 @@ feature -- Initialization
local local
-- h: CMS_HANDLER -- h: CMS_HANDLER
file_hdl: CMS_FILE_SYSTEM_HANDLER file_hdl: CMS_FILE_SYSTEM_HANDLER
dn: DIRECTORY_NAME
do do
create router.make (10) create router.make (10)
router.set_base_url (base_url) router.set_base_url (base_url)
@@ -82,12 +98,13 @@ feature -- Initialization
router.map (create {WSF_URI_MAPPING}.make ("/", create {CMS_HANDLER}.make (agent handle_home))) router.map (create {WSF_URI_MAPPING}.make ("/", create {CMS_HANDLER}.make (agent handle_home)))
router.map (create {WSF_URI_MAPPING}.make ("/favicon.ico", create {CMS_HANDLER}.make (agent handle_favicon))) router.map (create {WSF_URI_MAPPING}.make ("/favicon.ico", create {CMS_HANDLER}.make (agent handle_favicon)))
create file_hdl.make ("files") create file_hdl.make (files_location)
file_hdl.disable_index file_hdl.disable_index
file_hdl.set_max_age (8*60*60) file_hdl.set_max_age (8*60*60)
router.map (create {WSF_STARTS_WITH_MAPPING}.make ("/files/", file_hdl)) router.map (create {WSF_STARTS_WITH_MAPPING}.make ("/files/", file_hdl))
create file_hdl.make ("themes/default/res") create dn.make_from_string (theme_resource_location)
create file_hdl.make (theme_resource_location)
file_hdl.set_max_age (8*60*60) file_hdl.set_max_age (8*60*60)
router.map (create {WSF_STARTS_WITH_MAPPING}.make ("/theme/", file_hdl)) router.map (create {WSF_STARTS_WITH_MAPPING}.make ("/theme/", file_hdl))
end end
@@ -99,6 +116,9 @@ feature -- Initialization
loop loop
if m.item.is_enabled then if m.item.is_enabled then
m.item.register (Current) m.item.register (Current)
if attached {CMS_HOOK_AUTO_REGISTER} m.item as h_auto then
h_auto.hook_auto_register (Current)
end
end end
end end
end end
@@ -218,17 +238,54 @@ feature -- Hook: block
feature -- Router feature -- Router
site_name: STRING_32 site_name: READABLE_STRING_32
site_email: STRING site_email: READABLE_STRING_8
site_url: STRING site_url: READABLE_STRING_8
front_path: STRING = "/" site_dir: READABLE_STRING_8
site_var_dir: READABLE_STRING_8
files_location: READABLE_STRING_8
themes_location: READABLE_STRING_8
compute_theme_resource_location
local
dn: DIRECTORY_NAME
do
create dn.make_from_string (themes_location)
dn.extend (theme_name)
dn.extend ("res")
theme_resource_location := dn.string
end
theme_resource_location: READABLE_STRING_8
theme_name: READABLE_STRING_32
front_path: STRING
do
if attached base_url as l_base_url then
Result := l_base_url + "/"
else
Result := "/"
end
end
router: WSF_ROUTER router: WSF_ROUTER
base_url: detachable READABLE_STRING_8 base_url: detachable READABLE_STRING_8
-- Base url (related to the script path).
deferred
ensure
valid_base_url: (Result /= Void and then Result.is_empty) implies (Result.starts_with ("/") and not Result.ends_with ("/"))
end
server_base_url: detachable READABLE_STRING_8
-- Base url (related to absolute path).
deferred deferred
ensure ensure
valid_base_url: (Result /= Void and then Result.is_empty) implies (Result.starts_with ("/") and not Result.ends_with ("/")) valid_base_url: (Result /= Void and then Result.is_empty) implies (Result.starts_with ("/") and not Result.ends_with ("/"))
@@ -244,6 +301,13 @@ feature -- Router
router.map (create {WSF_URI_MAPPING}.make (a_uri, create {CMS_HANDLER}.make (proc))) router.map (create {WSF_URI_MAPPING}.make (a_uri, create {CMS_HANDLER}.make (proc)))
end end
feature -- Report
is_front_page (req: WSF_REQUEST): BOOLEAN
do
Result := req.path_info.same_string (front_path)
end
feature -- Storage feature -- Storage
session_controller (req: WSF_REQUEST): CMS_SESSION_CONTROLER session_controller (req: WSF_REQUEST): CMS_SESSION_CONTROLER
@@ -302,8 +366,11 @@ feature -- Core Execution
handle_favicon (req: WSF_REQUEST; res: WSF_RESPONSE) handle_favicon (req: WSF_REQUEST; res: WSF_RESPONSE)
local local
fres: WSF_FILE_RESPONSE fres: WSF_FILE_RESPONSE
fn: FILE_NAME
do do
create fres.make ("files/favicon.ico") create fn.make_from_string (theme_resource_location)
fn.set_file_name ("favicon.ico")
create fres.make (fn.string)
fres.set_expires_in_seconds (7 * 24 * 60 * 60) -- 7 jours fres.set_expires_in_seconds (7 * 24 * 60 * 60) -- 7 jours
res.send (fres) res.send (fres)
end end

View File

@@ -1,134 +0,0 @@
note
description: "Summary description for {CMS_THEME}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
DEFAULT_CMS_THEME
inherit
CMS_THEME
create
make
feature {NONE} -- Initialization
make (a_service: like service)
do
service := a_service
end
service: CMS_SERVICE
feature -- Access
name: STRING = "CMS"
regions: ARRAY [STRING]
once
Result := <<"header", "content", "footer", "first_sidebar", "second_sidebar">>
end
html_template: DEFAULT_CMS_HTML_TEMPLATE
local
tpl: like internal_html_template
do
tpl := internal_html_template
if tpl = Void then
create tpl.make (Current)
internal_html_template := tpl
end
Result := tpl
end
page_template: DEFAULT_CMS_PAGE_TEMPLATE
local
tpl: like internal_page_template
do
tpl := internal_page_template
if tpl = Void then
create tpl.make (Current)
internal_page_template := tpl
end
Result := tpl
end
css: STRING
do
Result := "[
body { margin: 0; }
div#header { background-color: #00a; color: #fff; border: solid 1px #00a; padding: 10px;}
div#header img#logo { float: left; margin: 3px; }
div#header div#title {font-size: 180%; font-weight: bold; }
ul.horizontal {
list-style-type: none;
}
ul.horizontal li {
display: inline;
padding: 5px;
}
div#first-menu { padding: 5px; color: #ccf; background-color: #006; }
div#first-menu a { color: #ccf; }
div#second-menu { color: #99f; background-color: #333; }
div#second-menu a { color: #99f; }
div#left_sidebar {
width: 150px;
border: solid 1px #009;
margin: 5px;
padding: 5px;
width: 150px;
display: inline;
float: left;
position: relative;
}
div#main-wrapper {
clear: both;
display: block;
height: 0;
}
div#main { margin: 0; padding: 10px; clear: both; height:0; display: block; }
div#content { padding: 10px; border: solid 1px #00f;
width: 700px;
display: inline;
float: left;
position: relative;
}
div#footer { margin: 10px 0 10px 0; clear: both; display: block; text-align: center; padding: 10px; border-top: solid 1px #00f; color: #fff; background-color: #333;}
div#footer a { color: #ff0; }
]"
end
feature -- Conversion
prepare (page: CMS_HTML_PAGE)
do
if attached css as t_css then
-- page.head_lines.extend ("<style type=%"text/css%">%N" + t_css + "%N</style>")
page.add_style (url ("/theme/style.css", Void), Void)
end
end
page_html (page: CMS_HTML_PAGE): STRING_8
local
l_content: STRING_8
do
prepare (page)
page_template.prepare (page)
l_content := page_template.to_html (page)
html_template.prepare (page)
html_template.register (l_content, "page")
Result := html_template.to_html (page)
end
feature {NONE} -- Internal
internal_page_template: detachable like page_template
internal_html_template: detachable like html_template
invariant
attached internal_page_template as inv_p implies inv_p.theme = Current
end

View File

@@ -1,46 +0,0 @@
note
description: "Summary description for {CMS_FORM_CHECKBOX_INPUT}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_FORM_CHECKBOX_INPUT
inherit
CMS_FORM_INPUT
redefine
specific_input_attributes_string
end
create
make
feature -- Access
checked: BOOLEAN
-- Current <input> element should be preselected when the page loads
input_type: STRING = "checkbox"
feature -- Change
set_checked (b: like checked)
do
checked := b
end
feature {NONE} -- Implementation
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
if checked then
Result := "checked=%"checked%""
end
end
invariant
end

View File

@@ -0,0 +1,131 @@
note
description: "Summary description for {CMS_THEME}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
DEFAULT_CMS_THEME
inherit
CMS_THEME
create
make
feature {NONE} -- Initialization
make (a_service: like service)
do
service := a_service
end
service: CMS_SERVICE
feature -- Access
name: STRING = "CMS"
regions: ARRAY [STRING]
once
Result := <<"header", "content", "footer", "first_sidebar", "second_sidebar">>
end
html_template: DEFAULT_CMS_HTML_TEMPLATE
local
tpl: like internal_html_template
do
tpl := internal_html_template
if tpl = Void then
create tpl.make (Current)
internal_html_template := tpl
end
Result := tpl
end
page_template: DEFAULT_CMS_PAGE_TEMPLATE
local
tpl: like internal_page_template
do
tpl := internal_page_template
if tpl = Void then
create tpl.make (Current)
internal_page_template := tpl
end
Result := tpl
end
-- css: STRING
-- do
-- Result := "[
-- body { margin: 0; }
-- div#header { background-color: #00a; color: #fff; border: solid 1px #00a; padding: 10px;}
-- div#header img#logo { float: left; margin: 3px; }
-- div#header div#title {font-size: 180%; font-weight: bold; }
-- ul.horizontal {
-- list-style-type: none;
-- }
-- ul.horizontal li {
-- display: inline;
-- padding: 5px;
-- }
-- div#first-menu { padding: 5px; color: #ccf; background-color: #006; }
-- div#first-menu a { color: #ccf; }
-- div#second-menu { color: #99f; background-color: #333; }
-- div#second-menu a { color: #99f; }
--
-- div#left_sidebar {
-- width: 150px;
-- border: solid 1px #009;
-- margin: 5px;
-- padding: 5px;
-- width: 150px;
-- display: inline;
-- float: left;
-- position: relative;
-- }
-- div#main-wrapper {
-- clear: both;
-- display: block;
-- height: 0;
-- }
-- div#main { margin: 0; padding: 10px; clear: both; height:0; display: block; }
-- div#content { padding: 10px; border: solid 1px #00f;
-- width: 700px;
-- display: inline;
-- float: left;
-- position: relative;
-- }
-- div#footer { margin: 10px 0 10px 0; clear: both; display: block; text-align: center; padding: 10px; border-top: solid 1px #00f; color: #fff; background-color: #333;}
-- div#footer a { color: #ff0; }
-- ]"
-- end
feature -- Conversion
prepare (page: CMS_HTML_PAGE)
do
page.add_style (url ("/theme/style.css", Void), Void)
end
page_html (page: CMS_HTML_PAGE): STRING_8
local
l_content: STRING_8
do
prepare (page)
page_template.prepare (page)
l_content := page_template.to_html (page)
html_template.prepare (page)
html_template.register (l_content, "page")
Result := html_template.to_html (page)
end
feature {NONE} -- Internal
internal_page_template: detachable like page_template
internal_html_template: detachable like html_template
invariant
attached internal_page_template as inv_p implies inv_p.theme = Current
end

View File

@@ -34,10 +34,20 @@ feature -- Execution
-- Computed response message. -- Computed response message.
local local
b: STRING_8 b: STRING_8
s: STRING
do do
create b.make_empty create b.make_empty
if attached text as t then if attached text as t then
set_title (request.path_info) s := request.path_info
if attached service.base_url as l_base_url then
if s.starts_with (l_base_url) then
s.remove_head (l_base_url.count)
if s.starts_with ("/") then
s.remove_head (1)
end
end
end
set_title (s)
b.append (t) b.append (t)
else else
set_title ("Page Not Found") set_title ("Page Not Found")

View File

@@ -0,0 +1,29 @@
note
description: "[
Summary description for {CMS_HOOK_AUTO_REGISTER}.
When inheriting from this class, the declared hooks are automatically
registered, otherwise, each descendant has to add it to the cms service
itself.
]"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_HOOK_AUTO_REGISTER
inherit
CMS_HOOK
feature -- Hook
hook_auto_register (a_service: CMS_SERVICE)
do
if attached {CMS_HOOK_MENU_ALTER} Current as h_menu_alter then
a_service.add_menu_alter_hook (h_menu_alter)
end
if attached {CMS_HOOK_BLOCK} Current as h_block then
a_service.add_block_hook (h_block)
end
end
end

View File

@@ -55,24 +55,45 @@ feature -- Access
end end
end end
link (a_text: READABLE_STRING_GENERAL; a_path: STRING; opts: detachable CMS_API_OPTIONS): STRING link (a_text: detachable READABLE_STRING_GENERAL; a_path: STRING; opts: detachable CMS_API_OPTIONS): STRING
local local
l_html: BOOLEAN l_html: BOOLEAN
t: READABLE_STRING_GENERAL
do do
l_html := True l_html := True
if opts /= Void then if opts /= Void then
l_html := opts.boolean_item ("html", l_html) l_html := opts.boolean_item ("html", l_html)
end end
Result := "<a href=%"" + checked_url (url (a_path, opts)) + "%">" Result := "<a href=%"" + checked_url (url (a_path, opts)) + "%">"
if a_text = Void then
t := a_path
else
t := a_text
end
if l_html then if l_html then
if attached {READABLE_STRING_8} a_text as t then Result.append (html_encoded (t))
else
Result.append (checked_plain (t))
end
Result.append ("</a>")
end
link_with_raw_text (a_text: detachable READABLE_STRING_8; a_path: STRING; opts: detachable CMS_API_OPTIONS): STRING
local
l_html: BOOLEAN
t: READABLE_STRING_8
do
l_html := True
if opts /= Void then
l_html := opts.boolean_item ("html", l_html)
end
Result := "<a href=%"" + checked_url (url (a_path, opts)) + "%">"
if a_text = Void then
t := a_path
else
t := a_text
end
Result.append (t) Result.append (t)
else
Result.append (a_text.to_string_8)
end
else
Result.append (checked_plain (a_text))
end
Result.append ("</a>") Result.append ("</a>")
end end
@@ -83,7 +104,7 @@ feature -- Access
node_link (n: CMS_NODE): like link node_link (n: CMS_NODE): like link
do do
Result := link (html_encoded (n.title), "/node/" + n.id.out, Void) Result := link (n.title, "/node/" + n.id.out, Void)
end end
user_url (u: CMS_USER): like url user_url (u: CMS_USER): like url

View File

@@ -26,9 +26,7 @@ feature -- Status
valid_credential (u,p: READABLE_STRING_32): BOOLEAN valid_credential (u,p: READABLE_STRING_32): BOOLEAN
do do
if attached storage.user_by_name (u) as l_user then Result := storage.is_valid_credential (u, p)
Result := attached l_user.encoded_password as l_pass and then l_pass.same_string (storage.encoded_password (p))
end
end end
end end

View File

@@ -0,0 +1,65 @@
note
description: "Summary description for {CMS_CSS}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_CSS
create
make
feature {NONE} -- Initialization
make
do
create items.make (3)
end
feature -- Access
items: ARRAYED_LIST [TUPLE [selectors: ITERABLE [CMS_CSS_SELECTOR]; style: CMS_CSS_STYLE]]
feature -- Conversion
string: READABLE_STRING_8
local
s: STRING_8
do
create s.make (64)
append_to (s)
Result := s
end
append_to (a_target: STRING_8)
local
s: STRING_8
s_selectors: STRING_8
do
create s.make (64)
create s_selectors.make (10)
across
items as c
loop
s_selectors.wipe_out
across
c.item.selectors as cs
loop
if not s_selectors.is_empty then
s_selectors.append_character (',')
end
s_selectors.append (cs.item)
end
if not s_selectors.is_empty then
a_target.append (s_selectors)
a_target.append_character (' ')
a_target.append_character ('{')
a_target.append (c.item.style)
a_target.append_character ('}')
a_target.append_character ('%N')
end
end
end
end

View File

@@ -0,0 +1,24 @@
note
description: "Summary description for {CMS_CSS_SELECTOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_CSS_SELECTOR
create
make_from_string
feature {NONE} -- Initialization
make_from_string (s: READABLE_STRING_8)
do
string := s
end
feature -- Conversion
string: READABLE_STRING_8
end

View File

@@ -0,0 +1,393 @@
note
description: "Summary description for {CMS_CSS_STYLE}."
date: "$Date$"
revision: "$Revision$"
EIS: "name=CSS reference", "protocol=URI", "src=http://www.w3schools.com/cssref/"
class
CMS_CSS_STYLE
create
make,
make_from_string
feature {NONE} -- Initialization
make
do
create {ARRAYED_LIST [READABLE_STRING_8]} items.make (3)
end
make_from_string (s: READABLE_STRING_8)
do
items := s.split (';')
end
items: LIST [READABLE_STRING_8]
feature -- Change
put_key_value (k,v: READABLE_STRING_8)
do
items.force (k + ": " + v)
end
feature -- Property: colors
put_color (v: READABLE_STRING_8)
do
put_key_value ("color", v)
end
put_background (v: READABLE_STRING_8)
--| ex: #00ff00 url('smiley.gif') no-repeat fixed center;
do
put_key_value ("background", v)
end
put_background_color (v: READABLE_STRING_8)
do
put_key_value ("background-color", v)
end
feature -- Property: fonts
put_font (v: READABLE_STRING_8)
do
put_key_value ("font", v)
end
put_font_family (v: READABLE_STRING_8)
do
put_key_value ("font-family", v)
end
put_font_size (v: READABLE_STRING_8)
do
put_key_value ("font-size", v)
end
put_font_style (v: READABLE_STRING_8)
do
put_key_value ("font-style", v)
end
put_font_weight (v: READABLE_STRING_8)
do
put_key_value ("font-weight", v)
end
put_font_bold
do
put_font_weight ("bold")
end
put_font_italic
do
put_font_style ("italic")
end
put_text_decoration (v: READABLE_STRING_8)
do
put_key_value ("text-decoration", v)
end
put_text_decoration_none
do
put_text_decoration ("none")
end
put_text_decoration_underline
do
put_text_decoration ("underline")
end
put_text_decoration_strike
do
put_text_decoration ("strike")
end
put_text_align (v: READABLE_STRING_8)
do
put_key_value ("text-align", v)
end
put_white_space (v: READABLE_STRING_8)
--| normal Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default
--| nowrap Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br /> tag is encountered
--| pre Whitespace is preserved by the browser. Text will only wrap on line breaks Acts like the <pre> tag in HTML
--| pre-line Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks
--| pre-wrap Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks
--| inherit Specifies that the value of the white-space property should be inherited from the parent element
do
put_key_value ("white-space", v)
end
put_white_space_nowrap
do
put_white_space ("nowrap")
end
put_white_space_pre
do
put_white_space ("pre")
end
feature -- Property: margin
put_margin (a_top, a_right, a_bottom, a_left: detachable READABLE_STRING_8)
local
v: STRING
do
create v.make (10)
if a_left /= Void then
v.append (a_left)
end
if not v.is_empty then
v.prepend_character (' ')
end
if a_bottom /= Void then
v.prepend (a_bottom)
else
v.prepend_character ('0')
end
if not v.is_empty then
v.prepend_character (' ')
end
if a_right /= Void then
v.prepend (a_right)
else
v.prepend_character ('0')
end
if not v.is_empty then
v.prepend_character (' ')
end
if a_top /= Void then
v.prepend (a_top)
else
v.prepend_character ('0')
end
put_key_value ("margin", v)
end
put_margin_top (v: READABLE_STRING_8)
do
put_key_value ("margin-top", v)
end
put_margin_right (v: READABLE_STRING_8)
do
put_key_value ("margin-right", v)
end
put_margin_bottom (v: READABLE_STRING_8)
do
put_key_value ("margin-bottom", v)
end
put_margin_left (v: READABLE_STRING_8)
do
put_key_value ("margin-left", v)
end
feature -- Property: padding
put_padding (a_top, a_right, a_bottom, a_left: detachable READABLE_STRING_8)
local
v: STRING
do
create v.make (10)
if a_left /= Void then
v.append (a_left)
end
if not v.is_empty then
v.prepend_character (' ')
end
if a_bottom /= Void then
v.prepend (a_bottom)
else
v.prepend_character ('0')
end
if not v.is_empty then
v.prepend_character (' ')
end
if a_right /= Void then
v.prepend (a_right)
else
v.prepend_character ('0')
end
if not v.is_empty then
v.prepend_character (' ')
end
if a_top /= Void then
v.prepend (a_top)
else
v.prepend_character ('0')
end
put_key_value ("padding", v)
end
put_padding_top (v: READABLE_STRING_8)
do
put_key_value ("padding-top", v)
end
put_padding_right (v: READABLE_STRING_8)
do
put_key_value ("padding-right", v)
end
put_padding_bottom (v: READABLE_STRING_8)
do
put_key_value ("padding-bottom", v)
end
put_padding_left (v: READABLE_STRING_8)
do
put_key_value ("padding-left", v)
end
feature -- Properties: layout
put_width (v: READABLE_STRING_8)
do
put_key_value ("width", v)
end
put_height (v: READABLE_STRING_8)
do
put_key_value ("height", v)
end
put_z_index (v: READABLE_STRING_8)
do
put_key_value ("z-index", v)
end
feature -- Property: border
put_border (a_border: detachable READABLE_STRING_8; a_style: READABLE_STRING_8; a_size: READABLE_STRING_8; a_color: READABLE_STRING_8)
-- "solid 1px color"
require
a_border /= Void implies (a_border.same_string ("top") or a_border.same_string ("right") or a_border.same_string ("bottom") or a_border.same_string ("left"))
local
k: STRING
do
k := "border"
if a_border /= Void then
k.append_character ('-')
k.append (a_border)
end
put_key_value (k, a_style + " " + a_size + " " + a_color)
end
put_border_style (a_style: READABLE_STRING_8)
-- "solid 1px color"
do
put_key_value ("border-style", a_style)
end
put_border_style_none (a_style: READABLE_STRING_8)
-- "solid 1px color"
do
put_border_style ("none")
end
feature -- Property: display
put_display (v: READABLE_STRING_8)
do
put_key_value ("display", v)
end
put_display_none
do
put_display ("none")
end
put_display_block
do
put_display ("block")
end
put_display_inline
do
put_display ("inline")
end
put_display_inline_block
do
put_display ("inline-block")
end
put_list_style (v: READABLE_STRING_8)
--| ex: list-style:square url("sqpurple.gif");
do
put_key_value ("list-style", v)
end
put_list_style_type (v: READABLE_STRING_8)
--circle The marker is a circle
--decimal The marker is a number. This is default for <ol>
--decimal-leading-zero The marker is a number with leading zeros (01, 02, 03, etc.)
--disc The marker is a filled circle. This is default for <ul>
--lower-alpha The marker is lower-alpha (a, b, c, d, e, etc.)
--lower-greek The marker is lower-greek
--lower-latin The marker is lower-latin (a, b, c, d, e, etc.)
--lower-roman The marker is lower-roman (i, ii, iii, iv, v, etc.)
--none No marker is shown
--square The marker is a square
--upper-alpha The marker is upper-alpha (A, B, C, D, E, etc.)
--upper-latin The marker is upper-latin (A, B, C, D, E, etc.)
--upper-roman The marker is upper-roman (I, II, III, IV, V, etc.)
do
put_key_value ("list-style-type", v)
end
feature -- Property: float ...
put_float (v: READABLE_STRING_8)
do
put_key_value ("float", v)
end
put_clear (v: READABLE_STRING_8)
do
put_key_value ("clear", v)
end
feature -- Conversion
append_inline_to (s: STRING_8)
do
append_to (s, False)
end
append_text_to (s: STRING_8)
do
append_to (s, True)
end
append_to (s: STRING_8; a_multiline: BOOLEAN)
local
n: INTEGER
do
n := 0
across
items as c
loop
if n > 0 then
if a_multiline then
s.append_character ('%N')
else
s.append_character (' ')
end
end
s.append (c.item)
s.append_character (';')
n := n + 1
end
end
end

View File

@@ -24,7 +24,7 @@ feature {NONE} -- Initialization
creation_date := dt creation_date := dt
name := n name := n
ensure ensure
valid_password: password = Void and encoded_password /= Void valid_password: password = Void
end end
make_new (n: like name) make_new (n: like name)
@@ -46,8 +46,6 @@ feature -- Access
password: detachable READABLE_STRING_32 password: detachable READABLE_STRING_32
encoded_password: detachable READABLE_STRING_8
email: detachable READABLE_STRING_8 email: detachable READABLE_STRING_8
profile: detachable CMS_USER_PROFILE profile: detachable CMS_USER_PROFILE
@@ -99,11 +97,6 @@ feature -- Element change
password := p password := p
end end
set_encoded_password (p: like encoded_password)
do
encoded_password := p
end
set_email (m: like email) set_email (m: like email)
do do
email := m email := m
@@ -155,4 +148,13 @@ feature -- Element change
set_last_login_date (create {DATE_TIME}.make_now_utc) set_last_login_date (create {DATE_TIME}.make_now_utc)
end end
feature {CMS_STORAGE} -- Security
encoded_password: detachable READABLE_STRING_8
set_encoded_password (p: like encoded_password)
do
encoded_password := p
end
end end

View File

@@ -22,6 +22,7 @@ feature {NONE} -- Initialization
create html_classes.make (2) create html_classes.make (2)
create items.make (10) create items.make (10)
set_method_post
end end
feature -- Access feature -- Access
@@ -37,6 +38,10 @@ feature -- Access
Result := items.count Result := items.count
end end
method: READABLE_STRING_8
-- Form's method
--| GET or POST
feature -- Validation feature -- Validation
validation_action: detachable PROCEDURE [ANY, TUPLE [CMS_FORM_DATA]] validation_action: detachable PROCEDURE [ANY, TUPLE [CMS_FORM_DATA]]
@@ -48,6 +53,16 @@ feature -- Validation
feature -- Element change feature -- Element change
set_method_get
do
method := "GET"
end
set_method_post
do
method := "POST"
end
set_validation_action (act: like validation_action) set_validation_action (act: like validation_action)
do do
validation_action := act validation_action := act
@@ -134,7 +149,7 @@ feature -- Conversion
local local
s: STRING s: STRING
do do
Result := "<form action=%""+ action +"%" id=%""+ id +"%" method=%"POST%" " Result := "<form action=%""+ action +"%" id=%""+ id +"%" method=%""+ method +"%" "
if not html_classes.is_empty then if not html_classes.is_empty then
create s.make_empty create s.make_empty
across across

View File

@@ -0,0 +1,81 @@
note
description: "Summary description for {CMS_FORM_CHECKBOX_INPUT}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_FORM_CHECKBOX_INPUT
inherit
CMS_FORM_INPUT
rename
default_value as value
redefine
specific_input_attributes_string,
child_to_html
end
CMS_FORM_SELECTABLE_ITEM
rename
is_selected as checked,
set_is_selected as set_checked
end
create
make,
make_with_text
feature -- Access
checked: BOOLEAN
-- Current <input> element should be preselected when the page loads
input_type: STRING = "checkbox"
text: detachable READABLE_STRING_32
feature -- Status report
is_same_value (v: READABLE_STRING_32): BOOLEAN
do
Result := attached value as l_value and then v.same_string (l_value)
end
feature -- Change
set_text (t: detachable READABLE_STRING_32)
do
text := t
end
set_checked (b: like checked)
do
checked := b
end
feature {NONE} -- Implementation
child_to_html (a_theme: CMS_THEME): detachable READABLE_STRING_8
-- Specific child element if any.
--| To redefine if needed
do
if attached text as t then
Result := a_theme.html_encoded (t)
elseif attached value as v then
Result := a_theme.html_encoded (v)
end
end
specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any.
-- To redefine if needed
do
if checked then
Result := "checked=%"checked%""
end
end
invariant
end

View File

@@ -0,0 +1,65 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
class
CMS_FORM_DIV
inherit
CMS_FORM_ITEM
ITERABLE [CMS_FORM_ITEM]
WITH_CSS_ID
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
create items.make (0)
end
feature -- Access
new_cursor: ITERATION_CURSOR [CMS_FORM_ITEM]
-- Fresh cursor associated with current structure
do
Result := items.new_cursor
end
feature -- Change
extend (i: CMS_FORM_ITEM)
do
items.force (i)
end
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
do
Result := "<div"
append_css_class_to (Result, Void)
append_css_id_to (Result)
append_css_style_to (Result)
Result.append (">%N")
across
items as c
loop
Result.append (c.item.to_html (a_theme))
end
Result.append ("%N</div>%N")
end
feature {NONE} -- Implementation
items: ARRAYED_LIST [CMS_FORM_ITEM]
end

View File

@@ -10,6 +10,8 @@ deferred class
inherit inherit
CMS_FORM_ITEM CMS_FORM_ITEM
WITH_CSS_ID
DEBUG_OUTPUT DEBUG_OUTPUT
feature -- Access feature -- Access
@@ -26,6 +28,7 @@ feature -- Access
is_readonly: BOOLEAN is_readonly: BOOLEAN
is_description_collapsible: BOOLEAN
feature -- Status report feature -- Status report
@@ -91,26 +94,32 @@ feature -- Element change
deferred deferred
end end
set_description_collapsible (b: BOOLEAN)
-- Set `is_description_collapsible' to `b'
do
is_description_collapsible := b
end
feature -- Conversion feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8 to_html (a_theme: CMS_THEME): STRING_8
local local
cl: STRING l_class_items: detachable ARRAYED_LIST [READABLE_STRING_8]
do do
create cl.make_empty create l_class_items.make (2)
if is_required then if is_required then
if not cl.is_empty then l_class_items.extend ("required")
cl.append_character (' ')
end
cl.append ("required")
end end
if is_invalid then if is_invalid then
if not cl.is_empty then l_class_items.extend ("error")
cl.append_character (' ')
end end
cl.append ("error") if l_class_items.is_empty then
l_class_items := Void
end end
create Result.make_from_string ("<div class=%""+ cl +"%">")
create Result.make_from_string ("<div")
append_css_class_to (Result, l_class_items)
Result.append_character ('>')
if attached label as lab then if attached label as lab then
Result.append ("<strong><label for=%"" + name + "%">" + lab + "</label></strong>") Result.append ("<strong><label for=%"" + name + "%">" + lab + "</label></strong>")
if is_required then if is_required then
@@ -120,8 +129,12 @@ feature -- Conversion
end end
Result.append (item_to_html (a_theme)) Result.append (item_to_html (a_theme))
if attached description as desc then if attached description as desc then
if is_description_collapsible then
Result.append ("<div class=%"description collapsible%"><div>Description ...</div><div>" + desc + "</div></div>")
else
Result.append ("<div class=%"description%">" + desc + "</div>") Result.append ("<div class=%"description%">" + desc + "</div>")
end end
end
Result.append ("</div>") Result.append ("</div>")
end end

View File

@@ -12,6 +12,8 @@ inherit
ITERABLE [CMS_FORM_ITEM] ITERABLE [CMS_FORM_ITEM]
WITH_CSS_ID
create create
make make
@@ -51,7 +53,12 @@ feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8 to_html (a_theme: CMS_THEME): STRING_8
do do
Result := "<fieldset>%N" Result := "<fieldset"
append_css_class_to (Result, Void)
append_css_id_to (Result)
append_css_style_to (Result)
Result.append (">%N")
if attached legend as leg then if attached legend as leg then
Result.append ("<legend>" + leg + "</legend>%N") Result.append ("<legend>" + leg + "</legend>%N")
end end

View File

@@ -15,7 +15,8 @@ inherit
end end
create create
make make,
make_with_text
feature -- Access feature -- Access

View File

@@ -17,6 +17,12 @@ feature {NONE} -- Initialization
name := a_name name := a_name
end end
make_with_text (a_name: like name; a_text: READABLE_STRING_32)
do
make (a_name)
set_text_value (a_text)
end
feature -- Access feature -- Access
default_value: detachable READABLE_STRING_32 default_value: detachable READABLE_STRING_32
@@ -75,6 +81,10 @@ feature -- Conversion
item_to_html (a_theme: CMS_THEME): STRING_8 item_to_html (a_theme: CMS_THEME): STRING_8
do do
Result := "<input type=%""+ input_type +"%" name=%""+ name +"%"" Result := "<input type=%""+ input_type +"%" name=%""+ name +"%""
append_css_class_to (Result, Void)
append_css_id_to (Result)
append_css_style_to (Result)
if is_readonly then if is_readonly then
Result.append (" readonly=%"readonly%"") Result.append (" readonly=%"readonly%"")
end end
@@ -95,11 +105,23 @@ feature -- Conversion
Result.append_character (' ') Result.append_character (' ')
Result.append (s) Result.append (s)
end end
if attached child_to_html (a_theme) as s then
Result.append (">")
Result.append (s)
Result.append ("</input>")
else
Result.append ("/>") Result.append ("/>")
end end
end
feature {NONE} -- Implementation feature {NONE} -- Implementation
child_to_html (a_theme: CMS_THEME): detachable READABLE_STRING_8
-- Specific child element if any.
--| To redefine if needed
do
end
specific_input_attributes_string: detachable STRING_8 specific_input_attributes_string: detachable STRING_8
-- Specific input attributes if any. -- Specific input attributes if any.
--| To redefine if needed --| To redefine if needed

View File

@@ -7,6 +7,11 @@ note
deferred class deferred class
CMS_FORM_ITEM CMS_FORM_ITEM
inherit
WITH_CSS_CLASS
WITH_CSS_STYLE
feature -- Conversion feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8 to_html (a_theme: CMS_THEME): STRING_8

View File

@@ -14,7 +14,8 @@ inherit
end end
create create
make make,
make_with_text
feature -- Access feature -- Access

View File

@@ -9,10 +9,18 @@ class
inherit inherit
CMS_FORM_INPUT CMS_FORM_INPUT
rename
default_value as value
redefine redefine
specific_input_attributes_string specific_input_attributes_string
end end
CMS_FORM_SELECTABLE_ITEM
rename
is_selected as checked,
set_is_selected as set_checked
end
create create
make make
@@ -23,6 +31,13 @@ feature -- Access
input_type: STRING = "radio" input_type: STRING = "radio"
feature -- Status report
is_same_value (v: READABLE_STRING_32): BOOLEAN
do
Result := attached value as l_value and then v.same_string (l_value)
end
feature -- Change feature -- Change
set_checked (b: like checked) set_checked (b: like checked)

View File

@@ -10,6 +10,8 @@ class
inherit inherit
CMS_FORM_FIELD CMS_FORM_FIELD
CMS_FORM_UTILITY
create create
make make
@@ -27,17 +29,18 @@ feature -- Access
feature -- Element change feature -- Element change
set_text_value (v: detachable like {CMS_FORM_SELECT_OPTION}.value) set_text_by_value (a_text: detachable READABLE_STRING_GENERAL)
local local
opt: CMS_FORM_SELECT_OPTION opt: CMS_FORM_SELECT_OPTION
l_found: BOOLEAN l_found: BOOLEAN
v: READABLE_STRING_8
do do
if v /= Void then if a_text /= Void then
v := html_encoded_string (a_text.to_string_32)
across across
options as o options as o
loop loop
-- FIXME: unicode ... if o.item.is_same_value (v) then
if o.item.value.same_string (v) then
l_found := True l_found := True
o.item.set_is_selected (True) o.item.set_is_selected (True)
else else
@@ -61,9 +64,9 @@ feature -- Element change
set_value (v: detachable WSF_VALUE) set_value (v: detachable WSF_VALUE)
do do
if attached {WSF_STRING} v as s then if attached {WSF_STRING} v as s then
set_text_value (s.value) set_text_by_value (s.value)
else else
set_text_value (Void) set_text_by_value (Void)
end end
end end
@@ -79,7 +82,13 @@ feature -- Conversion
l_is_already_selected: BOOLEAN l_is_already_selected: BOOLEAN
h: detachable STRING_8 h: detachable STRING_8
do do
Result := "<select name=%""+ name +"%" id=%""+ name +"-select%"" Result := "<select name=%""+ name +"%" "
if css_id = Void then
set_css_id (name +"-select")
end
append_css_class_to (Result, Void)
append_css_id_to (Result)
append_css_style_to (Result)
if is_readonly then if is_readonly then
Result.append (" readonly=%"readonly%" />") Result.append (" readonly=%"readonly%" />")

View File

@@ -7,6 +7,9 @@ note
class class
CMS_FORM_SELECT_OPTION CMS_FORM_SELECT_OPTION
inherit
CMS_FORM_SELECTABLE_ITEM
create create
make make
@@ -27,9 +30,14 @@ feature -- Status
is_selected: BOOLEAN is_selected: BOOLEAN
is_same_value (v: READABLE_STRING_32): BOOLEAN
do
Result := value.same_string (v)
end
feature -- Access feature -- Access
value: READABLE_STRING_8 value: READABLE_STRING_32
text: READABLE_STRING_8 text: READABLE_STRING_8

View File

@@ -0,0 +1,25 @@
note
description: "Summary description for {CMS_FORM_SELECTABLE_ITEM}."
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_FORM_SELECTABLE_ITEM
feature -- Status report
is_selected : BOOLEAN
deferred
end
is_same_value (v: READABLE_STRING_32): BOOLEAN
deferred
end
feature -- Change
set_is_selected (b: like is_selected)
deferred
end
end

View File

@@ -11,7 +11,8 @@ inherit
CMS_FORM_INPUT CMS_FORM_INPUT
create create
make make,
make_with_text
feature -- Access feature -- Access

View File

@@ -11,7 +11,8 @@ inherit
CMS_FORM_INPUT CMS_FORM_INPUT
create create
make make,
make_with_text
feature -- Access feature -- Access

View File

@@ -71,6 +71,11 @@ feature -- Conversion
Result.append (" cols=%"" + cols.out + "%"") Result.append (" cols=%"" + cols.out + "%"")
end end
append_css_class_to (Result, Void)
append_css_id_to (Result)
append_css_style_to (Result)
if is_readonly then if is_readonly then
Result.append (" readonly=%"readonly%">") Result.append (" readonly=%"readonly%">")
else else

View File

@@ -0,0 +1,22 @@
note
description: "Summary description for {CMS_FORM_UTILITY}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_FORM_UTILITY
feature -- Converter
html_encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
do
Result := html_encoder.encoded_string (s)
end
html_encoder: HTML_ENCODER
once
create Result
end
end

View File

@@ -0,0 +1,83 @@
note
description: "Summary description for {WITH_CSS_CLASS}."
date: "$Date$"
revision: "$Revision$"
deferred class
WITH_CSS_CLASS
feature -- Status report
css_classes: detachable LIST [READABLE_STRING_8]
feature -- Change
reset_css_classes
do
css_classes := Void
end
add_css_class (a_class: READABLE_STRING_8)
require
is_valid_css_class: is_valid_css_class (a_class)
local
lst: like css_classes
do
lst := css_classes
if lst = Void then
create {ARRAYED_LIST [READABLE_STRING_8]} lst.make (1)
css_classes := lst
end
lst.force (a_class)
end
feature -- Query
is_valid_css_class (s: detachable READABLE_STRING_8): BOOLEAN
do
Result := s /= Void implies (not s.is_empty)
-- To complete
end
feature -- Conversion
append_css_class_to (a_target: STRING; a_additional_classes: detachable ITERABLE [READABLE_STRING_8])
local
f: BOOLEAN
cl: READABLE_STRING_8
do
if css_classes /= Void or a_additional_classes /= Void then
a_target.append (" class=%"")
f := True -- is first
if attached css_classes as l_classes then
across
l_classes as c
loop
cl := c.item
if not cl.is_empty then
if not f then
a_target.append_character (' ')
end
a_target.append (cl)
end
end
end
if attached a_additional_classes as l_classes then
across
l_classes as c
loop
cl := c.item
if not cl.is_empty then
if not f then
a_target.append_character (' ')
end
a_target.append (cl)
end
end
end
a_target.append_character ('%"')
end
end
end

View File

@@ -0,0 +1,41 @@
note
description: "Summary description for {WITH_CSS_ID}."
date: "$Date$"
revision: "$Revision$"
deferred class
WITH_CSS_ID
feature -- Status report
css_id: detachable READABLE_STRING_8
feature -- Change
set_css_id (a_id: like css_id)
require
is_valid_css_id: is_valid_css_id (a_id)
do
css_id := a_id
end
feature -- Query
is_valid_css_id (s: detachable READABLE_STRING_8): BOOLEAN
do
Result := s /= Void implies (not s.is_empty)
-- To complete
end
feature -- Conversion
append_css_id_to (a_target: STRING)
do
if attached css_id as l_id then
a_target.append (" id=%"")
a_target.append (l_id)
a_target.append_character ('%"')
end
end
end

View File

@@ -0,0 +1,31 @@
note
description: "Summary description for {WITH_CSS_STYLE}."
date: "$Date$"
revision: "$Revision$"
deferred class
WITH_CSS_STYLE
feature -- Status report
css_style: detachable CMS_CSS_STYLE
feature -- Change
set_css_style (a_style: like css_style)
do
css_style := a_style
end
feature -- Conversion
append_css_style_to (a_target: STRING)
do
if attached css_style as l_css_style then
a_target.append (" style=%"")
l_css_style.append_inline_to (a_target)
a_target.append_character ('%"')
end
end
end

View File

@@ -0,0 +1,144 @@
note
description: "Summary description for {CMS_PAGER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_PAGER
create
make
feature {NONE} -- Initialization
make (tpl: READABLE_STRING_8; a_lower, a_upper: NATURAL_64; a_step: NATURAL_64)
do
create template.make (tpl)
lower := a_lower
upper := a_upper
step := a_step
end
feature -- Change
set_active_range (a_lower, a_upper: NATURAL_64)
do
if a_upper = 0 then
active_range := [{NATURAL_64} 1, {NATURAL_64} 0]
elseif a_lower > 0 and a_lower <= a_upper then
active_range := [a_lower, a_upper]
else
active_range := Void
end
ensure
valid_range: attached active_range as rg implies (rg.upper = 0 or else rg.lower <= rg.upper)
end
feature -- Access
template: URI_TEMPLATE
lower: NATURAL_64
upper: NATURAL_64
step: NATURAL_64
active_range: detachable TUPLE [lower_index, upper_index: NATURAL_64]
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
local
l_step: INTEGER
nb: INTEGER
curr: INTEGER
n, i: INTEGER
tb: HASH_TABLE [detachable ANY, STRING_8]
do
create Result.make (32)
Result.append ("<div")
Result.append_character ('>')
nb := ((upper - lower) // step).to_integer_32 + 1
if attached active_range as rg then
if rg.upper_index = 0 then
-- all
else
curr := ((rg.lower_index - lower) // step).to_integer_32
if step * curr.to_natural_64 < rg.lower_index then
curr := curr + 1
end
end
end
l_step := step.to_integer_32
create tb.make (2)
tb.force (1, "lower")
tb.force (step, "upper")
if curr > 1 then
if curr > 2 then
tb.force (1, "lower")
tb.force (l_step, "upper")
Result.append_character (' ')
Result.append (a_theme.link ("<<", template.expanded_string (tb), Void))
Result.append_character (' ')
end
tb.force ((curr - 1) * l_step + 1, "lower")
tb.force ((curr ) * l_step , "upper")
Result.append_character (' ')
Result.append (a_theme.link ("<", template.expanded_string (tb), Void))
Result.append_character (' ')
end
from
i := (curr - 1).max (1)
n := 5
until
n = 0 or i > nb
loop
Result.append_character (' ')
tb.force ((i - 1) * l_step + 1, "lower")
tb.force ((i ) * l_step , "upper")
if i = curr then
Result.append ("<strong>")
end
Result.append (a_theme.link (i.out, template.expanded_string (tb), Void))
if i = curr then
Result.append ("</strong>")
end
Result.append_character (' ')
i := i + 1
n := n - 1
end
if curr < nb then
Result.append_character (' ')
tb.force ((curr ) * l_step + 1, "lower")
tb.force ((curr + 1) * l_step , "upper")
Result.append (a_theme.link (">", template.expanded_string (tb), Void))
Result.append_character (' ')
if curr + 1 < nb then
tb.force ((nb - 1) * l_step + 1, "lower")
tb.force ( upper , "upper")
Result.append_character (' ')
Result.append (a_theme.link (">>", template.expanded_string (tb), Void))
Result.append_character (' ')
end
end
Result.append ("</div>")
Result.append ("curr=" + curr.out +" step=" + step.out + " nb=" + nb.out)
end
end

Some files were not shown because too many files have changed in this diff Show More