Sha256: a14ab2b51b82a65a2177c41581e7b53acc10d41bf386be613b362d98a6578f75

Contents?: true

Size: 1.83 KB

Versions: 12

Compression:

Stored size: 1.83 KB

Contents

require 'sproutcore/merb/bundle_controller'

module SproutCore
  module Merb
    module RouterMethods

      # Connect a BundleController to the specified location.  All requests 
      # matching this path root will by default be handled by this new 
      # controller.
      #
      # ==== Params
      # path<String>:: The root path or other matcher to use for the matcher.  
      #  This will be passed through to the router, so you can use anything 
      #  you like.
      #
      # === Options
      # library:: Optional path to the library that should be hosted
      # You can also include any other options that are known to Merb::Bundle
      #
      def connect_clients(match_path, opts ={}, &block)

        # Create library
        library_root = opts.delete(:library) || opts.delete(:library_root) || ::Merb.root
        library = Library.library_for(library_root, opts)
        if library.nil?
          raise "ERROR: No sc-config found at #{library_root}.  Make sure you start sc-server in a directory with an sc-config file."
        else
          SC.logger.debug "Loading SproutCore bundles in #{library.root_path}"
        end

        # Define new subclass of bundle controller
        cnt = 0
        while Object.const_defined?(class_name = "SproutCoreBundleController#{cnt}".to_sym)
          cnt += 1
        end
        klass = eval("class ::#{class_name} < SproutCore::Merb::BundleController; end; #{class_name}")

        # Register library for class in BundleController
        ::SproutCore::Merb::BundleController.register_library_for_class(library, klass)

        # Finally, register match
        return self.match(%r[^#{match_path}\/?.*]).to(:controller => "sprout_core_bundle_controller_#{cnt}", :action => 'main')

      end
    end
  end
end

# Install in router.
Merb::Router::Behavior.send(:include, SproutCore::Merb::RouterMethods)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sproutcore-0.9.12 lib/sproutcore/merb/router.rb
sproutcore-0.9.15 lib/sproutcore/merb/router.rb
sproutcore-0.9.14 lib/sproutcore/merb/router.rb
sproutcore-0.9.13 lib/sproutcore/merb/router.rb
sproutcore-0.9.18 lib/sproutcore/merb/router.rb
sproutcore-0.9.17 lib/sproutcore/merb/router.rb
sproutcore-0.9.16 lib/sproutcore/merb/router.rb
sproutcore-0.9.19 lib/sproutcore/merb/router.rb
sproutcore-0.9.22 lib/sproutcore/merb/router.rb
sproutcore-0.9.23 lib/sproutcore/merb/router.rb
sproutcore-0.9.21 lib/sproutcore/merb/router.rb
sproutcore-0.9.20 lib/sproutcore/merb/router.rb