Skip to content

Commit

Permalink
Show generated SPARQL on collapsed blocks
Browse files Browse the repository at this point in the history
Also teach generator to generate code for only one block
Also fix ASK code generation
  • Loading branch information
langsamu committed Apr 10, 2021
1 parent 8a72ad1 commit 36cd4db
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sparql-blockly",
"version": "0.0.4-16",
"version": "0.0.4-17",
"description": "A library for working with SPARQL in Blockly",
"main": "dist/index.js",
"license": "MIT",
Expand Down
16 changes: 14 additions & 2 deletions package/src/CodeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ export default class CodeGenerator extends Blockly.Generator {
.forEach(addToInstance)
}

public scrub_(block: Blockly.Block, code: string, thisOnly?: boolean): string {
if (!thisOnly) {
const next = block.getNextBlock();

if (next) {
code += this.blockToCode(next)
}
}

return code
}

public sparqlQuery(block: Blockly.Block): string {
const prologue = this.statementToCode(block, "prologue")
const value = this.valueToCode(block, "value")
Expand Down Expand Up @@ -82,7 +94,7 @@ export default class CodeGenerator extends Blockly.Generator {
public sparqlAskQuery(block: Blockly.Block): CodeTuple {
const value = this.valueToCode(block, "value")

const code = join(" ", "ASK", value)
const code = join("\n", "ASK", value)

return codeTuple(code)
}
Expand Down Expand Up @@ -900,7 +912,7 @@ export default class CodeGenerator extends Blockly.Generator {
const next = this.blockToCode(block.getNextBlock())

if (next) {
code += delimiter + next
code += delimiter
}

return code
Expand Down
18 changes: 18 additions & 0 deletions package/src/initialiseBlockly.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
import "./defineCustomBlocks"
import "./unregisterDefaultMenuItems"
import "./registerCustomMenuItems"
import * as Blockly from "blockly"
import CodeGenerator from "./CodeGenerator"

// This is what's displayed when block collapsed
Blockly.Block.prototype.toString = function () {
const code = new CodeGenerator().blockToCode(this, true)

if (code instanceof Array)
return code[0]
else
return code
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const blockly = Blockly as any
blockly.COLLAPSE_CHARS = 3000

Blockly.Field.prototype.maxDisplayLength = 3000
2 changes: 0 additions & 2 deletions package/src/unregisterDefaultMenuItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
ContextMenuRegistry.registry.unregister("undoWorkspace");
ContextMenuRegistry.registry.unregister("redoWorkspace");
ContextMenuRegistry.registry.unregister("cleanWorkspace");
ContextMenuRegistry.registry.unregister("collapseWorkspace");
ContextMenuRegistry.registry.unregister("expandWorkspace");
ContextMenuRegistry.registry.unregister("workspaceDelete");
ContextMenuRegistry.registry.unregister("blockDuplicate");
ContextMenuRegistry.registry.unregister("blockComment");
ContextMenuRegistry.registry.unregister("blockInline");
ContextMenuRegistry.registry.unregister("blockCollapseExpand");
ContextMenuRegistry.registry.unregister("blockDisable");
ContextMenuRegistry.registry.unregister("blockDelete");
ContextMenuRegistry.registry.unregister("blockHelp");

0 comments on commit 36cd4db

Please sign in to comment.