<commit_before>Magic is an IronRuby gem making it easier to develop Windows Forms and Silverlight UI with IronRuby.

Note that while developing it, it quickly became clear that Magic could be useful outside IronRuby and Windows Forms in the very near future (look at IDEAS to see where we're heading).

h1. USAGE

h2. Windows Forms

Here's a quick starter:

	form = Magic.build do
	  @menu = main_menu do
	    menu_item("&File") do
	      menu_item("&New")
	      menu_item("&Quit").click { Application.Exit }
	      menu_item("&Other Quit", :click => lambda { Application.Exit })
	    end
	  end
	  form(:text => "Title", :menu => @menu) do
	    flow_layout_panel(:dock => :fill) do
	      button(:text => "Click me!").click do
	        MessageBox.Show("Hello from button!")
	      end
	    end
	  end
	end

h2. Silverlight

Support has just been added. You'll need to run "rake compress" to create magic-compressed.rb, which gathers all the magic files into one. I didn't find a way yet to use the gem as-is.

Once you have magic-compressed.rb, you can use it like that:

	require "silverlight"
	require "magic-compressed"

	class App < SilverlightApplication
 
	  def initialize
	    application.root_visual = Magic.build do
	      stack_panel do
	        10.times { |i| text_block(:text => i.to_s, :width => 30,:height => 30) }
	      end
	    end
	  end
	end

	$app = App.new

It makes it easy to create XAML-free applications, or to reduce the amount of XAML to be created.

h1. UNDER THE COVER

A few points (see spec/magic_spec.rb for details):

* classes to be built are inferred from method calls (converted from snake_case to CamelCase)
** menu_item creates an instance of MenuItem
** button becomes Button
** flow_layout_panel becomes FlowLayoutPanel
* method calls automatically add the object to its parent children collection (if the object is a Control, a MenuItem or a UIElement - this will become configurable)
* if a Hash is passed, corresponding properties are set after instanciation (:text => "This is the text")
* if the property is an enum, snake_case symbol value is allowed (:dock => :fill is the same as :dock => DockStyle.Fill)
* handlers are registered if a lambda is passed (:click => lambda)
* handlers can also be registered by calling the block directly (button.lambda do ... end)
* instance variables can be reused (form.menu = @menu)
* non-control (like BackgroundWorker for long-running operations) instances can be created (worker = background_worker)
* the last evaluted expression is returned.

h1. TESTING

Magic comes with its set of specs (based on MSpec). You'll currently have to tweak Rakefile (see spec task) to match your environment. Then you can run:

  rake spec

to see all the (m)specs running.

Note that I currently use a few nasty mocks (see mocks.rb) that I'll need to clean-up.

h1. IDEAS

* build a website to make it easier to discover and understand
* become independent of Windows Forms (see Magic.method_missing for notes about that)
* use it to generate graphs with QuickGraph
* use it outside IronRuby (the coupling to IronRuby is quite isolated)

h1. COPYRIGHT

Copyright (c) 2008 <NAME>. See LICENSE for details.<commit_msg>Updated README with WPF support.<commit_after>Magic is an IronRuby gem making it easier to develop Windows Forms, WPF and Silverlight UI with IronRuby.

h1. USAGE

Here are quick starters:

h2. Windows Forms


	form = Magic.build do
	  @menu = main_menu do
	    menu_item("&File") do
	      menu_item("&New")
	      menu_item("&Quit").click { Application.Exit }
	      menu_item("&Other Quit", :click => lambda { Application.Exit })
	    end
	  end
	  form(:text => "Title", :menu => @menu) do
	    flow_layout_panel(:dock => :fill) do
	      button(:text => "Click me!").click do
	        MessageBox.Show("Hello from button!")
	      end
	    end
	  end
	end
	
	Application.Run(form)

h2. WPF

	window = Magic.build do
	  window(:width => 600, :height => 480, :title => 'Hello world!') do
	    stack_panel(:margin => thickness(30)) do
	      button(:content => 'Click me!', :font_size => 22).click do
	        MessageBox.show("Ok!")
	      end
	    end
	  end
	end

	app = Application.new
	app.run(window)

h2. Silverlight

You'll need to run "rake compress" to create magic-compressed.rb, which gathers all the magic files into one. Once you have magic-compressed.rb, you can use it like that:

	require "silverlight"
	require "magic-compressed"

	class App < SilverlightApplication
 
	  def initialize
	    application.root_visual = Magic.build do
	      stack_panel do
	        10.times { |i| text_block(:text => i.to_s, :width => 30,:height => 30) }
	      end
	    end
	  end
	end

	$app = App.new

It makes it easy to create XAML-free applications, or to reduce the amount of XAML to be created.

h1. UNDER THE COVER

A few points (see spec/magic_spec.rb for details):

* classes to be built are inferred from method calls (converted from snake_case to CamelCase)
** menu_item creates an instance of MenuItem
** button becomes Button
** flow_layout_panel becomes FlowLayoutPanel
* method calls automatically add the object to its parent children collection (if the object is a Control, a MenuItem or a UIElement - this will become configurable)
* if the parent responds to :content (eg: WPF Window), then parent.content will use the (unique) child
* if a Hash is passed, corresponding properties are set after instanciation (:text => "This is the text")
* if the property is an enum, snake_case symbol value is allowed (:dock => :fill is the same as :dock => DockStyle.Fill)
* handlers are registered if a lambda is passed (:click => lambda)
* handlers can also be registered by calling the block directly (button.lambda do ... end)
* instance variables can be reused (form.menu = @menu)
* non-control (like BackgroundWorker for long-running operations) instances can be created (worker = background_worker)
* the last evaluted expression is returned.

h1. TESTING

Magic comes with its set of specs (based on MSpec). You'll currently have to tweak Rakefile (see spec task) to match your environment.

Then you can run (either on Windows or Mac OS):

  rake spec

to see all the (m)specs running.

Note that I currently use a few nasty mocks (see mocks.rb) that I'll need to clean-up.

h1. IDEAS

* build a website to make it easier to discover and understand
* become independent of Windows Forms (see Magic.method_missing for notes about that)
* use it to generate graphs with QuickGraph
* use it outside IronRuby (the coupling to IronRuby is quite isolated)
* convert unknown methods to parent delegate registration, if available (useful for background work for instance)
* convert :margin => 30 to :margin => Thickness.new(30)

h1. COPYRIGHT

Copyright (c) 2008 <NAME>. See LICENSE for details.
{'fraction_non_alphanumeric': 0.07976453274466519, 'fraction_numerical': 0.007211184694628403, 'mean_word_length': 3.654794520547945, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5060934', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1886, 'n_words': 902}