Permalink
Browse files

Add rake tasks for generating a flat version of the docs for conversi…

…on to pdf with wkhtmltopdf.
  • Loading branch information...
1 parent 18e6a2d commit 7dfe2f75902a90a287dc3c4fa9b7f19d67d8c178 @nfagerlund nfagerlund committed Mar 18, 2011
View
@@ -5,3 +5,5 @@ output
.#*
log
.DS_Store
+pdf_output
+pdf_source
View
@@ -47,6 +47,30 @@ end
desc "Generate docs and serve locally"
task :run => [:generate, :serve]
+desc "Generate the documentation in a flat format for later PDF generation"
+task :generate_pdf do
+ system("rm -rf pdf_source")
+ system("cp -rf source pdf_source")
+ system("cp -rf pdf_mask/* pdf_source") # Copy in and/or overwrite differing files
+ # The point being, this way we don't have to maintain separate copies of the actual source files, and it's clear which things are actually different for the PDF version of the page.
+ Dir.chdir("pdf_source")
+ system("../vendor/gems/jekyll-0.7.0/bin/jekyll --kramdown ../pdf_output")
+ Rake::Task['references:symlink:for_pdf'].invoke
+ Dir.chdir("../pdf_output")
+ system("cat `cat ../pdf_source/page_order.txt` > rebuilt_index.html")
+ system("mv index.html original_index.html")
+ system("mv rebuilt_index.html index.html")
+ puts "Remember to run rake serve_pdf"
+ puts "Remember to run wkhtmltopdf cover http://localhost:9292/cover.html http://localhost:9292/ puppet.pdf"
+ Dir.chdir("..")
+end
+
+desc "Serve generated flat-for-PDF output on port 9292"
+task :serve_pdf do
+ system("rackup config_pdf.ru")
+end
+
+
desc "Build documentation for a new Puppet version"
task :build => [ 'references:check_version', 'references:fetch_tags', 'references:stub', 'references:puppetdoc', 'references:update_manpages']
@@ -92,7 +116,18 @@ namespace :references do
puts "#{name}: #{version}"
end
end
-
+
+ desc "Symlink the latest & stable directories when generating a flat page for PDFing"
+ task :for_pdf do
+ require 'puppet_docs'
+ PuppetDocs::Reference.special_versions.each do |name, (version, source)|
+ Dir.chdir '../pdf_output/references' do
+ ln_sf version.to_s, name.to_s
+ end
+ end
+
+ end
+
end
desc "Symlink the latest & stable directories"
View
@@ -0,0 +1,24 @@
+require 'pathname'
+
+class DirectoryIndex
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ %w(REQUEST_METHOD REQUEST_URI PATH_INFO).each do |name|
+ value = env[name]
+ if value && value =~ /\/$/
+ value << 'index.html'
+ end
+ end
+ @app.call(env)
+ end
+
+end
+
+puts ">>> Serving at http://localhost:9292"
+
+use DirectoryIndex
+run Rack::Directory.new(Pathname.new(__FILE__).parent + 'pdf_output')
@@ -0,0 +1,25 @@
+ {{ content }}
+
+
+ <div id="copyright">
+ <div class="site-width">
+ &copy; 2010 <a href="http://www.puppetlabs.com/" title="Puppet Labs">Puppet Labs</a>
+ <span class="vcard">
+ <span class="org"></span>
+ <a class="email" href="mailto:info@puppetlabs.com">info@puppetlabs.com</a>
+
+ <span class="adr">
+ <span class="street-address">411 NW Park Street</span>
+ /
+ <span class="locality">Portland</span>,
+ <span class="region">OR</span>
+ <span class="postal-code">97209</span>
+
+ </span>
+
+ <span class="tel">1-877-575-9775</span>
+ </span>
+ </div>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,5 @@
+{% capture clean_page_id %}{{ page.url | sanitizeid }}{% endcapture %}
+{% capture page_url %}{{ page.url }}{% endcapture %}
+<div class="individual-page" id="{{ clean_page_id }}">
+ {{ content | singlepagifylinks: page_url }}
+</div>
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html dir="ltr" lang="en-US">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Puppet Documentation | Puppet Labs</title>
+ <meta name="description" content="The open source leader in data center automation">
+ <link rel="alternate" type="text/xml" title="Puppet Labs RSS 0.92 Feed" href="http://puppetlabs.com/feed/rss/">
+ <link rel="alternate" type="application/atom+xml" title="Puppet Labs Atom Feed" href="http://puppetlabs.com/feed/atom/">
+ <link rel="alternate" type="application/rss+xml" title="Puppet Labs RSS 2.0 Feed" href="http://puppetlabs.com/feed/">
+ <link rel="pingback" href="http://puppetlabs.com/xmlrpc.php">
+ <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://puppetlabs.com/xmlrpc.php?rsd" />
+ <link rel='index' title='Puppet Labs' href='http://docs.puppetlabs.com' />
+
+
+
+ <!-- FIXME: absolute paths -->
+
+ <script type='text/javascript' src='/files/javascripts/html5.js'></script>
+ <script type='text/javascript' src='/files/javascripts/jquery-1.3.2.min.js'></script>
+ <script type='text/javascript' src='/files/javascripts/drop_down.js'></script>
+ <script type='text/javascript' src='/files/javascripts/cufon-yui.js'></script>
+ <script type='text/javascript' src='/files/fonts/Klavika_400-Klavika_600.font.js'></script>
+ <script type='text/javascript' src='/files/javascripts/ampersands.js'></script>
+ <script type='text/javascript' src='/files/javascripts/th_underscores.js'></script>
+
+ <!-- All in One SEO Pack 1.6.10.1 by Michael Torbert of Semper Fi Web Design[127,146] -->
+ <meta name="keywords" content="Puppet, puppet labs, reductive labs, open source, system administrator, ruby, data center, automation, support" />
+ <link rel="canonical" href="http://docs.puppetlabs.com" />
+ <!-- /all in one seo pack -->
+
+ <!-- FIXME: absolute paths -->
+
+ <link rel="stylesheet" type="text/css" href="/files/stylesheets/replacementstyle.css" media="screen">
+ <link rel="stylesheet" type="text/css" href="/files/stylesheets/syntax.css" media="screen"> <!-- index -->
+
+ <!--[if IE 7]>
+ <link rel="stylesheet" type="text/css" href="/files/stylesheets/ie_7.css" media="screen"> <!-- index -->
+ <![endif]-->
+
+ <!--[if IE 8]>
+ <link rel="stylesheet" type="text/css" href="/files/stylesheets/ie_8.css" media="screen"> <!-- index -->
+ <![endif]-->
+
+</head>
+
+
+
+
+ <body id="resources" class="docs">
+
+
+{% capture clean_page_id %}{{ page.url | sanitizeid }}{% endcapture %}
+{% capture page_url %}{{ page.url }}{% endcapture %}
+ {{ content | singlepagifylinks: page_url }}
+ <!-- Insert all other content here. There are a bunch of open divs right now, which are closed in bottom.html. -->
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+require 'jekyll'
+
+module SanitizeIDFilter
+ def sanitizeid(input)
+ input.gsub(/[\/\.]/, '-')
+ end
+end
+Liquid::Template.register_filter(SanitizeIDFilter)
@@ -0,0 +1,70 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+require 'jekyll'
+
+module SinglePagifyLinksFilter
+ def singlepagifylinks(input, url)
+ # Receive the URL, make an ID prefix.
+ id_prefix = url.gsub(/[\/\.]/, '-')
+ path_array = url.split(/\//)
+ # First, we need to make all the header element IDs unique, which we can do by just prefixing them with a unique ID for this HTML file. (We were passed this ID prefix as an argument to the filter call.)
+ # Actually, we need to catch lis (they're used in footnotes) as well as h\ds, because if we don't do that, we'll have to account for more types of link case than we want. This is harder than just diddling IDs for every element, because some of those are used for styling. we need to only touch the IDs that the stylesheet couldn't be aware of.
+ # We SHOULDN'T have to catch the divs that I'm manually linking to, because they are happening outside this filter. But those ARE going to be another link class, because we'll need to reach them pretty often and those links don't have an anchor attached.
+ input.gsub!(/<(h\d|li|sup3) id="([^"]+)">/, %Q{<\\1 id="#{id_prefix}-\\2">})
+ # Great, any links from outside this file will now be redirected to the proper unique IDs. Next, we need to make sure our outbound links are actually going to the correct place. We'll need to:
+ # * change ones that are internal to this file to point to the right place
+ # * Change ones pointing to other files without a positional anchor to point to the divs I made in default.html
+ # * Change ones pointing to positions in other files to point to the right place.
+
+ input.gsub!(/<a href="([^"]+)"( re.="footnote")?>/){ |match|
+ href = $1
+ if $2
+ footnotish = $2
+ else
+ footnotish = ''
+ end
+ case href
+ when /^#/
+ # internal to this page. we'll do a gsub to take care of the # at the same time, but to be honest this is kind of brittle and depends on kramdown never putting a / or a . or a literal # in any of the header or footnote IDs. But eh, I feel like it's probably a safe assumption.
+ newhref = id_prefix + href.gsub(/[\/\.#]/, '-')
+ %Q{<a href="##{newhref}"#{footnotish}>}
+ # We have an extra requirement to preserve the footnote extras if it's a natively internal link.
+ when /^(http:\/\/docs\.puppetlabs\.com\/|\/)/
+ # complete path, easy. And we can treat anchors the same way as slashes and periods, because of the way we constructed the IDs!
+ newhref = href.split('.com')[-1].gsub(/\/$/, '-index-html').gsub(/[\/\.#]/, '-')
+ # Oh and there's one case I'm not accounting for with that pair of chained gsubs, which are links that go places like ../#learning-puppet, reason being that you just shouldn't make those.
+ %Q{<a href="##{newhref}">}
+ when /^\.\//
+ # Relative to our current path. Prepend the entire path except for our own filename.
+ path_from_root = path_array.length > 2 ? '-' + path_array[1 .. -2].join('-') : ''
+ # That last bit is necessary to have links from /index.html to ./learning/ral.html or whatever not EXPLODE.
+ newhref = path_from_root + href.gsub(/^\./, '').gsub(/\/$/, '-index-html').gsub(/[\/\.#]/, '-')
+ # This looks like an indexing error and is worth explaining. Basically I wanted to do path_array[0..-2].join('-') and be done with it, but if our current file is in the root path, that subarray is actually just a string and the join won't work. So I do the first join manually just in case. Sorry. :/
+ %Q{<a href="##{newhref}">}
+ when /^\.\.\//
+ # Relative to the path above our current path. Very similar to the last one.
+ newhref = '-' + path_array[1 .. -3].join('-') + href.gsub(/^\.\./, '').gsub(/\/$/, '-index-html').gsub(/[\/\.#]/, '-')
+ %Q{<a href="##{newhref}">}
+ else
+ # It's probably an external link, so just leave it the hell alone.
+ %Q{<a href="#{href}">}
+ end
+ }
+
+ input
+ end
+end
+Liquid::Template.register_filter(SinglePagifyLinksFilter)
@@ -0,0 +1,6 @@
+---
+layout: bottom
+title: Puppet Labs Documentation
+---
+
+<!-- This is the end of the song. -->
View
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Puppet Documentation</title>
+ <link rel="stylesheet" type="text/css" href="/files/stylesheets/replacementstyle.css" media="screen">
+</head>
+<body>
+ <img src="images/PuppetLabshorizontal.png" alt="Puppet logo" width="754" height="352" style="display: block; margin-left: auto; margin-right: auto;" />
+ <h1 style="text-align: center;">Puppet Documentation</h1>
+ <p><small>(Generated on March 18, 2011; git revision ___)</small></p>
+</body>
+</html>
@@ -0,0 +1,5 @@
+$(document).ready(function() {
+ $( 'th' ).each( function() {
+ $( this ).html( $( this ).html().replace(/_/g, ' '));
+ })
+});
Oops, something went wrong.

0 comments on commit 7dfe2f7

Please sign in to comment.