skeleton 0.1.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,409 +0,0 @@
1
- class Template
2
-
3
- constructor: (@appName, @opts) ->
4
- # Directory defaults to `.` and remove trailing slash
5
- @appDirectory = if @opts.directory != '' then @opts.directory else '.'
6
- @appDirectory = @appDirectory.replace /\/$/, ''
7
-
8
- @files = this.setFiles()
9
-
10
- setFiles: ->
11
- files = {}
12
-
13
- # ./myapp
14
- files["#{@appDirectory}/#{@appName}/.gitignore"] = """
15
- node_modules/
16
- """
17
-
18
- files["#{@appDirectory}/#{@appName}/package.json"] = """
19
- {
20
- "name": "#{@appName}"
21
- , "version": "0.0.1"
22
- , "dependencies": {
23
- "express": "3.0.3"
24
- , "connect-assets": "2.3.3"
25
- #{this.getTemplateModule()}
26
- #{this.getCssModule()}
27
- #{this.getJsModule()}
28
- }
29
- , "scripts": {
30
- "start": "server.js"
31
- }
32
- , "engines": {
33
- "node": "#{process.version.replace 'v', ''}"
34
- , "npm": "1.1.x"
35
- }
36
- }
37
- """
38
-
39
- files["#{@appDirectory}/#{@appName}/Procfile"] = """
40
- web: node server.js
41
- """
42
-
43
- files["#{@appDirectory}/#{@appName}/README.md"] = """
44
- # #{@appName}
45
- ***
46
- App structure generated by [Skeleton](https://github.com/EtienneLem/skeleton)
47
- """
48
-
49
- files["#{@appDirectory}/#{@appName}/server.js"] = """
50
- require("coffee-script/register")
51
- require("./app/app.coffee")
52
- """
53
-
54
- # ./myapp/app
55
- files["#{@appDirectory}/#{@appName}/app/app.coffee"] = """
56
- # Modules
57
- express = require 'express'
58
- http = require 'http'
59
- #{ if @opts.renderer != 'jade' then "partials = require 'express-partials'\n" else ''}app = express()
60
-
61
- # Boot setup
62
- require("\#{__dirname}/../config/boot")(app)
63
-
64
- # Configuration
65
- app.configure ->
66
- port = process.env.PORT || 3000
67
- if process.argv.indexOf('-p') >= 0
68
- port = process.argv[process.argv.indexOf('-p') + 1]
69
-
70
- app.set 'port', port
71
- app.set 'views', "\#{__dirname}/views"
72
- app.set 'view engine', '#{@opts.renderer}'
73
- app.use express.static("\#{__dirname}/../public")
74
- app.use express.favicon()
75
- app.use express.logger('dev')
76
- app.use express.bodyParser()
77
- app.use express.methodOverride()
78
- #{ if @opts.renderer != 'jade' then 'app.use partials()\n ' else ''}app.use require('connect-assets')(src: "\#{__dirname}/assets")
79
- app.use app.router
80
-
81
- app.configure 'development', ->
82
- app.use express.errorHandler()
83
-
84
- # Routes
85
- require("\#{__dirname}/routes")(app)
86
-
87
- # Server
88
- http.createServer(app).listen app.get('port'), ->
89
- console.log "Express server listening on port \#{app.get 'port'} in \#{app.settings.env} mode"
90
- """
91
-
92
- # ./myapp/app/assets/css
93
- # Stylus
94
- if @opts.css == 'stylus'
95
- files["#{@appDirectory}/#{@appName}/app/assets/css/styles.styl"] = """
96
- // Based on <https://github.com/heliom/stylus-utils/blob/master/styles.styl-sample>
97
- // @import "nib"
98
-
99
- // Reset ---------------------------------------------------------------------
100
- *
101
- margin: 0; padding: 0
102
- -webkit-box-sizing: border-box
103
- -moz-box-sizing: border-box
104
- box-sizing: border-box
105
-
106
- // Base ----------------------------------------------------------------------
107
- $background-color = #f4f4f4
108
-
109
- html
110
- font-size: 62.5%
111
- height: 100%
112
-
113
- body
114
- font-size: 16px
115
- font-size: 1.6rem
116
- background-color: $background-color
117
-
118
- body, legend, input, textarea, button
119
- font-family: 'Helvetica Neue'
120
- line-height: 1.4
121
- color: #333
122
-
123
- a:link, a:visited { color: deeppink }
124
- a:focus, a:hover, a:visited:hover { color: hotpink }
125
- """
126
-
127
- # Less
128
- if @opts.css == 'less'
129
- files["#{@appDirectory}/#{@appName}/app/assets/css/styles.less"] = """
130
- // Based on <https://github.com/heliom/stylus-utils/blob/master/styles.styl-sample>
131
-
132
- // Reset ---------------------------------------------------------------------
133
- * {
134
- margin: 0; padding: 0;
135
- -webkit-box-sizing: border-box;
136
- -moz-box-sizing: border-box;
137
- box-sizing: border-box;
138
- }
139
-
140
- // Base ----------------------------------------------------------------------
141
- @background-color: #f4f4f4;
142
-
143
- html {
144
- font-size: 62.5%;
145
- height: 100%;
146
- }
147
-
148
- body {
149
- font-size: 16px;
150
- font-size: 1.6rem;
151
- background-color: @background-color;
152
- }
153
-
154
- body, legend, input, textarea, button {
155
- font-family: 'Helvetica Neue';
156
- line-height: 1.4;
157
- color: #333;
158
- }
159
-
160
- a:link, a:visited { color: deeppink }
161
- a:focus, a:hover, a:visited:hover { color: hotpink }
162
- """
163
-
164
- # css
165
- if @opts.css == 'css'
166
- files["#{@appDirectory}/#{@appName}/app/assets/css/styles.css"] = """
167
- /* Based on <https://github.com/heliom/stylus-utils/blob/master/styles.styl-sample> */
168
-
169
- /* Reset --------------------------------------------------------------------- */
170
- * {
171
- margin: 0; padding: 0;
172
- -webkit-box-sizing: border-box;
173
- -moz-box-sizing: border-box;
174
- box-sizing: border-box;
175
- }
176
-
177
- /* Base ---------------------------------------------------------------------- */
178
- html {
179
- font-size: 62.5%;
180
- height: 100%;
181
- }
182
-
183
- body {
184
- font-size: 16px;
185
- font-size: 1.6rem;
186
- background-color: #f4f4f4;
187
- }
188
-
189
- body, legend, input, textarea, button {
190
- font-family: 'Helvetica Neue';
191
- line-height: 1.4;
192
- color: #333;
193
- }
194
-
195
- a:link, a:visited { color: deeppink }
196
- a:focus, a:hover, a:visited:hover { color: hotpink }
197
- """
198
-
199
- # ./myapp/app/assets/js
200
- # CoffeeScript
201
- if @opts.js == 'coffee'
202
- files["#{@appDirectory}/#{@appName}/app/assets/js/scripts.coffee"] = """
203
- # console.log '#{@appName}'
204
- """
205
-
206
- # JavaScript
207
- if @opts.js == 'js'
208
- files["#{@appDirectory}/#{@appName}/app/assets/js/scripts.js"] = """
209
- // console.log('#{@appName}')
210
- """
211
-
212
- # ./myapp/app/controllers
213
- files["#{@appDirectory}/#{@appName}/app/controllers/application_controller.coffee"] = """
214
- module.exports = (app) ->
215
- class app.ApplicationController
216
-
217
- # GET /
218
- @index = (req, res) ->
219
- res.render 'index',
220
- view: 'index'
221
- """
222
-
223
- # ./myapp/app/helpers
224
- files["#{@appDirectory}/#{@appName}/app/helpers/index.coffee"] = """
225
- fs = require 'fs'
226
-
227
- # Recursively require a folder’s files
228
- exports.autoload = autoload = (dir, app) ->
229
- fs.readdirSync(dir).forEach (file) ->
230
- return if file is ".DS_Store"
231
- path = "\#{dir}/\#{file}"
232
- stats = fs.lstatSync(path)
233
-
234
- # Go through the loop again if it is a directory
235
- if stats.isDirectory()
236
- autoload path, app
237
- else
238
- require(path)?(app)
239
-
240
- # Return last item of an array
241
- # ['a', 'b', 'c'].last() => 'c'
242
- Array::last = ->
243
- this[this.length - 1]
244
-
245
- # Capitalize a string
246
- # string => String
247
- String::capitalize = () ->
248
- this.replace /(?:^|\\s)\\S/g, (a) -> a.toUpperCase()
249
-
250
- # Classify a string
251
- # application_controller => ApplicationController
252
- String::classify = (str) ->
253
- classified = []
254
- words = str.split('_')
255
- for word in words
256
- classified.push word.capitalize()
257
-
258
- classified.join('')
259
- """
260
-
261
- # ./myapp/app/routes
262
- files["#{@appDirectory}/#{@appName}/app/routes/index.coffee"] = """
263
- module.exports = (app) ->
264
- # Index
265
- app.get '/', app.ApplicationController.index
266
-
267
- # Error handling (No previous route found. Assuming it’s a 404)
268
- app.get '/*', (req, res) ->
269
- NotFound res
270
-
271
- NotFound = (res) ->
272
- res.render '404', status: 404, view: 'four-o-four'
273
- """
274
-
275
- # ./myapp/app/views
276
- # Ejs
277
- if @opts.renderer == 'ejs'
278
- files["#{@appDirectory}/#{@appName}/app/views/404.ejs"] = "<h1>Nothing here…</h1>"
279
-
280
- files["#{@appDirectory}/#{@appName}/app/views/index.ejs"] = """
281
- <h1>This page has been generated by <a href="https://github.com/EtienneLem/skeleton">Skeleton</a></h1>
282
- <p>Edit in <span>#{@appName}/views/index.ejs</span></p>
283
- """
284
-
285
- files["#{@appDirectory}/#{@appName}/app/views/layout.ejs"] = """
286
- <!DOCTYPE html>
287
- <html lang="en">
288
- <head>
289
- <meta charset="utf-8">
290
- <title>#{@appName}</title>
291
- <%- css('styles.css') %>
292
- </head>
293
- <body data-view="<%= view %>">
294
- <%- body %>
295
- <script>
296
- document.write('<script src=' +
297
- ('__proto__' in {} ? 'http://zeptojs.com/zepto.min.js' : 'http://code.jquery.com/jquery-1.7.2.min.js') +
298
- '><\\/script>')
299
- </script>
300
- <%- js('scripts.js') %>
301
- </body>
302
- </html>
303
- """
304
-
305
- # Jade
306
- if @opts.renderer == 'jade'
307
- files["#{@appDirectory}/#{@appName}/app/views/404.jade"] = """
308
- extends layout
309
-
310
- block content
311
- h1 Nothing here…
312
- """
313
-
314
- files["#{@appDirectory}/#{@appName}/app/views/index.jade"] = """
315
- extends layout
316
-
317
- block content
318
- h1 This page has been generated by <a href="https://github.com/EtienneLem/skeleton">Skeleton</a>
319
- p Edit in <span>#{@appName}/views/index.jade</span>
320
- """
321
-
322
- files["#{@appDirectory}/#{@appName}/app/views/layout.jade"] = """
323
- doctype html
324
- html(lang="en")
325
- head
326
- meta(charset="utf-8")
327
- title #{@appName}
328
- != css('styles.css')
329
-
330
- body(data-view="\#{view}")
331
- block content
332
-
333
- | <script>
334
- | document.write('<script src=' +
335
- | ('__proto__' in {} ? 'http://zeptojs.com/zepto.min.js' : 'http://code.jquery.com/jquery-1.7.2.min.js') +
336
- | '><\\/script>')
337
- | </script>
338
-
339
- != js('scripts.js')
340
- """
341
-
342
- # ./myapp/config
343
- files["#{@appDirectory}/#{@appName}/config/boot.coffee"] = """
344
- module.exports = (app) ->
345
- # Helpers
346
- app.helpers = require "\#{__dirname}/../app/helpers"
347
-
348
- # Lib
349
- app.helpers.autoload "\#{__dirname}/../lib", app
350
-
351
- # Controllers
352
- app.helpers.autoload "\#{__dirname}/../app/controllers", app
353
- """
354
-
355
- # ./myapp/lib/myapp
356
- files["#{@appDirectory}/#{@appName}/lib/#{@appName}/my_custom_class.coffee"] = """
357
- # module.exports = (app) ->
358
- # # Your code
359
- #
360
- #
361
- # Or if you want this to be a class
362
- #
363
- # module.exports = (app) ->
364
- # class app.MyCustomClass
365
- #
366
- # constructor: (args) ->
367
- # # Your code
368
- #
369
- # Usage: new app.MyCustomClass(args)
370
- """
371
-
372
- # ./myapp/public
373
- files["#{@appDirectory}/#{@appName}/public/empty"] = ""
374
-
375
- # Return the files object
376
- files
377
-
378
- getTemplateModule: ->
379
- module = ''
380
- spaces = ' '
381
-
382
- # Jade doesn’t need express-partials
383
- if @opts.renderer != 'jade'
384
- module = """
385
- , "express-partials": ">= 0.0.5"\n#{spaces}
386
- """
387
-
388
- module += """
389
- , "#{@opts.renderer}": "*"
390
- """
391
-
392
- module
393
-
394
- getCssModule: ->
395
- if @opts.css != 'css'
396
- """
397
- , "#{@opts.css}": "*"
398
- """
399
- else ''
400
-
401
- getJsModule: ->
402
- if @opts.js == 'coffee'
403
- """
404
- , "coffee-script": "*"
405
- """
406
- else ''
407
-
408
-
409
- module.exports = Template