Include an HTML generation of the book (via SVG).
This commit is contained in:
parent
055587d1d0
commit
72dfd5f12e
3 changed files with 138 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
|||
*.out
|
||||
my_book.tex
|
||||
tmp/
|
||||
site/
|
||||
|
|
49
Rakefile
49
Rakefile
|
@ -7,9 +7,58 @@ CLEAN.include('**/*.{aux,log,out}')
|
|||
CLEAN.include('tmp/**/*')
|
||||
CLOBBER.include('**/*.pdf')
|
||||
CLOBBER.include('content/**/*.tex')
|
||||
CLOBBER.include('site/**/*')
|
||||
|
||||
task :default => [:compile]
|
||||
|
||||
task :to_html do
|
||||
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
|
||||
command=%{pdf2svg tmp/#{@pdfname}.pdf site/#{@pdfname}-%d.svg all}
|
||||
system(command)
|
||||
hdecal=110
|
||||
vdecal=120
|
||||
nb_pages=0
|
||||
Dir["site/*.svg"].each do |fic|
|
||||
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
|
||||
target=File.open("site/index.html","w")
|
||||
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
|
||||
|
||||
task :compile do
|
||||
require 'rubygems'
|
||||
require 'kramdown'
|
||||
|
|
88
include/index.html
Normal file
88
include/index.html
Normal file
|
@ -0,0 +1,88 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="https://www.google.com/jsapi"></script>
|
||||
<script>
|
||||
google.load('jquery', '1.4.4');
|
||||
|
||||
var nb_pages=0;
|
||||
|
||||
function changeTo(n) {
|
||||
page = page + n;
|
||||
if (page == 1) {
|
||||
page=1;
|
||||
$('#previous').addClass('disable');
|
||||
} else if (page == nb_pages) {
|
||||
$('#next').addClass('disable');
|
||||
} else if (page<1) {
|
||||
page=1;
|
||||
return;
|
||||
} else if (page>nb_pages) {
|
||||
page=nb_pages;
|
||||
return;
|
||||
} else {
|
||||
$('#previous').removeClass('disable');
|
||||
$('#next').removeClass('disable');
|
||||
}
|
||||
fic = "krambook-" + page + ".svg";
|
||||
console.log("fic = " + fic);
|
||||
$('#frame').attr('src', fic );
|
||||
$('#nbpages').text("Page "+ page +" / "+nb_pages);
|
||||
}
|
||||
|
||||
</script>
|
||||
<script>
|
||||
var page=1;
|
||||
google.setOnLoadCallback( function() {
|
||||
$('#previous').click( function() { changeTo(-1); });
|
||||
$('#previous').addClass('disable');
|
||||
$('#next').click( function() { changeTo(1); });
|
||||
$('#nbpages').text("Page 1 / "+nb_pages);
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
#leftcolumn {float: left; width: 7em}
|
||||
#rightcolumn {float: right; width: 7em}
|
||||
.button {
|
||||
width: 7em;
|
||||
height: 3em;
|
||||
background: #ccc;
|
||||
color: #333;
|
||||
border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
-webkit-border-radius: 2px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
line-height: 3em; }
|
||||
|
||||
.disable {
|
||||
cursor: default;
|
||||
opacity: .3 }
|
||||
|
||||
#nbpages{
|
||||
float: right;
|
||||
width: 7em;
|
||||
height: 3em;
|
||||
line-height: 3em;
|
||||
background: #eee;
|
||||
text-align: center; }
|
||||
|
||||
#content {margin-left: auto; margin-right: auto; text-align: center}
|
||||
#frame {
|
||||
text-align: center; margin-left: auto; margin-right: auto;
|
||||
width: 492pt; height: 672pt; border: 1px solid #ccc}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="leftcolumn">
|
||||
<div id="previous" class="button">Previous</div>
|
||||
</div>
|
||||
<div id="rightcolumn">
|
||||
<div id="next" class="button">Next</div>
|
||||
<div id="nbpages"> Page 1 / ?? </div>
|
||||
</div>
|
||||
<div id="content">
|
||||
<iframe id="frame" src="krambook-1.svg" style=""frameborder="0" scrolling="no" ></iframe>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue