Skip to content

Commit

Permalink
Rakefile: Create offline versions, refactor.
Browse files Browse the repository at this point in the history
We now create a build for offline use that is used to generate a .deb and
archives for downloading.
  • Loading branch information
runpaint committed May 24, 2009
1 parent 2805a76 commit a5f23a7
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 147 deletions.
137 changes: 84 additions & 53 deletions Rakefile
Expand Up @@ -2,30 +2,41 @@ require 'rake/clean'
require 'hpricot' require 'hpricot'
require 'erb' require 'erb'


WEB_OUT = 'output/www'
OFFLINE_OUT = 'output/offline'
SOURCE_HTML = FileList['text/**/*.html'] SOURCE_HTML = FileList['text/**/*.html']
WWW_HTML = FileList['output/**/**/*.html'] WWW_HTML = FileList["#{WEB_OUT}/**/**/*.html"]
IMAGES = FileList['images/*'] IMAGES = FileList['images/*']
OUTPUT_HTML = 'output/all.html' OUTPUT_HTML = "#{WEB_OUT}/all.html"
PDF = "#{WEB_OUT}/vim-recipes.pdf"
CLOBBER.include('output','deb') CLOBBER.include('output','deb')
TEMPLATES_DIR = 'templates/'
TEMPLATE_WRAPPER = 'page.html'
TEMPLATE_NO_WRAP = [TEMPLATE_WRAPPER, 'atom.atom']

def bind(obj)
obj.send(:binding)
end


def template(filename,hash) def template(filename,hash)
ERB.new(File.open(filename).read).result( content = ERB.new(File.open(File.join(TEMPLATES_DIR,filename)).read).
OpenStruct.new(hash).send(:binding) result(bind(OpenStruct.new(hash)))
) return content if TEMPLATE_NO_WRAP.include? filename
template(TEMPLATE_WRAPPER, {:content => content}.merge(hash))
end end


directory "output" directory WEB_OUT


desc "Copy images to output directory" desc "Copy images to output directory"
task :images => :output task :images => WEB_OUT
task :images => IMAGES do |t| task :images => IMAGES do |t|
IMAGES.each do |image| IMAGES.each do |image|
cp image, "output" cp image, WEB_OUT
end end
end end


desc "Combine source HTML into single HTML file" desc "Combine source HTML into single HTML file"
task OUTPUT_HTML => [:output, :images] task OUTPUT_HTML => [WEB_OUT, :images]
file OUTPUT_HTML => SOURCE_HTML do |t| file OUTPUT_HTML => SOURCE_HTML do |t|
File.open(t.name,'w') do |out| File.open(t.name,'w') do |out|
SOURCE_HTML.sort.each do |source| SOURCE_HTML.sort.each do |source|
Expand All @@ -34,12 +45,14 @@ file OUTPUT_HTML => SOURCE_HTML do |t|
end end
end end


file 'output/vim-recipes.pdf' => OUTPUT_HTML do |t| file PDF => [OUTPUT_HTML,WEB_OUT] do |t|
system("prince #{t.prerequisites.first} #{t.name}") system("prince #{t.prerequisites.first} #{t.name}")
end end


desc "Generate the PDF" desc "Generate the PDF"
task :pdf => [:clobber, 'output/vim-recipes.pdf'] task :pdf => PDF do
rm OUTPUT_HTML
end


desc "Generate the Sitemap" desc "Generate the Sitemap"
task :sitemap do task :sitemap do
Expand Down Expand Up @@ -85,7 +98,7 @@ def make_toc
toc << { :id => h_tag['id'], :title => title, :file => f, toc << { :id => h_tag['id'], :title => title, :file => f,
:type => type, :section_name => section, :section_id => section_id, :type => type, :section_name => section, :section_id => section_id,
:recipe_id => recipe_id, :time => commit_time(f), :recipe_id => recipe_id, :time => commit_time(f),
:target_path => "output/#{section_id}/#{h_tag['id']}/index.html" } :target_path => "#{WEB_OUT}/#{section_id}/#{h_tag['id']}/index.html" }
end end
end end
toc toc
Expand All @@ -100,14 +113,14 @@ task :html => SOURCE_HTML do |t|
doc = Hpricot(source) doc = Hpricot(source)


