Class: Rack::Xapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/xapper.rb

Constant Summary collapse

APP_MANIFEST_TEMPLATE =
<<-TEMPLEND

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RuntimeVersion="2.0.31005.0" EntryPointAssembly="Microsoft.Scripting.Silverlight" EntryPointType="Microsoft.Scripting.Silverlight.DynamicApplication" ExternalCallersFromCrossDomain="ScriptableOnly">
  <!-- Add assembly references here -->
  <Deployment.Parts>
<!-- In the XAP -->
<!-- <AssemblyPart Source="Foo.dll" /> -->
<!-- Outside the XAP, same domain -->
<!-- <AssemblyPart Source="/Foo.dll" /> -->
<!-- Outside the XAP, different domain -->
<!-- <AssemblyPart Source="http://bar.com/Foo.dll" /> -->

  </Deployment.Parts>
  <!-- Add transparent platform extensions (.slvx) references here -->
  <Deployment.ExternalParts>
<!-- Example -->
<!-- <ExtensionPart Source="http://bar.com/v1/Foo.slvx" /> -->
  </Deployment.ExternalParts>
</Deployment>
 
TEMPLEND
LANGUAGES =
{
  :names => %w(IronPython Python py),
  :extensions => %w(.py),
  :context => "IronPython.Runtime.PythonContext",
  :assemblies => %w(IronPython.dll IronPython.Modules.dll),
  :external => "IronPython.slvx"
},
{
  :names => %w(IronRuby Ruby rb),
  :extensions => %w(.rb),
  :context => "IronRuby.Runtime.RubyContext",
  :assemblies => %w(IronRuby.dll IronRuby.Libraries.dll),
  :external => "IronRuby.slvx"
}
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
}

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Xapper

Returns a new instance of Xapper.



211
212
213
214
# File 'lib/rack/xapper.rb', line 211

def initialize(app, options={})
  @xap_options = DEFAULT_OPTIONS.merge(options)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/rack/xapper.rb', line 216

def call(env)
  path = env['PATH_INFO']
  can_serve = /#{@xap_options[:xap_name]}\.xap/ =~ path
  
  if can_serve
    file_server = XapFile.new(@xap_options)
    file_server.call(env)
  else
    @app.call(env)
  end
end