Anvil: The Ruby Application Framework
August 13th, 2007
Anvil just announced its conception onto rubyforge yesterday as plans are being set to organize how the new gem is going to be created. The gem is going to be a framework that wraps around the Wx::Ruby project in a way that is more concise and ruby-esk. The concepts are inspired by ruby on rails and Shoes (a project for allowing you to create little applications that act like web browsers). Here is a sample of the some of the code from the sample application called Hammer, a ruby/anvil-based text editor included in the applications folder of the repository:
The project is in need of talented and eager individuals to help it get off of its feet. If you are interested in contributing, check it out!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
anvil "Hammer" do |app| app.frame "Hammer", "Hammer", :maximize => true do |frame| # Create Menu Bar frame.menu_bar do |menu_bar| # File Menu menu_bar.menu "&File" do |item| item.add(:new) item.add(:open) item.separator item.add(:save) item.separator item.add(:preview) item.add(:print) item.separator item.add(:close) item.add(:quit) end # Edit Menu menu_bar.menu "&Edit" do |item| item.add(:undo) item.add(:redo) item.separator item.add(:cut) item.add(:copy) item.add(:paste) item.add(:delete) item.separator item.add(:selectall) item.separator item.add(:preferences) end # Search Menu menu_bar.menu "&Search" do |item| item.add(:find) item.add(:replace) end # Help Menu menu_bar.menu "&Help" do |item| item.add(:about) end end frame.text_control :size => { :width => 100, :height => 200 } frame.create_status_bar(2) frame.set_status_text("Hammer World!", 0) end end |
8 Responses to “Anvil: The Ruby Application Framework”
Sorry, comments are closed for this article.
August 16th, 2007 at 12:27 AM Sounds nice, I just have a problem with all the code being in one block. Maybe change it so the code is in a class? The item.add is somewhat repetitive, so you might want to add a method that takes an array of item names. Also, a Hello World app is always handy :)
September 12th, 2007 at 03:32 PM I feel like that would make things messier. I thought about even chaining them like item.add(:new).add(:open) but that's just as messy as item.add_collection([:new, :open]). I guess I could create a method for that, but what if you want to nest menus. I almost feel like a block visual represents a menu better than listing them like you describe. Thoughts?
September 12th, 2007 at 03:33 PM Also: With the new :render option you can shove view code into other files. Check it out here: http://grasprubyonrails.com/2007/8/16/mvc-support-and-view-rendering-in-anvil
September 12th, 2007 at 04:08 PM Glad to see other people taking on the charge to make these former C++ libs look like actual Ruby. With Shoes, my Profligacy project, and this there might be light at the end of the tunnel. Now if you can only solve the wx distribution hell.... Zed
September 12th, 2007 at 11:24 PM Very cool stuff! Came here from RubyInside, glad to hear about the project. I have been looking at ways to create little gui apps for myself.
September 13th, 2007 at 03:27 AM This looks really interesting. I also have an issue with having the code in one block but maybe it's the example? I've been programming Swing for the past 6 years and a common method of creating menus I use is to place the menu items into a .properties file and create them reading the file. Maybe we could have the same option here but placing the items into a ruby equivalent of a yaml file instead. We could have something like frame.menu_bar.load(yaml_file). Within the yaml file you could also specify the method called to handle the click on the menu item. Keep up the good work, I'll be watching the project. :)
September 18th, 2007 at 07:00 AM Certainly a good idea to extract all the build data into yaml file, or perhaps xml in a glade way. That can contribute to loosely couple the code and the design. How do you bind code to event ?
September 25th, 2007 at 04:21 AM My preference for things like menu's and status bars and toolbars etc is for them to act like services that individual components can request. I wrote a Swing based framework ages ago that pretty much did this. Essentially a widget would be have menu, status bar and toolbar requirements. When the widget is added to it's container it searches up the container hierarchy for a component that implements the desired service. When it finds the service it attaches itself. When the widget is removed or loses focus it can automatically remove itself from the service.