-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add page bundling and add module files to example subdirectory
- Loading branch information
Showing
4 changed files
with
132 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |