Use append_to_html rather than function to_html: STRING

this is mainly to avoid creating useless intermediary strings.
This commit is contained in:
Jocelyn Fiat
2013-02-26 12:22:53 +01:00
parent b543a6b6f2
commit 0902eef91c
17 changed files with 118 additions and 102 deletions

View File

@@ -210,11 +210,11 @@ feature -- Change
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
local
s: STRING
s: STRING_8
do
Result := "<form action=%""+ action +"%" id=%""+ id +"%" method=%""+ method +"%" "
a_html.append ("<form action=%""+ action +"%" id=%""+ id +"%" method=%""+ method +"%" ")
if not html_classes.is_empty then
create s.make_empty
across
@@ -225,15 +225,21 @@ feature -- Conversion
end
s.append (cl.item)
end
Result.append (" class=%"" + s + "%" ")
a_html.append (" class=%"" + s + "%" ")
end
Result.append (">%N")
a_html.append (">%N")
across
items as c
loop
Result.append (c.item.to_html (a_theme))
c.item.append_to_html (a_theme, a_html)
end
Result.append ("</form>%N")
a_html.append ("</form>%N")
end
to_html (a_theme: CMS_THEME): STRING_8
do
create Result.make_empty
append_to_html (a_theme, Result)
end
feature {NONE} -- Implementation

View File

@@ -14,7 +14,7 @@ inherit
redefine
set_value,
specific_input_attributes_string,
child_to_html
append_child_to_html
end
CMS_FORM_SELECTABLE_ITEM
@@ -83,16 +83,16 @@ feature -- Change
feature {NONE} -- Implementation
child_to_html (a_theme: CMS_THEME): detachable READABLE_STRING_8
append_child_to_html (a_theme: CMS_THEME; a_html: STRING_8)
-- Specific child element if any.
--| To redefine if needed
do
if attached raw_text as t then
Result := t
a_html.append (t)
elseif attached text as t then
Result := a_theme.html_encoded (t)
a_html.append (a_theme.html_encoded (t))
elseif attached value as v then
Result := a_theme.html_encoded (v)
a_html.append (a_theme.html_encoded (v))
end
end

View File

@@ -66,20 +66,20 @@ feature -- Change
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
do
Result := "<div"
append_css_class_to (Result, Void)
append_css_id_to (Result)
append_css_style_to (Result)
a_html.append ("<div")
append_css_class_to (a_html, Void)
append_css_id_to (a_html)
append_css_style_to (a_html)
Result.append (">%N")
a_html.append (">%N")
across
items as c
loop
Result.append (c.item.to_html (a_theme))
c.item.append_to_html (a_theme, a_html)
end
Result.append ("%N</div>%N")
a_html.append ("%N</div>%N")
end
feature {NONE} -- Implementation

View File

@@ -102,7 +102,7 @@ feature -- Element change
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
local
l_class_items: detachable ARRAYED_LIST [READABLE_STRING_8]
do
@@ -117,28 +117,28 @@ feature -- Conversion
l_class_items := Void
end
create Result.make_from_string ("<div")
append_css_class_to (Result, l_class_items)
Result.append_character ('>')
a_html.append ("<div")
append_css_class_to (a_html, l_class_items)
a_html.append_character ('>')
if attached label as lab then
Result.append ("<strong><label for=%"" + name + "%">" + lab + "</label></strong>")
a_html.append ("<strong><label for=%"" + name + "%">" + lab + "</label></strong>")
if is_required then
Result.append (" (<em>required</em>)")
a_html.append (" (<em>required</em>)")
end
Result.append ("<br/>%N")
a_html.append ("<br/>%N")
end
Result.append (item_to_html (a_theme))
append_item_to_html (a_theme, a_html)
if attached description as desc then
if is_description_collapsible then
Result.append ("<div class=%"description collapsible%"><div>Description ...</div><div>" + desc + "</div></div>")
a_html.append ("<div class=%"description collapsible%"><div>Description ...</div><div>" + desc + "</div></div>")
else
Result.append ("<div class=%"description%">" + desc + "</div>")
a_html.append ("<div class=%"description%">" + desc + "</div>")
end
end
Result.append ("</div>")
a_html.append ("</div>")
end
item_to_html (a_theme: CMS_THEME): STRING_8
append_item_to_html (a_theme: CMS_THEME; a_html: STRING_8)
deferred
end

View File

