Compare commits

..

3 Commits

Author SHA1 Message Date
061e88c9fe Added FEED.prune (a_item: FEED_ITEM). 2015-10-14 17:40:38 +02:00
66f204b1f2 Make custom error interface more flexible with READABLE_STRING_... instead of STRING_... 2015-10-10 00:58:07 +02:00
c92b1b8c3b Added feed to xhtml visitor.
Updated interfaces, mainly related to date attributes.
2015-10-09 19:08:53 +02:00
7 changed files with 276 additions and 10 deletions

View File

@@ -4,6 +4,7 @@
<root all_classes="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="base_extension" location="$ISE_LIBRARY\library\base_extension\base_extension-safe.ecf"/>
<library name="encoders" location="..\..\encoder\encoder-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<library name="uuid" location="$ISE_LIBRARY\library\uuid\uuid-safe.ecf"/>

View File

@@ -6,6 +6,7 @@
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="base_extension" location="$ISE_LIBRARY\library\base_extension\base_extension.ecf"/>
<library name="encoders" location="..\..\encoder\encoder.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
<library name="uuid" location="$ISE_LIBRARY\library\uuid\uuid.ecf"/>

View File

@@ -80,20 +80,40 @@ feature -- Element change
set_updated_date_with_text (a_date_text: detachable READABLE_STRING_32)
-- Set `date' from date string representation `a_date_text'.
obsolete
"Use set_date_with_text [oct/2015]"
do
set_date_with_text (a_date_text)
end
set_date_with_text (a_date_text: detachable READABLE_STRING_32)
-- Set `date' from date string representation `a_date_text'.
do
if a_date_text = Void then
date := Void
set_date (Void)
else
date := date_time (a_date_text)
set_date (date_time (a_date_text))
end
end
set_date (a_date: detachable DATE_TIME)
-- Set `date' from `a_date'.
do
date := a_date
end
extend (a_item: FEED_ITEM)
-- Add item `a_item' to feed `items'.
do
items.force (a_item)
end
prune (a_item: FEED_ITEM)
-- Remove feed item `a_item' from Current list of feed items.
do
items.prune (a_item)
end
extended alias "+" (a_feed: FEED): FEED
-- New feed object made from Current merged with a_feed.
local

View File

@@ -156,14 +156,29 @@ feature -- Element change
end
set_updated_date_with_text (a_date_text: detachable READABLE_STRING_32)
-- Set `date' from date string representation `a_date_text'.
obsolete
"Use set_date_with_text [oct/2015]"
do
set_date_with_text (a_date_text)
end
set_date_with_text (a_date_text: detachable READABLE_STRING_32)
-- Set `date' from date string representation `a_date_text'.
do
if a_date_text = Void then
date := Void
set_date (Void)
else
date := date_time (a_date_text)
set_date (date_time (a_date_text))
end
end
set_date (a_date: detachable DATE_TIME)
-- Set `date' from `a_date'.
do
date := a_date
end
set_author (a_author: detachable FEED_AUTHOR)
do
author := a_author

View File

