Skip to content

Commit

Permalink
Add prettier and run it
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jan 11, 2018
1 parent 1e02fcb commit 46912b2
Show file tree
Hide file tree
Showing 267 changed files with 12,143 additions and 11,934 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"promise-polyfill": "^6.0.2",
"babel-preset-env": "^1.6.1",
"chai": "^4.1.2",
"cross-env": "^5.0.5",
Expand All @@ -37,6 +36,8 @@
"jsdom": "^11.2.0",
"mocha": "^3.1.2",
"node-sass": "^4.5.3",
"prettier": "1.10.1",
"promise-polyfill": "^6.0.2",
"sinon": "^3.2.1",
"string-replace-loader": "^1.3.0",
"webpack": "^3.5.5",
Expand Down Expand Up @@ -81,6 +82,7 @@
"build:css": "node-sass src/styles/scss/main.scss dist/css/grapes.min.css --output-style compressed",
"v:patch": "npm version --no-git-tag-version patch",
"start": "npm run build:css -- -w & webpack-dev-server --open --progress --colors",
"format": "prettier --single-quote --write './{src,test}/**/*.js'",
"test": "cross-env NODE_PATH=./src mocha --compilers js:babel-core/register --require test/helper.js --timeout 10000 --recursive test/main.js",
"test:dev": "npm test -- -R min -w"
}
Expand Down
21 changes: 8 additions & 13 deletions src/asset_manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ module.exports = () => {
let assets, am, fu;

return {

/**
* Name of the module
* @type {String}
Expand Down Expand Up @@ -75,8 +74,7 @@ module.exports = () => {
c = config || {};

for (let name in defaults) {
if (!(name in c))
c[name] = defaults[name];
if (!(name in c)) c[name] = defaults[name];
}

const ppfx = c.pStylePrefix;
Expand All @@ -92,19 +90,19 @@ module.exports = () => {
// Collection visible in asset manager
collection: new Assets([]),
globalCollection: assets,
config: c,
config: c
};
fu = new FileUpload(obj);
obj.fu = fu;
am = new AssetsView(obj);

// Setup the sync between the global and public collections
assets.listenTo(assets, 'add', (model) => {
assets.listenTo(assets, 'add', model => {
this.getAllVisible().add(model);
em && em.trigger('asset:add', model);
});

assets.listenTo(assets, 'remove', (model) => {
assets.listenTo(assets, 'remove', model => {
this.getAllVisible().remove(model);
em && em.trigger('asset:remove', model);
});
Expand Down Expand Up @@ -136,7 +134,6 @@ module.exports = () => {
* }]);
*/
add(asset, opts = {}) {

// Put the model at the beginning
if (typeof opts.at == 'undefined') {
opts.at = 0;
Expand All @@ -153,7 +150,7 @@ module.exports = () => {
* var asset = assetManager.get('http://img.jpg');
*/
get(src) {
return assets.where({src})[0];
return assets.where({ src })[0];
},

/**
Expand Down Expand Up @@ -196,8 +193,7 @@ module.exports = () => {
var obj = {};
var assets = JSON.stringify(this.getAll().toJSON());
obj[this.storageKey] = assets;
if(!noStore && c.stm)
c.stm.store(obj);
if (!noStore && c.stm) c.stm.store(obj);
return obj;
},

Expand All @@ -219,7 +215,7 @@ module.exports = () => {
if (typeof assets == 'string') {
try {
assets = JSON.parse(data[name]);
} catch(err) {}
} catch (err) {}
}

if (assets && assets.length) {
Expand Down Expand Up @@ -357,7 +353,6 @@ module.exports = () => {
*/
onDblClick(func) {
c.onDblClick = func;
},

}
};
};
16 changes: 9 additions & 7 deletions src/asset_manager/model/Asset.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module.exports = require('backbone').Model.extend({

idAttribute: 'src',

defaults: {
type: '',
src: '',
type: '',
src: ''
},

/**
Expand All @@ -13,7 +12,9 @@ module.exports = require('backbone').Model.extend({
* @private
* */
getFilename() {
return this.get('src').split('/').pop();
return this.get('src')
.split('/')
.pop();
},

/**
Expand All @@ -22,7 +23,8 @@ module.exports = require('backbone').Model.extend({
* @private
* */
getExtension() {
return this.getFilename().split('.').pop();
},

return this.getFilename()
.split('.')
.pop();
}
});
9 changes: 4 additions & 5 deletions src/asset_manager/model/AssetImage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const Asset = require('./Asset');

module.exports = Asset.extend({

defaults: { ...Asset.prototype.defaults,
defaults: {
...Asset.prototype.defaults,
type: 'image',
unitDim: 'px',
height: 0,
width: 0,
},

width: 0
}
});
30 changes: 17 additions & 13 deletions src/asset_manager/model/Assets.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import TypeableCollection from 'domain_abstract/model/TypeableCollection';

module.exports = require('backbone').Collection.extend(TypeableCollection).extend({
types: [{
id: 'image',
model: require('./AssetImage'),
view: require('./../view/AssetImageView'),
isType(value) {
if (typeof value == 'string') {
return {
type: 'image',
src: value,
module.exports = require('backbone')
.Collection.extend(TypeableCollection)
.extend({
types: [
{
id: 'image',
model: require('./AssetImage'),
view: require('./../view/AssetImageView'),
isType(value) {
if (typeof value == 'string') {
return {
type: 'image',
src: value
};
}
return value;
}
return value;
}
}]
});
]
});
5 changes: 2 additions & 3 deletions src/asset_manager/view/AssetImageView.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module.exports = require('./AssetView').extend({

events: {
'click [data-toggle=asset-remove]': 'onRemove',
click: 'onClick',
dblclick: 'onDblClick',
dblclick: 'onDblClick'
},

getPreview() {
Expand Down Expand Up @@ -32,7 +31,7 @@ module.exports = require('./AssetView').extend({

init(o) {
const pfx = this.pfx;
this.className += ` ${pfx}asset-image`;
this.className += ` ${pfx}asset-image`;
},

/**
Expand Down
3 changes: 1 addition & 2 deletions src/asset_manager/view/AssetView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = Backbone.View.extend({

initialize(o = {}) {
this.options = o;
this.collection = o.collection;
Expand Down Expand Up @@ -55,5 +54,5 @@ module.exports = Backbone.View.extend({
el.innerHTML = this.template(this, this.model);
el.className = this.className;
return this;
},
}
});
13 changes: 6 additions & 7 deletions src/asset_manager/view/AssetsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ var AssetImageView = require('./AssetImageView');
var FileUploader = require('./FileUploader');

module.exports = Backbone.View.extend({

events: {
submit: 'handleSubmit',
submit: 'handleSubmit'
},

template(view) {
Expand Down Expand Up @@ -66,7 +65,7 @@ module.exports = Backbone.View.extend({
if (handleAdd) {
handleAdd(url);
} else {
this.options.globalCollection.add(url, {at: 0});
this.options.globalCollection.add(url, { at: 0 });
}
},

Expand All @@ -86,7 +85,7 @@ module.exports = Backbone.View.extend({
* @private
*/
getAddInput() {
if(!this.inputUrl || !this.inputUrl.value)
if (!this.inputUrl || !this.inputUrl.value)
this.inputUrl = this.el.querySelector(`.${this.pfx}add-asset input`);
return this.inputUrl;
},
Expand Down Expand Up @@ -127,11 +126,11 @@ module.exports = Backbone.View.extend({
const rendered = new model.typeView({
model,
collection,
config,
config
}).render().el;

if (fragment) {
fragment.appendChild( rendered );
fragment.appendChild(rendered);
} else {
const assetsEl = this.getAssetsEl();
if (assetsEl) {
Expand Down Expand Up @@ -172,7 +171,7 @@ module.exports = Backbone.View.extend({
const assets = this.$el.find(`.${this.pfx}assets`);
assets.empty();
this.toggleNoAssets(this.collection.length);
this.collection.each((model) => this.addAsset(model, fragment));
this.collection.each(model => this.addAsset(model, fragment));
assets.append(fragment);
},

Expand Down
Loading

0 comments on commit 46912b2

Please sign in to comment.