Ossicle is a project mainly written in ..., it's free.
This is a simple module of localStorage based persistence to override Backbone.sync
with ability to use different kinds of models with same keys (ie : "human|001", "doc|001", ...).
Use :
include backbone-sync-localstorage.js
Model and Collection must have a property storeName
:
window.Human = Backbone.Model.extend({
storeName : "humansDB"
});
window.Humans = Backbone.Collection.extend({
model : Human,
storeName : "humansDB"
});
key storage
of a model is calculated like that : storeName
+ "|" + model.id
then you can do that :
myModel.save() // save model to local storage
myModel.fetch() // get model from local storage
myModel.destroy() // delete model from local storage
myModelsCollection.fetch() // load all models from local storage
It's a "POC". Goal : to display a few pages (markdown format) stored on a GitHub repository.
The main idea is :
create a GitHub repository with a posts
directory (or an other name)
copy "somewhere" these files : https://github.com/k33g/ossicle :
.
|-- css
| `-- style.css
|-- js
| `-- backbone.sync
| |-- backbone-sync-github.js /* override Backbone.sync */
| `-- vendor
| |-- backbone-min.js
| |-- github.js
| |-- showdown.js
| |-- underscore-min.js
| `-- zepto.min.js
|-- bb-github-api.js
`-- index-bb-github-api.html
Edit bb-github-api.js
: you have to set the gitHubStorage
of the Backbone.Collection
window.Posts = Backbone.Collection.extend({
model : Post,
initialize : function() {
var that = this;
that.launch = arguments[1];
//Set the "gitHub storage"
this.gitHubStorage = new Store('k33g','ossicle','master','posts',
function(){
that.fetch({ result : function() {
that.launch(); /* launched when loaded */
}
});
});
}
});
Use : this.gitHubStorage = new Store(github_user_name, github_project_name, branch_name, directory_name, callback_function);
That's all.