|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
switching from page with puts to HTMLIn 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@..., <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 _______________________________________________ textmate mailing list textmate@... http://lists.macromates.com/listinfo/textmate |
|
|
Re: switching from page with puts to HTMLOn 7/3/09 11:25 AM, in article C6739B45.4B5BF%matt@..., "Matt
Neuburg" <matt@...> 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@..., <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 _______________________________________________ textmate mailing list textmate@... http://lists.macromates.com/listinfo/textmate |
|
|
Re: switching from page with puts to HTMLOn 4 Jul 2009, at 17:52, Matt Neuburg wrote:
> [...] > 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. There is not, and it’s not really possible to do since e.g. your HTML header/footer does not need this escaping, only your body does, so TM wouldn’t know when to filter. >> 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). There is no API to obtain this info, sry. _______________________________________________ textmate mailing list textmate@... http://lists.macromates.com/listinfo/textmate |
|
|
Re: switching from page with puts to HTMLOn 7/9/09 11:29 AM, in article
5D349936-2E10-44EC-A3B8-40FD52BB3F3A@..., "Allan Odgaard" <mailinglist@...> wrote: >>> 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). > > There is no API to obtain this info, sry. This is the only bad part. :) May I submit this as a feature request? Pls let me know if you need a motivating story... m. -- matt neuburg, phd = matt@..., <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 _______________________________________________ textmate mailing list textmate@... http://lists.macromates.com/listinfo/textmate |
|
|
Re: switching from page with puts to HTMLOn 9 Jul 2009, at 21:42, Matt Neuburg wrote:
>>> [...] is there a way I can detect whether we are currently set to >>> Create New Document or Show As HTML? [...] >> There is no API to obtain this info, sry. > > This is the only bad part. :) May I submit this as a feature > request? Pls > let me know if you need a motivating story... m. Better suggest what sort of API you want. I will expose both command title and its UUID in 2.0, and I _plan_ to expose a (bundle) query system (so a command can technically lookup its own output), though probably not in 2.0.0. I am rather hesitant about these things because it limits my wriggle room, for example in this case, 2.0 has the output split into “format” and “place”, had I done API in 1.x for commands to query the system as-is it would just add to the headache of providing backwards compatibility. In retrospect I am _very_ happy with the limited scriptability and plug-in API of 1.x :) _______________________________________________ textmate mailing list textmate@... http://lists.macromates.com/listinfo/textmate |
|
|
Re: switching from page with puts to HTMLOn 7/9/09 1:22 PM, in article
C67FC258-14A9-4280-BBFA-61BA0253F773@..., "Allan Odgaard" <mailinglist@...> wrote: > On 9 Jul 2009, at 21:42, Matt Neuburg wrote: > >>>> [...] is there a way I can detect whether we are currently set to >>>> Create New Document or Show As HTML? [...] >>> There is no API to obtain this info, sry. >> >> This is the only bad part. :) May I submit this as a feature >> request? Pls >> let me know if you need a motivating story... m. > > Better suggest what sort of API you want. Well, as you know, there is already a set of exit codes that can be set (exit_codes.rb) to indicate where we *should* produce our output. I guess I was hoping there might be some environment global indicating where the currently running command was *intending* to produce output. case ENV['TM_OUTPUT'] when 205 ... else ... end m. -- matt neuburg, phd = matt@..., <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 _______________________________________________ textmate mailing list textmate@... http://lists.macromates.com/listinfo/textmate |
| Free embeddable forum powered by Nabble | Forum Help |