@@ -82,23 +82,23 @@ feature -- Change
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
do
Result := "<fieldset"
append_css_class_to (Result, Void)
append_css_id_to (Result)
append_css_style_to (Result)
a_html.append ("<fieldset")
append_css_class_to (a_html, Void)
append_css_id_to (a_html)
append_css_style_to (a_html)
Result.append (">%N")
a_html.append (">%N")
if attached legend as leg then
Result.append ("<legend>" + leg + "</legend>%N")
a_html.append ("<legend>" + leg + "</legend>%N")
end
across
items as c
loop
Result.append (c.item.to_html (a_theme))
c.item.append_to_html (a_theme, a_html)
end
Result.append ("%N</fieldset>%N")
a_html.append ("%N</fieldset>%N")
end
feature {NONE} -- Implementation

View File

@@ -11,7 +11,7 @@ inherit
CMS_FORM_INPUT
redefine
input_type,
item_to_html
append_item_to_html
end
create
@@ -27,11 +27,11 @@ feature -- Access
feature -- Conversion
item_to_html (a_theme: CMS_THEME): STRING_8
append_item_to_html (a_theme: CMS_THEME; a_html: STRING_8)
do
Result := "<div style=%"display:none%">"
Result.append (Precursor (a_theme))
Result.append ("</div>")
a_html.append ("<div style=%"display:none%">")
Precursor (a_theme, a_html)
a_html.append ("</div>")
end
end

View File

@@ -78,45 +78,50 @@ feature -- Element change
feature -- Conversion
item_to_html (a_theme: CMS_THEME): STRING_8
append_item_to_html (a_theme: CMS_THEME; a_html: STRING_8)
local
old_count: INTEGER
do
Result := "<input type=%""+ input_type +"%" name=%""+ name +"%""
append_css_class_to (Result, Void)
append_css_id_to (Result)
append_css_style_to (Result)
a_html.append ("<input type=%""+ input_type +"%" name=%""+ name +"%"")
append_css_class_to (a_html, Void)
append_css_id_to (a_html)
append_css_style_to (a_html)
if is_readonly then
Result.append (" readonly=%"readonly%"")
a_html.append (" readonly=%"readonly%"")
end
if attached default_value as dft then
Result.append (" value=%"" + a_theme.html_encoded (dft) + "%"")
a_html.append (" value=%"" + a_theme.html_encoded (dft) + "%"")
end
if disabled then
Result.append (" disabled=%"disabled%"")
a_html.append (" disabled=%"disabled%"")
end
if size > 0 then
Result.append (" size=%"" + size.out + "%"")
a_html.append (" size=%"" + size.out + "%"")
end
if maxlength > 0 then
Result.append (" maxlength=%"" + maxlength.out + "%"")
a_html.append (" maxlength=%"" + maxlength.out + "%"")
end
if attached specific_input_attributes_string as s then
Result.append_character (' ')
Result.append (s)
a_html.append_character (' ')
a_html.append (s)
end
if attached child_to_html (a_theme) as s then
Result.append (">")
Result.append (s)
Result.append ("</input>")
a_html.append (">")
old_count := a_html.count
append_child_to_html (a_theme, a_html)
if a_html.count > old_count then
a_html.append ("</input>")
else
Result.append ("/>")
check a_html.item (a_html.count) = '>' end
a_html.put ('/', a_html.count) -- replace previous '>'
a_html.append (">")
end
end
feature {NONE} -- Implementation
child_to_html (a_theme: CMS_THEME): detachable READABLE_STRING_8
append_child_to_html (a_theme: CMS_THEME; a_html: STRING_8)
-- Specific child element if any.
--| To redefine if needed
do

View File

@@ -14,8 +14,14 @@ inherit
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
deferred
end
to_html (a_theme: CMS_THEME): STRING_8
do
create Result.make_empty
append_to_html (a_theme, Result)
end
end

View File

@@ -10,7 +10,7 @@ class
inherit
CMS_FORM_ITEM
redefine
to_html
append_to_html
end
create
@@ -36,14 +36,14 @@ feature -- Element change
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8
append_to_html (a_theme: CMS_THEME; a_html: STRING_8)
do
Result := item_to_html (a_theme)
append_item_html_to (a_theme, a_html)
end
item_to_html (a_theme: CMS_THEME): STRING_8
append_item_html_to (a_theme: CMS_THEME; a_html: STRING_8)
do
Result := text
a_html.append (text)
end
end

View File

