Skip to content

Commit 1b4b07f

Browse files
committed
Merge branch 'master' into help-pages
2 parents d0351e2 + 04ffda0 commit 1b4b07f

37 files changed

+106
-38
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ server/config/development.json
1010
server/config/seeds
1111
client/test/tests.coffee
1212
client/test/tests.js
13+
client/src/templates/templates.js

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ In **development**, supervisor is used to handle exceptions:
6363

6464
`cd server/ && npm start`
6565

66-
#### Compile coffeescripts
66+
#### Asset compilation
6767

68-
`cd client && grunt watch`
68+
*For more info, check out the [asset README](client/README.md).*
69+
70+
`cd client && grunt && grunt watch`
6971

7072
#### Logging in
7173

@@ -105,9 +107,11 @@ generates data in the same format as the indicator data backup in
105107

106108
* `cd server/ && npm run-script production`
107109

108-
#### Compile coffeescripts
110+
#### Asset compilation
111+
112+
*For more info, check out the [asset README](client/README.md).*
109113

110-
`cd client && grunt watch`
114+
`cd client && grunt`
111115

112116
#### Authentication and logging in
113117

client/.bowerrc

-3
This file was deleted.

client/Gruntfile.coffee

+43-29
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ module.exports = (grunt) ->
55
clean:
66
options:
77
force: true
8-
dist: [
9-
'dist/',
8+
ephemeral: [
9+
'src/templates/templates.js',
10+
'test/tests.js'
11+
]
12+
all: [
1013
'../server/public/css',
1114
'../server/public/font',
1215
'../server/public/images',
@@ -16,8 +19,8 @@ module.exports = (grunt) ->
1619

1720
coffee:
1821
source:
19-
src: 'dist/js/application.coffee'
20-
dest: 'dist/js/application.js'
22+
src: '../server/public/js/application.coffee'
23+
dest: '../server/public/js/application.js'
2124
ext: '.js'
2225
test:
2326
src: 'test/tests.coffee'
@@ -27,64 +30,70 @@ module.exports = (grunt) ->
2730
concat:
2831
source:
2932
src: grunt.file.readJSON('src/compile_manifest.json')
30-
dest: 'dist/js/application.coffee'
31-
dist:
32-
src: ['dist/js/templates.js', 'dist/js/application.js']
33-
dest: 'dist/js/application.js'
33+
dest: '../server/public/js/application.coffee'
3434
test:
3535
src: ['test/src/helpers.coffee', 'test/src/**/*.coffee']
3636
dest: 'test/tests.coffee'
3737

3838
handlebars:
3939
source:
4040
files:
41-
'dist/js/templates.js': ['src/templates/**/*.hbs']
41+
'src/templates/templates.js': ['src/templates/**/*.hbs']
4242
options:
4343
namespace: 'Handlebars.templates'
4444
processName: (filename) ->
4545
filename.replace(/^src\/templates\//, '')
4646

4747
copy:
48-
dist:
48+
libs:
4949
files: [
5050
expand: true
5151
cwd: 'src/images/'
52-
dest: 'dist/images'
52+
dest: '../server/public/images'
5353
src: '**/*'
5454
,
5555
expand: true
5656
cwd: 'src/vendor/'
57-
dest: 'dist/'
57+
dest: '../server/public/'
5858
src: ['**/*']
5959
]
60-
release:
60+
test:
6161
files: [
62-
expand: true
63-
cwd: 'dist/'
64-
dest: '../server/public'
65-
src: ['**/*']
66-
,
6762
expand: true
6863
cwd: 'test/'
6964
dest: '../server/public/js'
7065
src: 'tests.js'
7166
]
67+
templates:
68+
files: [
69+
expand: true
70+
cwd: 'src/templates/'
71+
src: 'templates.js'
72+
dest: '../server/public/js'
73+
]
7274

7375
sass:
7476
dist:
7577
files:
76-
'dist/css/main.css': 'src/sass/main.scss'
77-
'dist/css/report.css': 'src/sass/report.scss'
78-
'dist/css/dashboard.css': 'src/sass/dashboard.scss'
79-
'dist/css/about.css': 'src/sass/about.scss'
80-
'dist/css/indicator.css': 'src/sass/indicator.scss'
81-
'dist/css/theme.css': 'src/sass/theme.scss'
82-
'dist/css/login.css': 'src/sass/login.scss'
83-
'dist/css/rtl_overrides.css': 'src/sass/rtl_overrides.scss'
78+
'../server/public/css/main.css': 'src/css/main.scss'
79+
'../server/public/css/report.css': 'src/css/report.scss'
80+
'../server/public/css/dashboard.css': 'src/css/dashboard.scss'
81+
'../server/public/css/about.css': 'src/css/about.scss'
82+
'../server/public/css/indicator.css': 'src/css/indicator.scss'
83+
'../server/public/css/theme.css': 'src/css/theme.scss'
84+
'../server/public/css/login.css': 'src/css/login.scss'
85+
'../server/public/css/rtl_overrides.css': 'src/css/rtl_overrides.scss'
8486

8587
watch:
86-
files: ['src/**/*', 'test/src/**/*'],
87-
tasks: 'default'
88+
source:
89+
files: ['src/**/*.coffee']
90+
tasks: 'concat:source'
91+
templates:
92+
files: ['src/**/*.hbs']
93+
tasks: 'templates'
94+
tests:
95+
files: ['test/src/**/*.coffee']
96+
tasks: 'tests'
8897
)
8998

9099
grunt.loadNpmTasks('grunt-contrib-coffee')
@@ -95,4 +104,9 @@ module.exports = (grunt) ->
95104
grunt.loadNpmTasks('grunt-contrib-copy')
96105
grunt.loadNpmTasks('grunt-sass')
97106

98-
grunt.registerTask('default', ['clean', 'concat:source', 'coffee:source', 'handlebars', 'concat:dist', 'sass', 'concat:test', 'coffee:test', 'copy:dist', 'copy:release'])
107+
grunt.registerTask('templates', ['handlebars', 'copy:templates'])
108+
grunt.registerTask('source', ['concat:source', 'coffee:source'])
109+
grunt.registerTask('tests', ['concat:test', 'coffee:test', 'copy:test'])
110+
111+
grunt.registerTask('default', ['templates', 'source', 'tests', 'sass',
112+
'copy:libs', 'copy:test', 'clean:ephemeral'])

client/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# NRT Client Source
2+
3+
## Asset Compilation
4+
5+
Grunt is used to compile, combine and copy assets for use in the NRT
6+
server application. In production and development it is used for
7+
slightly different purposes.
8+
9+
## `grunt`
10+
Concatenates and compiles everything you need to run the application.
11+
12+
* concatenates Coffeescript files in to an `application.coffee`, then compiles them to javascript
13+
* compiles Handlebars templates and concatenates them in to an includable `templates.js` file.
14+
* concatenates and compiles SASS
15+
* copies libraries to the server `public/` directory.
16+
17+
## `grunt watch`
18+
For use in development, `grunt watch` watches your files for changes,
19+
and concatenates them when that happens.
20+
21+
It differs from the above in that rather than compiling coffeescript and SASS,
22+
it leaves simply concatenates them, then expects the coffeescript and node-sass
23+
middlewares to perform the compilation. This leads to better performance when
24+
working in development.
25+
26+
These middlewares are disabled in production (for speed), meaning this task alone
27+
will not work, and you must run `grunt` on it's own.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

server/app.coffee

+17
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ exports.createApp = ->
2121

2222
bindRoutesForApp = require('./route_bindings.coffee')
2323

24+
if app.get('env') isnt 'production'
25+
sass = require('node-sass')
26+
app.use sass.middleware(
27+
src: path.join(__dirname, "..", "client", "src")
28+
dest: path.join(__dirname, 'public')
29+
debug: true
30+
)
31+
32+
coffee = require('coffee-middleware')
33+
app.use coffee(
34+
src: path.join(__dirname, "public")
35+
compress: true
36+
force: true
37+
debug: true
38+
encodeSrc: false
39+
)
40+
2441
app.use express.static(path.join(__dirname, "public"))
2542

2643
app.engine "hbs", hbs.express3(

server/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "NODE_ENV=test mocha test/**/*.coffee test/**/**/*.coffee --compilers coffee:coffee-script --require coffee-script --ui qunit --reporter spec",
88
"test-debug": "NODE_ENV=test mocha test/**/*.coffee --compilers coffee:coffee-script --require coffee-script --ui qunit --reporter spec --debug",
9-
"start": "supervisor -e 'node,js,json,coffee,hbs' ./bin/server.js",
9+
"start": "supervisor -e 'node,js,json,coffee,hbs' -i ./public ./bin/server.js",
1010
"debug": "node --debug ./bin/server.js",
1111
"development": "echo 'Please use `npm start` to run the server in development mode'",
1212
"production": "NODE_ENV=production node ./bin/server.js",
@@ -43,7 +43,9 @@
4343
"connect-mongo": "~0.3.3",
4444
"connect-flash": "~0.1.1",
4545
"range_check": "0.0.4",
46-
"libxmljs": "~0.8.1"
46+
"libxmljs": "~0.8.1",
47+
"node-sass": "~0.8.1",
48+
"coffee-middleware": "~0.2.1"
4749
},
4850
"devDependencies": {
4951
"Faker": "0.5.11",

server/views/indicators/show.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<script src="/js/lib/esri-leaflet.js"></script>
1616
<script src="/js/lib/medium-editor.min.js"></script>
1717
<script src="/js/lib/Chart.min.js"></script>
18+
<script src="/js/templates.js"></script>
1819
<script src="/js/application.js"></script>
1920
{{/contentFor}}
2021

server/views/reports/index.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<script src="/js/lib/backbone-relational.js"></script>
77
<script src="/js/lib/handlebars.js"></script>
88
<script src="/js/lib/diorama.js"></script>
9+
<script src="/js/templates.js"></script>
910
<script src="/js/application.js"></script>
1011

1112
<script type="text/javascript">

server/views/reports/show.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<script src="/js/lib/leaflet.js"></script>
1313
<script src="/js/lib/jquery.sortable.min.js"></script>
1414
<script src="/js/lib/medium-editor.min.js"></script>
15+
<script src="/js/templates.js"></script>
1516
<script src="/js/application.js"></script>
1617

1718
<script type="text/javascript">

server/views/tests.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<script src="/js/lib/marked.js"></script>
3232
<script src="/js/lib/i18next.min.js"></script>
3333
<script src="/js/lib/Chart.min.js"></script>
34+
<script src="/js/templates.js"></script>
3435
<script src="/js/application.js"></script>
3536

3637
<script>

server/views/themes/index.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<script src="/js/lib/backbone-relational.js"></script>
4242
<script src="/js/lib/handlebars.js"></script>
4343
<script src="/js/lib/diorama.js"></script>
44+
<script src="/js/templates.js"></script>
4445
<script src="/js/application.js"></script>
4546
{{/contentFor}}
4647

server/views/themes/show.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<script src="/js/lib/handlebars.js"></script>
1313
<script src="/js/lib/diorama.js"></script>
1414
<script src="/js/lib/medium-editor.min.js"></script>
15+
<script src="/js/templates.js"></script>
1516
<script src="/js/application.js"></script>
1617
{{/contentFor}}
1718

0 commit comments

Comments
 (0)