From e7b8f398f70a958136b25028099b99c69f5d54a8 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 28 Feb 2013 19:36:09 +0100 Subject: [PATCH 1/3] improved CMS_CSS_STYLE and WITH_CSS_STYLE --- .../cms/src/kernel/cms_css_style.e | 67 +++++++++++++++++-- .../cms/src/kernel/form/with_css_style.e | 16 ++++- 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/draft/application/cms/src/kernel/cms_css_style.e b/draft/application/cms/src/kernel/cms_css_style.e index b0be7d53..d0bd4c05 100644 --- a/draft/application/cms/src/kernel/cms_css_style.e +++ b/draft/application/cms/src/kernel/cms_css_style.e @@ -7,26 +7,81 @@ note class CMS_CSS_STYLE +inherit + ITERABLE [READABLE_STRING_8] + create make, - make_from_string + make_with_string, + make_with_items convert - make_from_string ({READABLE_STRING_8, STRING_8}) + make_with_string ({READABLE_STRING_8, STRING_8}) feature {NONE} -- Initialization make do - create {ARRAYED_LIST [READABLE_STRING_8]} items.make (3) + make_with_items (create {like items}.make (3)) end - make_from_string (s: READABLE_STRING_8) + make_with_string (s: READABLE_STRING_8) do - items := s.split (';') + make_with_items (s.split (';')) end - items: LIST [READABLE_STRING_8] + make_with_items (lst: ITERABLE [READABLE_STRING_8]) + do + create items.make (5) + across + lst as c + loop + if attached {IMMUTABLE_STRING_8} c.item as imm then + items.force (imm) + else + items.force (create {IMMUTABLE_STRING_8}.make_from_string (c.item)) + end + end + end + + items: ARRAYED_LIST [IMMUTABLE_STRING_8] + +feature -- Access + + count: INTEGER + -- Count of style entities. + + new_cursor: ITERATION_CURSOR [READABLE_STRING_8] + do + Result := items.new_cursor + end + +feature -- Element change + + plus alias "+" (a_other: CMS_CSS_STYLE): like Current + -- + local + lst: ARRAYED_LIST [READABLE_STRING_8] + do + create lst.make (count + a_other.count) + lst.append (items) + across + a_other as c + loop + lst.force (c.item) + end + create Result.make_with_items (lst) + end + + append (a_other: CMS_CSS_STYLE) + -- Append style from `a_other' into Current + do + across + a_other as c + loop + items.force (c.item) + end + end feature -- Change diff --git a/draft/application/cms/src/kernel/form/with_css_style.e b/draft/application/cms/src/kernel/form/with_css_style.e index 6641b3ef..da2c9e17 100644 --- a/draft/application/cms/src/kernel/form/with_css_style.e +++ b/draft/application/cms/src/kernel/form/with_css_style.e @@ -12,9 +12,21 @@ feature -- Status report feature -- Change - set_css_style (a_style: like css_style) + reset_css_style do - css_style := a_style + css_style := Void + end + + add_css_style (a_style: like css_style) + local + s: like css_style + do + s := css_style + if s = Void then + css_style := a_style + elseif a_style /= Void then + css_style := s + a_style + end end feature -- Conversion From 5dd6079fad7f03c529d70239d67b4335765700ea Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 28 Feb 2013 19:36:30 +0100 Subject: [PATCH 2/3] add CMS_WIDGET_... to ease html page development. --- .../application/cms/src/widgets/cms_widget.e | 16 ++ .../cms/src/widgets/cms_widget_table.e | 177 ++++++++++++++++++ .../cms/src/widgets/cms_widget_table_column.e | 52 +++++ .../cms/src/widgets/cms_widget_table_item.e | 49 +++++ .../cms/src/widgets/cms_widget_table_row.e | 75 ++++++++ .../cms/src/widgets/cms_widget_text.e | 41 ++++ 6 files changed, 410 insertions(+) create mode 100644 draft/application/cms/src/widgets/cms_widget.e create mode 100644 draft/application/cms/src/widgets/cms_widget_table.e create mode 100644 draft/application/cms/src/widgets/cms_widget_table_column.e create mode 100644 draft/application/cms/src/widgets/cms_widget_table_item.e create mode 100644 draft/application/cms/src/widgets/cms_widget_table_row.e create mode 100644 draft/application/cms/src/widgets/cms_widget_text.e diff --git a/draft/application/cms/src/widgets/cms_widget.e b/draft/application/cms/src/widgets/cms_widget.e new file mode 100644 index 00000000..7566ab3c --- /dev/null +++ b/draft/application/cms/src/widgets/cms_widget.e @@ -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 diff --git a/draft/application/cms/src/widgets/cms_widget_table.e b/draft/application/cms/src/widgets/cms_widget_table.e new file mode 100644 index 00000000..26e8eef5 --- /dev/null +++ b/draft/application/cms/src/widgets/cms_widget_table.e @@ -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 ("") + + if has_title then + a_html.append ("") + across + columns as c + loop + c.item.append_table_header_to_html (a_theme, a_html) + end + a_html.append ("") + end + if attached head_data as l_head_data then + l_use_tbody := True + a_html.append ("") + append_data_to_html (l_head_data, a_theme, a_html) + a_html.append ("") + end + if attached foot_data as l_foot_data then + l_use_tbody := True + a_html.append ("") + append_data_to_html (l_foot_data, a_theme, a_html) + a_html.append ("") + end + + if attached data as l_data then + if l_use_tbody then + a_html.append ("") + end + append_data_to_html (l_data, a_theme, a_html) + if l_use_tbody then + a_html.append ("") + end + end + a_html.append ("") + 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 ("") + a_html.append ("") + if attached d.item as g then + a_html.append (g.out) + end + a_html.append ("") + a_html.append ("") + end + end + end + +end diff --git a/draft/application/cms/src/widgets/cms_widget_table_column.e b/draft/application/cms/src/widgets/cms_widget_table_column.e new file mode 100644 index 00000000..3e1da973 --- /dev/null +++ b/draft/application/cms/src/widgets/cms_widget_table_column.e @@ -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 ("') + if attached title as l_title then + a_html.append (a_theme.html_encoded (l_title)) + end + a_html.append ("") + end + +end diff --git a/draft/application/cms/src/widgets/cms_widget_table_item.e b/draft/application/cms/src/widgets/cms_widget_table_item.e new file mode 100644 index 00000000..6939c846 --- /dev/null +++ b/draft/application/cms/src/widgets/cms_widget_table_item.e @@ -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 ("') + content.append_to_html (a_theme, a_html) + a_html.append ("") + end + +end diff --git a/draft/application/cms/src/widgets/cms_widget_table_row.e b/draft/application/cms/src/widgets/cms_widget_table_row.e new file mode 100644 index 00000000..f01d2da2 --- /dev/null +++ b/draft/application/cms/src/widgets/cms_widget_table_row.e @@ -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 ("') + across + items as c + loop + c.item.append_to_html (a_theme, a_html) + end + a_html.append ("") + end + +end diff --git a/draft/application/cms/src/widgets/cms_widget_text.e b/draft/application/cms/src/widgets/cms_widget_text.e new file mode 100644 index 00000000..3d565e53 --- /dev/null +++ b/draft/application/cms/src/widgets/cms_widget_text.e @@ -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 From ce7be6ea34776ae70c489a5afa53cf49c89e1708 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 28 Feb 2013 19:37:06 +0100 Subject: [PATCH 3/3] added CMS widgets demonstration in DEMO_MODULE --- .../cms/example/src/module/demo/demo_module.e | 23 ++++- .../module/demo/demo_widget_cms_execution.e | 97 +++++++++++++++++++ 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 draft/application/cms/example/src/module/demo/demo_widget_cms_execution.e diff --git a/draft/application/cms/example/src/module/demo/demo_module.e b/draft/application/cms/example/src/module/demo/demo_module.e index 685a310d..5edae43e 100644 --- a/draft/application/cms/example/src/module/demo/demo_module.e +++ b/draft/application/cms/example/src/module/demo/demo_module.e @@ -10,6 +10,10 @@ class inherit CMS_MODULE + CMS_HOOK_MENU_ALTER + + CMS_HOOK_AUTO_REGISTER + create make @@ -30,19 +34,29 @@ feature {CMS_SERVICE} -- Registration register (a_service: CMS_SERVICE) do service := a_service + a_service.map_uri_template ("/demo/widget{/args}", agent handle_widget_demo (a_service, ?, ?)) a_service.map_uri_template ("/demo/date/{arg}", agent handle_date_time_demo (a_service, ?, ?)) a_service.map_uri_template ("/demo/format/{arg}", agent handle_format_demo (a_service, ?, ?)) end + menu_alter (a_menu_system: CMS_MENU_SYSTEM; a_execution: CMS_EXECUTION) + local + lnk: CMS_LOCAL_LINK +-- opts: CMS_API_OPTIONS + do + create lnk.make ("Demo::widget", "/demo/widget/") + a_menu_system.management_menu.extend (lnk) + end + feature -- Hooks links: HASH_TABLE [CMS_MODULE_LINK, STRING] -- Link indexed by path local --- lnk: CMS_MODULE_LINK + lnk: CMS_MODULE_LINK do create Result.make (0) --- create lnk.make ("Date/time demo") + create lnk.make ("Date/time demo") -- lnk.set_callback (agent process_date_time_demo, <<"arg">>) -- Result["/demo/date/{arg}"] := lnk end @@ -57,4 +71,9 @@ feature -- Hooks (create {ANY_CMS_EXECUTION}.make_with_text (req, res, cms, "

Demo::format

")).execute end + handle_widget_demo (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE) + do + (create {DEMO_WIDGET_CMS_EXECUTION}.make (req, res, cms)).execute + end + end diff --git a/draft/application/cms/example/src/module/demo/demo_widget_cms_execution.e b/draft/application/cms/example/src/module/demo/demo_widget_cms_execution.e new file mode 100644 index 00000000..d808bfe2 --- /dev/null +++ b/draft/application/cms/example/src/module/demo/demo_widget_cms_execution.e @@ -0,0 +1,97 @@ +note + description : "Objects that ..." + author : "$Author$" + date : "$Date$" + revision : "$Revision$" + +class + DEMO_WIDGET_CMS_EXECUTION + +inherit + CMS_EXECUTION + +create + make + +feature -- Execution + + process + local + args: like arguments + l_table: like new_table + s: STRING + do + args := arguments + if args.is_empty then + set_title ("Widgets") + set_main_content ("...") + else + + end + l_table := new_table + + create s.make_empty + l_table.append_to_html (theme, s) + set_main_content (s) + end + + new_table: CMS_WIDGET_TABLE [READABLE_STRING_8] + local + l_table: CMS_WIDGET_TABLE [READABLE_STRING_8] + do + create l_table.make + l_table.add_css_style ("width: 85%%; border: solid 1px #999; padding: 2px;") + + l_table.set_column_count (3) + l_table.column (1).set_title ("First") + l_table.column (2).set_title ("Second") + l_table.column (3).set_title ("Third") + + l_table.column (1).add_css_style ("width: 20%%") + l_table.column (2).add_css_style ("width: 40px") + l_table.column (3).add_css_style ("width: 40px") + + l_table.set_data (<<"foo", "bar", "foobar">>) + l_table.set_foot_data (<<"abc", "def">>) + l_table.set_compute_item_function (agent (d: READABLE_STRING_8): CMS_WIDGET_TABLE_ROW + local + i: INTEGER + w: CMS_WIDGET_TABLE_ITEM + do + create Result.make (d.count) + if d.is_case_insensitive_equal ("bar") then + Result.add_css_style ("background-color: #ccf;") + end + across + d as c + loop + i := i + 1 + create w.make_with_text (c.item.out) + if i = 1 then + w.add_css_style ("background-color: #333; color: white; font-weight: bold;") + elseif i > 3 then + w.add_css_style ("color: red; border: solid 1px red; padding: 3px;") + end + Result.force (w) + end + end) + + Result := l_table + end + + arguments: ARRAY [READABLE_STRING_32] + -- Path parameters arguments related to {/vars} + do + if + attached {WSF_TABLE} request.path_parameter ("args") as lst and then + attached lst.as_array_of_string as arr + then + Result := arr + else + create Result.make_empty + end + + Result.rebase (1) + end + +end