Skip to content

Instantly share code, notes, and snippets.

@mhulse
Created January 20, 2014 19:44
Show Gist options
  • Save mhulse/8527613 to your computer and use it in GitHub Desktop.
Save mhulse/8527613 to your computer and use it in GitHub Desktop.
NEWSCYCLE Solutions: DTI Lighting: Convert Delimited "Agate" to HTML Tables, a test ...
<script language="cache" method="pull" arguments='needle:%String="", haystack:%String="", to:%String=""' returntype="%ListOfDataTypes">
; TODO: Add comments.
new return
set return = ##class(%ListOfDataTypes).%New()
if ($length(needle) && $length(haystack) && $length(to)) {
new first, last
set (first, last) = 0
while($find(haystack, needle)) {
set first = $find(haystack, needle)
set last = $find($extract(haystack, first, $length(haystack)), to)
do return.Insert($extract(haystack, first, (last + first - $length(to)) - 2))
set haystack = $extract(haystack, (last + first), $length(haystack))
}
}
quit return
</script>
<script language="cache" method="agate2" arguments='list:%ListOfDataTypes' returntype="%ListOfDataTypes">
; TODO: Add comments.
new return, count1
set return = ##class(%ListOfDataTypes).%New()
set count1 = 0
set count1 = list.Count()
if (+count1) {
new count2, item
for i=1:1:count1 {
set item = ##class(%ListOfDataTypes).%New()
set count2 = 0
set count2 = $length(list.GetAt(i), $char(9))
for x=1:1:count2 {
do item.Insert($piece(list.GetAt(i), $char(9), x))
quit:(x>50) // Sanity
}
do return.Insert(item)
quit:(i>50) // Sanity
}
}
quit return
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Convert Delimited "Agate" to HTML Tables Test</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?3.0.0/build/cssfonts/fonts-min.css&3.0.0/build/cssreset/reset-min.css&3.0.0/build/cssbase/base-min.css">
<link rel="stylesheet" type="text/css" href="http://rg-assets.s3.amazonaws.com/v3.5/css/tables.css">
<style type="text/css" media="all">
<!--
/* Embedded CSS: */
body { padding: 1em; }
#main div { width: 630px; }
#main pre { width: 990px; background: #eee; border: 1px solid #999; padding: 10px; overflow: auto; }
#main div, #main img, #main pre { float: left; display: inline; margin: 20px; }
img { border: 1px solid #000; margin: 20px; display: block; }
p { font-weight: bold; margin: 2em 0; }
.clear:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
* html .clear { zoom: 1; }
*:first-child+html .clear { zoom: 1; }
-->
</style>
</head>
<body>
<csp:if condition='$get(%request.Data("cid", 1))'>
<csp:object name="gStory" classname="dt.cms.schema.CMSStory" objid="#($get(%request.Data("cid", 1)))#">
<csp:if condition=($isobject(gStory))>
<script language="cache" runat="server">
; TODO: Error checking on lists. Need validation.
//----------------------------------
// Declare:
//----------------------------------
new rulesObj, qf
//----------------------------------
// Initialize:
//----------------------------------
set rulesObj = ##class(dt.cms.support.Rules).%New()
set (qf) = ""
//----------------------------------
// Extract element:
//----------------------------------
set qf = rulesObj.extractStoryElement("QuickFacts", gStory, 0)
</script>
<csp:if condition=($length(qf))>
<script language="cache" runat="server">
//----------------------------------
// Declare:
//----------------------------------
new caption, thead, th, tbody, td
//----------------------------------
// Initialize:
//----------------------------------
set (caption, thead, th, tbody, td) = ##class(%ListOfDataTypes).%New()
//----------------------------------
// <caption>
//----------------------------------
set caption = ..pull("<p class=""StandingHeads-Pac10_Stands_Head_Box"">", qf, "</p>")
//----------------------------------
// <thead>
//----------------------------------
set thead = ..pull("<p class=""AgateSports-GEN_Stands_6col_BLD"">", qf, "</p>")
set th = ..agate2(thead)
//----------------------------------
// <tbody>
//----------------------------------
set tbody = ..pull("<p class=""AgateSports-GEN_Stands_6col_Team"">", qf, "</p>")
set td = ..agate2(tbody)
</script>
<div id="main" class="clear">
<div>
<table class="v1" summary="Optional. Provide a more detailed description of the table than is suitable for the caption element">
<caption><span>#(caption.GetAt(1))#</span></caption>
<thead>
<tr>
<csp:loop counter="i" from="1" to="#(th.Count())#">
<csp:loop counter="x" from="1" to="#(th.GetAt(i).Count())#">
<th scope="col">#(th.GetAt(i).GetAt(x))#</th>
</csp:loop>
</csp:loop>
</tr>
</thead>
<tfoot>
<tr class="odd ref">
<th scope="col" colspan="7">Footer goes here.</th>
</tr>
</tfoot>
<tbody>
<csp:loop counter="i" from="1" to="#(td.Count())#">
<csp:if condition=(i#2)>
<tr>
<csp:else>
<tr class="odd">
</csp:if>
<csp:loop counter="x" from="1" to="#(td.GetAt(i).Count())#">
<csp:if condition=(x=1)>
<td scope="row" class="row">
<csp:else>
<td>
</csp:if>
#(td.GetAt(i).GetAt(x))#
</td>
</csp:loop>
</tr>
</csp:loop>
</tbody>
</table> <!-- /.v1 -->
</div>
<pre>#(..EscapeHTML(qf))#</pre>
</div> <!-- /#main -->
<script language="cache" runat="server">
//----------------------------------
// Garbage collection:
//----------------------------------
kill caption, thead, th, tbody, td
</script>
<csp:else>
<p>The QuickFacts element does not exsit for this story.</p>
</csp:if>
<script language="cache" runat="server">
//----------------------------------
// Garbage collection:
//----------------------------------
kill rulesObj, qf
</script>
<csp:else>
<p>Not a story.</p>
</csp:if>
<csp:else>
<p>Put <code>?cid=24536140</code> in the URI.</p>
</csp:if>
<hr>
<img src="0307.jpg" alt="Sports front page May 7th">
<hr>
<p>[<a href="box.txt">View source</a>]</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment