2010-11-03 23:24:39 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
require 'rake/clean'
|
|
|
|
|
|
|
|
CLEAN.include('**/*.{aux,log,out}')
|
2010-11-04 09:33:52 +00:00
|
|
|
CLEAN.include('tmp/**/*')
|
2010-11-03 23:24:39 +00:00
|
|
|
CLOBBER.include('**/*.pdf')
|
|
|
|
CLOBBER.include('content/**/*.tex')
|
2010-11-18 01:13:58 +00:00
|
|
|
CLOBBER.include('site/**/*.html')
|
2010-11-18 09:24:37 +00:00
|
|
|
CLOBBER.include('site/**/*.svg')
|
2010-11-18 01:13:58 +00:00
|
|
|
CLOBBER.include('site/include/*')
|
2010-11-18 09:24:37 +00:00
|
|
|
CLOBBER.exclude('site/js')
|
2010-11-03 23:24:39 +00:00
|
|
|
|
|
|
|
task :default => [:compile]
|
|
|
|
|
2010-11-18 15:14:42 +00:00
|
|
|
task :svg do
|
2010-11-17 15:32:03 +00:00
|
|
|
class HTMLCompile
|
|
|
|
def initialize
|
|
|
|
eval File.read('config.rb')
|
|
|
|
puts @pdfname
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
FileUtils.mkdir_p("site")
|
|
|
|
|
|
|
|
if not FileTest.exists?( "tmp/#{@pdfname}.pdf" )
|
|
|
|
puts "run `rake compile` to generate the pdf file please"
|
|
|
|
exit 1
|
|
|
|
end
|
2010-11-19 09:48:28 +00:00
|
|
|
command=%{pdf2svg tmp/#{@pdfname}.pdf svgsite/#{@pdfname}-%d.svg all}
|
2010-11-19 14:43:38 +00:00
|
|
|
puts command
|
2010-11-17 15:32:03 +00:00
|
|
|
system(command)
|
|
|
|
hdecal=110
|
|
|
|
vdecal=120
|
|
|
|
nb_pages=0
|
2010-11-19 09:48:28 +00:00
|
|
|
Dir["svgsite/*.svg"].each do |fic|
|
2010-11-17 15:32:03 +00:00
|
|
|
f=File.open(fic,"r")
|
|
|
|
res=f.read().sub( /viewBox="(\d+) (\d+) (\d+) (\d+)"/) do
|
|
|
|
res=%{viewBox="}
|
|
|
|
res<<=%{#{Integer($1) + hdecal} }
|
|
|
|
res<<=%{#{Integer($2) + vdecal} }
|
|
|
|
res<<=%{#{Integer($3) - hdecal} }
|
|
|
|
res<<=%{#{Integer($4) - vdecal}"}
|
|
|
|
end
|
|
|
|
f.close
|
|
|
|
f=File.open(fic,"w")
|
|
|
|
f.write( res )
|
|
|
|
f.close
|
|
|
|
nb_pages+=1
|
|
|
|
end
|
2010-11-19 09:48:28 +00:00
|
|
|
target=File.open("svgsite/index.html","w")
|
2010-11-17 15:32:03 +00:00
|
|
|
src=File.open("include/index.html","r")
|
|
|
|
res=src.read()
|
|
|
|
src.close
|
|
|
|
|
|
|
|
res.sub!("var nb_pages=0","var nb_pages=#{nb_pages}")
|
|
|
|
target.write(res)
|
|
|
|
target.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
x=HTMLCompile.new
|
|
|
|
x.run
|
|
|
|
end
|
|
|
|
|
2010-11-18 15:14:42 +00:00
|
|
|
task :html do
|
2010-11-17 20:22:38 +00:00
|
|
|
require 'rubygems'
|
|
|
|
require 'kramdown'
|
|
|
|
require 'filters/markdown_macros'
|
2010-12-06 10:02:24 +00:00
|
|
|
require 'filters/markdown_postmacros'
|
2010-11-18 01:13:58 +00:00
|
|
|
require 'filters/html_template'
|
2010-12-06 12:46:46 +00:00
|
|
|
require 'filters/fix_postmacros'
|
2010-11-18 01:13:58 +00:00
|
|
|
require 'filters/mathjax'
|
2010-11-18 18:00:25 +00:00
|
|
|
require 'filters/links'
|
2010-11-17 20:22:38 +00:00
|
|
|
|
|
|
|
class KrambookCompile
|
|
|
|
require 'config_html.rb'
|
2010-11-19 15:15:22 +00:00
|
|
|
require 'date'
|
2010-11-17 20:22:38 +00:00
|
|
|
|
|
|
|
attr_accessor :filelist
|
|
|
|
|
2010-12-06 10:28:54 +00:00
|
|
|
def initialize
|
|
|
|
|
|
|
|
eval File.new('config_html.rb','r').read
|
|
|
|
|
|
|
|
@prefilters=[]
|
|
|
|
@prefilters<<=MarkdownMacros.new
|
|
|
|
@prefilters<<=MarkdownPostMacros.new
|
2010-12-06 12:46:46 +00:00
|
|
|
@prefilters<<=FixPostMacros.new
|
2010-12-06 10:28:54 +00:00
|
|
|
|
|
|
|
@postfilters=[]
|
|
|
|
html_template=HTMLTemplate.new
|
|
|
|
html_template.template=@general_template
|
|
|
|
html_template.title=@title
|
|
|
|
html_template.subtitle=@subtitle
|
|
|
|
html_template.author=@author
|
|
|
|
html_template.homeURL="index.html"
|
|
|
|
@postfilters<<=Links.new
|
|
|
|
@postfilters<<=html_template
|
|
|
|
@postfilters<<=MathJax.new
|
|
|
|
|
|
|
|
@filelist=Dir.glob("content/**/*.md").sort.map do |fic|
|
|
|
|
[ fic, fic.sub(/^content\//,"site/").sub(/.md$/,".html") ]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-17 20:22:38 +00:00
|
|
|
# take a string from kramdown
|
|
|
|
# returns LaTeX after filter
|
|
|
|
def compile_text(tmp)
|
|
|
|
@prefilters.each do |f|
|
|
|
|
tmp=f.run( tmp )
|
|
|
|
end
|
|
|
|
|
|
|
|
# compile to latex
|
2010-12-06 10:28:54 +00:00
|
|
|
# puts tmp
|
|
|
|
tmp=Kramdown::Document.new(tmp).to_html
|
2010-11-17 20:22:38 +00:00
|
|
|
|
|
|
|
# post filters
|
|
|
|
@postfilters.each{ |f| tmp=f.run(tmp) }
|
|
|
|
return tmp
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_template
|
|
|
|
txt=File.read(@template_file)
|
|
|
|
|
|
|
|
# puts "READ: " + txt
|
|
|
|
txt.sub!( /<!-- INCLUDES -->/ ) do
|
|
|
|
@filelist.map do |source,dest|
|
2010-11-29 12:37:47 +00:00
|
|
|
if File::basename(source) == '00_Macros.md'
|
|
|
|
""
|
2010-12-14 10:06:00 +00:00
|
|
|
elsif File::basename(source) =~ /\.hide\./
|
|
|
|
""
|
2010-11-29 12:37:47 +00:00
|
|
|
else
|
|
|
|
%{<div class="block">
|
|
|
|
<h3>
|
|
|
|
<a href="#{dest.sub(/^site\//,'')}">
|
|
|
|
#{File::basename(dest,'.html').sub(/^\d+_/,'')}
|
|
|
|
<span class="nicer">»</span>
|
|
|
|
</a>
|
|
|
|
</h3>
|
|
|
|
</div>}
|
|
|
|
end
|
2010-11-17 20:22:38 +00:00
|
|
|
end.join("\n") + '</ul>'
|
|
|
|
end
|
2010-11-19 15:15:22 +00:00
|
|
|
txt.gsub!(%r{<!-- Date -->},Date.today.to_s)
|
2010-11-17 20:22:38 +00:00
|
|
|
# puts "AFTER INCLUDES: " + txt
|
|
|
|
txt.gsub!(%r{<!-- Author -->},@author)
|
|
|
|
# puts "AFTER AUTHOR: " + txt
|
|
|
|
txt.gsub!(%r{<!-- Title -->},@title)
|
|
|
|
txt.gsub!(%r{<!-- Subtitle -->},@subtitle)
|
|
|
|
# puts "AFTER TITLE: " + txt
|
2010-11-18 01:13:58 +00:00
|
|
|
fic=File.new("site/index.html","w")
|
2010-11-17 20:22:38 +00:00
|
|
|
fic.write(txt)
|
|
|
|
fic.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2010-11-18 01:13:58 +00:00
|
|
|
i=-1
|
2010-11-17 20:22:38 +00:00
|
|
|
@filelist.each do |doublon|
|
2010-11-18 01:13:58 +00:00
|
|
|
i+=1
|
2010-11-17 20:22:38 +00:00
|
|
|
source=doublon[0]
|
|
|
|
dest=doublon[1]
|
|
|
|
puts source
|
|
|
|
|
|
|
|
# read and compile in LaTeX the .md file
|
2010-12-06 10:02:24 +00:00
|
|
|
templateindex=1
|
2010-11-18 01:13:58 +00:00
|
|
|
if (i+1)<@filelist.size
|
2010-11-18 18:00:25 +00:00
|
|
|
@postfilters[templateindex].nextURL = '/' + @filelist[i + 1][1].gsub('site/','')
|
2010-11-18 01:13:58 +00:00
|
|
|
else
|
2010-11-18 18:00:25 +00:00
|
|
|
@postfilters[templateindex].nextURL = "#"
|
2010-11-18 01:13:58 +00:00
|
|
|
end
|
|
|
|
if (i-1)>=0
|
2010-11-18 18:00:25 +00:00
|
|
|
@postfilters[templateindex].prevURL = '/' + @filelist[i - 1][1].gsub('site/','')
|
2010-11-18 01:13:58 +00:00
|
|
|
else
|
2010-11-18 18:00:25 +00:00
|
|
|
@postfilters[templateindex].prevURL = "#"
|
2010-11-18 01:13:58 +00:00
|
|
|
end
|
2010-11-17 20:22:38 +00:00
|
|
|
text=compile_text( File.new(source,"r").read )
|
|
|
|
|
|
|
|
# create directory if necessary
|
|
|
|
if not FileTest::directory?(File.dirname(dest))
|
|
|
|
FileUtils.mkdir_p(File.dirname(dest))
|
|
|
|
end
|
|
|
|
|
|
|
|
# write the .tex file
|
|
|
|
fic = File.new(dest,"w")
|
|
|
|
fic.write(text)
|
|
|
|
fic.close
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# write the .tex file containing all includes
|
|
|
|
process_template
|
|
|
|
|
2010-11-18 01:13:58 +00:00
|
|
|
system("cp -rf include site/")
|
2010-11-17 20:22:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
KrambookCompile.new.run
|
|
|
|
end
|
|
|
|
|
2010-11-03 23:24:39 +00:00
|
|
|
task :compile do
|
|
|
|
require 'rubygems'
|
|
|
|
require 'kramdown'
|
|
|
|
require 'filters/markdown_macros'
|
2010-12-06 10:02:24 +00:00
|
|
|
require 'filters/markdown_postmacros'
|
2010-12-06 12:46:46 +00:00
|
|
|
require 'filters/fix_postmacros_latex'
|
2010-11-03 23:24:39 +00:00
|
|
|
|
2010-11-09 10:32:47 +00:00
|
|
|
class KrambookCompile
|
|
|
|
require 'config.rb'
|
|
|
|
|
|
|
|
attr_accessor :filelist
|
|
|
|
|
|
|
|
# take a string from kramdown
|
|
|
|
# returns LaTeX after filter
|
|
|
|
def compile_text(tmp)
|
|
|
|
@prefilters.each do |f|
|
|
|
|
tmp=f.run( tmp )
|
|
|
|
end
|
|
|
|
|
|
|
|
# compile to latex
|
|
|
|
tmp=Kramdown::Document.new(tmp, :latex_headers => %w(chapter section subsection paragraph subparagraph subsubparagraph)).to_latex
|
|
|
|
|
|
|
|
# post filters
|
|
|
|
@postfilters.each{ |f| tmp=f.run(tmp) }
|
|
|
|
return tmp
|
2010-11-03 23:24:39 +00:00
|
|
|
end
|
|
|
|
|
2010-11-09 10:32:47 +00:00
|
|
|
def process_template
|
2010-11-09 10:58:15 +00:00
|
|
|
template=File.new(@template_file,"r")
|
2010-11-09 10:32:47 +00:00
|
|
|
txt=template.read
|
|
|
|
template.close
|
|
|
|
|
|
|
|
txt.sub!( /%%#INCLUDES#%%/ ) do
|
|
|
|
@filelist.map do |source,dest|
|
|
|
|
"\\include{#{dest.sub(/^tmp\//,'').sub(/.tex/,'')}}"
|
|
|
|
end.join("\n")
|
|
|
|
end.
|
|
|
|
sub!(%{\\author\{\}},'\author{'+@author+'}').
|
2010-12-10 13:19:08 +00:00
|
|
|
sub!(%{\\title\{\}},'\title{'+@title+'}')
|
2010-11-09 10:32:47 +00:00
|
|
|
fic=File.new("tmp/#{@pdfname}.tex","w")
|
|
|
|
fic.write(txt)
|
|
|
|
fic.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
|
|
|
|
eval File.new('config.rb','r').read
|
|
|
|
|
|
|
|
@prefilters=[]
|
|
|
|
@prefilters<<=MarkdownMacros.new
|
2010-12-06 10:02:24 +00:00
|
|
|
@prefilters<<=MarkdownPostMacros.new
|
2010-12-06 12:46:46 +00:00
|
|
|
@prefilters<<=FixPostMacros.new
|
2010-11-09 10:32:47 +00:00
|
|
|
|
|
|
|
@postfilters=[]
|
|
|
|
|
|
|
|
@filelist=Dir.glob("content/**/*.md").sort.map do |fic|
|
|
|
|
[ fic, fic.sub(/^content\//,"tmp/").sub(/.md$/,".tex") ]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
@filelist.each do |doublon|
|
|
|
|
source=doublon[0]
|
|
|
|
dest=doublon[1]
|
|
|
|
puts source
|
|
|
|
|
|
|
|
# read and compile in LaTeX the .md file
|
|
|
|
text=compile_text( File.new(source,"r").read )
|
|
|
|
|
|
|
|
# create directory if necessary
|
|
|
|
if not FileTest::directory?(File.dirname(dest))
|
|
|
|
FileUtils.mkdir_p(File.dirname(dest))
|
|
|
|
end
|
|
|
|
|
|
|
|
# write the .tex file
|
|
|
|
fic = File.new(dest,"w")
|
|
|
|
fic.write(text)
|
|
|
|
fic.close
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# write the .tex file containing all includes
|
|
|
|
process_template
|
|
|
|
|
|
|
|
# launch the xelatex process
|
|
|
|
system("cp -rf include tmp/")
|
2010-11-09 10:58:15 +00:00
|
|
|
|
2010-11-09 10:32:47 +00:00
|
|
|
system("cd tmp; xelatex #{@pdfname}; cd ..")
|
|
|
|
# on Ubuntu replace by
|
|
|
|
# system("gnome-open #{@pdfname}.pdf")
|
|
|
|
|
2010-11-19 15:45:29 +00:00
|
|
|
system("\\cp -f tmp/#{@pdfname}.pdf #{@pdfname}.pdf")
|
2010-11-09 10:32:47 +00:00
|
|
|
|
|
|
|
# open the pdf
|
|
|
|
system("open tmp/#{@pdfname}.pdf")
|
|
|
|
end
|
2010-11-03 23:24:39 +00:00
|
|
|
end
|
2010-11-09 10:32:47 +00:00
|
|
|
KrambookCompile.new.run
|
2010-11-03 23:24:39 +00:00
|
|
|
end
|