Permalink
Browse files

v0.3. Now supports multiple filepad instances

  • Loading branch information...
1 parent d628936 commit d7c6d3499e6ededef08c701183ba4c253548d06f @balupton committed May 20, 2011
Showing with 48 additions and 38 deletions.
  1. +7 −6 README.md
  2. +38 −30 lib/filepad.coffee
  3. +1 −1 package.json
  4. +2 −1 server.coffee
View
13 README.md
@@ -35,8 +35,8 @@ FilePad is a file browser and editor built with node.js, coffeecript and nowpad
require('coffee-script');
filepad = require('filepad');
- // Setup with your Express Server
- filepad.setup(app,pathToEdit);
+ // Initialise the FilePad Server
+ filepad.setup(pathToEdit,options);
```
- With Node.js in CoffeeScript
@@ -45,14 +45,15 @@ FilePad is a file browser and editor built with node.js, coffeecript and nowpad
# Include FilePad
filepad = require 'filepad'
- # Setup with your Express Server
- filepad.setup app, pathToEdit
-
-The `app` variable is your express server, and the `pathToEdit` variable is the full path of the directory you want to edit with FilePad
+ # Initialise the FilePad Server
+ filepad.setup pathToEdit, options
## History
+- v0.3 May 20, 2011
+ - Now supports multiple filepad isntances
+
- v0.2 May 19, 2011
- Got file saving going
- Got file listings refreshing when files are added or deleted
View
68 lib/filepad.coffee
@@ -9,13 +9,13 @@ watch = require 'watch'
util = require 'bal-util'
coffee = require 'coffee-script'
-# -------------------------------------
-# Server
+# Filepad
+class Filepad
-filepad =
# Server
- app: null
+ server: null
everyone: null
+ port: 9573
filePath: process.cwd()
publicPath: __dirname+'/public'
@@ -27,49 +27,53 @@ filepad =
slugsToValue: {}
# Initialise
- init: ->
- # File Path
- if process.argv[2]
- @filePath = process.argv[2]
- if @filePath.substring(0,1) is '.'
- @filePath = process.cwd() + '/' + @filePath
- fs.realpath @filePath, (err,@filePath) =>
- @initServer()
+ constructor: ({path,port}={}) ->
+ # Prepare
+ @filePath = path || process.argv[2] || @filePath
+ @port = port || @port
+
+ # Correct
+ if @filePath.substring(0,1) is '.'
+ @filePath = process.cwd() + '/' + @filePath
- # Init Server
- initServer: ->
+ # Check
+ fs.realpath @filePath, (err) =>
+ throw err
+
# Create Server
- @app = express.createServer()
+ @server = express.createServer()
# Configure Server
- @app.configure =>
+ @server.configure =>
# Standard
- @app.use express.errorHandler()
- @app.use express.bodyParser()
- @app.use express.methodOverride()
+ @server.use express.errorHandler()
+ @server.use express.bodyParser()
+ @server.use express.methodOverride()
# Routing
- @app.use @app.router
- @app.use express.static @publicPath
+ @server.use @server.router
+ @server.use express.static @publicPath
# Now.js
- @everyone = now.initialize @app, clientWrite: false
+ @everyone = now.initialize @server, clientWrite: false
# Nowpad
- nowpad.setup @app, @everyone
+ nowpad.setup @server, @everyone
# Coffee4Clients
- coffee4clients.setup @app, @publicPath
+ coffee4clients.setup @server, @publicPath
# Init Server
- @app.listen(9573);
- console.log 'Express server listening on port %d', @app.address().port
+ @server.listen @port
+ console.log 'Express server listening on port %d', @server.address().port
# File Center then Communication Center
@fileCenter => @comCenter()
# Establish a File Center
fileCenter: (next) ->
+ filepad = @
+
# Scan the directory for files
util.scandir(
# Path
@@ -97,7 +101,7 @@ filepad =
)
# Setup up watches for the files
- watch.createMonitor @filePath, (monitor) =>
+ watch.createMonitor @filePath, (monitor) ->
# File Changed
# monitor.on 'changed', (fileFullPath,newStat,oldStat) ->
# DocPad.generate()
@@ -122,6 +126,8 @@ filepad =
# Add a file
addFile: (fileFullPath) ->
+ filepad = @
+
# Fetch
fileRelativePath = fileFullPath.replace(@filePath,'').replace(/^\/+/,'')
fileSlug = util.generateSlugSync fileRelativePath
@@ -192,6 +198,7 @@ filepad =
# Establish Communication Center between Client and Server
comCenter: ->
+ filepad = @
everyone = @everyone
# A client has connected
@@ -265,9 +272,10 @@ filepad =
# Clients will be synced
throw new Error 'not yet implemented'
-
-# Initialise
-filepad.init()
+# API
+filepad =
+ createInstance: (config) ->
+ return new Filepad(config)
# Export
module.exports = filepad
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "filepad",
- "version": "0.2.2",
+ "version": "0.3.0",
"description": "FilePad is a file browser and editor built with node.js, coffeecript and nowpad",
"homepage": "https://github.com/balupton/filepad",
"keywords": [
View
3 server.coffee
@@ -1 +1,2 @@
-require __dirname+'/lib/filepad.coffee'
+filepad = require __dirname+'/lib/filepad.coffee'
+filepad.createInstance()

0 comments on commit d7c6d34

Please sign in to comment.