Skip to content

Commit

Permalink
Merge branch 'gh-pages' of github.com:prose/prose into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dhcole committed Mar 25, 2013
2 parents 943b3d4 + b2ea449 commit a3a9990
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
39 changes: 22 additions & 17 deletions _includes/model.js
Expand Up @@ -62,7 +62,7 @@ function authenticate() {
});
return false;
} else {
return true;
return true;
}
}

Expand All @@ -74,7 +74,7 @@ function logout() {

// Load Application
// -------
//
//
// Load everything that's needed for the app + header

function loadApplication(cb) {
Expand All @@ -99,7 +99,7 @@ function loadApplication(cb) {
_.each(repos, function(r) {
owners[r.owner.login] = owners[r.owner.login] ? owners[r.owner.login].concat([r]) : [r];
});

cb(null, {
"available_repos": repos,
"organizations": orgs,
Expand All @@ -109,7 +109,7 @@ function loadApplication(cb) {
});

},
error: function(err) {
error: function(err) {
cb('error', { "available_repos": [], "owners": {} });
}
});
Expand All @@ -122,7 +122,7 @@ function loadApplication(cb) {

// Load Repos
// -------
//
//
// List all available repositories for a certain user

function loadRepos(username, cb) {
Expand All @@ -145,7 +145,7 @@ function loadRepos(username, cb) {

// Load Branches
// -------
//
//
// List all available branches of a repository

function loadBranches(user, repo, cb) {
Expand Down Expand Up @@ -196,7 +196,7 @@ function getFiles(tree, path, searchstr) {
});

// Sort by name
files = _.sortBy(files, function(entry){
files = _.sortBy(files, function(entry){
return (entry.type === "tree" ? "A" : "B") + entry.path;
});

Expand All @@ -209,7 +209,7 @@ function getFiles(tree, path, searchstr) {

// Load Posts
// -------
//
//
// List all postings for a given repo+branch+path plus load _config.yml

function loadPosts(user, reponame, branch, path, cb) {
Expand Down Expand Up @@ -263,7 +263,7 @@ function serialize(content, metadata) {

// Save File
// -------
//
//
// Store a file to GitHub

function saveFile(user, repo, branch, path, content, message, cb) {
Expand All @@ -274,7 +274,7 @@ function saveFile(user, repo, branch, path, content, message, cb) {

// Fork repository
// -------
//
//
// Creates a fork for the current user

function forkRepo(user, reponame, branch, cb) {
Expand Down Expand Up @@ -305,7 +305,7 @@ function forkRepo(user, reponame, branch, cb) {

// New pull request
// -------
//
//
// Creates a new pull request

function createPullRequest(user, repo, pull, cb) {
Expand All @@ -319,7 +319,7 @@ function createPullRequest(user, repo, pull, cb) {

// Patch File
// -------
//
//
// Send a pull request on GitHub

function patchFile(user, repo, branch, path, content, message, cb) {
Expand Down Expand Up @@ -361,7 +361,7 @@ function movePost(user, repo, branch, path, newPath, cb) {

// New Post
// -------
//
//
// Prepare new empty post

function emptyPost(user, repo, branch, path, cb) {
Expand All @@ -377,6 +377,11 @@ function emptyPost(user, repo, branch, path, cb) {
rawMetadata = cfg.prose.metadata[path];
try {
metadata = jsyaml.load(rawMetadata);
if (metadata.date=="CURRENT_DATETIME") {
var current = (new Date()).format('Y-m-d H:i');
metadata.date = current;
rawMetadata = rawMetadata.replace("CURRENT_DATETIME", current);
}
} catch(err) {
console.log('ERROR encoding YAML');
// No-op
Expand All @@ -399,7 +404,7 @@ function emptyPost(user, repo, branch, path, cb) {

// Load Post
// -------
//
//
// List all postings for a given repository
// Looks into _posts/blog

Expand All @@ -422,7 +427,7 @@ function loadPost(user, repo, branch, path, file, cb) {
return !!(app.state.permissions && app.state.permissions.push);
}

if (!_.jekyll(path, file)) return {
if (!_.hasMetadata(content)) return {
raw_metadata: "",
content: content,
published: false,
Expand All @@ -442,11 +447,11 @@ function loadPost(user, repo, branch, path, file, cb) {
cb(err, _.extend(post, {
"sha": commit,
"markdown": _.markdown(file),
"jekyll": _.jekyll(path, file),
"jekyll": _.hasMetadata(data),
"repo": repo,
"path": path,
"file": file,
"persisted": true
}));
});
}
}
5 changes: 5 additions & 0 deletions _includes/util.js
Expand Up @@ -83,6 +83,11 @@ _.jekyll = function(path, file) {
return !!(path.match('_posts') && _.markdown(file));
};

// check if a given file has YAML frontmater
// -------
_.hasMetadata = function(content) {
return content.match( /^(---\n)((.|\n)*?)\n---\n?/ );
}

// Extract file extension
// -------
Expand Down
6 changes: 4 additions & 2 deletions _includes/views/application.js
Expand Up @@ -14,10 +14,10 @@ views.Application = Backbone.View.extend({
toggleView: function (e) {
e.preventDefault();
e.stopPropagation();

var link = $(e.currentTarget),
route = link.attr('href').replace(/^\//, '');

$('.toggle-view.active').removeClass('active');
link.addClass('active');
router.navigate(route, true);
Expand Down Expand Up @@ -103,6 +103,7 @@ views.Application = Backbone.View.extend({
if (err) return this.notify('error', 'The requested resource could not be found.');
data.preview = !(mode === "edit");
data.lang = _.mode(file);
console.error(data);
this.replaceMainView(window.authenticated ? "post" : "read-post", new views.Post({ model: data, id: 'post' }).render());
var that = this;
}, this));
Expand All @@ -118,6 +119,7 @@ views.Application = Backbone.View.extend({
data.jekyll = _.jekyll(path, data.file);
data.preview = false;
data.markdown = _.markdown(data.file);
data.lang = _.mode(data.file);
this.replaceMainView("post", new views.Post({ model: data, id: 'post' }).render());
this.mainView._makeDirty();
app.state.file = data.file;
Expand Down

0 comments on commit a3a9990

Please sign in to comment.