cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/slop/samples/javateach/java-source/org/nothing SomeTest.java
Date Tue, 14 Oct 2003 12:00:05 GMT
bdelacretaz    2003/10/14 05:00:05

  Added:       src/blocks/slop/samples/javateach javateach.css
                        jt-to-html.xsl
               src/blocks/slop/samples/javateach/java-source/org/nothing
                        SomeTest.java
  Log:
  javateach sample - poor man's literate programming tool
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/slop/samples/javateach/javateach.css
  
  Index: javateach.css
  ===================================================================
  /**
      CSS stylesheet for javateach
      Main looks inspired from linotype CSS stylesheets
  */
  
  #content {
      font-family: "georgia", "times", "times new roman", serif;
      height:100%;
  }
  
  h1 {
      margin-bottom: 0;
      font-variant: small-caps;
      background: transparent;
      font-size: 150%;
  }
  
  h1.pageTitle {
      font-size: 180%;
      border-bottom: solid red 1px;
  }
  
  h2 {
      margin-bottom: 0;
      background: transparent;
      font-size: 125%;
  }
  
  h3 {
      margin-bottom: 0;
      background: transparent;
  }
  
  a {
  	text-decoration: none;
  	color: #000;
  	border-bottom: 1px dotted #777;
  	margin: 0px 2px 0px 2px;
  	padding: 1px 1px 1px 1px;
  }
  
  a:hover {
  	border: 1px dotted #000;
  	background-color: #eee;
  	padding: 1px 2px 1px 2px;
  	margin: 0px;
  }
  
  a:active {
  	background-color: #ccc !important;
  	position: relative;
  	top: 1px;
  	left: 1px;
  	padding: 1px 2px 1px 2px;
  	margin: 0px;
  }
  
  a:focus {
  	border: 1px solid #fff !important;
  	background-color: #ccc !important;
  	padding: 1px 2px 1px 2px;
  	margin: 0px;
  }
  
  .lineNumber {
      display: inline;
      color: grey;
  }
  
  pre {
      border: 1px dotted #000;
      padding: 10px;
      margin: 20px;
      font-size: 120%;
      background: #FFFFCC;
  }
  
  .teachingComments {
      margin-left: 10px;
  }
  
  .commentLine {
      display: inline;
  }
  
  
  
  
  1.1                  cocoon-2.1/src/blocks/slop/samples/javateach/jt-to-html.xsl
  
  Index: jt-to-html.xsl
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
      Convert slop output to HTML for the javateach sample
      $Id: jt-to-html.xsl,v 1.1 2003/10/14 12:00:05 bdelacretaz Exp $
  -->
  <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:slop="http://apache.org/cocoon/slop/parser/1.0"
  >
  
      <xsl:param name="pageTitle" select="'Javateach sample - using the Cocoon SLOP parser'"/>
  
      <!-- keys based on last preceding lpstart or lpend, used to split between code and
teaching comments -->
      <xsl:key
          name="lastMarkKey"
          match="slop:*" use="generate-id(preceding::slop:*[self::slop:__lpstart|self::slop:__lpend][1])"
      />
  
      <xsl:template match="/">
          <html>
              <head>
                  <title><xsl:value-of select="$pageTitle"/></title>
                  <link rel="stylesheet" type="text/css" href="css/javateach.css"/>
              </head>
              <body>
                  <div id="content">
                      <h1 class="pageTitle"><xsl:value-of select="$pageTitle"/></h1>
                      <div class="code">
                          <pre>
                              <xsl:apply-templates
                                  select="slop:parsed-text/slop:*[not(preceding::slop:__lpstart)
and not(self::slop:__lpstart)]"
                                  mode="code"
                              />
                          </pre>
                      </div>
                      <xsl:apply-templates select="slop:parsed-text/slop:__lpstart|slop:parsed-text/slop:__lpend"/>
                  </div>
              </body>
          </html>
  
      </xsl:template>
  
      <xsl:template match="slop:__lpstart">
          <div class="teachingComments">
              <xsl:apply-templates select="key('lastMarkKey',generate-id(.))" mode="teachingComments"/>
          </div>
      </xsl:template>
  
      <xsl:template match="slop:__lpend">
          <div class="code">
              <pre>
                  <xsl:apply-templates select="key('lastMarkKey',generate-id(.))" mode="code"/>
              </pre>
          </div>
      </xsl:template>
  
      <xsl:template match="slop:*" mode="teachingComments">
          <xsl:value-of select="concat(substring-after(.,'//'),'&#xD;')" disable-output-escaping="yes"/>
      </xsl:template>
  
      <xsl:template match="slop:*" mode="code">
          <span class="lineNumber">
              <xsl:value-of select="concat(@line-number,'  ')"/>
          </span>
          <span class="codeLine">
              <xsl:value-of select="concat(.,'&#xD;')"/>
          </span>
      </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  cocoon-2.1/src/blocks/slop/samples/javateach/java-source/org/nothing/SomeTest.java
  
  Index: SomeTest.java
  ===================================================================
  // (currently lpstart comments at the very start do not work)
  package org.nothing;
  
  //lpstart:
  //  <h1>What's this?</h1>
  //  Based on the Slop parser, Javateach creates a nice HTML page from the source code of
a Java class.
  //  The idea is to write explanations of the code inline, allowing explanations and code
to stay together,
  //  and keeping line numbers accurate.
  //
  //  <h1>Teaching comments</h1>
  //  Comments like this one, surrounded by lpstart/lpend will be extracted from the source
  //  code to create an HTML presentation which mixes teaching comments and code.
  //lpend:
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  //lpstart:
  //  Here we could explain what class comments are about.
  //lpend:
  
  /** Simple example of java code parsing with Slop.
   *  The aim is to create a minimal "literate programming" system for teaching,
   *  where java code is decorated with narrative comments. */
  
  //lpstart:
  //  <h2>Here's the class declaration</h2>
  //  This class does nothing useful, it does not even compile, it is only used to
  //  test the javateach formatting.
  //  <br/>
  //  Code indentation is preserved, this is set by SlopGenerator parameters
  //  in the sitemap.
  //lpend:
  
  public class SomeTest implements SlopParser,SlopConstants {
      private ContentHandler contentHandler;
  
      /** chars that can be part of a field name (other than letters) */
      private final static String DEFAULT_TAGNAME_CHARS = "-_";
      private String tagnameChars = DEFAULT_TAGNAME_CHARS;
  
  //lpstart:
  // lp markers have to start in column 1.
  // <br/>
  // HTML constructs are <b>allowed</b> in lp comments:
  // <ul>
  // <li>You like bullet points, I'm sure...</li>
  // <li>Here's the second one</li>
  // </ul>
  // Links also work, like <a href="http://www.perdu.com" target="_new">this</a>.
  //lpend:
  
      /** optionally preserve whitespace in input */
      private boolean preserveSpace = false;
  
      /** result of parsing a line */
      static class ParsedLine {
          final String name;
          final String contents;
  
          ParsedLine(String elementName, String elementContents) {
              name = elementName;
              contents = elementContents;
          }
      }
  
  //lpstart:
  //    SetValidTagname() is used to define a list of valid character for XML element
  //    names.
  //lpend:
  
      /** set the list of valid chars for tag names (in addition to letters) */
      public void setValidTagnameChars(String str) {
          tagnameChars = str;
      }
  
  }
  
  
  

Mime
View raw message