MVC Support and view rendering in Anvil
August 16th, 2007
Anvil is growing rapidly and keeps getting cooler everyday! It now has support for MVC architecture (models are missing right now, but will be implemented soon) and it boasts a cool new way to shuffle away some of the code in your application view to other views like partials in rails. From the example I posted in the previous post, you can now do:
app/views/application.rb
app/views/frames/hamr_frame.rb
app/views/menus/file_menu.rb
This new way makes your code much neater. Support for putting all of the code into your application.rb file is still there, but having the ability to shuffle it away is very nice. Anyway, check out the projects: anvil.rubyforge.org and hamr.rubyforge.org.
app/views/application.rb
1 2 3 |
anvil "Hammer" do |app| app.frame "Hamr", :render => 'hamr', :title => "Hamr", :maximize => true end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Create Menu Bar frame.menu_bar "Main" do |menu_bar| menu_bar.menu "&File", :render => 'file' menu_bar.menu "&Edit", :render => 'edit' menu_bar.menu "&Search", :render => 'search' menu_bar.menu "&Help", :render => 'help' end frame.text_control "Editor", :size => { :width => 100, :height => 200 }, :style => [ :multiline, :rich, :rich2 ] frame.create_status_bar(2) frame.set_status_text("Hamr World!", 0) |
1 2 3 4 5 6 7 8 9 10 |
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) |
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 |