Permalink
Browse files

Add groff rendering (README.[1-9])

  • Loading branch information...
1 parent 1f9b0bd commit 6ca46abe21710bffc87bb2e084d2cc5644c5ebc7 @defunkt defunkt committed Mar 11, 2010
Showing with 357 additions and 1 deletion.
  1. +12 −1 lib/github/markup.rb
  2. +23 −0 lib/github/markups.rb
  3. +138 −0 test/markups/README.1
  4. +184 −0 test/markups/README.1.html
View
@@ -34,7 +34,18 @@ def command(command, regexp, &block)
add_markup(regexp) do |content|
rendered = execute(command, content)
rendered = rendered.to_s.empty? ? content : rendered
- block ? block.call(rendered) : rendered
+
+ if block && block.arity == 2
+ # If the block takes two arguments, pass new content and old
+ # content.
+ block.call(rendered, content)
+ elsif block
+ # One argument is just the new content.
+ block.call(rendered)
+ else
+ # No block? No problem!
+ rendered
+ end
end
end
View
@@ -28,3 +28,26 @@
$1
end
end
+
+#
+# man pages!
+#
+command('groff -t -e -mandoc -Thtml -P -l -P -r -', /\d/) do |rendered, original|
+ # Try to grab the name and section.
+ if original =~ /^.TH (\S+).*?(\d).*$/
+ # Clear out the gunk, "MUSTACHE" => MUSTACHE
+ name, section = $1, $2
+ name.gsub!(/"|'/, '')
+
+ # make MUSTACHE(1)
+ title = "#{name}(#{section})"
+
+ # Classy divs.
+ left = "<div float='left'>#{title}</div>"
+ right = "<div float='right'>#{title}</div>"
+ end
+
+ if rendered =~ /<body>\s*(.+)\s*<\/body>/mi
+ $1.gsub(/<hr>/, '').gsub(/(<h1.+?h1>)/, "<div>#{left}\\1#{right}</div>")
+ end
+end
View
@@ -0,0 +1,138 @@
+.\" generated with Ron/v0.3
+.\" http://github.com/rtomayko/ron/
+.
+.TH "MUSTACHE" "1" "March 2010" "DEFUNKT" "Mustache Manual"
+.
+.SH "NAME"
+\fBmustache\fR \-\- Mustache processor
+.
+.SH "SYNOPSIS"
+\fBcat data.yml template.mustache | mustache\fR
+.
+.SH "DESCRIPTION"
+Mustache is a logic\-less templating system for HTML, config files,
+anything.
+.
+.P
+The \fBmustache\fR command processes a Mustache template preceded by YAML
+frontmatter from standard input and prints one or more documents to
+standard output.
+.
+.P
+YAML frontmatter beings with \fB---\fR on a single line, followed by YAML,
+ending with another \fB---\fR on a single line, e.g.
+.
+.IP "" 4
+.
+.nf
+
+\fB---
+names: [ {name: chris}, {name: mark}, {name: scott} ]
+--- \fR
+.
+.fi
+.
+.IP "" 0
+.
+.P
+If you are unfamiliar with YAML, it is a superset of JSON. Valid JSON
+should work fine.
+.
+.P
+After the frontmatter should come any valid Mustache template. See
+mustache(5) for an overview of Mustache templates.
+.
+.P
+For example:
+.
+.IP "" 4
+.
+.nf
+
+\fB{{#names}}
+ Hi {{name}}!
+{{/names}} \fR
+.
+.fi
+.
+.IP "" 0
+.
+.P
+Now let's combine them.
+.
+.IP "" 4
+.
+.nf
+
+\fB$ cat data.yml
+---
+names: [ {name: chris}, {name: mark}, {name: scott} ]
+---
+$ cat template.mustache
+{{#names}}
+ Hi {{name}}!
+{{/names}}
+
+$ cat data.yml template.mustache | mustache
+Hi chris!
+Hi mark!
+Hi scott!
+\fR
+.
+.fi
+.
+.IP "" 0
+.
+.P
+If you provide multiple YAML documents (as delimited by \fB---\fR), your
+template will be rendered multiple times. Like a mail merge.
+.
+.P
+For example:
+.
+.IP "" 4
+.
+.nf
+
+\fB$ cat data.yml
+---
+name: chris
+---
+name: mark
+---
+name: scott
+---
+$ cat template.mustache
+Hi {{name}}!
+
+$ cat data.yml template.mustache | mustache
+Hi chris!
+Hi mark!
+Hi scott!
+\fR
+.
+.fi
+.
+.IP "" 0
+.
+.SH "INSTALLATION"
+If you have RubyGems installed:
+.
+.IP "" 4
+.
+.nf
+
+\fBgem install mustache \fR
+.
+.fi
+.
+.IP "" 0
+.
+.SH "COPYRIGHT"
+Mustache is Copyright (C) 2009 Chris Wanstrath
+.
+.P
+Original CTemplate by Google
+.
+.SH "SEE ALSO"
+mustache(5), mustache(7), gem(1),\fIhttp://defunkt.github.com/mustache/\fR
View
@@ -0,0 +1,184 @@
+<div><div float='left'>MUSTACHE(1)</div><h1 align=center>MUSTACHE</h1><div float='right'>MUSTACHE(1)</div></div>
+
+
+
+<a name="NAME"></a>
+<h2>NAME</h2>
+
+
+
+<p style="margin-left:11%; margin-top: 1em"><b>mustache</b>
+&minus;&minus; Mustache processor</p>
+
+<a name="SYNOPSIS"></a>
+<h2>SYNOPSIS</h2>
+
+
+<p style="margin-left:11%; margin-top: 1em"><b>cat data.yml
+template.mustache | mustache</b></p>
+
+<a name="DESCRIPTION"></a>
+<h2>DESCRIPTION</h2>
+
+
+<p style="margin-left:11%; margin-top: 1em">Mustache is a
+logic&minus;less templating system for HTML, config files,
+anything.</p>
+
+<p style="margin-left:11%; margin-top: 1em">The
+<b>mustache</b> command processes a Mustache template
+preceded by YAML frontmatter from standard input and prints
+one or more documents to standard output.</p>
+
+<p style="margin-left:11%; margin-top: 1em">YAML
+frontmatter beings with <b>---</b> on a single line,
+followed by YAML, ending with another <b>---</b> on a single
+line, e.g.</p>
+
+<table width="100%" border=0 rules="none" frame="void"
+ cellspacing="0" cellpadding="0">
+<tr valign="top" align="left">
+<td width="17%"></td>
+<td width="5%">
+
+
+<p style="margin-top: 1em" valign="top"><b>---</b></p></td>
+<td width="78%">
+</td>
+</table>
+
+<p style="margin-left:17%;"><b>names: [ {name: chris},
+{name: mark}, {name: scott} ] <br>
+---</b></p>
+
+<p style="margin-left:11%; margin-top: 1em">If you are
+unfamiliar with YAML, it is a superset of JSON. Valid JSON
+should work fine.</p>
+
+<p style="margin-left:11%; margin-top: 1em">After the
+frontmatter should come any valid Mustache template. See
+mustache(5) for an overview of Mustache templates.</p>
+
+<p style="margin-left:11%; margin-top: 1em">For
+example:</p>
+
+<table width="100%" border=0 rules="none" frame="void"
+ cellspacing="0" cellpadding="0">
+<tr valign="top" align="left">
+<td width="17%"></td>
+<td width="15%">
+
+
+
+<p style="margin-top: 1em" valign="top"><b>{{#names}}</b></p> </td>
+<td width="68%">
+</td>
+</table>
+
+<p style="margin-left:17%;"><b>Hi {{name}}! <br>
+{{/names}}</b></p>
+
+<p style="margin-left:11%; margin-top: 1em">Now let&rsquo;s
+combine them.</p>
+
+<table width="100%" border=0 rules="none" frame="void"
+ cellspacing="0" cellpadding="0">
+<tr valign="top" align="left">
+<td width="17%"></td>
+<td width="21%">
+
+
+<p style="margin-top: 1em" valign="top"><b>$ cat
+data.yml</b></p> </td>
+<td width="62%">
+</td>
+</table>
+
+<p style="margin-left:17%;"><b>--- <br>
+names: [ {name: chris}, {name: mark}, {name: scott} ] <br>
+--- <br>
+$ cat template.mustache <br>
+{{#names}} <br>
+Hi {{name}}! <br>
+{{/names}}</b></p>
+
+<p style="margin-left:17%; margin-top: 1em"><b>$ cat
+data.yml template.mustache | mustache <br>
+Hi chris! <br>
+Hi mark! <br>
+Hi scott!</b></p>
+
+<p style="margin-left:11%; margin-top: 1em">If you provide
+multiple YAML documents (as delimited by <b>---</b>), your
+template will be rendered multiple times. Like a mail
+merge.</p>
+
+<p style="margin-left:11%; margin-top: 1em">For
+example:</p>
+
+<table width="100%" border=0 rules="none" frame="void"
+ cellspacing="0" cellpadding="0">
+<tr valign="top" align="left">
+<td width="17%"></td>
+<td width="21%">
+
+
+<p style="margin-top: 1em" valign="top"><b>$ cat
+data.yml</b></p> </td>
+<td width="62%">
+</td>
+</table>
+
+<p style="margin-left:17%;"><b>--- <br>
+name: chris <br>
+--- <br>
+name: mark <br>
+--- <br>
+name: scott <br>
+--- <br>
+$ cat template.mustache <br>
+Hi {{name}}!</b></p>
+
+<p style="margin-left:17%; margin-top: 1em"><b>$ cat
+data.yml template.mustache | mustache <br>
+Hi chris! <br>
+Hi mark! <br>
+Hi scott!</b></p>
+
+<a name="INSTALLATION"></a>
+<h2>INSTALLATION</h2>
+
+
+<p style="margin-left:11%; margin-top: 1em">If you have
+RubyGems installed:</p>
+
+<table width="100%" border=0 rules="none" frame="void"
+ cellspacing="0" cellpadding="0">
+<tr valign="top" align="left">
+<td width="17%"></td>
+<td width="31%">
+
+
+<p style="margin-top: 1em" valign="top"><b>gem install
+mustache</b></p> </td>
+<td width="52%">
+</td>
+</table>
+
+<a name="COPYRIGHT"></a>
+<h2>COPYRIGHT</h2>
+
+
+<p style="margin-left:11%; margin-top: 1em">Mustache is
+Copyright (C) 2009 Chris Wanstrath</p>
+
+<p style="margin-left:11%; margin-top: 1em">Original
+CTemplate by Google</p>
+
+<a name="SEE ALSO"></a>
+<h2>SEE ALSO</h2>
+
+
+<p style="margin-left:11%; margin-top: 1em">mustache(5),
+mustache(7),
+gem(1),<i>http://defunkt.github.com/mustache/</i></p>

0 comments on commit 6ca46ab

Please sign in to comment.