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.
This commit is contained in:
2015-09-16 10:02:09 +02:00
parent a5e150d1c0
commit e2c70e6d70
13 changed files with 67 additions and 39 deletions

View File

@@ -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 ("</feed>")
end
visit_entry (a_entry: FEED_ENTRY)
visit_item (a_entry: FEED_ITEM)
do
buffer.append (indentation)
buffer.append ("<entry>%N")

View File

@@ -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

View File

@@ -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)

View File

@@ -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]
-- <Precursor>
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

View File

@@ -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$"

View File

@@ -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

View File

@@ -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 ("<item>%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)

View File

@@ -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

View File

@@ -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 ("#")

View File

@@ -16,7 +16,7 @@ feature -- Visit
deferred
end
visit_entry (a_entry: FEED_ENTRY)
visit_item (a_item: FEED_ITEM)
deferred
end

View File

@@ -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

View File

@@ -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

View File

@@ -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