Merge "LESS integration for development and production evironments"

This commit is contained in:
Jenkins 2013-12-05 13:30:27 +00:00 committed by Gerrit Code Review
commit 1c649e1535
8 changed files with 57 additions and 20 deletions

2
.gitignore vendored
View File

@ -24,6 +24,8 @@ lock
node_modules node_modules
nailgun/static/js/libs/bower nailgun/static/js/libs/bower
nailgun/static/css/styles.css
.idea .idea
.DS_Store .DS_Store

View File

@ -26,6 +26,10 @@ module.exports = function(grunt) {
modules: [{name: "js/main"}], modules: [{name: "js/main"}],
waitSeconds: 60, waitSeconds: 60,
optimize: "uglify2", optimize: "uglify2",
optimizeCss: "standard",
pragmas: {
compressed: true
},
} }
} }
}, },
@ -48,6 +52,12 @@ module.exports = function(grunt) {
} }
} }
}, },
less: {
all: {
src: 'static/css/styles.less',
dest: 'static/css/styles.css',
}
},
bower: { bower: {
install: { install: {
options: { options: {
@ -68,8 +78,9 @@ module.exports = function(grunt) {
}); });
grunt.loadNpmTasks('grunt-contrib-requirejs'); grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-jslint'); grunt.loadNpmTasks('grunt-jslint');
grunt.loadNpmTasks('grunt-bower-task'); grunt.loadNpmTasks('grunt-bower-task');
grunt.registerTask('build', ['bower', 'requirejs']); grunt.registerTask('build', ['bower', 'less', 'requirejs']);
grunt.registerTask('default', ['build']); grunt.registerTask('default', ['build']);
}; };

View File

@ -10,7 +10,8 @@
"jquery.timeout": "http://jquery-timeout.googlecode.com/files/jquery.timeout-1.1.0.js", "jquery.timeout": "http://jquery-timeout.googlecode.com/files/jquery.timeout-1.1.0.js",
"backbone.stickit": "https://raw.github.com/NYTimes/backbone.stickit/b450a07b2cecb3ad0343096f29e0332d5f9508b0/backbone.stickit.js", "backbone.stickit": "https://raw.github.com/NYTimes/backbone.stickit/b450a07b2cecb3ad0343096f29e0332d5f9508b0/backbone.stickit.js",
"i18next": "1.7.1", "i18next": "1.7.1",
"backbone-deep-model": "0.10.4" "backbone-deep-model": "0.10.4",
"less": "1.5.1"
}, },
"exportsOverride": { "exportsOverride": {
"jquery": { "jquery": {
@ -42,6 +43,9 @@
}, },
"backbone-deep-model": { "backbone-deep-model": {
"js": "distribution/deep-model.js" "js": "distribution/deep-model.js"
},
"less": {
"js": "dist/less-1.5.1.js"
} }
}, },
"ignore": [ "ignore": [

View File

@ -14,28 +14,32 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import jinja2
import mimetypes import mimetypes
import posixpath import os.path
import web import web
from nailgun.settings import settings from nailgun.settings import settings
render = web.template.render(settings.TEMPLATE_DIR)
class IndexHandler(object): class IndexHandler(object):
def GET(self): def GET(self):
return render.index() tpl_path = os.path.join(settings.TEMPLATE_DIR, 'index.html')
with open(tpl_path, 'r') as f:
tpl = jinja2.Template(f.read())
return tpl.render(**{
'use_less': bool(settings.DEVELOPMENT)
})
class StaticHandler(object): class StaticHandler(object):
def GET(self, fl): def GET(self, fl):
fl_path = posixpath.join(settings.STATIC_DIR, fl) fl_path = os.path.join(settings.STATIC_DIR, fl)
mimetype = mimetypes.guess_type(fl_path)[0] mimetype = mimetypes.guess_type(fl_path)[0]
if mimetype: if mimetype:
web.header("Content-Type", mimetype) web.header("Content-Type", mimetype)
try: if os.path.exists(fl_path):
f = open(fl_path, 'r') with open(fl_path, 'r') as f:
return f.read() return f.read()
except Exception: else:
raise web.notfound() raise web.notfound()

View File

@ -0,0 +1 @@
@import 'main.css';

View File

@ -8,14 +8,13 @@
<meta name="description" content=""> <meta name="description" content="">
<meta name="author" content=""> <meta name="author" content="">
<link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
<link href="/static/css/main.css" rel="stylesheet"> {% if use_less %}
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements --> <link href="/static/css/styles.less" rel="stylesheet/less">
<!--[if lt IE 9]> {% else %}
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <link href="/static/css/styles.css" rel="stylesheet">
<![endif]--> {% endif %}
<script data-main="/static/js/main" src="/static/js/libs/bower/requirejs/js/require.js"></script> <script data-main="/static/js/main" src="/static/js/libs/bower/requirejs/js/require.js"></script>
</head> </head>
<body> <body>
<div id="wrap"> <div id="wrap">
<div class="container"> <div class="container">

View File

@ -34,6 +34,7 @@ requirejs.config({
i18next: 'js/libs/bower/i18next/js/i18next-1.7.1', i18next: 'js/libs/bower/i18next/js/i18next-1.7.1',
underscore: 'js/libs/bower/lodash/js/lodash', underscore: 'js/libs/bower/lodash/js/lodash',
deepModel: 'js/libs/bower/backbone-deep-model/js/deep-model', deepModel: 'js/libs/bower/backbone-deep-model/js/deep-model',
less: 'js/libs/bower/less/js/less-1.5.1',
app: 'js/app', app: 'js/app',
models: 'js/models', models: 'js/models',
collections: 'js/collections', collections: 'js/collections',
@ -83,7 +84,22 @@ requirejs.config({
}); });
require([ require([
'jquery', 'underscore', 'backbone', 'stickit', 'deepModel', 'coccyx', 'i18next', 'bootstrap', 'retina', 'jquery-checkbox', 'jquery-timeout', 'jquery-ui', 'jquery-autoNumeric', 'jquery',
'underscore',
'backbone',
'stickit',
'deepModel',
'coccyx',
'i18next',
'bootstrap',
'retina',
'jquery-checkbox',
'jquery-timeout',
'jquery-ui',
'jquery-autoNumeric',
//>>excludeStart("compressed", pragmas.compressed);
'less',
//>>excludeEnd("compressed");
'app' 'app'
], function() { ], function() {
'use strict'; 'use strict';

View File

@ -154,7 +154,7 @@ function run_ui_tests {
fi fi
echo "Done" echo "Done"
test_server_config=$compressed_static_dir/settings.yaml test_server_config=$compressed_static_dir/settings.yaml
echo -e "DEVELOPMENT: 0\nSTATIC_DIR: '$compressed_static_dir'" > $compressed_static_dir/settings.yaml echo -e "DEVELOPMENT: 0\nSTATIC_DIR: '$compressed_static_dir'\nTEMPLATE_DIR: '$compressed_static_dir'" > $compressed_static_dir/settings.yaml
test_server_port=5544 test_server_port=5544
test_server_cmd="./manage.py run --port=$test_server_port --config=$test_server_config --fake-tasks --fake-tasks-tick-count=80 --fake-tasks-tick-interval=1" test_server_cmd="./manage.py run --port=$test_server_port --config=$test_server_config --fake-tasks --fake-tasks-tick-count=80 --fake-tasks-tick-interval=1"
old_server_pid=`ps aux | grep "$test_server_cmd" | grep -v grep | awk '{ print $2 }'` old_server_pid=`ps aux | grep "$test_server_cmd" | grep -v grep | awk '{ print $2 }'`