if (entry[:type] == :section) || (entry[:id] == 'introduction') if (entry[:type] == :section) || (entry[:id] == 'introduction')
page = template('templates/chapter.html', page = template('chapter.html',
{:title => entry[:id] == 'introduction' ? 'Preliminaries' : entry[:title], {:title => entry[:id] == 'introduction' ? 'Preliminaries' : entry[:title],
:recipes => toc.select do |e| :recipes => toc.select do |e|
(e[:section_id] == entry[:section_id]) && (e[:section_id] == entry[:section_id]) &&
(e[:type] == :recipe) (e[:type] == :recipe)
end end
}) })
path = "output/#{entry[:section_id]}/index.html" path = "#{WEB_OUT}/#{entry[:section_id]}/index.html"
mkdir_p File.dirname(path) mkdir_p File.dirname(path)
File.open(path,'w'){|f| f.puts page} File.open(path,'w'){|f| f.puts page}
end end
Expand Down Expand Up @@ -140,73 +153,91 @@ task :html => SOURCE_HTML do |t|
|e| e[:type] == :recipe}.first |e| e[:type] == :recipe}.first
prv = idx == 0 ? toc[-1] : toc[0..(idx - 1)].select{ prv = idx == 0 ? toc[-1] : toc[0..(idx - 1)].select{
|e| e[:type] == :recipe}[-1] |e| e[:type] == :recipe}[-1]
page = template('templates/recipe.html', page = template('recipe.html',
{:body => doc.to_s, :title => entry[:title], :id => entry[:id], {:body => doc.to_s, :title => entry[:title], :id => entry[:id],
:section_id => entry[:section_id], :section => entry[:section_name], :section_id => entry[:section_id], :section => entry[:section_name],
:next_e => nxt, :prev_e => prv}) :next_e => nxt, :prev_e => prv})
#FIXME: Use :target_path instead: #FIXME: Use :target_path instead:
path = "output/#{entry[:section_id]}/#{entry[:id]}/index.html" path = "#{WEB_OUT}/#{entry[:section_id]}/#{entry[:id]}/index.html"
mkdir_p File.dirname(path) mkdir_p File.dirname(path)
File.open(path,'w') {|file| file.puts page} File.open(path,'w') {|file| file.puts page}
entry[:body] = doc.to_s entry[:body] = doc.to_s
end end
end end
page = template('templates/toc.html', page = template('toc.html',
{:toc => toc.dup.reject{|e| e[:type] == :subsection}}) {:toc => toc.dup.reject{|e| e[:type] == :subsection},
mkdir_p 'output/toc' :title => 'Table of Contents'})
File.open('output/toc/index.html','w') {|file| file.puts page} mkdir_p "#{WEB_OUT}/toc"
File.open("#{WEB_OUT}/toc/index.html",'w') {|file| file.puts page}
recipes_by_time = toc.reject{|e| e[:type] == :subsection}. recipes_by_time = toc.reject{|e| e[:type] == :subsection}.
sort_by{|e| e[:time]}.reverse sort_by{|e| e[:time]}.reverse
page = template('templates/atom.atom', page = template('atom.atom',
{:toc => recipes_by_time, :updated => recipes_by_time.first[:time]}) {:toc => recipes_by_time, :updated => recipes_by_time.first[:time]})
File.open('output/index.atom','w') {|file| file.puts page} File.open("#{WEB_OUT}/index.atom",'w') {|file| file.puts page}
end end


directory 'output/css' directory "#{WEB_OUT}/css"
desc "Generate the website" desc "Generate the website"
task :www => ['output/vim-recipes.pdf',:html, 'output/css'] do multitask :www => ["#{WEB_OUT}/vim-recipes.pdf",:html, "#{WEB_OUT}/css", :offline] do
FileList['www/*', 'www/.[a-z]*'].each {|f| cp f, 'output/'} FileList['www/*', 'www/.[a-z]*'].each {|f| cp f, WEB_OUT}
File.open('output/css/style.css','w') do |merged| File.open("#{WEB_OUT}/css/style.css",'w') do |merged|
['main','web'].each do |name| ['main','web'].each do |name|
merged.print File.open('templates/' + name + '.css').read merged.print File.open(File.join(TEMPLATES_DIR, name + '.css')).read
end end
end end
cp_r 'js', 'output/' cp_r 'js', WEB_OUT
end end


