0

I am developing a tool that discovers network services enabled on host and writes short summary on them like this:

init,1
└── login,1560 --
 └── bash,1629
 └── nc,12137 -lup 50505
{
 :net => [
 [0] "*:50505 IPv4 UDP "
 ],
 :fds => [
 [0] "/root (cwd)",
 [1] "/",
 [2] "/bin/nc.traditional",
 [3] "/xochikit/ld_poison.so (stat: No such file or directory)",
 [4] "/dev/tty2",
 [5] "*:50505"
 ]
}

It proved to be very nice formatted and useful for quick discovery thanks to colors provided by the awesome_print gem. However, its output is just a text. One issue is that if I want to share it, I lose colors. I'd also like to fold and unfold parts of objects, quickly jump to specific processes and what not? Adding comments, for example. Thus I want something web-based.

What is the best approach to implement features like these? I haven't worked with web interfaces before and I don't have much experience with Ruby.

Update:

Maybe I didn't write my willings clear enough.

I think I want something that behaves like Chromium's chrome://chrome/settings/ (or better, of course). Is there maybe an erb template or manual showing how to implement that? I thought this is a thing needed often enough.

asked Nov 27, 2012 at 20:10
1
  • I'm not a Ruby pro nor have I ever used Sinatra but this sounds like something that may be a good fit for. sinatrarb.com/intro Commented Nov 27, 2012 at 20:22

3 Answers 3

2

Try using a Rack middleware to pygmentize things: https://github.com/bry4n/rack-pygments

Edit per Walter's suggestions:

You've got serializable Ruby objects and it sounds like you want to render them to web pages. I'd recommend starting with something like Sinatra for the web framework, Pygments for the code coloring/highlighting, and from there perhaps handroll a little jQuery plugin to make indented code blocks collapsible.

Notes: I recommend Pygments because I like it and because Github uses it. The Rack middleware above is intended to allow you to automagically pygmentize code at the server level by adding a tag to the code block you'd like to see marked up.

answered Dec 4, 2012 at 1:07
4
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Commented Dec 4, 2012 at 2:00
  • You're probably right, Walter. I fired this one off before going AFK for a while because I thought the link might be useful. As an aside, I wondered if this question was even valid for the site - it seems so specific and time-sensitive (Ruby web services and code highlighting in late 2012) that I'd expect to see it on SO. Commented Dec 4, 2012 at 2:13
  • 1
    Nice edit. Don't worry about a question that might be a better fit for SO. If the question is a better fit for SO, it will get migrated along with your answer. Commented Dec 4, 2012 at 2:47
  • 1
    This seems to be the best solution. I'll implement what you suggest the next time our teams needs my script. Commented Dec 10, 2012 at 0:29
1

Sinatra would probably be the lightest approach.

Rails brings more overhead, but is also very easy to use and deploy. If your app will be expanding and be incorporating things like users and logins, it might be better to tackle Rails.

Both should work fine, and there are lots of coding examples and tutorials for basic applications using each.

answered Nov 27, 2012 at 20:52
0

This is the kind of processing you usually perform on the client-side (that is: inside the web browser) with AJAX (HTML, Javascript and CSS). There are many libraries that can do this job out there. Search for AJAX foldable tree, AJAX table and so on. JQuery and other well-known libraries have table/tree widgets you can use for this.

Have a look at these AJAX table/grid widgets, for example:

https://stackoverflow.com/questions/1503810/what-javascript-table-widgets-are-available

Most likely, you will have to package your data as a JSON or a XML hierarchycal structure before sending it to your AJAX viewer. JSON and XML will allow you to easily share your data with other people, as well. They are both largely recognized as standard data exchange formats.

answered Nov 29, 2012 at 8:23
2
  • Thank you, this is the way I go unless someone says "This is already implemented here". I just thought there already exists an easy to use and customize html-visualizer for Ruby objects. Commented Nov 29, 2012 at 13:09
  • Oh, well, if you just need a Ruby-to-HTML pretty printer, you can find a few of them on the Net: stackoverflow.com/questions/3375709/… . You just have to keep in mind that your current Ruby output is (and must be) some kind of hierarchical markup like XML, JSON and so on. From this text-based hierarchical structure you can easily get a formatted HTML (or XML) output. Have a look at the Ruby markdown processors: ruby-toolbox.com/categories/markup_processors . Commented Nov 29, 2012 at 13:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.