BullScript

Better JS through BS.

What’s This?

BullScript is Javascript, but with a handful of helpful new bits, so you can get on with web-development and do it a little faster; a little better.

K Then. What’s Good About It?

Inline HTML

Shouldn’t HTML be, like, a real type when you’re doing web-development?

var bar = <div class="abc">
            Hello <a href="#{href}">#{name}</a>, sup?
          </div>;
var bar = $('<div class="abc"> '+
              'Hello <a href="' + href + '">' + name + '</a>, sup? '+
            '</div>');

Well, not a real type, but as close as we can get without pretending we’re a new language. You can write it out—all multiline—you can substitute in variables and it’s initialized as a jQuery object. The JavaScript is always generated one-to-one with your BullScript.

Variable Substitution

Of course, Ruby-style variable substitutions works in normal strings too:

var foo = "Hello #{name}, ‘sup?";
var foo = "Hello " + name + ", ‘sup?";

Multiline Strings

var foo = """Line one
var=         Line #{two}
var=         Line three"""
var foo = "Line one\n"+
var=      "Line " + two + "\n"+
var=      "Line three"

Fancy Escaping

"foo #n{bar} jee"
"foo " + (bar || '') + " jee"
"http://foo.com/#x{bar}/jee"
"http://foo.com/" + encodeURIComponent(bar) + "/jee"

In fact there is more to this: they call through to bs.js so that the escapes are more useful. #n{} will output an empty string for null and undefined, while #N{} will do so for empty Arrays, Objects and anything else that is falsey. #x{} does “pretty” escaping, ie. encodeURIComponent but replacing %20s with +s, while #N{} does full escaping, that is encodeURIComponent but it also encodes !'() which doesn’t hurt, but can avoid certain categories of bug. If you want vanilla encodeURIComponent then (currently) you’ll have to call it yourself.

Custom Escaping

Bullscript accepts any letter in variable substitution escapes. Eg: #f{foo} is compiled to bs.f(foo). So you can define your own escape sequences that suit your coding-style or project respectively.

So… How Do I Use It?

  1. Save your files with a .bs extension.
  2. Use our tmLanguage file for syntax highlighting.
  3. Compile your BS to JS when needed using bsc:
    • Sinatra
      get '/*.js' do |fn|
        `./bsc #{fn}.bs`
      end
      
    • Make
      %.js: %.bs
          ./bsc $< > $@
      
    • Fork this repository and submit your own usage-examples.

Just-in-Time compilation

Yes, we plan to rewrite the compiler in JavaScript so you can compile your BullScript in the browser as it’s needed. But we aren’t there yet.