desc "Upload the website" desc "Upload the website"
task :upload => [:www, :sitemap] do task :upload => [:www, :sitemap] do
rm OUTPUT_HTML rm OUTPUT_HTML
sh "rsync -vaz output/ vim.runpaint.org:/home/public/" sh "rsync -vaz #{WEB_OUT}/ vim.runpaint.org:/home/public/"
Rake::Task['sitemap_notify'].invoke Rake::Task['sitemap_notify'].invoke
sh 'git push' sh 'git push'
end end


desc "Generate the .deb" desc "Generate the .deb"
task :deb => [:www] do task :deb => [:offline_html] do
deb_dir = 'deb/usr/share/doc/vimrecipes' dir = 'deb/usr/share/doc/vimrecipes/html'
html_dir = deb_dir + '/html' mkdir_p dir
mkdir_p html_dir cp_r OFFLINE_OUT, dir
cp 'output/toc/index.html', html_dir end
#sh "gzip -c output/vim-recipes.pdf >#{deb_dir}/vim-recipes.pdf.gz"
FileList['output/*/','output/*.png'].each {|d| cp_r d, html_dir} desc "Generate the offline HTML"
FileList["#{html_dir}/*.html", "#{html_dir}/*/*.html", task :offline_html => [:html] do
"#{html_dir}/*/*/*.html"].each do |file| cp_r WEB_OUT, OFFLINE_OUT
prefix = '../' * (file.count('/') - html_dir.count('/') - 1) chdir OFFLINE_OUT do
doc = Hpricot(File.open(file).read) mv "toc/index.html", 'index.html'
doc.search('link[@rel=alternate]').remove rmdir 'toc'
doc.search('form, script, noscript').remove rm 'index.atom'
if doc.at('#disqus_thread') FileList["*.html", "*/*.html", "*/*/*.html"].each do |file|
doc.at('#disqus_thread').after('<script src="/js/footnotes.js">') prefix = '../' * (file.count('/') + 1 - OFFLINE_OUT.count('/'))
end doc = Hpricot(File.open(file).read)
%w{href src}.each do |attr| doc.search('link[@rel=alternate]').remove
doc.search("*[@#{attr}]").each do |tag| doc.search('form, script, noscript').remove
next unless tag[attr].start_with? '/' if doc.at('#disqus_thread')
tag[attr] = prefix + tag[attr][1..-1] doc.at('#disqus_thread').after('<script src="/js/footnotes.js">')
tag[attr] += 'index.html' if tag[attr].end_with? '/'
tag[attr] = tag[attr].sub('/toc','') || tag[attr]
end end
end %w{href src}.each do |attr|
File.open(file,'w').puts doc doc.search("*[@#{attr}]").each do |tag|
next unless tag[attr].start_with? '/'
tag[attr] = prefix + tag[attr][1..-1]
tag[attr] += 'index.html' if tag[attr].end_with? '/'
tag[attr] = tag[attr].sub('/toc','') || tag[attr]
end
end
File.open(file,'w').puts doc
end
end
end

desc "Create offline archive"
task :offline => [:pdf, :offline_html] do
cp File.join(WEB_OUT,'vim-recipes.pdf'), OFFLINE_OUT
chdir 'output' do
cp_r("offline", 'vim-recipes')
sh "tar cjf vim-recipes.tar.bz2 vim-recipes"
sh "zip -qr vim-recipes.zip vim-recipes"
mv(FileList["vim-recipes.*"],'www/')
end end
end end
2 changes: 1 addition & 1 deletion sitemap_config.xml
Expand Up @@ -37,7 +37,7 @@
--> -->
<site <site
base_url="http://vim.runpaint.org/" base_url="http://vim.runpaint.org/"
store_into="output/sitemap.xml" store_into="output/www/sitemap.xml"
verbose="1" verbose="1"
sitemap_type="web"> sitemap_type="web">


