BooでSilverlight
BooでSilverlightができるようなので、ちょっとやってみた。
今回使ったのは以下のツール
- Boo 0.9
- NAnt 0.85 - コンパイルとZIP圧縮に使った
- Silverlight 2 SDK
準備
ここからBooをダウンロードして、Booのバイナリ一式を適当なフォルダに置いてパスを通しておく。
開発
まずはフォルダ構成を決めておく
-[SilverBoo] |-[ClientBin] |-SilverBoo.xap |-[lib] |-Boo.Lang.dll (XAPに含める) |-AppManifest.xaml |-App.boo |-Page.xaml |-Page.xaml.boo |-index.htm |-default.build (NAntビルドファイル)
Silverlightやったことある人には違和感が無いと思うので説明は省いて、中身を書いていく。
まずはマニフェストファイルから
AppManifest.xaml
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="SilverBoo" EntryPointType="SilverBoo.App" RuntimeVersion="2.0.31005.0"> <Deployment.Parts> <AssemblyPart x:Name="SilverBoo" Source="SilverBoo.dll" /> <AssemblyPart x:Name="Boo.Lang" Source="Boo.Lang.dll" /> </Deployment.Parts> </Deployment>
次、Webページ
index.htm
<html> <head> <title>SilverBoo</title> </head> <body> <object id="SilverlightPlugin" data="data:application/x-silverlight," type="application/x-silverlight-2" width="300" height="300"> <param name="source" value="ClientBin/SilverBoo.xap" /> <param name="onerror" value="onSilverlightError" /> <param name="onload" value="onload" /> <param name="background" value="#00000000" /> <param name="initParams" value="reportErrors=errorLocation" /> <param name="windowless" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /> </a> </object> </body> </html>
特に説明はいらないね。
次はアプリケーションクラス、エントリポイントになるクラスね。
App.boo
namespace SilverBoo import System.Windows class App(Application): def constructor(): Startup += onStartup def onStartup(sender, e): self.RootVisual = Page()
Page.xaml
<UserControl x:Class="SilverBoo.Page" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid x:Name="LayoutRoot" Background="White"> <Button Width="80" Height="30" Content="click me" Click="Button_Click" /> </Grid> </UserControl>
XAMLに対応するクラス
Page.xaml.boo
namespace SilverBoo import System import System.Windows import System.Windows.Controls class Page(UserControl): def constructor(): Application.LoadComponent(self, Uri("/Page.xaml", UriKind.Relative)) def Button_Click(s, e): cast(Button, s).Content = "Boo"
default.build
<?xml version="1.0" encoding="shift-jis"?> <project xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd" default="build" name="SilverBoo"> <property name="temp.dir" value="__temp__" /> <property name="output.dir" value="ClientBin" /> <target name="build"> <mkdir dir="${temp.dir}" /> <mkdir dir="${output.dir}" /> <booc target="library" output="${temp.dir}/SilverBoo.dll" nostdlib="true" debug="false"> <sources basedir="."> <include name="*.boo" /> </sources> <references basedir="C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies"> <include name="system.dll" /> <include name="System.Windows.dll" /> <include name="System.Windows.Controls.dll" /> <include name="System.Windows.Browser.dll" /> </references> </booc> <zip zipfile="${output.dir}/SilverBoo.xap"> <fileset> <include name="Page.xaml" /> <include name="AppManifest.xaml" /> </fileset> <fileset basedir="${temp.dir}"> <include name="SilverBoo.dll" /> </fileset> <fileset basedir="lib"> <include name="Boo.Lang.dll" /> </fileset> </zip> <delete dir="${temp.dir}" /> </target> </project>
コンソールから以下のコマンドを入力すればビルドできる。
PS SilverBoo\> nant /t:net-2.0
Booといってもコンパイルしてしまえば、C#で使ったものと何も変わらないので普通に書くことができる。
どうしてもBooでSilverlghtがしたいという人はお試しあれ。
デモ
*1:ちなみにDynamic Silverilghtではない