summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2016-07-08 17:47:01 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2016-07-08 17:47:01 +0100
commit629010aa6e5c5aa57c2a43eebc4247b4819a1e7d (patch)
tree12415affe846bb4b1c3be5fc01c16977ad62a6b0
parentf5ebbf1091519ecab54e31cfa9395ac8c0856e5e (diff)
downloadsievely-master.tar.bz2
Support size testsHEADmaster
-rw-r--r--sievely/blocks.js23
-rw-r--r--sievely/funcs.js14
-rw-r--r--sievely/generator.js10
-rw-r--r--sievely/toolbox.xml1
4 files changed, 48 insertions, 0 deletions
diff --git a/sievely/blocks.js b/sievely/blocks.js
index 8274d01..cadd824 100644
--- a/sievely/blocks.js
+++ b/sievely/blocks.js
@@ -110,6 +110,29 @@ Blockly.Blocks['sievely_header'] = {
}
};
+Blockly.Blocks['sievely_size'] = {
+ init: function() {
+ this.appendDummyInput()
+ .appendField("the message is")
+ .appendField(new Blockly.FieldDropdown([["at least", ":over"], ["at most", ":under"]]), "TEST")
+ .appendField(new Blockly.FieldTextInput("10K"), "SIZE")
+ .appendField("in size");
+ this.setOutput(true, "Boolean");
+ this.setColour(Sievely.Blocks.BOOLEAN_HUE);
+ this.setTooltip('');
+ this.setHelpUrl(Sievely.Blocks.HELP_URL);
+ },
+ onchange: function() {
+ var inputvalue = this.getFieldValue('SIZE');
+ var sanitised = Sievely.sanitiseSieveNumber(inputvalue);
+ if (inputvalue == sanitised) {
+ this.setWarningText(null);
+ } else {
+ this.setWarningText("Input '" + inputvalue + "' interpreted as '" + sanitised + "'");
+ }
+ }
+};
+
/* Actions */
Blockly.Blocks['sievely_fileinto'] = {
diff --git a/sievely/funcs.js b/sievely/funcs.js
index 2c697de..590e406 100644
--- a/sievely/funcs.js
+++ b/sievely/funcs.js
@@ -231,3 +231,17 @@ Sievely.inject = function() {
x.open("GET", "/sievely/toolbox.xml", true);
x.send(null);
}
+
+Sievely.sanitiseSieveNumber = function(in_n) {
+ // Sieve numbers are of the form nnnn{K,M,G}
+ in_n = in_n.replace(/ /, "");
+ var last = in_n.slice(-1).toUpperCase();
+ if (last == "K" || last == "M" || last == "G") {
+ in_n = in_n.slice(0, -1);
+ } else {
+ last = ""
+ }
+ in_n = Number(in_n) || 0;
+ if (in_n < 0) { in_n = -in_n; }
+ return in_n.toString() + last;
+}
diff --git a/sievely/generator.js b/sievely/generator.js
index 2a14346..5304d79 100644
--- a/sievely/generator.js
+++ b/sievely/generator.js
@@ -117,6 +117,16 @@ Sievely.Generator['sievely_stop'] = function(block) {
return "stop;\n";
}
+Sievely.Generator['sievely_size'] = function(block) {
+ var test = block.getFieldValue('TEST');
+ var size = block.getFieldValue('SIZE');
+ size = Sievely.sanitiseSieveNumber(size);
+ return ["size " + test + " " + size, Sievely.Generator.ORDER_ANY];
+}
+
+
+
+
Sievely.Generator['sievely_folder'] = function(block) {
var val = block.getFieldValue('FOLDER');
return [Sievely.Generator.quote_(val), Sievely.Generator.ORDER_ANY];
diff --git a/sievely/toolbox.xml b/sievely/toolbox.xml
index 6e13ba2..f93b529 100644
--- a/sievely/toolbox.xml
+++ b/sievely/toolbox.xml
@@ -46,6 +46,7 @@
</shadow>
</value>
</block>
+ <block type="sievely_size"></block>
</category>
<category name="Headers and Values">
<block type="sievely_header">