0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Cleaning up old juggling stuff in a separate commit

This commit is contained in:
Hannah Wolfe 2013-05-16 22:16:44 +01:00
parent ef94f3b778
commit 325ded8a12
5 changed files with 0 additions and 319 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,20 +0,0 @@
[
{
"key": "url",
"value": "http://localhost:3333",
"createdBy": 1,
"updatedBy": 1
},
{
"key": "title",
"value": "John O'Nolan",
"createdBy": 1,
"updatedBy": 1
},
{
"key": "description",
"value": "Interactive designer, public speaker, startup advisor and writer. Living in Austria, attempting world domination via keyboard.",
"createdBy": 1,
"updatedBy": 1
}
]

View file

@ -1,15 +0,0 @@
[
{
"id": "1",
"username": "johnonolan",
"firstName": "John",
"lastName": "O'Nolan",
"emailAddress": "john@onolan.org",
"profilePicture": "logo.png",
"coverPicture": "",
"bio": "Interactive designer, public speaker, startup advisor and writer. Living in Austria, attempting world domination via keyboard.",
"url": "john.onolan.org",
"createdBy": 1,
"updatedBy": 1
}
]

View file

@ -1,147 +0,0 @@
/**
* Provides access to data via the JugglingDb ORM
*/
/*globals module, require */
(function () {
"use strict";
var schema = require('./schema').schema,
fs = require('fs'),
_ = require('underscore'),
DataProvider,
instance;
function populateData(callback) {
// TODO: convert to promises
schema.models.Setting.findOne({}, function (error, data) {
if (data === null) {
// we haven't loaded any data yet
fs.readFile(__dirname + '/data/fixtures/users.json', function (error, data) {
if (error) {
throw error;
}
var users = JSON.parse(data);
_.each(users, function (post) {
schema.models.User.create(post, function (error, data) {
console.log('User created error', error);
console.log('User created data', data);
});
});
fs.readFile(__dirname + '/data/fixtures/posts.json', function (error, data) {
if (error) {
throw error;
}
var posts = JSON.parse(data),
post;
_.each(posts, function (_post) {
post = new schema.models.Post(_post);
post.preCreate(function () {
post.save(function (error, data) {
console.log('Post created error', error);
console.log('Post created data', data);
});
});
});
fs.readFile(__dirname + '/data/fixtures/settings.json', function (error, data) {
if (error) {
throw error;
}
var posts = JSON.parse(data);
_.each(posts, function (post) {
schema.models.Setting.create(post, function (error, data) {
console.log('Setting created error', error);
console.log('Setting created data', data);
});
});
callback();
});
});
});
} else {
callback();
}
});
}
DataProvider = function () {
if (!instance) {
instance = this;
if (process.env.forcePopulate) {
populateData();
}
}
return instance;
};
DataProvider.prototype.posts = function () {};
/**
* Naive find all
* @param callback
*/
DataProvider.prototype.posts.findAll = function (callback) {
schema.models.Post.all(callback);
};
/**
* Naive find one where args match
* @param args
* @param callback
*/
DataProvider.prototype.posts.findOne = function (args, callback) {
schema.models.Post.findOne({where: args}, callback);
};
/**
* Naive add
* @param _post
* @param callback
*/
DataProvider.prototype.posts.add = function (_post, callback) {
var post = new schema.models.Post(_post);
post.preCreate(function () {
post.save(callback);
});
};
/**
* Naive edit
* @param _post
* @param callback
*/
DataProvider.prototype.posts.edit = function (_post, callback) {
schema.models.Post.findOne({where: {id: _post.id}}, function (error, post) {
post = _.extend(post, _post);
schema.models.Post.updateOrCreate(post, callback);
});
};
DataProvider.prototype.posts.destroy = function (_identifier, callback) {
schema.models.Post.findOne({where: {id: _identifier}}, function (error, post) {
schema.models.Post.destroy(post.id, callback);
});
};
DataProvider.prototype.populateData = populateData;
module.exports = DataProvider;
}());

View file

@ -1,113 +0,0 @@
/**
* Database Schema, created with JugglingDB
*
* Vastly incomplete!
*/
/*global module, require */
(function () {
"use strict";
var Schema = require('jugglingdb').Schema,
schema = new Schema('sqlite3', {
database: __dirname + '/../data/datastore.db'
}),
Showdown = require('showdown'),
converter = new Showdown.converter(),
Post,
User,
Setting;
/*------------------------------------------------------------------------------------
POST / Post / Posts
------------------------------------------------------------------------------------*/
Post = schema.define('Post', {
title: String,
slug: String,
content: Schema.Text,
contentHtml: Schema.Text,
featured: Boolean,
image: String,
status: String,
language: String,
createdAt: Date,
createdBy: Number,
updatedAt: Date,
updatedBy: Number
});
Post.prototype.generateSlug = function () {
return this.title.replace(/\:/g, '').replace(/\s/g, '-').toLowerCase();
};
Post.prototype.preCreate = function (next) {
//console.log('pre create 1', this);
this.createdAt = this.createdAt || new Date();
this.slug = this.slug || this.generateSlug();
// this.language = this.language || ghost.config().defaultLang;
// this.status = this.status || ghost.statuses().draft
this.featured = false;
// console.log('pre create 2', this);
next();
};
// Validations
Post.validatesPresenceOf('title', {message: 'Post title cannot be blank'});
//Post.validatesPresenceOf('slug');
//Post.validatesPresenceOf('language', {message: 'Language cannot be blank'});
//Post.validatesUniquenessOf('slug');
//Post.validatesLengthOf('language', {min: 2, max: 5}, "The language code should be between 2 and 5 chars long, E.g. 'en' or 'en_GB' ");
// doesn't get run on update
Post.beforeSave = Post.beforeUpdate = function (next, data) {
console.log('before s1', data);
// set updated
data.updatedAt = new Date();
data.contentHtml = converter.makeHtml(data.content);
next();
};
/*------------------------------------------------------------------------------------
USER / User / Users
------------------------------------------------------------------------------------*/
User = schema.define('User', {
username: String,
firstName: String,
lastName: String,
emailAddress: String,
profilePicture: String,
coverPicture: String,
bio: Schema.Text,
url: String,
createdAt: Date,
createdBy: Number,
updatedAt: Date,
updatedBy: Number
});
/*------------------------------------------------------------------------------------
SETTING / Setting / Settings
------------------------------------------------------------------------------------*/
Setting = schema.define('Setting', {
key: String,
value: Schema.Text,
createdAt: Date,
createdBy: Number,
updatedAt: Date,
updatedBy: Number
});
/*------------------------------------------------------------------------------------
RELATIONSHIPS
------------------------------------------------------------------------------------*/
User.hasMany(Post, {as: 'posts', foreignKey: 'createdBy'});
Post.belongsTo(User, {as: 'author', foreignKey: 'createdBy'});
schema.autoupdate();
exports.schema = schema;
}());