Skip to content

Commit

Permalink
add page bundling and add module files to example subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
MayaGans committed Jun 18, 2019
1 parent eb0e614 commit 5b65f8e
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 8 deletions.
27 changes: 19 additions & 8 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
options(blogdown.author = "Maya Gans",
blogdown.ext = ".Rmd",
blogdown.subdir = "post",
blogdown.yaml.empty = TRUE,
blogdown.new_bundle = TRUE,
blogdown.title_case = TRUE)
rprofile <- Sys.getenv("R_PROFILE_USER", "~/.Rprofile")
# in .Rprofile of the website project
if (file.exists("~/.Rprofile")) {
base::sys.source("~/.Rprofile", envir = environment())
}

options(blogdown.new_bundle = TRUE)

options(
blogdown.author = "Maya Gans",
blogdown.ext = ".Rmd",
blogdown.subdir = "post",
blogdown.yaml.empty = TRUE,
blogdown.new_bundle = TRUE,
blogdown.title_case = TRUE
)

rprofile <- Sys.getenv("R_PROFILE_USER", "~/.Rprofile") # This line and below added in from Blogdown Day 3 slides for bundling

if (file.exists(rprofile)) {
source(file = rprofile)
}
}
16 changes: 16 additions & 0 deletions static/example/example_module/example_withModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
goog.provide('Blockly.Blocks.texts'); // Deprecated
goog.provide('Blockly.Constants.Text');
goog.require('Blockly.Blocks');
goog.require('Blockly');

Blockly.JavaScript['example_CreateDataSet'] = function(block) {
return "new Analysis.Analysis()"
}

Blockly.JavaScript['example_IncrementDataSet'] = function(block) {
return '.increment()'
}

Blockly.JavaScript['example_DisplayDataSet'] = function(block) {
return '.display()'
}
85 changes: 85 additions & 0 deletions static/example/example_module/index_withModule.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blockly Demo</title>

<!-- require the compressed blockly and JS scripts -->
<!-- still need to dig into these to see what exactly is required -->

<script src="../blockly_compressed.js"></script>
<script src="../javascript_compressed.js"></script>

<style>
body {
background-color: #fff;
font-family: sans-serif;
}
h1 {
font-weight: normal;
font-size: 140%;
}
</style>
</head>
<body>


<h1>Simple Blockly Demo</h1>

<p>
<button onclick="showCode()">Show JavaScript</button>
<button onclick="runCode()">Run JavaScript</button>
</p>

<div id="blocklyDiv" style="height: 200px; width: 650px; display: inline-block; vertical-align: top"></div>

<!-- within the toolbox we use the type id to display the blocks we want -->
<xml id="toolbox" style="display: none">
<block type="example_CreateDataSet"></block>
<block type="example_IncrementDataSet"></block>
<block type="example_DisplayDataSet"></block>
</xml>

<!-- AFTER the toolbox is declared we run the script for those blocks -->
<script src="../example_blocks.js"></script>
<script src="example_withModule.js"></script>

<script>

// create workspace for blocks using inject
// access media for the toolbox
import Analysis from "myModule.js";

var demoWorkspace = Blockly.inject('blocklyDiv',
{media: '../media/',
toolbox: document.getElementById('toolbox'),
trashcan: true
});


function showCode() {
// Generate JavaScript code and display it.
var code = Blockly.JavaScript.workspaceToCode(demoWorkspace);
alert(code);
}

function runCode() {
// Generate JavaScript code and run it.
window.LoopTrap = 1000;
Blockly.JavaScript.INFINITE_LOOP_TRAP =
'if (--window.LoopTrap == 0) throw "Infinite loop.";\n';
var code = Blockly.JavaScript.workspaceToCode(demoWorkspace);
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
try {
alert(eval(code));
} catch (e) {
alert(e);
}
}

</script>



</body>
</html>
12 changes: 12 additions & 0 deletions static/example/example_module/myModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default class Analysis {
constructor () {
this.value = 0
}
increment () {
this.value += 1;
return this
}
display () {
return this.value
}
}

0 comments on commit 5b65f8e

Please sign in to comment.