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

@@ -0,0 +1,32 @@
note
description: "Summary description for {CMS_BLOCK}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_BLOCK
feature -- Access
name: READABLE_STRING_8
deferred
end
title: detachable READABLE_STRING_32
deferred
end
feature -- status report
is_enabled: BOOLEAN
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
deferred
end
invariant
end

View File

@@ -0,0 +1,46 @@
note
description: "Summary description for {CMS_CONTENT_BLOCK}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_CONTENT_BLOCK
inherit
CMS_BLOCK
create
make
feature {NONE} -- Initialization
make (a_name: like name; a_title: like title; a_body: like body; a_format: like format)
do
is_enabled := True
name := a_name
title := a_title
body := a_body
format := a_format
end
feature -- Access
name: READABLE_STRING_8
title: detachable READABLE_STRING_32
body: READABLE_STRING_8
format: CMS_FORMAT
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
do
Result := format.to_html (body)
end
invariant
end

View File

@@ -0,0 +1,60 @@
note
description: "Summary description for {CMS_CONTENT_TYPE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_CONTENT_TYPE
feature -- Access
name: READABLE_STRING_8
-- Internal name
deferred
end
title: READABLE_STRING_8
deferred
end
description: detachable READABLE_STRING_8
-- Optional description
deferred
end
available_formats: LIST [CMS_FORMAT]
deferred
end
feature -- Factory
fill_edit_form (f: CMS_FORM; a_node: detachable CMS_NODE)
-- Fill the edit form `f'
deferred
end
change_node (a_execution: CMS_EXECUTION; a_form_data: CMS_FORM_DATA; a_node: like new_node)
-- Apply data from `a_form_data' to a_node
require
a_node.has_id
deferred
end
new_node (a_execution: CMS_EXECUTION; a_form_data: CMS_FORM_DATA; a_node: detachable like new_node): CMS_NODE
-- New content created with `a_form_data'
deferred
ensure
a_node /= Void implies a_node = Result
end
feature {NONE} -- Implementation: helper
formats: CMS_FORMATS
once
create Result
end
invariant
end

View File

@@ -0,0 +1,45 @@
note
description: "Summary description for {CMS_MENU_BLOCK}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_MENU_BLOCK
inherit
CMS_BLOCK
create
make
feature {NONE} -- Initialization
make (a_menu: like menu)
do
is_enabled := True
menu := a_menu
name := a_menu.name
title := a_menu.title
end
feature -- Access
menu: CMS_MENU
name: READABLE_STRING_8
title: detachable READABLE_STRING_32
is_horizontal: BOOLEAN
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
do
Result := a_theme.menu_html (menu, is_horizontal)
end
invariant
end

View File

@@ -0,0 +1,101 @@
note
description: "Summary description for {WSF_CMS_NODE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_NODE
feature -- Access
id: INTEGER
-- Unique identifier of Current.
title: detachable READABLE_STRING_32
-- Associated title (optional).
deferred
end
body: detachable READABLE_STRING_8
-- Body of Current.
deferred
end
format: CMS_FORMAT
-- Format associated with `body'
deferred
end
content_type_name: STRING
-- Associated content type name
deferred
end
feature -- status report
has_id: BOOLEAN
do
Result := id > 0
end
feature -- Access: status
author: detachable CMS_USER
creation_date: DATE_TIME
modification_date: DATE_TIME
feature -- Change
set_id (a_id: like id)
require
not has_id
do
id := a_id
end
set_author (u: like author)
do
author := u
end
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
local
d: STRING
do
Result := "<div class=%"node " + content_type_name + "%" id=%"nid-" + id.out + "%">"
if attached title as l_title then
Result.append ("<div class=%"title%">" + a_theme.node_link (Current) + "</div>")
end
create d.make_empty
if attached author as u then
d.append ("by " + a_theme.user_link (u) + " ")
end
if attached modification_date as dt then
d.append ("last modified: " + dt.year.out + "/" + dt.month.out + "/" + dt.day.out + "")
end
if not d.is_empty then
Result.append ("<div class=%"description%">")
Result.append (d)
Result.append ("</div>")
end
if attached body as b then
Result.append ("<div class=%"inner%">")
Result.append (format.to_html (b))
Result.append ("</div>")
end
Result.append ("</div>")
end
feature {NONE} -- Implementation: helper
formats: CMS_FORMATS
once
create Result
end
end

View File

@@ -0,0 +1,44 @@
note
description : "[
Filtered html format
]"
date : "$Date$"
revision : "$Revision$"
class
CMS_FILTERED_HTML_FORMAT
inherit
CMS_FORMAT
redefine
default_create
end
feature {NONE} -- Initialization
default_create
do
Precursor
create filters.make (3)
filters.force (create {CMS_URL_FILTER})
filters.force (create {CMS_HTML_FILTER})
filters.force (create {CMS_LINE_BREAK_CONVERTER_FILTER})
-- help := "<ul><li>Web page addresses and e-mail addresses turn into links automatically.</li><li>Allowed HTML tags: "
-- across
-- allowed_html_tags as c
-- loop
-- help.append ("&lt;" + c.item + "&gt; ")
-- end
-- help.append ("</li><li>Lines and paragraphs break automatically.</li></ul>")
end
feature -- Access
name: STRING = "filtered_html"
title: STRING_8 = "Filtered HTML"
filters: ARRAYED_LIST [CMS_FILTER]
end

