GithubHelp home page GithubHelp logo

epq / scratchblocks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scratchblocks/scratchblocks

0.0 2.0 0.0 36.9 MB

Make pictures of Scratch blocks from text.

Home Page: http://scratchblocks.github.io/

License: Other

JavaScript 93.08% CSS 3.36% HTML 3.56%

scratchblocks's Introduction

Make pictures of Scratch blocks from text.

Screenshot

Try it out!


scratchblocks is used to write Scratch scripts:

It's MIT licensed, so you can use it in your projects. (But do send me a link on Twitter!)

For the full guide to the syntax, see the wiki.

Usage

MediaWiki

Use the MediaWiki plugin. (This is what the Scratch Wiki uses.)

WordPress

I found a WordPress plugin. It might work for you; I haven't tried it.

Pandoc

Code Club use their own lesson_format tool to generate the PDF versions of their project guides. It uses the pandoc_scratchblocks plugin they wrote to make pictures of Scratch scripts.

This would probably be a good way to write a Scratch book.

HTML

Include the scratchblocks JS file on your webpage:

<script src="https://scratchblocks.github.io/js/scratchblocks-3.x-min.js"></script>

Then call scratchblocks.renderMatching after the page has loaded, which will render matching page elements to shiny scratch blocks. Its sole argument is the CSS-style selector for the elements that contain the scratchblocks code. It uses pre.blocks by default.

scratchblocks.renderMatching('pre.blocks');

If you want to use Scratch 3.0 styles, add the style argument.

scratchblocks.renderMatching('pre.blocks', {style: 'scratch3'});

Inline blocks

To use blocks inside a paragraph...

I'm rather fond of the <code class="b">stamp</code> block in Scratch.

...make a separate call to renderMatching using the inline argument.

scratchblocks.renderMatching("code.b", {inline: true});

Server-side (Node)

There's an experimental Node port thanks to @arve0.

Example usage:

var scratchblocks = require('scratchblocks');
var doc = scratchblocks.parse(`
when flag clicked
`)
doc.render(svg => {
  var content = doc.exportSVGString()
  console.log(content);
})
$node test.js > foo.xml

Browserify

You can even use scratchblocks with browserify, if you're into that sort of thing.

Once you've got browserify set up to build a client-side bundle from your app code, you can just add scratchblocks to your dependencies, and everything should Just Work™.

var scratchblocks = require('scratchblocks');
scratchblocks.renderMatching('pre.blocks');

Languages

To update the translations:

npm upgrade scratchr2_translations
npm run locales

In the browser, include translations.js, translations-all.js or build your own language pack.

translations.js contains all the languages needed on the Scratch Forums.

translations-all.js contains all the languages Scratch supports.

If you want to build your own language pack, use scratchblocks.loadLanguage(lang) where lang is the contents of src/locales/lang.json.

Adding a language

Each language requires some additional words which aren't in Scratch itself (mainly the words used for the flag and arrow images). I'd be happy to accept pull requests for those! You'll need to rebuild the translations with npm run locales after editing the aliases.

Development

This should set you up and start a http-server for development:

npm install
npm start

Then open http://localhost:8000/ :-)

For more details, see CONTRIBUTING.md.

Credits

Many, many thanks to the contributors!

  • Authored by tjvr
  • Icons derived from Scratch Blocks (Apache License 2.0)
  • Scratch 2 SVG proof-of-concept, shapes & filters by as-com
  • Anna helped with a formula, and pointed out that I can't read graphs
  • JSO designed the syntax and wrote the original Block Plugin
  • Help with translation code from joooni
  • Block translations from the Scratch translation server
  • Ported to node by arve0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.