@@ -103,38 +103,38 @@ feature -- Element change
feature -- Conversion
item_to_html (a_theme: CMS_THEME): STRING_8
append_item_to_html (a_theme: CMS_THEME; a_html: STRING_8)
local
l_is_already_selected: BOOLEAN
h: detachable STRING_8
do
Result := "<select name=%""+ name +"%" "
a_html.append ("<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)
append_css_class_to (a_html, Void)
append_css_id_to (a_html)
append_css_style_to (a_html)
if is_readonly then
Result.append (" readonly=%"readonly%" />")
a_html.append (" readonly=%"readonly%" />")
else
Result.append ("/>")
a_html.append ("/>")
end
across
options as o
loop
Result.append ("<option value=%"" + o.item.value + "%" ")
a_html.append ("<option value=%"" + o.item.value + "%" ")
-- if not l_is_already_selected then
if
o.item.is_selected
then
l_is_already_selected := True
Result.append (" selected=%"selected%"")
a_html.append (" selected=%"selected%"")
end
-- end
Result.append (">" + o.item.text + "</option>%N")
a_html.append (">" + o.item.text + "</option>%N")
if attached o.item.description as d then
if h = Void then
create h.make_empty
@@ -142,9 +142,9 @@ feature -- Conversion
h.append ("<div id=%"" + name + "-" + o.item.value + "%" class=%"option%"><strong>"+ o.item.text +"</strong>:"+ d + "</div>")
end
end
Result.append ("</select>%N")
a_html.append ("</select>%N")
if h /= Void then
Result.append ("<div class=%"select help collapsible%" id=%"" + name + "-help%">" + h + "</div>%N")
a_html.append ("<div class=%"select help collapsible%" id=%"" + name + "-help%">" + h + "</div>%N")
end
end

View File

@@ -61,30 +61,29 @@ feature -- Element change
feature -- Conversion
item_to_html (a_theme: CMS_THEME): STRING_8
append_item_to_html (a_theme: CMS_THEME; a_html: STRING_8)
do
Result := "<textarea name=%""+ name +"%""
a_html.append ("<textarea name=%""+ name +"%"")
if rows > 0 then
Result.append (" rows=%"" + rows.out + "%"")
a_html.append (" rows=%"" + rows.out + "%"")
end
if cols > 0 then
Result.append (" cols=%"" + cols.out + "%"")
a_html.append (" cols=%"" + cols.out + "%"")
end
append_css_class_to (Result, Void)
append_css_id_to (Result)
append_css_style_to (Result)
append_css_class_to (a_html, Void)
append_css_id_to (a_html)
append_css_style_to (a_html)
if is_readonly then
Result.append (" readonly=%"readonly%">")
a_html.append (" readonly=%"readonly%">")
else
Result.append (">")
a_html.append (">")
end
if attached default_value as dft then
Result.append (a_theme.html_encoded (dft))
a_html.append (a_theme.html_encoded (dft))
end
Result.append ("</textarea>")
a_html.append ("</textarea>")
end
end

View File

@@ -82,7 +82,7 @@ feature -- Execution
end
fd.apply_to_associated_form
end
b.append (f.to_html (theme))
f.append_to_html (theme, b)
end
else
set_title ("Access denied")

View File

@@ -87,7 +87,7 @@ feature -- Execution
end
fd.apply_to_associated_form
end
b.append (f.to_html (theme))
f.append_to_html (theme, b)
end
else
b.append ("<h1>Access denied</h1>")

View File

@@ -112,7 +112,7 @@ feature -- Execution
end
fd.apply_to_associated_form
end
b.append (f.to_html (theme))
f.append_to_html (theme, b)
set_main_content (b)
end
end

View File

@@ -105,7 +105,7 @@ feature -- Execution
end
fd.apply_to_associated_form
end
b.append (f.to_html (theme))
f.append_to_html (theme, b)
end
end
set_main_content (b)

View File

@@ -34,7 +34,7 @@ feature -- Execution
if attached u.email as l_email then
f := new_password_form (url (request.path_info, Void), "new-password")
b.append ("Password reset instructions will be mailed to <em>" + l_email + "</em>. You must " + link ("log out", "/user/logout", Void) + " to use the password reset link in the e-mail.")
b.append (f.to_html (theme))
f.append_to_html (theme, b)
else
b.append ("Your account does not have any email address set!")
set_redirection (url ("/user/"+ u.id.out +"/edit", Void))
@@ -84,7 +84,7 @@ feature -- Execution
end
fd.apply_to_associated_form
end
b.append (f.to_html (theme))
f.append_to_html (theme, b)
end
end
set_main_content (b)

View File

@@ -103,7 +103,7 @@ feature -- Execution
end
fd.apply_to_associated_form
end
b.append (f.to_html (theme))
f.append_to_html (theme, b)
end
end
set_main_content (b)