Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plantingjs from npm #68

Merged
merged 7 commits into from
Jan 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
'extends': 'airbnb',
'ecmaFeatures': {'modules': true},
'env': {
'es6': true,
'browser': true,
'node': true
},
'parser': 'babel-eslint'
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

.coverage
db.sqlite3
wysadzulice/static/plantingjs
node_modules
wysadzulice/static
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ WYSADZULICE.PL
## Synopsis

Django-based application that run http://wysadzulice.pl


## How to install
* Install Python requirements
* Install Node requirements
* Create db
* gulp build
* Run server
115 changes: 115 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import autoprefixer from 'gulp-autoprefixer';
import babelify from 'babelify';
import browserify from 'browserify';
import concat from 'gulp-concat';
import del from 'del';
import domain from 'domain';
import flatten from 'gulp-flatten';
import filter from 'gulp-filter';
import gulp from 'gulp';
import gutil from 'gulp-util';
import hbsfy from 'hbsfy';
import plumber from 'gulp-plumber';
import sass from 'gulp-sass';
import tap from 'gulp-tap';


/* Default task */
gulp.task('default', function() {
gulp.start('build');
});


/* Removing whole ./wysadzulice/static/ directory */
gulp.task('clean', del.bind(null, './wysadzulice/static'));


/* Building JS */
gulp.task('js', function() {
return gulp.src('./wysadzulice/assets/main.js')
.pipe(plumber())
.pipe(tap(function(file) {
const dom = domain.create();
dom.on('error', function(err) {
gutil.log(
gutil.colors.red('Browserify compile error:'),
err.message, '\n\t',
gutil.colors.cyan('in file'), file.path
);
gutil.beep();
});
dom.run(function() {
file.contents = browserify({
entries: [file.path],
debug: false,
standalone: 'Planting',
paths: ['./node_modules/', './wysadzulice/assets/'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we always use relative paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably right. Because all js modules available in wysadzulice/assets will be imported into main using relative paths, it looks, that we can freely remove this option from browserify.

I will do it at today's meeting.

transform: [
[hbsfy, {
global: true,
ignore: /\/node_modules\/(?!plantingjs\/)/,
}],
[babelify, {
global: true,
ignore: /\/node_modules\/(?!plantingjs\/)/,
}],
],
}).bundle();
});
}))
.pipe(gulp.dest('./wysadzulice/static/wysadzulice/js/'));
});
/* End of building JS */

/* Building CSS */
gulp.task('css:main', function() {
return gulp.src('./wysadzulice/assets/styles/**/*.scss')
.pipe(sass())
.pipe(autoprefixer({browsers: ['last 1 version']}))
.pipe(concat('main.css'))
.pipe(gulp.dest('./wysadzulice/static/wysadzulice/styles/'));
});

gulp.task('css:vendor', function() {
return gulp.src([
'./node_modules/jquery-ui/themes/base/jquery-ui.css',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need jquery-ui here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked it it used in plantingjs, and have just recreate gulp task from there - in plantingjs we are concatenating jquery-ui.css, so we are doing that here also.

Maybe we should create separate task for plantingjs to investigate if we really are using these styles?

'./node_modules/jquery-ui/themes/base/jquery.ui.dialog.css',
'./node_modules/plantingjs/src/styles/*.scss',
])
.pipe(sass())
.pipe(concat('vendor.css'))
.pipe(gulp.dest('./wysadzulice/static/wysadzulice/styles/'));
});

gulp.task('css', ['css:vendor', 'css:main']);
/* End of building CSS */


/* Building fonts */
gulp.task('fonts', function() {
return gulp.src('./node_modules/plantingjs/src/fonts/**/*')
.pipe(filter('**/*.{eot,svg,ttf,woff}'))
.pipe(flatten())
.pipe(gulp.dest('./wysadzulice/static/wysadzulice/fonts'));
});
/* End of building fonts */


/* Building assets */
gulp.task('assets:main', function() {
return gulp.src('./wysadzulice/assets/assets/**/*')
.pipe(gulp.dest('./wysadzulice/static/wysadzulice/assets/main'));
});

gulp.task('assets:vendor', function() {
return gulp.src('./wysadzulice/assets/assets/**/*')
.pipe(gulp.dest('./wysadzulice/static/wysadzulice/assets/vendor'));
});

gulp.task('assets', ['assets:main', 'assets:vendor']);
/* End of building assets */


/* Building all frontend assets */
gulp.task('build', ['assets', 'css', 'fonts', 'js']);
/* End of building all frontend assets */
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"dependencies": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need whole plantingjs stack here?
Also it's good idea to separate dev dependencies from dependencies (http://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies) - we can create separate issue for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right here, but because we need to build plantingjs here, we need also this dependencies. I believe when we will create proper npm package (that one with all kind of scripts) we will be able to remove lot of these dependencies.

And as for dev dependencies - I will create separate issue for that - we will do it in less busy time.

"babelify": "^6.4.0",
"browserify": "^11.2.0",
"plantingjs": "git://github.com/komitywa/plantingjs",
"babel-core": "^5.8.29",
"gulp": "^3.9.0",
"gulp-util": "^3.0.6",
"hbsfy": "^2.4.1",
"handlebars": "^4.0.4",
"gulp-plumber": "^1.0.1",
"gulp-tap": "^0.1.3",
"gulp-autoprefixer": "^1.0.1",
"gulp-sass": "^2.0.4",
"jquery-ui": "^1.10.5",
"del": "^0.1.0",
"gulp-filter": "^1.0.2",
"gulp-flatten": "^0.0.4"
}
}
47 changes: 47 additions & 0 deletions wysadzulice/assets/assets/manifesto.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"lat": 52.3965155,
"lng": 16.8978846,
"zoom": 14,
"toolboxobjects": [
{
"projections": [
"/static/wysadzulice/assets/main/objects/00.png",
"/static/wysadzulice/assets/main/objects/10.png",
"/static/wysadzulice/assets/main/objects/20.png",
"/static/wysadzulice/assets/main/objects/30.png",
"/static/wysadzulice/assets/main/objects/40.png",
"/static/wysadzulice/assets/main/objects/50.png",
"/static/wysadzulice/assets/main/objects/60.png",
"/static/wysadzulice/assets/main/objects/70.png",
"/static/wysadzulice/assets/main/objects/80.png",
"/static/wysadzulice/assets/main/objects/00.png",
"/static/wysadzulice/assets/main/objects/10.png",
"/static/wysadzulice/assets/main/objects/20.png",
"/static/wysadzulice/assets/main/objects/30.png",
"/static/wysadzulice/assets/main/objects/40.png",
"/static/wysadzulice/assets/main/objects/50.png",
"/static/wysadzulice/assets/main/objects/60.png",
"/static/wysadzulice/assets/main/objects/70.png",
"/static/wysadzulice/assets/main/objects/80.png",
"/static/wysadzulice/assets/main/objects/00.png",
"/static/wysadzulice/assets/main/objects/10.png",
"/static/wysadzulice/assets/main/objects/20.png",
"/static/wysadzulice/assets/main/objects/30.png",
"/static/wysadzulice/assets/main/objects/40.png",
"/static/wysadzulice/assets/main/objects/50.png",
"/static/wysadzulice/assets/main/objects/60.png",
"/static/wysadzulice/assets/main/objects/70.png",
"/static/wysadzulice/assets/main/objects/80.png",
"/static/wysadzulice/assets/main/objects/00.png",
"/static/wysadzulice/assets/main/objects/10.png",
"/static/wysadzulice/assets/main/objects/20.png",
"/static/wysadzulice/assets/main/objects/30.png",
"/static/wysadzulice/assets/main/objects/40.png",
"/static/wysadzulice/assets/main/objects/50.png",
"/static/wysadzulice/assets/main/objects/60.png",
"/static/wysadzulice/assets/main/objects/70.png",
"/static/wysadzulice/assets/main/objects/80.png"
]
}
]
}
3 changes: 3 additions & 0 deletions wysadzulice/assets/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Planting from 'plantingjs';

