Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add example

  • Loading branch information...
commit a900c2c2a368b0620b9bfeed4ba3cff7ba8a001c 1 parent d804e7c
@EtienneLem authored
View
1  example/.gitignore
@@ -0,0 +1 @@
+node_modules/
View
3  example/README.md
@@ -0,0 +1,3 @@
+# example
+***
+App structure generated by [Skeleton](https://github.com/EtienneLem/skeleton)
View
36 example/app/app.coffee
@@ -0,0 +1,36 @@
+# Modules
+express = require 'express'
+http = require 'http'
+partials = require 'express-partials'
+app = express()
+
+# Boot setup
+require("#{__dirname}/../config/boot")(app)
+
+# Configuration
+app.configure ->
+ port = process.env.PORT || 3000
+ if process.argv.indexOf('-p') >= 0
+ port = process.argv[process.argv.indexOf('-p') + 1]
+
+ app.set 'port', port
+ app.set 'views', "#{__dirname}/views"
+ app.set 'view engine', 'ejs'
+ app.use express.static("#{__dirname}/../public")
+ app.use express.favicon()
+ app.use express.logger('dev')
+ app.use express.bodyParser()
+ app.use express.methodOverride()
+ app.use partials()
+ app.use require('connect-assets')(src: "#{__dirname}/assets")
+ app.use app.router
+
+app.configure 'development', ->
+ app.use express.errorHandler()
+
+# Routes
+require("#{__dirname}/routes")(app)
+
+# Server
+http.createServer(app).listen app.get('port'), ->
+ console.log "Express server listening on port #{app.get 'port'} in #{app.settings.env} mode"
View
29 example/app/assets/css/styles.styl
@@ -0,0 +1,29 @@
+// Based on <https://github.com/heliom/stylus-utils/blob/master/styles.styl-sample>
+// @import "nib"
+
+// Reset ---------------------------------------------------------------------
+*
+ margin: 0; padding: 0
+ -webkit-box-sizing: border-box
+ -moz-box-sizing: border-box
+ box-sizing: border-box
+
+// Base ----------------------------------------------------------------------
+$background-color = #f4f4f4
+
+html
+ font-size: 62.5%
+ height: 100%
+
+body
+ font-size: 16px
+ font-size: 1.6rem
+ background-color: $background-color
+
+body, legend, input, textarea, button
+ font-family: 'Helvetica Neue'
+ line-height: 1.4
+ color: #333
+
+a:link, a:visited { color: deeppink }
+a:focus, a:hover, a:visited:hover { color: hotpink }
View
1  example/app/assets/js/scripts.coffee
@@ -0,0 +1 @@
+# console.log 'example'
View
7 example/app/controllers/application_controller.coffee
@@ -0,0 +1,7 @@
+module.exports = (app) ->
+ class app.ApplicationController
+
+ # GET /
+ @index = (req, res) ->
+ res.render 'index',
+ view: 'index'
View
33 example/app/helpers/index.coffee
@@ -0,0 +1,33 @@
+fs = require 'fs'
+
+# Recursively require a folder’s files
+exports.autoload = autoload = (dir, app) ->
+ fs.readdirSync(dir).forEach (file) ->
+ path = "#{dir}/#{file}"
+ stats = fs.lstatSync(path)
+
+ # Go through the loop again if it is a directory
+ if stats.isDirectory()
+ autoload path, app
+ else
+ require(path)?(app)
+
+# Return last item of an array
+# ['a', 'b', 'c'].last() => 'c'
+Array::last = ->
+ this[this.length - 1]
+
+# Capitalize a string
+# string => String
+String::capitalize = () ->
+ this.replace /(?:^|\s)\S/g, (a) -> a.toUpperCase()
+
+# Classify a string
+# application_controller => ApplicationController
+String::classify = (str) ->
+ classified = []
+ words = str.split('_')
+ for word in words
+ classified.push word.capitalize()
+
+ classified.join('')
View
10 example/app/routes/index.coffee
@@ -0,0 +1,10 @@
+module.exports = (app) ->
+ # Index
+ app.get '/', app.ApplicationController.index
+
+ # Error handling (No previous route found. Assuming it’s a 404)
+ app.get '/*', (req, res) ->
+ NotFound res
+
+ NotFound = (res) ->
+ res.render '404', status: 404, view: 'four-o-four'
View
1  example/app/views/404.ejs
@@ -0,0 +1 @@
+<h1>Nothing here…</h1>
View
2  example/app/views/index.ejs
@@ -0,0 +1,2 @@
+<h1>This page has been generated by <a href="https://github.com/EtienneLem/skeleton">Skeleton</a></h1>
+<p>Edit in <span>example/views/index.ejs</span></p>
View
17 example/app/views/layout.ejs
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>example</title>
+ <%- css('styles.css') %>
+ </head>
+ <body data-view="<%= view %>">
+ <%- body %>
+ <script>
+ document.write('<script src=' +
+ ('__proto__' in {} ? 'http://zeptojs.com/zepto.min.js' : 'http://code.jquery.com/jquery-1.7.2.min.js') +
+ '><\/script>')
+ </script>
+ <%- js('scripts.js') %>
+ </body>
+</html>
View
9 example/config/boot.coffee
@@ -0,0 +1,9 @@
+module.exports = (app) ->
+ # Helpers
+ app.helpers = require "#{__dirname}/../app/helpers"
+
+ # Lib
+ app.helpers.autoload "#{__dirname}/../lib", app
+
+ # Controllers
+ app.helpers.autoload "#{__dirname}/../app/controllers", app
View
13 example/lib/example/my_custom_class.coffee
@@ -0,0 +1,13 @@
+# module.exports = (app) ->
+# # Your code
+#
+#
+# Or if you want this to be a class
+#
+# module.exports = (app) ->
+# class app.MyCustomClass
+#
+# constructor: (args) ->
+# # Your code
+#
+# Usage: new app.MyCustomClass(args)
View
18 example/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "example"
+ , "version": "0.0.1"
+ , "dependencies": {
+ "express": "3.0.x"
+ , "connect-assets": "2.1.x"
+ , "express-partials": ">= 0.0.5"
+ , "ejs": "*"
+ , "stylus": "*"
+ , "coffee-script": "*"
+ }
+ , "scripts": {
+ "start": "server.js"
+ }
+ , "engines": {
+ "node": "*"
+ }
+}
View
2  example/server.js
@@ -0,0 +1,2 @@
+require("coffee-script")
+require("./app/app.coffee")
Please sign in to comment.
Something went wrong with that request. Please try again.