Rack Xapper

This is a Rack Middleware which will generate Silverlight xap files for DLR projects. It mimics the functionality of Chiron the development server for working with Silverlight and the DLR. This enables integration of Silverlight in any framework that supports Rack (Merb/Rails/Sinatra/…).

Configuration options

By default the middleware makes some decisions on how it thinks your application is structured.

DEFAULT_OPTIONS= {
  :assembly_path => ::File.dirname(__FILE__) + '/../assemblies',
  :xap_path => "sl",
  :source_path => 'app/silverlight',
  :extra_app_files => [],
  :xap_name => 'app',
  :external_url_prefix => "/dlr-slvx",
  :root => 'public',
  :sl_version => :clr2,
  :languages => LANGUAGES,
  :app_manifest => APP_MANIFEST_TEMPLATE
}

You can override any of these settings and I’ll explain them first:

  • :assembly_path: the place to look for the silverlight and DLR assemblies

  • :xap_path: the folder under the root where the xap will be saved

  • :source_path: the folder containing the application entry point and source files

  • :extra_app_files: extra folders that should be included in the xap file

  • :xap_name: the name of the xap file

  • :root: the root folder for the xap path

  • :sl_version: the silverlight version to use (currently :clr2, :clr3)

  • :languages: the supported languages

  • :app_manifest: the template used to generate the AppManifest.xaml file

Frameworks support

Rack is supported by many frameworks but some are configured differently. Here are some examples to get you started

Rails configuration

# in environment.rb
config.gem "rack-xapper", :lib => "rack/xapper", :source => "http://gemcutter.org"
config.middleware.use "Rack::Xapper", :source_path => "app/silverlight"

Sinatra configuration

require 'rack/xapper'

class Application < Sinatra::Application
  use Rack::Xapper, :source_path => "silverlight"
end

Rack configuration

# in config.ru
require 'rack/xapper' 

use Rack::Xapper, :source_path => "silverlight"

Note

  • This is the result of a late night hacking session so the library is a little light on tests.

  • This middleware has a dependency on rubyzip2 but unfortunately the gemspec of rubyzip2 is faulty. It’s missing the version.rb file. I’ve sent a pull request to the owner of that gem so hopefully it will be fixed soon.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 Ivan Porto Carrero. See LICENSE for details.