#!/usr/bin/env ruby __DIR__ = Dir.pwd require 'rubygems' require 'merb-core' require 'merb-slices' slice_name = File.basename(__DIR__) Merb::Config.use { |c| c[:framework] = { :public => [Merb.root / "public", nil] } c[:session_store] = 'none' c[:exception_details] = true } if File.exists?(slice_file = File.join(__DIR__, 'lib', "#{slice_name}.rb")) Merb::BootLoader.before_app_loads do $SLICE_MODULE = Merb::Slices.filename2module(slice_file) require slice_file end Merb::BootLoader.after_app_loads do # See Merb::Slices::ModuleMixin - $SLICE_MODULE is used as a flag Merb::Router.prepare do slice($SLICE_MODULE) slice_id = slice_name.gsub('-', '_').to_sym slice_routes = Merb::Slices.named_routes[slice_id] || {} # Setup a / root path matching route - try several defaults route = slice_routes[:home] || slice_routes[:index] if route params = route.params.inject({}) do |hsh,(k,v)| hsh[k] = v.gsub("\"", '') if k == :controller || k == :action hsh end match('/').to(params) else match('/').to(:controller => 'merb_slices', :action => 'index') end end end else puts "No slice found (expected: #{slice_name})" exit end class MerbSlices < Merb::Controller def index html = "
#{slice.description}
" html << "