Permalink
Browse files

initial commit

  • Loading branch information...
MaksJS committed Feb 19, 2013
0 parents commit 031576d2434939e499d01fa719434e80f7fd78f8
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
@@ -0,0 +1,215 @@
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+
+[Dd]ebug/
+[Rr]elease/
+x64/
+build/
+[Bb]in/
+[Oo]bj/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+*.ncrunch*
+.*crunch*.local.xml
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+*.pubxml
+
+# NuGet Packages Directory
+## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+#packages/
+
+# Windows Azure Build Output
+csx
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+*.pfx
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+#############
+## Windows detritus
+#############
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac crap
+.DS_Store
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist/
+build/
+eggs/
+parts/
+var/
+sdist/
+develop-eggs/
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
135 README.md
@@ -0,0 +1,135 @@
+Express Simple MVC
+==================
+
+Very simple and lightweight framework to improve Express JS MVC's architecture written in CoffeeScript.
+It provides a simple way to create models and controllers with an object-oriented approach (CoffeeScript).
+
+## How it works
+
+Create your express application as usual and use the "simple_mvc" function
+
+```coffeescript
+express = require 'express'
+{simple_mvc} = require 'express-simple-mvc'
+require 'namespace'
+
+app = express()
+app.listen 3000
+simple_mvc app
+```
+
+You'll also need a namespace pattern for coffeescript, you can install it with npm install
+
+Create a directory called "config" with a file called "routes" inside.
+Define your routes (inspired by Play! Framework), for example :
+
+ # Routes
+ # This file defines all application routes (Higher priority routes first)
+ # ~~~~
+
+ GET / controllers.Players.index
+
+ GET /players controllers.Players.index
+ GET /players/new controllers.Players.new
+ GET /players/:id controllers.Players.show
+ GET /players/:id/edit controllers.Players.edit
+ POST /players controllers.Players.create
+ PUT /players/:id controllers.Players.update
+ DELETE /players/:id controllers.Players.delete
+
+Create a models and a controllers directory with a Players controller and a Player model.
+For example, simple CRUD (don't forget the namespace)
+
+```coffeescript
+namespace controllers:
+
+ class Players
+
+ # Import Player model from models namespace
+ {Player} = models
+
+ # GET /players
+ @index: =>
+ Player.all (players) =>
+ @res.send players
+
+ # GET /players/:id
+ @show: =>
+ Player.read @req.params.id, (player) =>
+ @res.send player
+
+ # GET /players/new
+ @new: =>
+ @res.render 'newForm'
+
+ # GET /players/:id/edit
+ @edit: =>
+ Player.read @req.params.id, (player) =>
+ @res.render 'editForm'
+ player: player
+
+ # POST /players
+ @create: =>
+ Player.create @req.param('player'), =>
+ @res.send 'New player successfully created !'
+
+ # PUT /players/:id
+ @update: =>
+ Player.update @req.params.id, @req.param('player'), =>
+ @res.send "Player #{@req.param('id')} successfully updated !"
+
+ # DELETE /players/:id
+ @delete: =>
+ Player.delete @req.params.id, ->
+ @res.send "Player #{@req.param('id')} successfully deleted !"
+```
+
+Properties @req and @res are automatically send to the controller, you don't need to pass them as params as you would do before with Express
+
+And the for the model (I use mongoose here, but you can adapt it)
+
+```coffeescript
+mongoose = require 'mongoose'
+
+namespace models:
+
+ class Player
+
+ @schema =
+ pseudo: String
+ x:
+ type: Number
+ default: 0
+ y:
+ type: Number
+ default: 0
+
+ @model = mongoose.model 'Player', new mongoose.Schema @schema
+
+ @all: (cb) ->
+ @model.find null, (err, docs) ->
+ if err then throw err
+ cb docs
+
+ @create: (doc, cb) ->
+ new @model(doc).save (err) ->
+ if err then throw err
+ do cb
+
+ @read: (_id, cb) ->
+ @model.findById _id, (err, doc) ->
+ if err then throw err
+ cb doc
+
+ @update: (_id, doc, cb) ->
+ @model.findByIdAndUpdate _id, doc, (err) ->
+ if err then throw err
+ do cb
+
+ @delete: (_id, cb) ->
+ @model.findByIdAndRemove _id, (err) ->
+ if err then throw err
+ do cb
+```
+
+And that's all ! Looks difficult ? Have a look at the source code in /src (only 50 lines !) or run the example.
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1,7 @@
+Express Simple MVC example
+==========================
+
+How to run
+
+ npm install
+ npm start
Oops, something went wrong.

0 comments on commit 031576d

Please sign in to comment.