So apparently I haven’t updated my blog in quite a while. Quite a lot has happened since the last update.
I started working at IT Mill, the company behind the Vaadin framework.I’ve gotten off to a good start, I’m currently working on something I call TouchKit. It’s a combination of a few custom components and extensions to Vaadin that allows you to create web applications that look like iPhone applications using nothing but Java. Check out the video preview below:
Well, that’s all for now. I’ll try to get back to the habit of updating the blog a bit more often again
A while back, I needed to quickly write some documentation that needed to be in XHTML format. Writing in plain XHTML is a pain, so I decided to write the documentation in Textile and then convert it to XHTML before publishing.
The problem I found was that all Textile converters were made for use in blogs and other online tools. What I needed was a good old-fashioned command line program to convert a given textile file into XHTML.
Fortunately, using Ruby and the excellent RedCloth gem, I could write a small script to accomplish this in a few minutes.
If you have any similar needs, copy the source into a file named textile2html, make it executable (chmod +x) and place it somewhere in your path. Then all you have to do is call textile2html with the textile file as an argument:
$ textile2html documentation.textile
#!/usr/bin/env ruby -wKU
require "rubygems"
require "RedCloth"
if ARGV.size != 1
puts "Usage: textile2html file.textile"
exit
end
# Read input file
textile_string = ""
begin
input_file = File.new(ARGV[0], "r")
input_file.each do |line|
textile_string+=line
end
input_file.close
rescue
puts "Could not read input file."
exit
end
# Create output file
filename = ARGV[0].gsub(/\.\w+$/, "")
begin
output_file = File.new("#{filename}.html", "w")
rescue
puts "Could not create output file."
exit
end
html_header = <<DOC
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>
DOC
html_header += filename;
html_header += <<DOC
</title>
</head>
<body>
DOC
html_footer = <<DOC
</body>
</html>
DOC
html_output = RedCloth.new(textile_string).to_html
output_file.puts(html_header)
output_file.puts(html_output)
output_file.puts(html_footer)
output_file.close
puts "Done."
As I am probably going to post much on programming, I felt that I needed a way of highlighting code syntax and showing it in an easier to read format to you. At first I thought of just using Alex Gorbatchev’s SyntaxHighlighter. It turned out that there were in fact several WordPress plugins using Alex’s highlighter. Many of the existing highlighters did not work very well, they simply included the JavaScript file, requiring users to insert
<pre name="code" class="html">
...
</pre>
into the HTML. The problem is that WordPress’ HTML editor strips out the name=”code” part, rendering the plugins useless.
What I settled on using, for the time being at least, is Vijesh Mehta Syntax Highlighter WordPress Plugin. The plugin still requires manual HTML editing, but avoids the stripping of the name attribute by using class=”brush:language_name” instead.
So, as a start for my posts on programming: the classical “hello world”, in ruby this time.