From e2c70e6d70ea85677002727d95c6a98f63452db9 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Wed, 16 Sep 2015 10:02:09 +0200 Subject: [PATCH] Updated a few comments. Renamed generator to follow *_FEED_GENERATOR naming. Renamed feed entry as feed item. Made FEED conforms to ITERABLE [FEED_ITEM] for convenience. --- ...atom_generator.e => atom_feed_generator.e} | 6 ++--- .../parser/feed/src/atom/atom_feed_parser.e | 4 ++-- .../parser/feed/src/feed_default_parsers.e | 10 ++++++--- library/text/parser/feed/src/kernel/feed.e | 20 +++++++++++++---- .../text/parser/feed/src/kernel/feed_author.e | 5 ++++- .../src/kernel/{feed_entry.e => feed_item.e} | 12 +++++++--- ...s_2_generator.e => rss_2_feed_generator.e} | 22 +++++++++---------- .../parser/feed/src/rss/rss_2_feed_parser.e | 4 ++-- ...or.e => feed_to_string_32_debug_visitor.e} | 11 ++++++---- .../parser/feed/src/support/feed_visitor.e | 2 +- library/text/parser/feed/tests/application.e | 6 ++--- .../text/parser/feed/tests/atom_test_set.e | 2 +- library/text/parser/feed/tests/rss_test_set.e | 2 +- 13 files changed, 67 insertions(+), 39 deletions(-) rename library/text/parser/feed/src/atom/{atom_generator.e => atom_feed_generator.e} (98%) rename library/text/parser/feed/src/kernel/{feed_entry.e => feed_item.e} (91%) rename library/text/parser/feed/src/rss/{rss_2_generator.e => rss_2_feed_generator.e} (82%) rename library/text/parser/feed/src/support/{feed_to_string_32_visitor.e => feed_to_string_32_debug_visitor.e} (94%) diff --git a/library/text/parser/feed/src/atom/atom_generator.e b/library/text/parser/feed/src/atom/atom_feed_generator.e similarity index 98% rename from library/text/parser/feed/src/atom/atom_generator.e rename to library/text/parser/feed/src/atom/atom_feed_generator.e index 00f1a8d3..4f15a225 100644 --- a/library/text/parser/feed/src/atom/atom_generator.e +++ b/library/text/parser/feed/src/atom/atom_feed_generator.e @@ -4,7 +4,7 @@ note revision: "$Revision$" class - ATOM_GENERATOR + ATOM_FEED_GENERATOR inherit FEED_VISITOR @@ -44,7 +44,7 @@ feature -- Visitor append_content_tag_to ("updated", Void, date_to_string (dt), buffer) end across - a_feed.entries as ic + a_feed.items as ic loop ic.item.accept (Current) end @@ -53,7 +53,7 @@ feature -- Visitor buffer.append ("") end - visit_entry (a_entry: FEED_ENTRY) + visit_item (a_entry: FEED_ITEM) do buffer.append (indentation) buffer.append ("%N") diff --git a/library/text/parser/feed/src/atom/atom_feed_parser.e b/library/text/parser/feed/src/atom/atom_feed_parser.e index b8c538c1..ae945cf7 100644 --- a/library/text/parser/feed/src/atom/atom_feed_parser.e +++ b/library/text/parser/feed/src/atom/atom_feed_parser.e @@ -36,7 +36,7 @@ feature -- Access local l_title: READABLE_STRING_32 x_entry, x_link: detachable XML_ELEMENT - e: FEED_ENTRY + e: FEED_ITEM l_author: FEED_AUTHOR lnk: FEED_LINK s: STRING_32 @@ -92,7 +92,7 @@ feature -- Access e.set_author (l_author) end end - Result.add_entry (e) + Result.add_item (e) end end end diff --git a/library/text/parser/feed/src/feed_default_parsers.e b/library/text/parser/feed/src/feed_default_parsers.e index a7711614..c6dc4d7d 100644 --- a/library/text/parser/feed/src/feed_default_parsers.e +++ b/library/text/parser/feed/src/feed_default_parsers.e @@ -1,5 +1,8 @@ note - description: "Collection of default feed parsers." + description: "[ + Collection of default feed parsers provided by the current library. + A new parser can be easily added via `parsers.extend (...)'. + ]" date: "$Date$" revision: "$Revision$" @@ -32,7 +35,8 @@ feature -- Access feature -- Access - feed_from_string (a_atom_content: READABLE_STRING_8): detachable FEED + feed_from_string (a_content: READABLE_STRING_8): detachable FEED + -- Feed object from `a_content' string, if a parser is able to parse.it. local p: XML_STANDARD_PARSER cb_tree: XML_CALLBACKS_FILTER_DOCUMENT @@ -41,7 +45,7 @@ feature -- Access create p.make create cb_tree.make_null p.set_callbacks (cb_tree) - p.parse_from_string_8 (a_atom_content) + p.parse_from_string_8 (a_content) if p.is_correct then xdoc := cb_tree.document Result := feed (xdoc) diff --git a/library/text/parser/feed/src/kernel/feed.e b/library/text/parser/feed/src/kernel/feed.e index 8a951519..b5e85730 100644 --- a/library/text/parser/feed/src/kernel/feed.e +++ b/library/text/parser/feed/src/kernel/feed.e @@ -9,6 +9,8 @@ class inherit FEED_HELPERS + ITERABLE [FEED_ITEM] + create make @@ -17,7 +19,7 @@ feature {NONE} -- Initialization make (a_title: READABLE_STRING_GENERAL) do create title.make_from_string_general (a_title) - create entries.make (1) + create items.make (1) create links.make (1) end @@ -42,9 +44,17 @@ feature -- Access links: STRING_TABLE [FEED_LINK] -- Url indexed by relation - entries: ARRAYED_LIST [FEED_ENTRY] + items: ARRAYED_LIST [FEED_ITEM] -- List of feed items. +feature -- Access + + new_cursor: ITERATION_CURSOR [FEED_ITEM] + -- + do + Result := items.new_cursor + end + feature -- Element change set_description (a_description: detachable READABLE_STRING_GENERAL; a_description_content_type: like description_content_type) @@ -69,6 +79,7 @@ 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'. do if a_date_text = Void then date := Void @@ -77,9 +88,10 @@ feature -- Element change end end - add_entry (e: FEED_ENTRY) + add_item (a_item: FEED_ITEM) + -- Add item `a_item' to feed `items'. do - entries.force (e) + items.force (a_item) end feature -- Visitor diff --git a/library/text/parser/feed/src/kernel/feed_author.e b/library/text/parser/feed/src/kernel/feed_author.e index 7d841d2b..86cc45e8 100644 --- a/library/text/parser/feed/src/kernel/feed_author.e +++ b/library/text/parser/feed/src/kernel/feed_author.e @@ -1,5 +1,8 @@ note - description: "Object representing author of Feed or feed entry." + description: "[ + Author of feed or feed entry. + - name and email information. + ]" date: "$Date$" revision: "$Revision$" diff --git a/library/text/parser/feed/src/kernel/feed_entry.e b/library/text/parser/feed/src/kernel/feed_item.e similarity index 91% rename from library/text/parser/feed/src/kernel/feed_entry.e rename to library/text/parser/feed/src/kernel/feed_item.e index 097acf89..8fc6a8c4 100644 --- a/library/text/parser/feed/src/kernel/feed_entry.e +++ b/library/text/parser/feed/src/kernel/feed_item.e @@ -1,10 +1,15 @@ note - description: "Item of feed." + description: "[ + A feed contains a list of items. + This FEED_ITEM interface provides + - title, description, content, id, date, ... + - could be compared with other item to sort by date+title. + ]" date: "$Date$" revision: "$Revision$" class - FEED_ENTRY + FEED_ITEM inherit FEED_HELPERS @@ -41,6 +46,7 @@ feature -- Access -- By default, this should be text/html. content_type_or_default (dft: READABLE_STRING_8): READABLE_STRING_8 + -- Associated content type, and if none, return given value `dft'. do if attached content_type as l_type then Result := l_type @@ -166,7 +172,7 @@ feature -- Visitor accept (vis: FEED_VISITOR) do - vis.visit_entry (Current) + vis.visit_item (Current) end end diff --git a/library/text/parser/feed/src/rss/rss_2_generator.e b/library/text/parser/feed/src/rss/rss_2_feed_generator.e similarity index 82% rename from library/text/parser/feed/src/rss/rss_2_generator.e rename to library/text/parser/feed/src/rss/rss_2_feed_generator.e index 640693ae..2c008620 100644 --- a/library/text/parser/feed/src/rss/rss_2_generator.e +++ b/library/text/parser/feed/src/rss/rss_2_feed_generator.e @@ -4,7 +4,7 @@ note revision: "$Revision$" class - RSS_2_GENERATOR + RSS_2_FEED_GENERATOR inherit FEED_VISITOR @@ -43,7 +43,7 @@ feature -- Visitor append_content_tag_to ("lastBuildDate", Void, date_to_string (dt), buffer) end across - a_feed.entries as ic + a_feed.items as ic loop ic.item.accept (Current) end @@ -55,33 +55,33 @@ feature -- Visitor ]") end - visit_entry (a_entry: FEED_ENTRY) + visit_item (a_item: FEED_ITEM) do buffer.append (indentation) buffer.append ("%N") indent - append_content_tag_to ("title", Void, a_entry.title, buffer) - if attached a_entry.date as dt then + append_content_tag_to ("title", Void, a_item.title, buffer) + if attached a_item.date as dt then append_content_tag_to ("pubDate", Void, date_to_string (dt), buffer) end across - a_entry.links as tb + a_item.links as tb loop tb.item.accept (Current) end - if attached a_entry.author as u then + if attached a_item.author as u then u.accept (Current) end - if attached a_entry.categories as cats then + if attached a_item.categories as cats then across cats as ic loop append_content_tag_to ("category", Void, ic.item, buffer) end end - append_content_tag_to ("guid", Void, a_entry.id, buffer) - append_content_tag_to ("description", Void, a_entry.description, buffer) - append_cdata_content_tag_to ("content:encoded", Void, a_entry.content, buffer) + append_content_tag_to ("guid", Void, a_item.id, buffer) + append_content_tag_to ("description", Void, a_item.description, buffer) + append_cdata_content_tag_to ("content:encoded", Void, a_item.content, buffer) exdent buffer.append (indentation) diff --git a/library/text/parser/feed/src/rss/rss_2_feed_parser.e b/library/text/parser/feed/src/rss/rss_2_feed_parser.e index e9e860ca..3a8eafdb 100644 --- a/library/text/parser/feed/src/rss/rss_2_feed_parser.e +++ b/library/text/parser/feed/src/rss/rss_2_feed_parser.e @@ -40,7 +40,7 @@ feature -- Access local lnk: FEED_LINK x_item, x_content, x_author: detachable XML_ELEMENT - e: FEED_ENTRY + e: FEED_ITEM l_author: FEED_AUTHOR do if attached xdoc.element_by_name ("rss") as x_rss then @@ -112,7 +112,7 @@ feature -- Access else e.set_content (xml_element_code (x_content), Void) end - Result.add_entry (e) + Result.add_item (e) end end end diff --git a/library/text/parser/feed/src/support/feed_to_string_32_visitor.e b/library/text/parser/feed/src/support/feed_to_string_32_debug_visitor.e similarity index 94% rename from library/text/parser/feed/src/support/feed_to_string_32_visitor.e rename to library/text/parser/feed/src/support/feed_to_string_32_debug_visitor.e index db795e07..7c028fed 100644 --- a/library/text/parser/feed/src/support/feed_to_string_32_visitor.e +++ b/library/text/parser/feed/src/support/feed_to_string_32_debug_visitor.e @@ -1,10 +1,13 @@ note - description: "Convert a FEED to STRING_32 representation. Mostly for debug output." + description: "[ + Convert a FEED to STRING_32 representation. + Mostly for debug output! + ]" date: "$Date$" revision: "$Revision$" class - FEED_TO_STRING_32_VISITOR + FEED_TO_STRING_32_DEBUG_VISITOR inherit FEED_VISITOR @@ -55,7 +58,7 @@ feature -- Visitor append_new_line across - a_feed.entries as ic + a_feed.items as ic loop exdent append_text (create {STRING_32}.make_filled ('-', 40)) @@ -66,7 +69,7 @@ feature -- Visitor end end - visit_entry (a_entry: FEED_ENTRY) + visit_item (a_entry: FEED_ITEM) do if attached a_entry.id as l_id then append_text ("#") diff --git a/library/text/parser/feed/src/support/feed_visitor.e b/library/text/parser/feed/src/support/feed_visitor.e index 05a8cba2..0e01763a 100644 --- a/library/text/parser/feed/src/support/feed_visitor.e +++ b/library/text/parser/feed/src/support/feed_visitor.e @@ -16,7 +16,7 @@ feature -- Visit deferred end - visit_entry (a_entry: FEED_ENTRY) + visit_item (a_item: FEED_ITEM) deferred end diff --git a/library/text/parser/feed/tests/application.e b/library/text/parser/feed/tests/application.e index 4de78ed2..221f9d0b 100644 --- a/library/text/parser/feed/tests/application.e +++ b/library/text/parser/feed/tests/application.e @@ -43,9 +43,9 @@ feature -- Initialization test_feed (t: READABLE_STRING_8) local feed_parser: FEED_DEFAULT_PARSERS - vis: FEED_TO_STRING_32_VISITOR - gen: RSS_2_GENERATOR - atom_gen: ATOM_GENERATOR + vis: FEED_TO_STRING_32_DEBUG_VISITOR + gen: RSS_2_FEED_GENERATOR + atom_gen: ATOM_FEED_GENERATOR s: STRING_32 s8: STRING_8 pp: XML_PRETTY_PRINT_FILTER diff --git a/library/text/parser/feed/tests/atom_test_set.e b/library/text/parser/feed/tests/atom_test_set.e index 72c73ecc..68eab06e 100644 --- a/library/text/parser/feed/tests/atom_test_set.e +++ b/library/text/parser/feed/tests/atom_test_set.e @@ -19,7 +19,7 @@ feature -- Test routines -- New test routine local feed_parser: FEED_DEFAULT_PARSERS - vis: FEED_TO_STRING_32_VISITOR + vis: FEED_TO_STRING_32_DEBUG_VISITOR s: STRING_32 do create feed_parser diff --git a/library/text/parser/feed/tests/rss_test_set.e b/library/text/parser/feed/tests/rss_test_set.e index 860823c0..9c94a3c8 100644 --- a/library/text/parser/feed/tests/rss_test_set.e +++ b/library/text/parser/feed/tests/rss_test_set.e @@ -16,7 +16,7 @@ feature -- Test routines -- New test routine local feed_parser: FEED_DEFAULT_PARSERS - vis: FEED_TO_STRING_32_VISITOR + vis: FEED_TO_STRING_32_DEBUG_VISITOR s: STRING_32 do create feed_parser