Monday, November 08, 2010 at 12:00 AM.

scripting2Suite.server.getStoryText

on getStoryText (adrstory, flExpanded=true, flComments=false) {
	<<Changes
		<<7/7/10; 12:00:37 PM by DW
			<<Instead of using the class "show" to display non-hidden text, use a special class for non-hidden text on an index page, "showForIndexPage." It has left indentation set to zero, because we're only displaying two-level hierarchy. If this were to change we'd have to change the class definition in the stylesheet.
		<<7/4/10; 5:48:56 PM by DW
			<<Add optional parameter, flComments.
		<<6/7/10; 7:32:55 AM by DW
			<<Add optional parameter, flExpanded.
		<<6/6/10; 9:11:11 AM by DW
			<<Common code for building the aggregate pages: the home page, daily pages and month pages. We return the text for a single story. 
	local (adrcache = @adrstory^.textCache);
	bundle { //see if you can get it from the cache
		if defined (adrcache^) {
			if adrcache^.flExpanded == flExpanded {
				if adrcache^.whenLastBuild >= adrstory^.whenLastSave {
					adrcache^.ctrefs++;
					adrcache^.whenLastRef = clock.now ();
					return (adrcache^.htmltext)}}}};
	local (htmltext = "\r\r", indentlevel = 0, idstory, icon);
	local (permalinkImg = string (scripting2Suite.data.html.sharpPermalinkImg));
	on add (s) {
		htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"};
	on decode (s) {
		return (xml.entitydecode (s, true))};
	bundle { //set idStory
		idstory = string.lastfield (adrstory^.url, "/");
		idstory = string.nthfield (idstory, ".", 1)};
	bundle { //set icon
		local (iconname);
		if flExpanded {
			iconname = "minus"}
		else {
			iconname = "plus"};
		<<icon = "<a href=\"javascript:expandCollapse('" + idstory + "');\"><img border=\"0\" align=\"left\" id=\"img_" + idstory + "\" src=\"http://www.scripting.com/mktree/" + iconname + ".gif\"></a> "
		icon = scripting2Suite.server.getExpandCollapseIcon (idstory, flExpanded, "showForIndexPage")};
	bundle { //add the story title
		local (permalink = "<a href=\"" + adrstory^.url + "\">" + string (scripting2Suite.data.html.arrowPermalinkImg) + "</a>");
		add ("<h4 class=\"expandableHeadline\">" + icon + adrstory^.title + " " + permalink + "</h4>")};
	bundle { //add the <div> for expand/collapse
		local (classname);
		if flExpanded {
			classname = "showForIndexPage"}
		else {
			classname = "hide"};
		add ("<div class=\"" + classname + "\" id=\"" + idstory + "\" name=\"" + idstory + "\">"); indentlevel++};
	local (adrsummit = scripting2Suite.server.getStorySummit (adrstory), adr);
	for adr in adrsummit {
		if nameof (adr^) endswith "outline" {
			add ("<p class=\"storyText\">" + decode (xml.getattributevalue (adr, "text")) + scripting2Suite.server.getLinkHtml (adr) + "</p>")}};
	bundle { //add timestamp, permalink, comment link
		local (permalink, commentlink);
		bundle { //set permalink
			permalink = "<a href=\"" + adrstory^.url + "\">" + permalinkImg + "</a> "};
		bundle { //set comment javascript
			if flComments and (adrstory^.postdate >= date ("11/3/2007")) {
				commentlink = "  <a href=\"" + adrstory^.url + "#disqus_thread\"></a>."}
			else {
				commentlink = ""}};
		add ("<p class=\"storyTimeStamp\">" + permalink + adrstory^.postdate + ". " + commentlink + "</p>")};
	bundle { //add the closing </div>
		add ("</div>"); indentlevel--};
	bundle { //manage cache
		if not defined (adrcache^) {
			new (tabletype, adrcache);
			adrcache^.htmltext = htmltext;
			adrcache^.whenLastBuild = clock.now ();
			adrcache^.flExpanded = flExpanded;
			adrcache^.ctrefs = 0}};
	return (htmltext)};
bundle { //test code
	script.startprofile (true);
	s = getStoryText (@config.scripting2.server.users.davewiner.calendar.["2010"].["05"].["12"].["03059"]);
	script.stopprofile (@scratchpad.storytextprofile);
	edit (@scratchpad.storytextprofile);
	webbrowser.displaytext (s)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.