Friday, July 9, 2010

New Face New Look

Finally given this blog a face-lifting. Well, 99.9% of the credit goes to (1) coderay, (2) syntax highlighting railscast, & (3) the new template designer of blogger.com, while the rest falls under some minor hackish tweaking on my part. Anyway, here's the fragment that customizes the blog template:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<style type='text/css'>
code, table.coderay {
background-color: #111111;
color: #E6E0DB;
overflow: auto;
display: block;
margin: 15px 0px 0px 0px;
padding: 0px 20px 15px 20px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
}
table.coderay { padding: 0px 20px 0px 0px; }
table.coderay td.line_numbers { color: #444444; padding: 0px 5px 0px 8px; }
table.coderay td.code { padding-left: 5px; }
table.coderay .an { color:#E7BE69 } /* html attribute */
table.coderay .c { color:#BC9358; font-style: italic; } /* comment */
table.coderay .ch { color:#509E4F } /* escaped character */
table.coderay .cl { color:#FFF } /* class */
table.coderay .co { color:#FFF } /* constant */
table.coderay .fl { color:#A4C260 } /* float */
table.coderay .fu { color:#FFC56D } /* function */
table.coderay .gv { color:#D0CFFE } /* global variable */
table.coderay .i { color:#A4C260 } /* integer */
table.coderay .il { background:#151515 } /* inline code */
table.coderay .iv { color:#D0CFFE } /* instance variable */
table.coderay .pp { color:#E7BE69 } /* doctype */
table.coderay .r { color:#CB7832 } /* keyword */
table.coderay .rx { color:#A4C260 } /* regex */
table.coderay .s { color:#A4C260 } /* string */
table.coderay .sy { color:#6C9CBD } /* symbol */
table.coderay .ta { color:#E7BE69 } /* html tag */
table.coderay .pc { color:#6C9CBD } /* boolean */
</style>

Plus the help of the script ~/bin/code2html.rb:
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env ruby

require 'rubygems'
require 'coderay'

puts %|#{coderay.scan_file(ARGV[0]).html(:line_numbers => :table)}|.
gsub('coderay','coderay').split('<pre').map{|s|
!s.include?('</pre>') ? s.gsub("\n",'').squeeze(' ') : (
parts = s.split('</pre>')
[parts[0], parts[1].gsub("\n",'').squeeze(' ')].join('</pre>')
)
}.join('<pre')

As ~/bin is already in my $PATH, all i need to do to convert any code to the nice code blocks u see here is to run:

code2html.rb <PATH_TO_ANY_FILE>

Hmmmm .. not too bad rite ? Now, what is left is to set aside some time to do some cleaning up for the rest of this blog (sweat).

No comments:

Post a Comment

Labels