Expand Down
31 changes: 0 additions & 31 deletions templates/chapter.html
@@ -1,38 +1,7 @@
<html>
<head>
<meta charset="utf-8">
<title>Vim Recipes: <%= title %></title>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<link rel="alternate" type="application/atom+xml" title="Recipes Atom feed"
href="/index.atom"/>
</head>
<body>
<form action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="012927387456573046134:nfygyscsu3q">
<input type="hidden" name="ie" value="UTF-8">&nbsp;
<input name="q" size="25">&nbsp;
<input type="submit" name="root" value="Search">
</div>
</form>
<p><a href="/toc/">Vim Recipes</a> <span>&#8227;</span> <i><%= title %></i></p> <p><a href="/toc/">Vim Recipes</a> <span>&#8227;</span> <i><%= title %></i></p>
<h1><%= title %></h1> <h1><%= title %></h1>
<ul> <ul>
<% recipes.each do |r| %> <% recipes.each do |r| %>
<li><a href="/<%= r[:section_id] %>/<%= r[:id] %>/"><%= r[:title] %></a> <li><a href="/<%= r[:section_id] %>/<%= r[:id] %>/"><%= r[:title] %></a>
<% end %> <% end %>
<ul> <ul>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl."
: "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost +
"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-8774571-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>
<html>
31 changes: 31 additions & 0 deletions templates/page.html
@@ -0,0 +1,31 @@
<html>
<head>
<meta charset="utf-8">
<title>Vim Recipes: <%= title %></title>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<link rel="alternate" type="application/atom+xml" title="Recipes Atom feed"
href="/index.atom"/>
</head>
<body>
<form action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="012927387456573046134:nfygyscsu3q">
<input type="hidden" name="ie" value="UTF-8">&nbsp;
<input name="q" size="25">&nbsp;
<input type="submit" name="root" value="Search">
</div>
</form>
<%= content %>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl."
: "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost +
"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-8774571-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>
30 changes: 0 additions & 30 deletions templates/recipe.html
@@ -1,20 +1,3 @@
<html>
<head>
<meta charset="utf-8">
<title>Vim Recipes: <%= title %></title>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<link rel="alternate" type="application/atom+xml" title="Recipes Atom feed"
href="/index.atom"/>
</head>
<body>
<form action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="012927387456573046134:nfygyscsu3q">
<input type="hidden" name="ie" value="UTF-8">&nbsp;
<input name="q" size="25">&nbsp;
<input type="submit" name="root" value="Search">
</div>
</form>
<p><a href="/toc/">Vim Recipes</a> <span>&#8227;</span> <a href="/<%= section_id %>/"><%= section %></a> <span>&#8227;</span> <p><a href="/toc/">Vim Recipes</a> <span>&#8227;</span> <a href="/<%= section_id %>/"><%= section %></a> <span>&#8227;</span>
<i><%= title %></i></p> <i><%= title %></i></p>
<div class="nav"><a <div class="nav"><a
Expand Down Expand Up @@ -54,16 +37,3 @@
</script> </script>


<script type="text/javascript" src="/js/footnotes.js"></script> <script type="text/javascript" src="/js/footnotes.js"></script>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl."
: "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost +
"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-8774571-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>
30 changes: 0 additions & 30 deletions templates/toc.html
@@ -1,20 +1,3 @@
<html>
<head>
<meta charset="utf-8">
<title>Vim Recipes: Table of Contents</title>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<link rel="alternate" type="application/atom+xml" title="Recipes Atom feed"
href="/index.atom"/>
</head>
<body>
<form action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="012927387456573046134:nfygyscsu3q">
<input type="hidden" name="ie" value="UTF-8">&nbsp;
<input name="q" size="25">&nbsp;
<input type="submit" name="root" value="Search">
</div>
</form>
<p><a href="/">Vim Recipes</a> <span>&#8227;</span> <i>Table of <p><a href="/">Vim Recipes</a> <span>&#8227;</span> <i>Table of
Contents</i></p> Contents</i></p>
<h1>Table of Contents</h1> <h1>Table of Contents</h1>
Expand All @@ -37,16 +20,3 @@ <h1>Table of Contents</h1>
<% end <% end
end %> end %>
</ul> </ul>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl."
: "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost +
"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-8774571-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions text/01_pre/00-head.html
Expand Up @@ -4,8 +4,8 @@
<head> <head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Vim Recipes - A cookbook for the Vim text editor</title> <title>Vim Recipes - A cookbook for the Vim text editor</title>
<link rel="stylesheet" type="text/css" href="../templates/main.css"/> <link rel="stylesheet" type="text/css" href="../../templates/main.css"/>
<link rel="stylesheet" type="text/css" href="../templates/pdf.css"/> <link rel="stylesheet" type="text/css" href="../../templates/pdf.css"/>
<meta name="author" content="Run Paint Run Run" /> <meta name="author" content="Run Paint Run Run" />
<meta name="subject" content="Vim text editor" /> <meta name="subject" content="Vim text editor" />
<meta name="keywords" content="vim cookbook recipes technical software <meta name="keywords" content="vim cookbook recipes technical software
Expand Down

0 comments on commit a5f23a7

Please sign in to comment.