Better JS through BS.
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.
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.
Of course, Ruby-style variable substitutions works in normal strings too:
var foo = "Hello #{name}, ‘sup?";
var foo = "Hello " + name + ", ‘sup?";
var foo = """Line one
var= Line #{two}
var= Line three"""var foo = "Line one\n"+
var= "Line " + two + "\n"+
var= "Line three"
"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.
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.
.bs extension.bsc:
get '/*.js' do |fn|
`./bsc #{fn}.bs`
end
%.js: %.bs
./bsc $< > $@
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.