View File

@@ -0,0 +1,46 @@
note
description: "Summary description for {WSF_CMS_FORMAT}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_FORMAT
feature -- Access
name: STRING
deferred
end
title: READABLE_STRING_8
deferred
end
help: STRING
do
create Result.make (0)
across
filters as c
loop
if attached c.item.help as h and then not h.is_empty then
Result.append ("<li>" + h + "</li>")
end
end
end
filters: LIST [CMS_FILTER]
deferred
end
to_html (a_text: READABLE_STRING_8): STRING_8
do
create Result.make_from_string (a_text)
across
filters as c
loop
c.item.filter (Result)
end
end
end

View File

@@ -0,0 +1,54 @@
note
description: "Summary description for {CMS_FORMATS}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_FORMATS
feature -- Access
format (a_name: like {CMS_FORMAT}.name): detachable CMS_FORMAT
do
across
all_formats as c
until
Result /= Void
loop
if c.item.name.same_string (a_name) then
Result := c.item
end
end
end
all_formats: LIST [CMS_FORMAT]
once
create {ARRAYED_LIST [CMS_FORMAT]} Result.make (3)
Result.force (plain_text)
Result.force (full_html)
Result.force (filtered_html)
end
default_format: CMS_FORMAT
do
Result := plain_text --FIXME
end
plain_text: CMS_PLAIN_TEXT_FORMAT
once
create Result
end
full_html: CMS_FULL_HTML_FORMAT
once
create Result
end
filtered_html: CMS_FILTERED_HTML_FORMAT
once
create Result
end
end

View File

@@ -0,0 +1,35 @@
note
description : "[
Full html format
]"
date : "$Date$"
revision : "$Revision$"
class
CMS_FULL_HTML_FORMAT
inherit
CMS_FORMAT
redefine
default_create
end
feature {NONE} -- Initialization
default_create
do
Precursor
create filters.make (2)
filters.force (create {CMS_URL_FILTER})
filters.force (create {CMS_LINE_BREAK_CONVERTER_FILTER})
end
feature -- Access
name: STRING = "full_html"
title: STRING_8 = "Full HTML"
filters: ARRAYED_LIST [CMS_FILTER]
end

View File

@@ -0,0 +1,49 @@
note
description : "[
Plain Text format
]"
date : "$Date$"
revision : "$Revision$"
class
CMS_PLAIN_TEXT_FORMAT
inherit
CMS_FORMAT
redefine
default_create,
help
end
feature {NONE} -- Initialization
default_create
do
Precursor
create filters.make (2)
filters.force (create {CMS_HTML_TO_TEXT_FILTER})
filters.force (create {CMS_LINE_BREAK_CONVERTER_FILTER})
end
feature -- Access
name: STRING = "plain_text"
title: STRING_8 = "Plain text"
help: STRING
do
Result := "<li>No HTML tags allowed.</li>"
Result.append (Precursor)
end
-- <ul>
-- <li>No HTML tags allowed.</li>
-- <li>Web page addresses and e-mail addresses turn into links automatically.</li>
-- <li>Lines and paragraphs break automatically.</li>
-- </ul>
-- ]"
filters: ARRAYED_LIST [CMS_FILTER]
end

View File

@@ -0,0 +1,35 @@
note
description: "Summary description for {CMS_FILTER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_FILTER
feature -- Access
name: READABLE_STRING_8
deferred
end
title: READABLE_STRING_8
deferred
end
description: READABLE_STRING_8
deferred
end
help: READABLE_STRING_8
do
Result := description
end
feature -- Conversion
filter (s: STRING_8)
deferred
end
end

View File