@@ -0,0 +1,229 @@
note
description: "[
Convert a FEED to XHTML representation.
]"
date: "$Date: 2015-10-08 10:45:13 +0200 (jeu., 08 oct. 2015) $"
revision: "$Revision: 97964 $"
class
FEED_TO_XHTML_VISITOR
inherit
FEED_VISITOR
SHARED_HTML_ENCODER
create
make
feature {NONE} -- Initialization
make (a_buffer: STRING_8)
do
buffer := a_buffer
create today.make_now_utc
description_enabled := False
limit := -1
end
buffer: STRING_8
-- Output buffer.
today: DATE_TIME
-- Current date.
feature -- Access
header: detachable READABLE_STRING_8
-- Optional header.
footer: detachable READABLE_STRING_8
-- Optional footer.
feature -- Settings
limit: INTEGER
-- Number of item to include in XHTML generation.
-- Default: -1 => No limit
description_enabled: BOOLEAN
-- Generate description?
-- Default: False
feature -- Element change
set_limit (nb: INTEGER)
-- Set `limit' to `nb'.
do
limit := nb
end
set_description_enabled (b: BOOLEAN)
-- Set `description_enabled' to `b'.
do
description_enabled := b
end
set_header (h: like header)
do
header := h
end
set_footer (f: like footer)
do
footer := f
end
feature -- Visitor
visit_feed (a_feed: FEED)
local
nb: INTEGER
do
append ("<div class=%"feed%">")
if attached header as h then
append (h)
append ("%N")
end
if attached a_feed.date as dt then
append ("<!-- date:")
append (dt.out)
append (" -->%N")
end
append ("<ul>%N")
if
description_enabled and then
attached a_feed.description as l_desc and then
l_desc.is_valid_as_string_8
then
append ("<div class=%"description%">")
append (l_desc.to_string_8)
append ("</div>")
end
nb := limit
across
a_feed as ic
until
nb = 0
loop
ic.item.accept (Current)
nb := nb - 1
end
if attached footer as f then
append (f)
append ("%N")
end
append ("</ul>%N")
end
visit_item (a_entry: FEED_ITEM)
local
lnk: detachable FEED_LINK
do
append ("<li>%N")
lnk := a_entry.link
if attached a_entry.date as dt then
append ("<div class=%"date%">")
append_date_time_to (dt, today.date, buffer)
append ("</div>%N")
end
if lnk /= Void then
append ("<a href=%"" + lnk.href + "%">")
else
check has_link: False end
append ("<a href=%"#%">")
end
append_as_html_encoded (a_entry.title)
append ("</a>%N")
debug
if attached a_entry.categories as l_categories and then not l_categories.is_empty then
append ("<div class=%"category%">")
across
l_categories as cats_ic
loop
append_as_html_encoded (cats_ic.item)
append (" ")
end
append ("</div>%N")
end
end
if
description_enabled and then
attached a_entry.description as l_entry_desc
then
if l_entry_desc.is_valid_as_string_8 then
append ("<div class=%"description%">")
append (l_entry_desc.as_string_8)
append ("</div>%N")
else
check is_html: False end
end
end
append ("</li>%N")
end
visit_link (a_link: FEED_LINK)
do
append ("<a href=%"" + a_link.href + "%">")
append_as_html_encoded (a_link.relation)
append ("</a>%N")
end
visit_author (a_author: FEED_AUTHOR)
do
end
feature -- Helper
append_as_html_encoded (s: READABLE_STRING_GENERAL)
do
buffer.append (html_encoder.general_encoded_string (s))
end
append (s: READABLE_STRING_8)
do
buffer.append (s)
end
append_date_time_to (dt: DATE_TIME; a_today: DATE; a_output: STRING_GENERAL)
do
if dt.year /= a_today.year then
a_output.append (dt.year.out)
a_output.append (",")
end
a_output.append (" ")
append_month_mmm_to (dt.month, a_output)
a_output.append (" ")
if dt.day < 10 then
a_output.append ("0")
end
a_output.append (dt.day.out)
end
append_month_mmm_to (m: INTEGER; s: STRING_GENERAL)
require
1 <= m and m <= 12
do
inspect m
when 1 then s.append ("Jan")
when 2 then s.append ("Feb")
when 3 then s.append ("Mar")
when 4 then s.append ("Apr")
when 5 then s.append ("May")
when 6 then s.append ("Jun")
when 7 then s.append ("Jul")
when 8 then s.append ("Aug")
when 9 then s.append ("Sep")
when 10 then s.append ("Oct")
when 11 then s.append ("Nov")
when 12 then s.append ("Dec")
else
-- Error
end
end
end

View File

@@ -2,8 +2,8 @@ note
description : "Objects that represent a custom error"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-10-10 00:55:41 +0200 (sam., 10 oct. 2015) $"
revision: "$Revision: 97980 $"
class
ERROR_CUSTOM
@@ -24,7 +24,7 @@ feature {NONE} -- Initialization
if a_message /= Void then
message := a_message
else
message := "Error: " + a_name + " (code=" + a_code.out + ")"
message := {STRING_32} "Error: " + a_name + " (code=" + a_code.out + ")"
end
end

View File

@@ -2,8 +2,8 @@ note
description : "Objects that handle error..."
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-10-10 00:55:41 +0200 (sam., 10 oct. 2015) $"
revision: "$Revision: 97980 $"
class
ERROR_HANDLER
@@ -216,7 +216,7 @@ feature -- Basic operation
on_error_added (a_error)
end
add_error_details, add_custom_error (a_code: INTEGER; a_name: STRING; a_message: detachable STRING_32)
add_error_details, add_custom_error (a_code: INTEGER; a_name: STRING; a_message: detachable READABLE_STRING_32)
-- Add custom error to the stack of error
local
e: ERROR_CUSTOM