Skip to content
This repository has been archived by the owner on Apr 19, 2019. It is now read-only.

Commit

Permalink
Add save and load.
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed May 3, 2012
1 parent 347260f commit 7d4427a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/gollum/frontend/app.rb
Expand Up @@ -42,6 +42,14 @@ class App < Sinatra::Base
show_page_or_file('Home')
end

get '/data/*' do
@name = params[:splat].first
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
if page = wiki.page(@name)
page.raw_data
end
end

get '/edit/*' do
@name = params[:splat].first
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
Expand Down
48 changes: 48 additions & 0 deletions lib/gollum/frontend/public/gollum/livepreview/index.html
Expand Up @@ -91,6 +91,54 @@
editor.setBehavioursEnabled(true);

window.onload = function() {
// RegExp from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
$.key = function(key){
var value = new RegExp('[\\?&]' + key + '=([^&#]*)').exec(window.location.href);
return (!value) ? 0 : value[1] || 0;
}

/* Load markdown from /data/page into the ace editor. */
jQuery.ajax({
type: "GET",
url: "/data/" + $.key("page"),
success: function(data) {
editorSession.setValue(data);
}
});

$.save = function() {
// if &create=true then handle create instead of edit.
var create = $.key("create");

if (create) {
jQuery.ajax({
type: "POST",
url: "/create",
data: { page: $.key("page"), format: "markdown", content: editorSession.getValue() },
success: function() {
// on success, load the new page.
window.location = window.location.origin + "/" + $.key("page");
}
});
} else {
jQuery.ajax({
type: "POST",
url: "/edit/" + $.key("page"),
data: { format: "markdown", content: editorSession.getValue() },
success: function() {
// on success, load the new page.
window.location = window.location.origin + "/" + $.key("page");
}
});
} // end else
}

$('#save').click(function() {
console.log("save clicked!");
// Save page and navigate to the new page on success.
$.save();
});

// onChange calls applyTimeout which rate limits the calling of makePreviewHtml based on render time.
editor.on('change', applyTimeout);
makePreviewHtml(); // preview default text on load
Expand Down

0 comments on commit 7d4427a

Please sign in to comment.