Skip to content

Instantly share code, notes, and snippets.

@gre
Created January 7, 2012 12:30
Show Gist options
  • Save gre/1574637 to your computer and use it in GitHub Desktop.
Save gre/1574637 to your computer and use it in GitHub Desktop.
Grisbi HTML's export stylifier

What?

Grisbi is a personal finance manager http://www.grisbi.org/

This script helps you to make Gribsi HTML report export looking nicer. It only works with "Revenus et dépenses" report mode. (incomes and expenses)

How To

  • In Grisbi, export your Reports as HTML
  • Add main.js and main.css in the same directory of the exported HTML.
  • Edit the exported HTML: add the "main.js" script at the end of the body:
...
  <script src="main.js"></script>
</body>
</html>
  • Open the HTML file in your browser.
  • Print it (with a printer or in a PDF file)

Important Note: you need to adapt the script for your language.

About

This script is kind of a hack, the best way would be to implement it in the program itself, but I need time for that..

If any Grisbi developer come here, feel very free to take my work ;)

Licence

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE !

html, body {
font-size: 10px;
width: 90%;
margin: 0 auto;
}
h1 {
font-size: 1.5em;
}
h1, h2 {
text-align: center;
margin: 0;
padding: 0;
}
dl {
margin: 0;
}
#wrapper > section {
width: 46%;
padding: 2%;
float: left;
}
#wrapper > dl.total {
clear: both;
font-size: 2em;
text-align: center;
}
#wrapper > dl.total dt {
display: inline;
font-weight: bold;
}
#wrapper > dl.total dd {
display: inline;
}
section dl dt {
width: 70%;
display: inline-block;
}
section dl dd {
text-align: right;
width: 30%;
margin: 0;
display: inline-block;
}
section dl:last-child {
font-size: 1.2em;
}
(function(){
var base = '';
fullFunc({
css : [ base + "main.css"],
js : [],
ready : function() {
var totalTitle = "Total général :";
// Extract datas into obj
var obj = {};
obj.title = $('font[size="+5"]').text();
var cat = null;
var subcat = null;
$('tr').each(function(i){
var tr = $(this);
if(tr.find('font[size="+5"]').size()>0) return;
if(tr.find('font[size="+2"]').size()>0) {
cat = tr.find('font[size="+2"]').text();
subcat = null;
return;
}
if(cat) {
if(!obj[cat]) obj[cat]={};
if(tr.find('td').size()==1) {
var val = $.trim(tr.find('td').text());
if(!val) return;
subcat = val;
return;
}
var tds = tr.find('td');
var o = {};
var size = tds.size();
if(size>=2) {
o.title = $.trim(tds.eq(size-2).text());
o.value = $.trim(tds.eq(size-1).text());
}
if(!o.title || !o.value) {
subcat = null;
return;
}
if(subcat) {
if(!obj[cat][subcat]) obj[cat][subcat] = [];
obj[cat][subcat].push(o);
}
else {
obj[cat][o.title] = o.value;
}
}
});
var total = obj["Dépenses"][totalTitle];
if(total) {
delete obj["Dépenses"][totalTitle];
obj[totalTitle] = total;
}
console.log( obj )
// Create a new fresh HTML
$('body').empty().append('<div id="wrapper" />');
var wrapper = $('#wrapper');
wrapper.append( $('<h1/>').text(obj.title) );
$.each(["Revenus", "Dépenses"], function(i, cat){
var section = $('<section />')
section.append( $('<h2/>').text(cat) );
var data = obj[cat];
for(var key in data) {
var value = data[key];
if(typeof(value)=="string") {
var dl = $('<dl />');
var dt = $('<dt/>').text(key);
dl.append( dt );
dl.append( $('<dd/>').text(value) );
section.append(dl);
}
else {
section.append( $('<h3 />').text(key) );
var dl = $('<dl />');
for(var k in value) {
var d = value[k];
dl.append( $('<dt/>').text(d.title) );
dl.append( $('<dd/>').text(d.value) );
}
section.append(dl);
}
}
wrapper.append(section);
});
var dl = $('<dl class="total" />');
dl.append( $('<dt/>').text(totalTitle) );
dl.append( $('<dd/>').text(obj[totalTitle]) );
wrapper.append(dl);
}
});
}());
// jQuery bookmarklet magic...
// ... by Brett Barros (& Paul Irish)
// ... http://www.latentmotion.com/downloads/blank-bookmarklet-v1.js
function fullFunc(a){function d(b){if(b.length===0){a.ready();return false}
$.getScript(b[0],function(){d(b.slice(1))})}function e(b){$.each(b,function(c,f){$("<link>")
.attr({href:f,rel:"stylesheet",type:'text/css'}).appendTo("head")})}a.jqpath=a.
jqpath||"http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js";
(function(b){var c=document.createElement("script");c.type="text/javascript";c.src=b;
c.onload=function(){e(a.css);d(a.js)};document.body.appendChild(c)})(a.jqpath)};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment