Skip to content

Commit

Permalink
Merge pull request awestruct#92 from wesbos/master
Browse files Browse the repository at this point in the history
Asciidoc scratchpad
  • Loading branch information
LightGuard committed Nov 1, 2013
2 parents f3cc233 + e9fd56d commit b7b7216
Show file tree
Hide file tree
Showing 14 changed files with 15,107 additions and 72 deletions.
11 changes: 11 additions & 0 deletions assets/javascripts/controllers/awCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function AwCtrl($sce, $scope, $routeParams, $route,Data, Repo, $resource, $http, $window, Token) {

// window object for ease of debugging
window.$scope = $scope;
window.$sce = $sce;
window.$http = $http;

window.onbeforeunload = function(e){
var currPath = $scope.currentFile.links[0].url,
Expand Down Expand Up @@ -155,6 +157,9 @@ function AwCtrl($sce, $scope, $routeParams, $route,Data, Repo, $resource, $http,
$scope.edit = function(file) {
var path = file.links[0].url,
session;

// set ace path
ace.config.set('basePath', '/assets/vendor/ace');

// Make sure we aren't abandoning the current changes
if($scope.currentFile) {
Expand Down Expand Up @@ -457,4 +462,10 @@ function AwCtrl($sce, $scope, $routeParams, $route,Data, Repo, $resource, $http,
// pass down to child scope
angular.element(document.querySelector('.tools')).scope().insertImage(path);
}

$scope.cheatSheet = function() {
var scope = angular.element(document.querySelector('.scratchpad')).scope();
scope.loadScripts();
$scope.toggleOverlay('cheat');
}
}
55 changes: 55 additions & 0 deletions assets/javascripts/controllers/scratchpadCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function ScratchpadCtrl($scope, Data, $http){
var editor = $scope.scratchpad,
scriptsLoaded = false;

$scope.aceChanged = function(e) {
var text = $scope.scratchpad.getValue();
var html = Opal.Asciidoctor.$render(text);
document.querySelector('.scratchpad-preview').innerHTML = html;
};

// Because Asciidoctor.js and opal.js are so large, we will load them on demand
$scope.loadScripts = function(callback) {
if(scriptsLoaded) { return; } // only load once
scriptsLoaded = true;

// Load Opal /assets/vendor/opal.js
loadJS('/assets/vendor/opal.js',function() {
// console.log("Opload Loaded.");
});

loadJS('/assets/vendor/asciidoctor.js',function() {
// console.log("Asciidoctor Loaded.");
$http.get('/partials/asciidoc.html').then(function(res){
var adoc = res.data.replace(/<br \/>/gi,'\n');
$scope.scratchpad.getSession().setValue(adoc);
$scope.aceChanged();
});
});

// setup the editor
$scope.scratchpad.setShowPrintMargin(false);
$scope.scratchpad.setTheme("ace/theme/github");
$scope.scratchpad.getSession().setMode("ace/mode/asciidoc");



window.s =$scope.scratchpad;
// $scope.scratchpad.edit("testing 123");
}

function loadJS(scriptPath, callback) {
var scriptNode = document.createElement('script');
scriptNode.type = 'text/javascript';
scriptNode.src = scriptPath;

var headNode = document.getElementsByTagName('head');
if (headNode[0] != null)
headNode[0].appendChild(scriptNode);

if (callback != null) {
scriptNode.onreadystagechange = callback;
scriptNode.onload = callback;
}
}
}
2 changes: 1 addition & 1 deletion assets/javascripts/controllers/toolsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function ToolsCtrl($scope, Data){
exec: function(text, blank, name) {
var text = text || "";
// return text+"\n![](#{site.context_url}"+name+")\n";
return text+"\nimage::#{site.context_url}"+name+"\n";
return text+"\nimage::#{site.context_url}"+name+"[]\n";
},
blockLevel : true
},
Expand Down
1 change: 1 addition & 0 deletions assets/javascripts/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//= require app
//= require controllers/awCtrl
//= require controllers/toolsCtrl
//= require controllers/scratchpadCtrl
//= require services/data
//= require services/repo
//= require filters/filters
Expand Down
Loading

0 comments on commit b7b7216

Please sign in to comment.