Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-blockly

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-blockly

quickly bootstrap Blockly instances in node and browser

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

create-blockly

create-blockly makes it easy to create Blockly instances in both node and the browser (using browserify).

In the browser, Blockly will always be installed in the most flexible and isolated way, using the Blockly's resizable iframe method.

Browser Example

First, make sure you have node and npm installed on your machine.

Create a new directory with create-blockly installed:

mkdir MyProject
cd MyProject
npm install create-blockly

Create "browser.js" that instantiates Blockly:

var createBlockly = require("create-blockly");
var Blockly = createBlockly({

  // This is where the iframed resizable Blockly will be embedded.
  container: document.getElementById("my-editor"),

  // Make the default set of blocks available, with English translations.
  // (you can choose other translations like "create-blockly/Msg/zh_tw")
  extensions: [
    require("create-blockly/Blocks"), // Blockly.Blocks
    require("create-blockly/Msg/en"), // English translations
    require("create-blockly/Javascript"), // Blockly.Javascript exporting
  ],

  // This is the toolbox that defines which blocks are visible.
  // http://code.google.com/p/blockly/wiki/Toolbox
  toolbox: document.getElementById("my-toolbox")

});

// Whenever this Blockly editor changes, log the generated Javscript code.
// More Blockly documentation at http://code.google.com/p/blockly/w/list
Blockly.addChangeListener(function() {
  var code = Blockly.Javascript.workspaceToCode();
  console.log(code);
});

Create the associated "browser.html" to load the Javascript:

<html>
  <head>
    <script type="text/javascript" src="browser.js"></script>
  </head>
  <body>
    
    <!-- This is where the iframed resizable Blockly will be embedded. -->
    <div id="my-editor"></div>
    
    <!-- This is the toolbox that defines which blocks are visible. -->
    <!-- http://code.google.com/p/blockly/wiki/Toolbox -->
    <xml id="my-toolbox" style="display:none">
      <category name="Control">
        <block type="controls_if"></block>
        <block type="controls_whileUntil"></block>
      </category>
      <category name="Logic">
        <block type="logic_boolean"></block>
        <block type="logic_operation"></block>
      </category>
      <category name="Text">
        <block type="text"></block>
        <block type="text_print"></block>
      </category>
    </xml>

  </body>
</html>

Install helpers for the server:

npm install express enchilada

Create the "server.js" to serve the demo:

var express = require("express");
var enchilada = require("enchilada");

var app = express();
app.use(express.logger());
app.use(enchilada(__dirname));
app.use(express.static(__dirname));
app.listen(1337);
console.log("Running demo on localhost:1337")

Run the server and open localhost:1337 in your browser:

$ node server.js
Running demo on localhost:1337

Wishlist

  • Allow checking out specific revisions of Blockly source from svn
  • Allow user to specify their own copy of Blockly source

References

Contributing

Just make a pull request :)

Keywords

FAQs

Package last updated on 07 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc