diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..eb23e6c --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,92 @@ +/** + * @author: EgorKluch (EgorKluch@gmail.com) + * @date: 29.12.13 + */ + +'use strict'; + +module.exports = function (grunt) { + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + + browserify: { + index: { + src: ['scripts/pages/index.js'], + dest: 'js/index.js', + options: { + transform: ['brfs'], + debug: true + } + } + }, + + copy: { + pages: { + files: [ + { + expand: true, + cwd: 'scripts/pages/', + src: '**', + dest: 'js/' + } + ] + } + }, + + clean: { + vod: ['js/**/*'] + }, + + watch: { + files: ['js/**/*'], + tasks: ['build'], + options: { + atBegin: true, + spawn: false + } + }, + + jshint: { + options: { + globals: { + '$': true, + 'ko': true, + 'Common': true, + 'keynav': true, + 'EPG': true, + oipfObjectFactory: true + }, + node: true, + browser: true, + strict: true, + eqeqeq: true, + eqnull: true, + forin: true, + immed: true, + indent: 2, + latedef: true, + newcap: true, + quotmark: 'single', + undef: true, + trailing: true, + boss: true, + laxbreak: true + }, + allFiles: [ + 'Gruntfile.js', + 'app.js', + 'scripts/**/*.js' + ] + } + }); + + grunt.loadNpmTasks('grunt-browserify'); + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + + grunt.registerTask('build', ['clean', 'copy', 'browserify']); +}; diff --git a/app.js b/app.js index 75a5171..4706d4e 100644 --- a/app.js +++ b/app.js @@ -3,36 +3,25 @@ * @date: 29.12.13 */ +'use strict'; + var express = require('express'); -var app = express(); var config = require('./config/config'); -var mysql = require('mysql'); -var connection = mysql.createConnection(config.mysql); -connection.connect(function(err) { - //if (err) throw err; - console.log('Mysql is connected!'); -}); - +var app = express(); app.configure(function(){ + // Config twig app.set('views', __dirname + '/templates'); app.set('view engine', 'twig'); - - // This section is optional and can be used to configure twig. app.set('twig options', { strict_variables: true }); + app.use('/js', express.static('js')); + app.use('/css', express.static('css')); }); -app.get('/', function (req, res) { - connection.query('SELECT 1', function (err, rows) { - console.log(rows); - res.render('index', { - message : "Hello World" - }); - }); -}); +require('./config/routes')(app); -app.listen(3000); -console.log('Express started on port 3000'); +app.listen(config.port); +console.log('Express started on port ' + config.port); diff --git a/config/config.sample.js b/config/config.sample.js index 581ae3a..7ecf981 100644 --- a/config/config.sample.js +++ b/config/config.sample.js @@ -4,6 +4,8 @@ */ module.exports = { + port: 3000, + mysql: { host: 'localhost', user: 'root', diff --git a/config/routes.js b/config/routes.js new file mode 100644 index 0000000..d2b7361 --- /dev/null +++ b/config/routes.js @@ -0,0 +1,33 @@ +/** + * @author: EgorKluch (EgorKluch@gmail.com) + * @date: 29.12.13 + */ + +var _ = require('underscore'); + +var render = function (app, template, script, style, data, callback) { + if (_.isFunction(data)) { + callback = data; + data = {}; + } + data.script = '/js/' + template; + data.style = '/css/' + style; + app.render(template, data, function (err, html) { + if (err) throw err; + callback(html); + }); +}; + +module.exports = function (app) { + app.get('/', function (req, res) { + render(app, 'index.twig', 'index.js', 'main.css', function (html) { + res.send(html); + }); + }); + + app.use(function(req, res){ + render(app, 'notFound.twig', 'index.js', 'main.css', function (html) { + res.send(404, html); + }); + }); +}; diff --git a/css/main.less b/css/main.less new file mode 100644 index 0000000..0d4e3ea --- /dev/null +++ b/css/main.less @@ -0,0 +1,96 @@ +@blueColor: #45688E; +@grayColor: #b0b0b0; + +body { + margin: 0; + padding: 0; + border: 0; + font-family: 'Open Sans'; + font-size: 15px; + font-weight: 400; + font-style: normal; + font-size-adjust: none; + line-height: 21px; + vertical-align: baseline; +} + +a.button { + color: @blueColor; + font-weight: bold; +} + +h1 { + text-transform: uppercase; + color: @blueColor; +} + +h2 { + text-transform: uppercase; + font-size: 25px; + font-weight: bold; + color: @blueColor; + margin-top: 5px; +} + +#leftBar { + padding-top: 15px; + width: 200px; + float: left; + min-height: 800px; + border-right: 2px solid @grayColor; + + .menu { + a { + display: block; + } + } +} + +#content { + width: 570px; + float: right; + padding-top: 15px; + + td.label { + text-align: right; + } +} + +#wrapper { + width: 800px; + margin: auto; + margin-top: 5px; +} + +#header { + padding-bottom: 5px; + border-bottom: 2px solid @grayColor; + + a { + text-decoration: none; + color: @blueColor; + } +} + +#loginForm { + display: inline-block; + font-size: 13px; + + .title { + text-align: center; + font-weight: bold; + } + + .inputContainer { + display: inline-block; + } + + a { + font-size: 12px; + } + + input { + width: 100px; + padding: 0; + } +} diff --git a/scripts/common/Core.js b/scripts/common/Core.js new file mode 100644 index 0000000..04de437 --- /dev/null +++ b/scripts/common/Core.js @@ -0,0 +1,43 @@ +/** + * @author: EgorKluch (EgorKluch@gmail.com) + * @date: 28.12.13 + */ + +'use strict'; + +var $ = require('jquery-browserify'); + +var Core = function () { + if (Core.instance) { + return Core.instance; + } + Core.instance = this; + + $('#leftBar').css('height', $('#content').height()); + + return this; +}; + +Core.prototype.doRequest = function (url, data, callback, returnResponse) { + if (!data) data = {}; + if (returnResponse === undefined) returnResponse = true; + if (this.token) data.token = this.token; + $.ajax({ + dataType: 'json', + url: url, + method: 'POST', + data: data, + success: function (response) { + if (response.error) { + console.error(response); + return; + } + if (callback) { + response = returnResponse ? response : undefined; + callback(response); + } + } + }); +}; + +module.exports = Core; diff --git a/scripts/pages/index.js b/scripts/pages/index.js new file mode 100644 index 0000000..df40360 --- /dev/null +++ b/scripts/pages/index.js @@ -0,0 +1,12 @@ +/** + * @author: EgorKluch (EgorKluch@gmail.com) + * @date: 28.12.13 + */ + +'use strict'; + +var Core = require('../common/Core'); + +$(document).ready(function () { + var core = new Core(); +}); diff --git a/src/Core.js b/src/Core.js new file mode 100644 index 0000000..989170e --- /dev/null +++ b/src/Core.js @@ -0,0 +1,24 @@ +/** + * @author: EgorKluch (EgorKluch@gmail.com) + * @date: 29.12.13 + */ + +var Mysql = require('./Mysql'); + +var config = require('./config/config'); + +var Core = function (callback) { + if (Core.instance) { + if (callback) callback(Core.instance); + return Core.instance; + } + Core.instance = this; + + new Mysql(function (response) { + this.mysql = response; + if (callback) callback(this); + }.bind(this)); + return this; +}; + +exports = Core; diff --git a/src/Mysql.js b/src/Mysql.js index 36fdbca..6f8f026 100644 --- a/src/Mysql.js +++ b/src/Mysql.js @@ -11,6 +11,7 @@ var config = require('../config/config'); var Mysql = function (callback) { if (Mysql.instance) { + if (callback) callback(Mysql.instance); return Mysql.instance; } Mysql.instance = this; diff --git a/templates/base.twig b/templates/base.twig new file mode 100755 index 0000000..1f0faeb --- /dev/null +++ b/templates/base.twig @@ -0,0 +1,35 @@ + + + + + + + Аукцион картин + + + + + + + +
+ + {% include 'header.twig' %} + +
+
+ {% include 'user/leftBlock.twig' %} + {% block leftBar %}{% endblock %} +
+
+

{% block title %}{% endblock %}

+ {% block content %}{% endblock %} +
+
+ + {% include 'footer.twig' %} + +
+ + + diff --git a/templates/footer.twig b/templates/footer.twig new file mode 100755 index 0000000..e69de29 diff --git a/templates/header.twig b/templates/header.twig new file mode 100755 index 0000000..d81a163 --- /dev/null +++ b/templates/header.twig @@ -0,0 +1,3 @@ + diff --git a/templates/index.twig b/templates/index.twig old mode 100644 new mode 100755 index e322e04..95317de --- a/templates/index.twig +++ b/templates/index.twig @@ -1,3 +1,12 @@ - +{% extends "base.twig" %} -

{{ message }}

\ No newline at end of file +{% block scripts %} + +{% endblock %} + +{% block title %} + Добро пожаловать +{% endblock %} + +{% block content %} +{% endblock %} diff --git a/templates/notFound.twig b/templates/notFound.twig new file mode 100755 index 0000000..ba4bfae --- /dev/null +++ b/templates/notFound.twig @@ -0,0 +1,9 @@ +{% extends "base.twig" %} + +{% block title %} + Страница не найдена +{% endblock %} + +{% block content %} + К сожалению, данной страницы не существует. +{% endblock %} diff --git a/templates/src/index.twig b/templates/src/index.twig new file mode 100755 index 0000000..639e1c3 --- /dev/null +++ b/templates/src/index.twig @@ -0,0 +1,11 @@ +{% extends "base.twig" %} + +{% block scripts %} +{% endblock %} + +{% block title %} + Добро пожаловать +{% endblock %} + +{% block content %} +{% endblock %} diff --git a/templates/user/leftBlock.twig b/templates/user/leftBlock.twig new file mode 100755 index 0000000..523fad6 --- /dev/null +++ b/templates/user/leftBlock.twig @@ -0,0 +1,23 @@ +
+ {% if not user %} + + + +
Логин: + +
Пароль: + +
+
+ + +
+ {% else %} + + {% endif %} +