add CMS_WIDGET_... to ease html page development.

This commit is contained in:
Jocelyn Fiat
2013-02-28 19:36:30 +01:00
parent e7b8f398f7
commit 5dd6079fad
6 changed files with 410 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
note
description: "Summary description for {CMS_WIDGET}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_WIDGET
feature -- Conversion
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
deferred
end
end

View File

@@ -0,0 +1,177 @@
note
description: "Summary description for {CMS_WIDGET_TABLE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_WIDGET_TABLE [G]
inherit
CMS_WIDGET
WITH_CSS_ID
WITH_CSS_CLASS
WITH_CSS_STYLE
create
make
feature {NONE} -- Initialization
make
do
create columns.make_empty
end
feature -- Access
column_count: INTEGER
do
Result := columns.count
end
columns: ARRAY [CMS_WIDGET_TABLE_COLUMN]
column (c: INTEGER): CMS_WIDGET_TABLE_COLUMN
do
if c > column_count then
set_column_count (c)
end
Result := columns[c]
end
has_title: BOOLEAN
do
Result := across columns as c some c.item.title /= Void end
end
head_data: detachable ITERABLE [G]
-- thead
foot_data: detachable ITERABLE [G]
-- tfoot
data: detachable ITERABLE [G]
-- tbody
compute_item_function: detachable FUNCTION [ANY, TUPLE [data: G], CMS_WIDGET_TABLE_ROW]
feature -- Change
set_head_data (d: like head_data)
do
head_data := d
end
set_foot_data (d: like foot_data)
do
foot_data := d
end
set_data (d: like data)
do
data := d
end
set_compute_item_function (fct: like compute_item_function)
do
compute_item_function := fct
end
set_column_count (nb: INTEGER)
do
if nb > columns.count then
-- columns.conservative_resize_with_default (create {CMS_WIDGET_TABLE_COLUMN}, 1, nb)
from
until
columns.count = nb
loop
columns.force (create {CMS_WIDGET_TABLE_COLUMN}.make (columns.upper + 1), columns.upper + 1)
end
else
columns.remove_tail (columns.count - nb)
end
end
set_column_title (c: INTEGER; t: READABLE_STRING_32)
do
if c > column_count then
set_column_count (c)
end
if attached column (c) as col then
col.set_title (t)
end
end
feature -- Conversion
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
local
l_use_tbody: BOOLEAN
do
a_html.append ("<table")
append_css_id_to (a_html)
append_css_class_to (a_html, Void)
append_css_style_to (a_html)
a_html.append (">")
if has_title then
a_html.append ("<tr>")
across
columns as c
loop
c.item.append_table_header_to_html (a_theme, a_html)
end
a_html.append ("</tr>")
end
if attached head_data as l_head_data then
l_use_tbody := True
a_html.append ("<thead>")
append_data_to_html (l_head_data, a_theme, a_html)
a_html.append ("</thead>")
end
if attached foot_data as l_foot_data then
l_use_tbody := True
a_html.append ("<tfoot>")
append_data_to_html (l_foot_data, a_theme, a_html)
a_html.append ("</tfoot>")
end
if attached data as l_data then
if l_use_tbody then
a_html.append ("<tbody>")
end
append_data_to_html (l_data, a_theme, a_html)
if l_use_tbody then
a_html.append ("</tbody>")
end
end
a_html.append ("</table>")
end
append_data_to_html (lst: ITERABLE [G]; a_theme: CMS_THEME; a_html: STRING_8)
local
fct: like compute_item_function
do
fct := compute_item_function
across
lst as d
loop
if fct /= Void and then attached fct.item ([d.item]) as r then
r.append_to_html (a_theme, a_html)
else
a_html.append ("<tr>")
a_html.append ("<td>")
if attached d.item as g then
a_html.append (g.out)
end
a_html.append ("</td>")
a_html.append ("</tr>")
end
end
end
end

View File

@@ -0,0 +1,52 @@
note
description: "Summary description for {CMS_WIDGET_COLUMN}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_WIDGET_TABLE_COLUMN
inherit
WITH_CSS_CLASS
WITH_CSS_STYLE
create
make
feature {NONE} -- Initialization
make (i: like index)
do
index := i
end
feature -- Access
index: INTEGER
title: detachable READABLE_STRING_32
feature -- Change
set_title (t: like title)
do
title := t
end
feature -- Conversion
append_table_header_to_html (a_theme: CMS_THEME; a_html: STRING_8)
do
a_html.append ("<th")
append_css_class_to (a_html, Void)
append_css_style_to (a_html)
a_html.append_character ('>')
if attached title as l_title then
a_html.append (a_theme.html_encoded (l_title))
end
a_html.append ("</th>")
end
end

View File

@@ -0,0 +1,49 @@
note
description: "Summary description for {CMS_WIDGET_TABLE_ITEM}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_WIDGET_TABLE_ITEM
inherit
CMS_WIDGET
WITH_CSS_CLASS
WITH_CSS_STYLE
create
make_with_text,
make_with_content
feature {NONE} -- Initialization
make_with_text (a_text: READABLE_STRING_8)
do
make_with_content (create {CMS_WIDGET_TEXT}.make_with_text (a_text))
end
make_with_content (a_widget: CMS_WIDGET)
do
content := a_widget
end
feature -- Access
content: CMS_WIDGET
feature -- Conversion
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
do
a_html.append ("<td")
append_css_class_to (a_html, Void)
append_css_style_to (a_html)
a_html.append_character ('>')
content.append_to_html (a_theme, a_html)
a_html.append ("</td>")
end
end

View File

@@ -0,0 +1,75 @@
note
description: "Summary description for {CMS_WIDGET_TABLE_ROW}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_WIDGET_TABLE_ROW
inherit
WITH_CSS_CLASS
WITH_CSS_STYLE
ITERABLE [CMS_WIDGET_TABLE_ITEM]
create
make,
make_with_items
feature {NONE} -- Initialization
make (n: INTEGER)
do
create items.make (n)
end
make_with_items (lst: ITERABLE [CMS_WIDGET_TABLE_ITEM])
local
n: INTEGER
do
across lst as c loop
n := n + 1
end
make (n)
across
lst as c
loop
add_item (c.item)
end
end
items: ARRAYED_LIST [CMS_WIDGET_TABLE_ITEM]
feature -- Access
new_cursor: ITERATION_CURSOR [CMS_WIDGET_TABLE_ITEM]
do
Result := items.new_cursor
end
feature -- Change
force, add_item (w: CMS_WIDGET_TABLE_ITEM)
do
items.force (w)
end
feature -- Conversion
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
do
a_html.append ("<tr")
append_css_class_to (a_html, Void)
append_css_style_to (a_html)
a_html.append_character ('>')
across
items as c
loop
c.item.append_to_html (a_theme, a_html)
end
a_html.append ("</tr>")
end
end

View File

@@ -0,0 +1,41 @@
note
description: "Summary description for {CMS_WIDGET_TEXT}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_WIDGET_TEXT
inherit
CMS_WIDGET
create
make_with_text
feature {NONE} -- Initialization
make_with_text (a_text: READABLE_STRING_8)
do
text := a_text
end
feature -- Access
text: READABLE_STRING_8
feature -- Change
set_text (a_text: like text)
do
text := a_text
end
feature -- Conversion
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
do
a_html.append (text)
end
end