[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[QUIZ] Object Browser (#8

James Gray

11/19/2004 2:07:00 PM

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.grayproductions.net/...

3. Enjoy!

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

by Jim Menard

Recently on ruby-talk, itsme123 asked if there was a generic object browser that
will "interactively browse a graph of connected objects by showing their
instance variables and letting me click through to browse".

The quiz challenge: write such a browser. It should be able to start at any
object or, if none is given to it, start at the main object ("self" at the top
level of any Ruby script).

The interface to the browser can be text-based or graphical.

I'm thinking of something like the Squeak Explorer (the new inspector). It's a
window that displays the object with an open/close triangle next to it. Click
the triangle, and the ivars are exposed.

V root: an OrderedCollection(a MyClass, a Number)
V 1: a MyClass
> name: 'the name'
> anotherIvar: 42
> 2: a Number

That's just one possible UI, of course.

Bonus points for allowing modification of instance variable values and for
allowing inspection of classes (remember, classes are objects, too!).


35 Answers

Its Me

11/19/2004 3:39:00 PM

0

I'd suggest looking at the design docs for Omnibrowser
http://www.wiresong.ca/Om..., a flexible object browser which uses
explicit meta-objects to configure things like what messages to send the
object being browsed. Class-based meta-objects could simply show all
instance variables; but other meta-objects could do fancier and more
selective browsing.

And if anyone wants to try a graphical view of an object graph (invaluable
at times) ruby-graphviz painlessly gives a png/gif drawing of an object
graph, even a clickable image-map for browsing.

Imho, either of these would be great. Some smart combination of the two
would be dynamite!

"Ruby Quiz" <james@grayproductions.net> wrote in message
news:20041119140626.XVOZ14730.lakermmtao03.cox.net@localhost.localdomain...
> The three rules of Ruby Quiz:
>
> 1. Please do not post any solutions or spoiler discussion for this quiz
until
> 48 hours have passed from the time on this message.
>
> 2. Support Ruby Quiz by submitting ideas as often as you can:
>
> http://www.grayproductions.net/...
>
> 3. Enjoy!
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-=-=-=
>
> by Jim Menard
>
> Recently on ruby-talk, itsme123 asked if there was a generic object
browser that
> will "interactively browse a graph of connected objects by showing their
> instance variables and letting me click through to browse".
>
> The quiz challenge: write such a browser. It should be able to start at
any
> object or, if none is given to it, start at the main object ("self" at the
top
> level of any Ruby script).
>
> The interface to the browser can be text-based or graphical.
>
> I'm thinking of something like the Squeak Explorer (the new inspector).
It's a
> window that displays the object with an open/close triangle next to it.
Click
> the triangle, and the ivars are exposed.
>
> V root: an OrderedCollection(a MyClass, a Number)
> V 1: a MyClass
> > name: 'the name'
> > anotherIvar: 42
> > 2: a Number
>
> That's just one possible UI, of course.
>
> Bonus points for allowing modification of instance variable values and for
> allowing inspection of classes (remember, classes are objects, too!).
>
>


Brian Schröder

11/23/2004 12:26:00 AM

0

Hello Group,

Thanks for the quiz. I always wanted to learn more about the reflection capabilites of ruby, and indeed there is quite a lot to learn. This quiz was not too complicated, but the design of a good gui takes a lot of time. (Especially if you're not accustomed to the toolkit).

I implemented a gnome2/gtk version. I did not use code from the other solution, but the next step will be to see what I can borrow.

I submit now, because I've already invested too much time. The code is not beautifull and could need a heavy facelift.

The difference to the other solution is, that I'm starting with a class-tree from which you can get to all the objects. I think the right pane in my solution is more or less what was specified in the quiz.

You can see the code and screenshots at:

http://ruby.brian-schroeder.de/quiz/objec...

Regards,

Brian

--
Brian Schröder
http://www.brian-sch...



Charles Mills

11/23/2004 12:34:00 AM

0

On Nov 22, 2004, at 4:26 PM, Brian Schröder wrote:

> Hello Group,
>
> Thanks for the quiz. I always wanted to learn more about the
> reflection capabilites of ruby, and indeed there is quite a lot to
> learn. This quiz was not too complicated, but the design of a good gui
> takes a lot of time. (Especially if you're not accustomed to the
> toolkit).
>
> I implemented a gnome2/gtk version. I did not use code from the other
> solution, but the next step will be to see what I can borrow.
>
> I submit now, because I've already invested too much time. The code is
> not beautifull and could need a heavy facelift.
>
> The difference to the other solution is, that I'm starting with a
> class-tree from which you can get to all the objects. I think the
> right pane in my solution is more or less what was specified in the
> quiz.
>
> You can see the code and screenshots at:
>
> http://ruby.brian-schroeder.de/quiz/objec...
>
That is *really* nice. Very impressive. Kudos.

-Charlie




James Gray

11/23/2004 2:42:00 AM

0

On Nov 22, 2004, at 6:26 PM, Brian Schröder wrote:

> Hello Group,
>
> Thanks for the quiz. I always wanted to learn more about the
> reflection capabilites of ruby, and indeed there is quite a lot to
> learn. This quiz was not too complicated, but the design of a good gui
> takes a lot of time. (Especially if you're not accustomed to the
> toolkit).

I've been unfortunately, very busy this weekend and haven't had time to
play with the quiz. (I promise to get back in the game on the next
one!)

However, I have to take a moment to say... Wow. Very nice job Brian.
I'm impressed.

James Edward Gray II




Zach Dennis

11/23/2004 4:54:00 PM

0

Brian, this is very cool....very very cool! Thanks for making this
viewable online w/screenshots as well.

Zach



Brian Schröder wrote:

> Hello Group,
>
> Thanks for the quiz. I always wanted to learn more about the reflection capabilites of ruby, and indeed there is quite a lot to learn. This quiz was not too complicated, but the design of a good gui takes a lot of time. (Especially if you're not accustomed to the toolkit).
>
> I implemented a gnome2/gtk version. I did not use code from the other solution, but the next step will be to see what I can borrow.
>
> I submit now, because I've already invested too much time. The code is not beautifull and could need a heavy facelift.
>
> The difference to the other solution is, that I'm starting with a class-tree from which you can get to all the objects. I think the right pane in my solution is more or less what was specified in the quiz.
>
> You can see the code and screenshots at:
>
> http://ruby.brian-schroeder.de/quiz/objec...
>
> Regards,
>
> Brian
>



Jim Freeze

11/23/2004 7:26:00 PM

0

* Brian Schröder <ruby@brian-schroeder.de> [2004-11-23 09:26:11 +0900]:

I particularly liked the clean colorization of the ruby code. What did you use
(and what color style) to convert the Ruby code to HTML?


--
Jim Freeze
Code Red. Code Ruby



Brian Schröder

11/23/2004 7:39:00 PM

0

On Wed, 24 Nov 2004 04:26:17 +0900
jim@freeze.org wrote:

> * Brian Schröder <ruby@brian-schroeder.de> [2004-11-23 09:26:11 +0900]:
>
> I particularly liked the clean colorization of the ruby code. What did you use
> (and what color style) to convert the Ruby code to HTML?
>
>

I use xemacs' htmlize package to convert the ruby-code to html. Then I include a stylesheet. (You can copy that from my page if you want)

The important snippets of the Makefile I use:


htmlize: $(patsubst %.rb,browse/%-rb.html,$(wildcard *.rb))

browse/%-rb.html: %.rb
mkdir -p browse/unsuccessfull
xemacs -nw -eval '(htmlize-file "$<" "$@")' -kill && mv $@ $@.temp && cat $@.temp | ruby -e 'puts $$stdin.read.gsub(/<style type="text\/css">.*<\/style>/m, "<link id=\"css\" href=\"../ruby.css\" rel=\"stylesheet\">")' > $@ && rm $@.temp


Regards,

Brian

--
Brian Schröder
http://www.brian-sch...



Jim Freeze

11/23/2004 10:47:00 PM

0

* Brian Schröder <ruby@brian-schroeder.de> [2004-11-24 04:38:41 +0900]:

> > I particularly liked the clean colorization of the ruby code. What did you use
> > (and what color style) to convert the Ruby code to HTML?
>
> I use xemacs' htmlize package to convert the ruby-code to html. Then I include a stylesheet. (You can copy that from my page if you want)
>
> htmlize: $(patsubst %.rb,browse/%-rb.html,$(wildcard *.rb))
>
> browse/%-rb.html: %.rb
> mkdir -p browse/unsuccessfull
> xemacs -nw -eval '(htmlize-file "$<" "$@")' -kill && > mv $@ $@.temp && > cat $@.temp | ruby -e 'puts $$stdin.read.gsub(/<style type="text\/css">.*<\/style>/m, "<link id=\"css\" href=\"../ruby.css\" rel=\"stylesheet\">")' > $@ && > rm $@.temp

Thanks. Uhh, sorry to be so dense, but (not being an emacs person) it
appears that htmlize-file.el is not part of the xemacs distro and I'm not
sure what version to get. Also, it would be great if you could provide a
command line example without the make cipher added. The obvious:

xemacs -nw -eval '(htmlize-file "myfile.rb")' -kill

doesn't seem to work.

--
Jim Freeze
Code Red. Code Ruby



Brian Schröder

11/24/2004 8:32:00 AM

0

On Wed, 24 Nov 2004 07:47:03 +0900
jim@freeze.org wrote:

> * Brian Schröder <ruby@brian-schroeder.de> [2004-11-24 04:38:41 +0900]:
>
> > > I particularly liked the clean colorization of the ruby code. What did you use
> > > (and what color style) to convert the Ruby code to HTML?
> >
> > I use xemacs' htmlize package to convert the ruby-code to html. Then I include a stylesheet. (You can copy that from my page if you want)
> >
> > htmlize: $(patsubst %.rb,browse/%-rb.html,$(wildcard *.rb))
> >
> > browse/%-rb.html: %.rb
> > mkdir -p browse/unsuccessfull
> > xemacs -nw -eval '(htmlize-file "$<" "$@")' -kill && > > mv $@ $@.temp && > > cat $@.temp | ruby -e 'puts $$stdin.read.gsub(/<style type="text\/css">.*<\/style>/m, "<link id=\"css\" href=\"../ruby.css\" rel=\"stylesheet\">")' > $@ && > > rm $@.temp
>
> Thanks. Uhh, sorry to be so dense, but (not being an emacs person) it
> appears that htmlize-file.el is not part of the xemacs distro and I'm not
> sure what version to get. Also, it would be great if you could provide a
> command line example without the make cipher added. The obvious:
>
> xemacs -nw -eval '(htmlize-file "myfile.rb")' -kill
>
> doesn't seem to work.
>

Hello Jim,

I installed htmlize as part of the debian package

emacs-goodies-el - Miscellaneous add-ons for Emacs

In your example you forgot the output file. It should be

xemacs -nw -eval '(htmlize-file "myfile.rb" "myfile-rb.html")' -kill

Or you can try it interactively

open a ruby file in xemacs
C-x C-f myfile.rb

htmlize the buffer
M-x htmlize-buffer

save the file
C-x C-s myfile-rb.html

Make shure that you have turned font-lock on, such that the file is fontified in xemacs.

HTH,

Brian

--
Brian Schröder
http://www.brian-sch...



Brian Schröder

11/25/2004 12:29:00 AM

0

So I took some time and refactored my solution. It now has a modular and extendible structure (at least I hope so). It should be possible to easily write non-gtk ui's and extend the reporting capabilities.

The code is at the same location as before
http://ruby.brian-schroeder.de/quiz/objec...

The screenshots are not updated.

It now is able to do more or less exactly the same as before, but the code has changed a lot. I could not let code as bad as the previous solution exist under my name ;).

Missing things:
- look at jamis solution and merge interesting parts.
- Polish the ui
- Inlcude Breakpoint support.

I hope that I can spare some hours this weekend to accomplish this.

I hope i do not "get charged per email" ;), and nobody will hate me because I put code into the public domain without the capabilities and spare time to support it ;).

Regards,

Brian Schröder

On Tue, 23 Nov 2004 09:26:11 +0900
Brian Schröder <ruby@brian-schroeder.de> wrote:

> Hello Group,
>
> Thanks for the quiz. I always wanted to learn more about the reflection capabilites of ruby, and indeed there is quite a lot to learn. This quiz was not too complicated, but the design of a good gui takes a lot of time. (Especially if you're not accustomed to the toolkit).
>
> I implemented a gnome2/gtk version. I did not use code from the other solution, but the next step will be to see what I can borrow.
>
> I submit now, because I've already invested too much time. The code is not beautifull and could need a heavy facelift.
>
> The difference to the other solution is, that I'm starting with a class-tree from which you can get to all the objects. I think the right pane in my solution is more or less what was specified in the quiz.
>
> You can see the code and screenshots at:
>
> http://ruby.brian-schroeder.de/quiz/objec...
>
> Regards,
>
> Brian
>
> --
> Brian Schröder
> http://www.brian-sch...
>


--
Brian Schröder
http://www.brian-sch...