export default Planting;
47 changes: 0 additions & 47 deletions wysadzulice/static/manifesto.json

This file was deleted.

8 changes: 4 additions & 4 deletions wysadzulice/templates/new_planting.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<meta name=description>
<meta name=viewport content="width=device-width, initial-scale=1, minimal-ui">
<title>plantingjs</title>
<link rel=stylesheet href="{% static "plantingjs/styles/main.css" %}">
<link rel=stylesheet href="{% static "wysadzulice/styles/vendor.css" %}">
<link rel=stylesheet href="{% static "wysadzulice/styles/main.css" %}">
</head>
<body>
<script type=text/javascript src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9fmhpMCKGM6BCMtsnn05GfxEK77jRHjc"></script>
<div id="viewport" class="viewport"></div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
Expand All @@ -28,12 +28,12 @@

}
</script>
<script src="{% static "plantingjs/js/main.js" %}"></script>
<script src="{% static "wysadzulice/js/main.js" %}"></script>
<script type="text/javascript">
$(function() {
PlantingInstance = new Planting( {
container:document.querySelector('.viewport'),
manifestoUrl: '{% static "manifesto.json" %}',
manifestoUrl: '{% static "wysadzulice/assets/main/manifesto.json" %}',
googleApiKey: 'AIzaSyD9fmhpMCKGM6BCMtsnn05GfxEK77jRHjc',
onSave: simple_save_callback
});
Expand Down
1 change: 1 addition & 0 deletions wysadzulice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.shortcuts import redirect
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt

from . import models


Expand Down