[TxMt] switching from page with puts to HTML
Matt Neuburg
matt at tidbits.com
Fri Jul 3 18:25:57 UTC 2009
In developing my bundle, I've been issuing feedback to the user with Create
New Document. Now that things are working decently, I want to switch to Show
As HTML. Here's the problem. Throughout my routines, when I want to issue
some feedback, I just say "puts". Now, however, using Show As HTML, I want
to wrap this in some way such that every time there is a "puts" I grab it,
shove a <br> on the end, and pass it along, so that my output appears
streaming into the HTML window as the script runs.
So, yeah, I could look thru all my code, find every "puts", and append the
<br> myself. But I don't want to. I want to just wrap up what I'm already
doing and perform the transformation as the input appears. There must be
some simple way to do this.
Here's what I have so far:
def self.perform(command_name, *args)
require "#{ENV["TM_SUPPORT_PATH"]}/lib/web_preview.rb"
STDOUT.sync = true
html_header(command_name.to_s)
puts "<pre>"
self.send(command_name, *args) # FIX ME
puts "</pre>"
html_footer()
end
It's that "self.send" line that I want to wrap up in some way so that I can
intercept the output from each "puts" within my routines and modify it.
Oh, and while we're up: is there a way I can detect whether we are currently
set to Create New Document or Show As HTML? I'd like to funnel all my
commands thru this one bottleneck but NOT do all that stuff if we are set to
Create New Document (in that case I just want to pass the output thru
untouched).
Thx! m.
--
matt neuburg, phd = matt at tidbits.com, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
More information about the textmate
mailing list