<code language=ruby>
some ruby code
</code>
require 'syntax/convertors/html'
require 'win32/clipboard'
include Win32
namespace :format do
desc "This task will format code in the clipboard or file specified by file=\"filename\" as html"
task :ruby4display do
BloggingTools.ruby4display
end
desc "This task will format code in the clipboard or file specified by file=\"filename\" as html"
task :html4display do
BloggingTools.html4display
end
end
#Actual functions are defined in a separate class to ease testing and keep things clean and dry
class BloggingTools
def self.ruby4display
convertor = Syntax::Convertors::HTML.for_syntax "ruby"
code_html = convertor.convert(input)
output code_html
end
def self.html4display
convertor = Syntax::Convertors::HTML.for_syntax "xml"
code_html = convertor.convert(input)
output code_html
end
def self.input
if ENV['file']
puts "#{ENV['file']} will be processed and copied to the clipboard"
in_data = File.read(ENV['file'])
else
puts "no arguments supplied data will be taken from clipboard"
in_data = Clipboard.data
end
end
def self.output code_html
if ENV['file']
fn= "#{File.basename(ENV['file'], File.extname(ENV['file']))}.html"
puts "output to file #{fn}"
in_data = File.open(fn, File::WRONLY|File::TRUNC|File::CREAT)
in_data.puts code_html
else
puts "output to clipboard"
Clipboard.set_data(code_html)
end
end
end
July 2007 August 2007 September 2007 December 2007 January 2008 February 2008 March 2008 April 2008 June 2008 July 2008 August 2008 October 2008 November 2008 January 2009
Subscribe to Comments [Atom]