@@ -0,0 +1,126 @@
note
description: "Summary description for {CMS_HTML_FILTER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_HTML_FILTER
inherit
CMS_FILTER
redefine
default_create
end
feature {NONE} -- Initialization
default_create
do
Precursor
allowed_html_tags := <<"a", "em", "strong", "cite", "blockquote", "code", "ul", "ol", "li", "dl">>
description := "Allowed HTML tags: "
across
allowed_html_tags as c
loop
description.append ("&lt;" + c.item + "&gt; ")
end
end
feature -- Access
name: STRING_8 = "html_filter"
title: STRING_8 = "HTML filter"
description: STRING_8
allowed_html_tags: ITERABLE [READABLE_STRING_8]
feature -- Conversion
filter (a_text: STRING_8)
local
l_new: STRING_8
i: INTEGER
n: INTEGER
in_tag: BOOLEAN
p1, p2: INTEGER
do
create l_new.make (a_text.count)
from
p1 := 1
i := a_text.index_of ('<', 1)
if i > 0 then
l_new.append (a_text.substring (1, i - 1))
end
n := a_text.count
until
i = 0 or i > n
loop
if a_text[i] = '<' then
in_tag := True
p1 := i
p2 := a_text.index_of ('>', i + 1)
if p2 = 0 then
-- next '<'
i := a_text.index_of ('<', i + 1)
if i > 0 then
l_new.append (a_text.substring (p1, i - 1))
end
else
if is_authorized (a_text.substring (p1, p2)) then
l_new.append (a_text.substring (p1, p2))
i := a_text.index_of ('<', p2 + 1)
else
i := a_text.index_of ('<', p2 + 1)
end
if i > 0 then
l_new.append (a_text.substring (p2 + 1, i - 1))
end
end
else
i := i + 1
end
end
l_new.append (a_text.substring (p1, n))
a_text.wipe_out
a_text.append (l_new)
end
is_authorized (s: READABLE_STRING_8): BOOLEAN
-- Is `s' authorized?
--| `s' has either "<....>" or "<..../>" or "</.....>"
local
l_tagname: detachable STRING
i,n,p1: INTEGER
do
-- create l_tagname.make_empty
from
i := 2 -- skip first '<'
n := s.count
until
i > n or l_tagname /= Void
loop
if p1 > 0 then
if s[i].is_space or s[i] = '/' or s[i] = '>' then
l_tagname := s.substring (p1, i - 1)
end
else
if s[i].is_space or s[i] = '/' then
else
p1 := i
end
end
i := i + 1
end
if l_tagname /= Void then
l_tagname.to_lower
Result := across allowed_html_tags as c some c.item.same_string (l_tagname) end
else
Result := True
end
end
end

View File

@@ -0,0 +1,34 @@
note
description: "Summary description for {CMS_HTML_TO_TEXT_FILTER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_HTML_TO_TEXT_FILTER
inherit
CMS_FILTER
feature -- Access
name: STRING_8 = "html_to_text"
title: STRING_8 = "HTML to text"
description: STRING_8 = "Replaces HTML tags and entities with plain text formatting, moving links at the end. This filter is just for text messages and it isn't safe for rendering content on a web page."
feature -- Conversion
filter (a_text: STRING_8)
local
enc: HTML_ENCODER
s: STRING_8
do
create enc
s := enc.encoded_string (a_text)
a_text.wipe_out
a_text.append (s)
end
end

View File

@@ -0,0 +1,34 @@
note
description: "Summary description for {CMS_HTML_FILTER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_LINE_BREAK_CONVERTER_FILTER
inherit
CMS_FILTER
redefine
help
end
feature -- Access
name: STRING_8 = "line_break_converter"
title: STRING_8 = "Line break converter"
help: STRING = "Lines and paragraphs break automatically"
description: STRING_8 = "Converts line breaks into HTML (i.e. &lt;br&gt; and &lt;p&gt; tags)."
feature -- Conversion
filter (a_text: STRING_8)
do
a_text.replace_substring_all ("%N", "<br/>%N")
-- FIXME jfiat [2012/09/12] :also use <p> ...
end
end

View File

@@ -0,0 +1,77 @@
note
description: "Summary description for {CMS_NO_HTML_FILTER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_NO_HTML_FILTER
inherit
CMS_FILTER
redefine
default_create
end
feature {NONE} -- Initialization
default_create
do
Precursor
end
feature -- Access
name: STRING_8 = "no_html_filter"
title: STRING_8 = "No HTML filter"
description: STRING_8 = "HTML tags removed! "
feature -- Conversion
filter (a_text: STRING_8)
local
l_new: STRING_8
i: INTEGER
n: INTEGER
in_tag: BOOLEAN
p1, p2: INTEGER
do
create l_new.make (a_text.count)
from
p1 := 1
i := a_text.index_of ('<', 1)
if i > 0 then
l_new.append (a_text.substring (1, i - 1))
end
n := a_text.count
until
i = 0 or i > n
loop
if a_text[i] = '<' then
in_tag := True
p1 := i
p2 := a_text.index_of ('>', i + 1)
if p2 = 0 then
-- next '<'
i := a_text.index_of ('<', i + 1)
if i > 0 then
l_new.append (a_text.substring (p1, i - 1))
end
else
i := a_text.index_of ('<', p2 + 1)
if i > 0 then
l_new.append (a_text.substring (p2 + 1, i - 1))
end
end
else
i := i + 1
end
end
l_new.append (a_text.substring (p1, n))
a_text.wipe_out
a_text.append (l_new)
end
end

View File

@@ -0,0 +1,33 @@
note
description: "Summary description for {CMS_URL_FILTER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_URL_FILTER
inherit
CMS_FILTER
redefine
help
end
feature -- Access
name: STRING_8 = "url"
title: STRING_8 = "URL filter"
description: STRING_8 = "Turns web and e-mail addresses into clickable links."
help: STRING = "Web page addresses and e-mail addresses turn into links automatically."
feature -- Conversion
filter (a_text: STRING_8)
do
--| FIXME jfiat [2012/09/12] : todo
end
end