Skip to content

Commit

Permalink
Merge pull request #356 from jywarren/macro-editor
Browse files Browse the repository at this point in the history
Macro editor
  • Loading branch information
jywarren committed Apr 16, 2016
2 parents b95d82f + 8f452d9 commit a40932c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 52 deletions.
1 change: 0 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<% end %>

<%= javascript_include_tag "application" %>
<%= javascript_include_tag "spectralworkbench/SpectralWorkbench" %>
<%= csrf_meta_tag %>

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
Expand Down
87 changes: 44 additions & 43 deletions app/views/macros/_scripting.html.erb
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
<div id="term"></div>
<p><small>Read about the <a href="https://publiclab.org/wiki/spectral-workbench-api">Spectral Workbench API</a></small></p>
<pre id="editor" style="height:200px;">
spectrum.addAndParseTag('smooth:10'); // Smooth the spectrum

<script src="/lib/jquery.terminal/js/jquery.terminal-0.9.3.min.js"></script>
<script src="/lib/jquery.terminal/js/jquery.mousewheel-min.js"></script>
<link href="/lib/jquery.terminal/css/jquery.terminal-0.9.2.css" rel="stylesheet"/>
// spectrum.addAndUploadTag('smooth:10'); // <== to save </pre>

<style>
<p>
<a class="btn-editor-run btn btn-lg btn-primary">Run</a>
<a class="btn-editor-save btn btn-lg">Save as Gist</a>
<small>Read about the <a href="https://publiclab.org/wiki/spectral-workbench-api">Spectral Workbench API</a></small>
</p>

#term {

-webkit-border-radius: 4px;
border-radius: 4px;
-moz-border-radius: 4px;
-moz-border-radius: 4px;

}

</style>
<script src="/lib/ace-builds/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>

<script>

var init_terminal,
terminal = false,
term;
var editor = ace.edit("editor");
editor.setTheme("ace/theme/twilight");
editor.session.setMode("ace/mode/javascript");

jQuery(function($, undefined) {

init_terminal = function() {

if (terminal == false) {
term = $('#term').terminal(function(command, term) {
if (command !== '') {
try {
var result = window.eval(command);
if (result !== undefined) {
term.echo(new String(result));
}
} catch(e) {
term.error(new String(e));
}
} else {
term.echo('');
}
}, {
greetings: 'Spectral Workbench JS scripting console:',
name: 'js',
height: 200,
prompt: 'js> '});
}
$('.btn-editor-run').click(function() {

terminal = true;
eval(editor.getValue());

}
});

$('.btn-editor-save').click(function() {

var data = {
"description": "A script saved from https://spectralworkbench.org",
"public": true,
"files": {
"main.js": {
"content": editor.getValue()
}
}
}
$.ajax({
url: 'https://api.github.com/gists',
type: 'POST',
dataType: 'json',
data: JSON.stringify(data)
})
.success( function(e) {
window.open(e.html_url);
$('.tab-tab-comments').click();
$('#comment-body').val("Script [saved as a Gist](" + e.html_url + ") from the scripting tab. Fork it to continue working on it!");
$('#comment-submit').click();
})
.error( function(e) {
console.warn("gist save error", e);
});

});

});
</script>
12 changes: 6 additions & 6 deletions app/views/spectrums/show2.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@
<div class="span8">

<ul class="nav nav-tabs">
<li class="active"><a href="#tab-tools" data-toggle="tab"><i class="fa fa-cog"></i> Tools</a></li>
<li> <a href="#tab-sets" data-toggle="tab"><i class="fa fa-list"></i> Sets</a></li>
<li> <a href="#tab-comments" data-toggle="tab"><i class="fa fa-comments"></i> <%= @spectrum.comments.length %> Comments</a></li>
<% if @spectrum.forks %><li><a href="#tab-forks" data-toggle="tab"><i class="fa fa-code-fork"></i> <%= @spectrum.forks.length %> Forks</a></li><% end %>
<li> <a href="#tab-scripting" data-toggle="tab" onClick="init_terminal();"><i class="fa fa-terminal"></i> Scripting</a></li>
<li class="comparisons" style="display:none;"><a href="#tab-comparisons" data-toggle="tab"><i class="fa fa-columns"></i> Comparisons</a></li>
<li class="active"><a class="tab-tab-tools" href="#tab-tools" data-toggle="tab"><i class="fa fa-cog"></i> Tools</a></li>
<li> <a class="tab-tab-sets" href="#tab-sets" data-toggle="tab"><i class="fa fa-list"></i> Sets</a></li>
<li> <a class="tab-tab-comments" href="#tab-comments" data-toggle="tab"><i class="fa fa-comments"></i> <%= @spectrum.comments.length %> Comments</a></li>
<% if @spectrum.forks %><li><a class="tab-tab-forks" href="#tab-forks" data-toggle="tab"><i class="fa fa-code-fork"></i> <%= @spectrum.forks.length %> Forks</a></li><% end %>
<li> <a class="tab-tab-scripting" href="#tab-scripting" data-toggle="tab"><i class="fa fa-terminal"></i> Scripting</a></li>
<li class="comparisons" style="display:none;"><a class="tab-tab-comparisons" href="#tab-comparisons" data-toggle="tab"><i class="fa fa-columns"></i> Comparisons</a></li>
</ul>

<div class="tab-content">
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Spectral Workbench",
"version": "2.0.0-beta.2",
"dependencies": {
"spectral-workbench": "~0.0.5",
"spectral-workbench": "~0.0.7",
"d3": "~3.3.13",
"nvd3": "~1.7.1",
"fontawesome": "~4.5.0",
Expand All @@ -15,7 +15,7 @@
"moment": "~2.10.6",
"jasmine-ajax": "jasmine/jasmine-ajax#v3.2.0",
"leaflet": "0.7.3",
"jquery.terminal": "~0.9.3"
"ace-builds": "~1.2.3"
},
"resolutions": {
"d3": "^3.4.4",
Expand Down

0 comments on commit a40932c

Please sign in to comment.