render.d (975B)
1 /// Generate an RSS-Feed out of an DRSS-Class 2 module drss.render; 3 import kxml.xml; 4 import drss.rss; 5 import std.typecons; 6 import std.range; 7 8 public alias DRSS_Header=Tuple!(string, string); 9 10 /** 11 * Interprets the header and generates the template for the atom-feed 12 * 13 * Params: 14 * h=The header-tuple 15 * Returns: 16 * The XmlNode to the root-node of an valid atom-feed 17 */ 18 XmlNode getRSSRoot(DRSS_Header[] h){ 19 XmlNode rss = new XmlNode("feed"); 20 rss.setAttribute("xmlns","http://www.w3.org/2005/Atom"); 21 foreach(DRSS_Header hh; h){ 22 rss.addChild(new XmlNode(hh[0]).addCData(hh[1])); 23 } 24 return rss; 25 } 26 27 /** 28 * Generates a full-blown Atom-XML-Tree corresponding to rss. 29 * 30 * Params: 31 * rss = The feed 32 * h = The extra headers to add to the feed 33 * Returns: 34 * An XmlNode pointing to a Atom-Document. 35 */ 36 XmlNode generateRSS(T)(DRSS!(T) rss, DRSS_Header[] h){ 37 XmlNode root = getRSSRoot(h); 38 foreach(ref T p; rss.entries){ 39 root.addChild(p.toXML()); 40 } 41 return root; 42 }