lib/md2man/rakefile.rb in md2man-1.4.1 vs lib/md2man/rakefile.rb in md2man-1.4.2
- old
+ new
@@ -38,36 +38,129 @@
#-----------------------------------------------------------------------------
desc 'Build HTML manual pages from Markdown files in man/.'
task 'md2man:web' => 'man/index.html'
#-----------------------------------------------------------------------------
+wrap_html_template = lambda do |title, content|
+<<WRAP_HTML_TEMPLATE
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8" />
+ <title>#{title}</title>
+ <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
+ <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" />
+ <style type="text/css">
+ @media all {
+ .manpage h1 {
+ font-weight: normal;
+ font-size: smaller;
+ text-align: right;
+ }
+ .manpage h2,
+ .manpage h3,
+ .manpage h4,
+ .manpage h5,
+ .manpage h6 {
+ margin-top: 1em;
+ }
+ }
+ @media screen {
+ .manpage {
+ font-family: monospace;
+ max-width: 78ex;
+ }
+ .manpage h1 {
+ margin-top: -5em;
+ }
+ }
+
+ @media print {
+ .navbar {
+ display: none;
+ }
+
+ /* improve readability of revealed hyperlink URLs */
+ a:after {
+ font-family: monospace;
+ }
+
+ /* internal links and manual page cross-references */
+ a[href^='#'], a[href^='../man'] {
+ color: inherit;
+ font-weight: bolder;
+ text-decoration: none;
+ }
+
+ /* undo bootstrap's revealing of those hyperlinks */
+ a[href^='#']:after, a[href^='../man']:after {
+ content: none;
+ }
+ }
+ </style>
+</head>
+<body>#{content}</body>
+</html>
+WRAP_HTML_TEMPLATE
+end
+
+parse_manpage_name = lambda do |html_file_name|
+ html_file_name.pathmap('%n').sub(/\.(.+)$/, '(\1)')
+end
+
+parse_manpage_info = lambda do |html_file_body|
+ html_file_body.scan(%r{<h2.*?>NAME</h2>(.+?)<h2}m).flatten.first.
+ to_s.split(/\s+-\s+/, 2).last.to_s.gsub(/<.+?>/, '') # strip HTML
+end
+
file 'man/index.html' => webs do |t|
- output = []
- dirs = webs.group_by {|web| web.pathmap('%d') }.each do |dir, dir_webs|
- subdir = dir.pathmap('%f')
- output << %{<h2 id="#{subdir}">#{subdir}</h2>}
+ buffer = ['<div class="container-fluid">']
+ webs.group_by {|web| web.pathmap('%d') }.each do |dir, dir_webs|
+ subdir = dir.sub('man/', '')
+ buffer << %{<h2 id="#{subdir}">#{subdir}</h2>}
+
dir_webs.each do |web|
- title = web.pathmap('%n').sub(/\.(.+)$/, '(\1)')
- link = %{<a href="#{subdir}/#{web.pathmap('%f')}">#{title}</a>}
- info = File.read(web).scan(%r{<h2.*?>NAME</h2>(.+?)<h2}m).flatten.first.
- to_s.split(/\s+-\s+/, 2).last.to_s.gsub(/<.+?>/, '') # strip HTML
- output << "<dl><dt>#{link}</dt><dd>#{info}</dd></dl>"
+ name = parse_manpage_name.call(web)
+ info = parse_manpage_info.call(File.read(web))
+ link = %{<a href="#{subdir}/#{web.pathmap('%f')}">#{name}</a>}
+ buffer << %{<dl class="dl-horizontal"><dt>#{link}</dt><dd>#{info}</dd></dl>}
end
- File.open("#{dir}/index.html", 'w') do |f|
- f << %{<meta http-equiv="refresh" content="0;url=../index.html##{subdir}"/>}
- end
end
- File.open(t.name, 'w') {|f| f.puts output }
+ buffer << '</div>'
+ content = buffer.join
+
+ title = t.name.pathmap('%X')
+ output = wrap_html_template.call(title, content)
+ File.open(t.name, 'w') {|f| f << output }
end
mkds.zip(webs).each do |src, dst|
render_file_task.call src, dst, lambda {|input|
require 'md2man/html/engine'
output = Md2Man::HTML::ENGINE.render(input)
- navbar = '<div class="manpath-navigation">' + [
- %{<a href="../index.html">#{dst.pathmap('%1d')}</a>},
- %{<a href="index.html">#{dst.pathmap('%-1d')}</a>},
- %{<a href="">#{dst.pathmap('%n')}</a>},
- ].join(' → ') + '</div>'
- [navbar, output, navbar].join('<hr/>')
+
+ name = parse_manpage_name.call(dst)
+ info = parse_manpage_info.call(output)
+ title = [name, info].join(' — ')
+
+ subdir = dst.pathmap('%d').sub('man/', '')
+ ascend = '../' * subdir.count('/').next
+ content = [
+ '<div class="navbar">',
+ '<div class="navbar-inner">',
+ '<span class="brand">',
+ %{<a href="#{ascend}index.html##{subdir}">#{subdir}</a>},
+ '/',
+ dst.pathmap('%n'),
+ '</span>',
+ '</div>',
+ '</div>',
+ '<div class="container-fluid">',
+ '<div class="manpage">',
+ output,
+ '</div>',
+ '</div>',
+ ].join
+
+ wrap_html_template.call title, content
}
end