[TxMt] Re: switching from page with puts to HTML

Matt Neuburg matt at tidbits.com
Sat Jul 4 15:52:45 UTC 2009


On 7/3/09 11:25 AM, in article C6739B45.4B5BF%matt at tidbits.com, "Matt
Neuburg" <matt at tidbits.com> wrote:

> 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.

Solved this in a hacky way by interposing an object that masquerades as
$stdout and intercepts and modifies output before passing it along to the
real stdout. But I'm hoping someone will tell me there's already a simpler
built-in way to do this in TextMate.
 
> 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).

Have not solved this one yet. Hints appreciated. 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