Due to the method_missing way that the CGI module handles HTML tags, however, it turns out to be quite simple: invoke cgi.script, passing all tag parameters as a hash, and pass the Javascript code as a string in the block:
cgi.out {
cgi.html {
cgi.head {
cgi.title {
"Test"
} +
cgi.html {
cgi.head {
cgi.title {
"Test"
} +
# Javascript library to include
cgi.script( 'src' => 'dygraph-combined.js',
'type' => 'text/javascript') {
}
} +
cgi.script( 'src' => 'dygraph-combined.js',
'type' => 'text/javascript') {
}
} +
cgi.body {
cgi.br +
cgi.div( 'id' => 'graphdiv' ) +
cgi.br +
cgi.script( 'type' => 'text/javascript') {
cgi.br +
cgi.div( 'id' => 'graphdiv' ) +
cgi.br +
cgi.script( 'type' => 'text/javascript') {
# Javascript to execute
'g = new Dygraph(
document.getElementById("graphdiv"),
"Date,Temperature\n" +
"2008-05-07,75\n" +
"2008-05-08,70\n" +
"2008-05-09,80\n"
);
'
}
'g = new Dygraph(
document.getElementById("graphdiv"),
"Date,Temperature\n" +
"2008-05-07,75\n" +
"2008-05-08,70\n" +
"2008-05-09,80\n"
);
'
}
}
}
No comments:
Post a Comment