Changeset 4 in recipecards for trunk


Ignore:
Timestamp:
09/11/13 19:49:05 (11 years ago)
Author:
peter
Message:
  • put the recipe XML into a namespace (http://xmlns.grim.ath.cx/recipe)
  • match "degrees" and turn it into a degree symbol
  • added a recipe.html.xsl stylesheet that transforms recipe XML into HTML marked up with the hRecipe microformat
Location:
trunk
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/recipe.html.xsl

    r2 r4  
    22 
    33<xsl:stylesheet version="1.0" 
    4   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    5   xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
     4  xmlns="http://www.w3.org/1999/xhtml" 
     5  xmlns:recipe="http://xmlns.grim.ath.cx/recipe" 
     6  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    67 
    7   <!-- TODO: come up with various page configurations, 
    8        e.g. index card, half letter, full letter hole-punched, etc. 
    9   --> 
    10   <xsl:param name="size">5x8</xsl:param> 
    11   <xsl:variable name="height" select="substring-before($size, 'x')"/> 
    12   <xsl:variable name="width" select="substring-after($size, 'x')"/> 
    13  
    14   <xsl:template match="recipe"> 
    15     <fo:root font-family="DejaVuSerif" font-size="10pt"> 
    16       <fo:layout-master-set> 
    17         <fo:simple-page-master master-name="recipe-card" page-height="{$height}in" page-width="{$width}in"> 
    18           <fo:region-body margin=".25in .5in .25in .25in"/> 
    19         </fo:simple-page-master> 
    20       </fo:layout-master-set> 
    21  
    22       <fo:page-sequence master-reference="recipe-card"> 
    23         <fo:flow flow-name="xsl-region-body"> 
    24           <xsl:apply-templates/> 
    25         </fo:flow> 
    26       </fo:page-sequence> 
    27     </fo:root> 
     8  <xsl:template match="recipe:recipe"> 
     9    <html> 
     10      <head> 
     11        <xsl:apply-templates select="title" mode="head"/> 
     12      </head> 
     13      <body class="hRecipe"> 
     14        <xsl:apply-templates/> 
     15      </body> 
     16    </html> 
    2817  </xsl:template> 
    2918 
    30   <xsl:template match="title"> 
    31     <fo:block margin-bottom=".5em" font-weight="bold"> 
    32       <xsl:value-of select="."/> 
    33     </fo:block> 
     19  <xsl:template match="recipe:title" mode="head"> 
     20    <title><xsl:value-of select="."/></title> 
    3421  </xsl:template> 
    3522 
    36   <xsl:template match="ingredients"> 
    37     <fo:block margin-bottom=".5em"> 
    38       <xsl:apply-templates/> 
    39     </fo:block> 
     23  <xsl:template match="recipe:title"> 
     24    <h1 class="fn"><xsl:value-of select="."/></h1> 
    4025  </xsl:template> 
    4126 
    42   <xsl:template match="ingredient"> 
    43     <fo:block line-height="1.25"><xsl:value-of select="."/></fo:block> 
     27  <xsl:template match="recipe:ingredients"> 
     28    <ul> 
     29      <xsl:apply-templates/> 
     30    </ul> 
    4431  </xsl:template> 
    4532 
    46   <xsl:template match="note"> 
    47     <fo:block line-height="1.25" margin-left="1em" font-size="90%"><xsl:value-of select="."/></fo:block> 
     33  <xsl:template match="recipe:ingredient"> 
     34    <li class="ingredient"><xsl:value-of select="."/></li> 
    4835  </xsl:template> 
    4936 
    50   <xsl:template match="para"> 
    51     <fo:block margin-bottom=".5em"> 
     37  <xsl:template match="recipe:note"> 
     38    <div style="margin-left:1em; font-size: 90%"><xsl:value-of select="."/></div> 
     39  </xsl:template> 
     40 
     41  <xsl:template match="recipe:para"> 
     42    <p> 
    5243      <xsl:value-of select="."/> 
    53     </fo:block> 
     44    </p> 
    5445  </xsl:template> 
    5546 
  • trunk/recipe.xsl

    r2 r4  
    33<xsl:stylesheet version="1.0" 
    44  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     5  xmlns:recipe="http://xmlns.grim.ath.cx/recipe" 
    56  xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    67 
     
    1213  <xsl:variable name="width" select="substring-after($size, 'x')"/> 
    1314 
    14   <xsl:template match="recipe"> 
     15  <xsl:template match="recipe:recipe"> 
    1516    <fo:root font-family="DejaVuSerif" font-size="10pt"> 
    1617      <fo:layout-master-set> 
     
    2829  </xsl:template> 
    2930 
    30   <xsl:template match="title"> 
     31  <xsl:template match="recipe:title"> 
    3132    <fo:block margin-bottom=".5em" font-weight="bold"> 
    3233      <xsl:value-of select="."/> 
     
    3435  </xsl:template> 
    3536 
    36   <xsl:template match="ingredients"> 
     37  <xsl:template match="recipe:ingredients"> 
    3738    <fo:block margin-bottom=".5em"> 
    3839      <xsl:apply-templates/> 
     
    4041  </xsl:template> 
    4142 
    42   <xsl:template match="ingredient"> 
     43  <xsl:template match="recipe:ingredient"> 
    4344    <fo:block line-height="1.25"><xsl:value-of select="."/></fo:block> 
    4445  </xsl:template> 
    4546 
    46   <xsl:template match="note"> 
     47  <xsl:template match="recipe:note"> 
    4748    <fo:block line-height="1.25" margin-left="1em" font-size="90%"><xsl:value-of select="."/></fo:block> 
    4849  </xsl:template> 
    4950 
    50   <xsl:template match="para"> 
     51  <xsl:template match="recipe:para"> 
    5152    <fo:block margin-bottom=".5em"> 
    5253      <xsl:value-of select="."/> 
  • trunk/recipe2xml

    r2 r4  
    22use strict; 
    33 
     4#TODO: look at this existing XML format: http://www.happy-monkey.net/recipebook/doc/author-tutorial.html 
     5 
    46$/ = ''; 
    57 
    6 print "<recipe>\n"; 
     8print qq{<recipe xmlns="http://xmlns.grim.ath.cx/recipe">\n}; 
    79while (<>) { 
    810    chomp; 
     
    3739        s/(\d)x/$1⨯/g; 
    3840        # temperature 
    39         s/(\d)\s*deg.(\s*F)?/$1℉/g; 
     41        s/(\d)\s*deg(\.|rees)(\s*F)?/$1℉/g; 
    4042        # fractions 
    4143        s{1/3}{⅓}g; 
Note: See TracChangeset for help on using the changeset viewer.