diff --git a/library/text/parser/feed/feed-safe.ecf b/library/text/parser/feed/feed-safe.ecf index 63c57f4a..3c5a7dda 100644 --- a/library/text/parser/feed/feed-safe.ecf +++ b/library/text/parser/feed/feed-safe.ecf @@ -4,6 +4,7 @@ + diff --git a/library/text/parser/feed/feed.ecf b/library/text/parser/feed/feed.ecf index 6e0fb7cb..a69dd4e4 100644 --- a/library/text/parser/feed/feed.ecf +++ b/library/text/parser/feed/feed.ecf @@ -6,6 +6,7 @@ + diff --git a/library/text/parser/feed/src/kernel/feed.e b/library/text/parser/feed/src/kernel/feed.e index 9b788db2..95a6e60e 100644 --- a/library/text/parser/feed/src/kernel/feed.e +++ b/library/text/parser/feed/src/kernel/feed.e @@ -80,14 +80,28 @@ 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 diff --git a/library/text/parser/feed/src/kernel/feed_item.e b/library/text/parser/feed/src/kernel/feed_item.e index f2b7e9ea..3709e885 100644 --- a/library/text/parser/feed/src/kernel/feed_item.e +++ b/library/text/parser/feed/src/kernel/feed_item.e @@ -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 diff --git a/library/text/parser/feed/src/support/feed_to_xhtml_visitor.e b/library/text/parser/feed/src/support/feed_to_xhtml_visitor.e new file mode 100644 index 00000000..738fe4c6 --- /dev/null +++ b/library/text/parser/feed/src/support/feed_to_xhtml_visitor.e @@ -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 ("
") + if attached header as h then + append (h) + append ("%N") + end + if attached a_feed.date as dt then + append ("%N") + end + + append ("
    %N") + if + description_enabled and then + attached a_feed.description as l_desc and then + l_desc.is_valid_as_string_8 + then + append ("
    ") + append (l_desc.to_string_8) + append ("
    ") + 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 ("
%N") + end + + visit_item (a_entry: FEED_ITEM) + local + lnk: detachable FEED_LINK + do + append ("
  • %N") + lnk := a_entry.link + + if attached a_entry.date as dt then + append ("
    ") + append_date_time_to (dt, today.date, buffer) + append ("
    %N") + end + if lnk /= Void then + append ("") + else + check has_link: False end + append ("") + end + append_as_html_encoded (a_entry.title) + append ("%N") + debug + if attached a_entry.categories as l_categories and then not l_categories.is_empty then + append ("
    ") + across + l_categories as cats_ic + loop + append_as_html_encoded (cats_ic.item) + append (" ") + end + append ("
    %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 ("
    ") + append (l_entry_desc.as_string_8) + append ("
    %N") + else + check is_html: False end + end + end + append ("
  • %N") + end + + visit_link (a_link: FEED_LINK) + do + append ("") + append_as_html_encoded (a_link.relation) + append ("%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