             
             window.close()
         
+
+
+
+
+        ## ----------- cheerio ------------- ##
+        
+        
+        ##
+        ##
+        ##
+        _processContent_cheerio: (req, res, content, model, fn)->
+            
+            ##
+            @_getContext (err, ctx)=>
+                return fn(err) if err
+                
+                ##
+                @_initContext req, res, ctx, (err)=>
+                    
+                    ##
+                    ctx.$ = ctx.window.$ = require('cheerio').load content
+                    
+                    ctx.__initTime__ = +new Date()
+                    
+                    ##
+                    ctx.__done__ = (err, result)=>
+                        return fn(err) if err
+                        
+                        fn null, result
+                        
+                        @_releaseContext ctx
+                    
+                    ##    
+                    require('vm').runInContext "(#{__boot_cheerio__})(#{model})", ctx    
+            
+
+            
+        ##
+        ##
+        ##
+        _createContext: (fn)->
+            vm = require('vm')
+            
+            ##
+            ctx = vm.createContext 
+                window: {}
+                process: process
+                console: console
+            
+            ##
+            vm.runInContext @__SCRIPT+"var floyd = require('floyd');", ctx
+            
+            ctx.floyd.__parent = 
+                lookup: (name, identity, fn)=>                      
+                    @lookup name, identity, (err, ctx)=>
+                        fn err, ctx
+            
+            ctx.floyd.system.platform = 'cheerio'
+            ctx.floyd.system.os = floyd.system.os
+            ctx.floyd.system.libdir = floyd.system.libdir
+            ctx.floyd.system.appdir = floyd.system.appdir
+            ctx.floyd.tools.files = floyd.tools.files
+            
+            ##
+            fn null, ctx
+        
+        
+        ##
+        ##
+        ##
+        _getContext: (fn)->
+            
+            if @__POOL__.length
+                fn null, @__POOL__.pop()
+                
+            else
+                @_createContext fn
+            
+        ##
+        ##
+        ##
+        _releaseContext: (ctx)->
+            persistentKeys = ['floyd', 'require', '_modules', 'process', 'console']
+            
+            if @__POOL__.length < @data.poolsize
+                for key, value of ctx
+                    if persistentKeys.indexOf(key) is -1
+                        delete ctx[key]
+                
+                ## check again... just for the case
+                if @__POOL__.length < @data.poolsize
+                    @__POOL__.push ctx
+        
+
+        ##
+        ##
+        ##
+        _initContext: (req, res, ctx, done)->    
+            
+            ##
+            ctx.location = require('url').parse 'http://'+req.headers.host+req.url.substr (req.vhostpath||'').length
+        
+            ## fake the protocol while forwarded from https proxy
+            if ctx.location.protocol is 'http:' && req.headers['x-forwarded-proto'] is 'https'
+                ctx.location.protocol = 'https:'
+                ctx.location.href = ctx.location.href.replace /^http\:/, 'https:'                
+            
+            ##
+            ctx.document =
+                referer: req.referer
+                cookie: 'FSID='+req.session.SID+'; path=/; httponly'    
+            
+            ##
+            ctx.window = 
+                document:   ctx.document
+                location:   ctx.location
+                floyd:      ctx.floyd
+            
+            ##
+            done()
+
+
+
+##
+
+##
+## remote code - gets evaluated into the cheerio context
+##
+__boot_cheerio__ = (config)->
+
+    floyd.init config, (err, ctx)=>
+        return __done__(err) if err
+        
+        __done__ null, $.html()
+        
+        stopped = !ctx.stop
+        destroyed = !ctx.destroy
+
+        next = (err)->
+            return console.error(err) if err
+            
+            if !stopped && stopped = true
+
+                ctx.stop next
+                
+            else if !destroyed && destroyed = true
+
+                ctx.destroy()
+                    
+        
+        next()
 
 
 


## 

jsdom = require 'jsdom'

Url = require 'url'

files = floyd.tools.files

module.exports = 


                        
                        floyd.tools.http.files.resolve url, _public, (err, file)=>
                            return fn(err) if err
                            
                            files = floyd.tools.files
                            
                            if files.fs.lstatSync(file).isDirectory()
                                file = files.path.join file, @data.find 'index'
