Opal chapter 4_a_new_hope

Post on 18-May-2015

1.521 views 0 download

Tags:

description

Opal presentation given at OC Ruby 7/25/2013

Transcript of Opal chapter 4_a_new_hope

my-preamble

OPAL - CHAPTER 4: ANEW HOPE

FORREST CHANGFKCHANG2000@YAHOO.COM

WHO CODES RUBY?

WHO WORKS WITH THE WEB?

WHO LIKES JAVASCRIPT

WHO LIKES RUBY BETTER?

from http://dark--romance.deviantart.com/art/Screamy-and-

Bee-love-Ruby-146852940

YOU ARE MY AUDIENCE

THE PITCH

OPAL WILL MAKE YOU HAPPY

STEP BACK

(from:

)

http://www.celiajohnsononline.com/knee-exercises-osteoarthritis-joint-pain/

WHAT IS OPAL?Ruby to JS Source to Source, similar to CoffescriptRuntime (supports method missing, operator overloading,etc)

TOTALLY AWESOME

AS CODEclass Opal < Ruby include Browser::Access include Javascript::Interaction

runs_in :browser runs_in :nodeend

WHAT'S CURRENTLY UNDERGITHUB.COM/OPAL

PAGE 2

THE RUBY WAY

Matz wrote in an introductory article to Ruby

"For me the purpose of life is partly to have joy. Programmersoften feel joy when they can concentrate on the creative sideof programming, So Ruby is designed to make programmers

happy."

OPAL IS THE RUBY WAY

(from

)

http://www.get-covers.com/do-more-of-what-makes-you-happy/

OPAL IS JDD FOR MEJoy Driven Development

no need for it, but I can't stop codingForrest just loves to write opal (Test Infected parody)

WHAT IF YOU CODE RUBY IN THE BROWSER?

TOP 7 REASONS WHY OPAL WILL MAKE YOUHAPPY

1. It is a viable Ruby2. Greenspun's 10th Rule, Opal Edition3. Solves things the Ruby way4. Tools you already know and love5. Easy integration with Ruby6. Better tools (In Browser)7. A new future

#1 VIABLE - NOT A TOYIn production - 5 + apps, 2 more coming soonReal Ruby1.9.3 - compliant (mostly)passes 1377 rubyspec examplesruns asciidoc gem unmodifiedruns mspec gem unmodifiedcan compile itself

Capable of compiling complex codeIs written in Ruby, easy to contribute

RUBY LANGUAGE FEATURES IN OPALclassesmodules & mixinssingleton methodsmethod_missingarity checkslambdablocksyieldCONSTANTSglobal variables

MORE FEATURESclass variablesinstance variableEnumerableBasicObjectKernelNilClassRangeHashString InterpolationHeredocs%w splits

DON'T UNDERESTIMATE THE POWER OF ABETTER LANGUAGE

opal-irb, opal-inspector, easy to writeleads us to Greenspun's 10th rule

GREENSPUN'S 10TH RULEAny sufficiently complicated C or Fortran program contains

an ad hoc, informally-specified, bug-ridden, slowimplementation of half of Common Lisp.

#2 GREENSPUN'S 10TH RULE, OPAL EDITIONAny sufficiently complicated Javascript program contains an

ad hoc, informally-specified, bug-ridden, slow implementationof half of Ruby

JAVASCRIPT EFFORTS THAT IMITATE RUBY ORRAILS

PROTOTYPE

UNDERSCORE

HTTP://RUBYJS.ORG

STRUKT

STRINGJS

HTTP://JSCLASS.JCOGLAN.COM

HTTP://CODE.GOOGLE.COM/P/JOOSE-JS/

HTTP://BLOG.JAVASCRIPTMVC.COM/?P=61

HTTPS://GITHUB.COM/TOBEYTAILOR/DEF.JS

HTTP://YEHUDAKATZ.COM/2012/01/10/JAVASCRIPT-NEEDS-BLOCKS/

HTTP://WWW.CODEPROJECT.COM/ARTICLES/31452/RAIYA-IN-HUMAX-V0-3-EXTENDING-YOUR-JAVASCRIPT-CLAS

HTTP://WWW.SCATTERPOLL.COM/#TITLE-SLIDE

ACTIVEJS

REDSCRIPT

FORML

OTHER ATTEMPTS TO DO RUBY ON JS

(from:

)

https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS

WHY NOT THE REAL THING?

OPAL IS RUBY

#3 SOLVING THINGS THE RUBY WAYpackaging/modulesjavascript integrationtesting

PACKAGING AND MODULE

JAVASCRIPT MODULES long article

AMDCommonJSHarmony

http://addyosmani.com/writing-modular-js/

MODULESDo This

define( module_id /*optional*/, [dependencies] /*optional*/, definition function /*function for instantiating the module or object*/);// Consider 'foo' and 'bar' are two external modules// In this example, the 'exports' from the two modules loaded are passed as// function arguments to the callback (foo and bar)// so that they can similarly be accessed

And Thisrequire(['foo', 'bar'], function ( foo, bar ) { // rest of your code here foo.doSomething();});

RUBYrequireuses gems

require 'file_or_gem_you_want'

OPALrequireuses gemsopal-sprockets handles requiresalso include templates

require 'file_gem_template_you_want'

FOR NON RAILS STANDALONE - RAKEFILErequire 'bundler/setup'# require 'opal/rake_task'require 'opal'require 'opal-sprockets'

desc "build jqconsole based irb"task :build_jqconsole do

File.open("js/app-jqconsole.js", "w+") do |out| env = Opal::Environment.new env.append_path "examples" env.append_path "opal" out << env["app-jqconsole"].to_s end # system "terminal-notifier -title 'opal-irb build' -message 'js file built'" system "open -a 'Google Chrome' index-jq.html"end

FOR NON RAILS STANDALONE APP-JQCONSOLE.RBrequire 'opal'require 'opal-jquery'require 'opal-parser'require 'opal_irb_jqconsole'

Document.ready? do OpalIrbJqconsole.create("#console")end

JAVASCRIPT INTEGRATIONx strings (backticks %x)method missing

window = windowwindow.location

TESTINGopal-specrake/phantomjsin browser

OPAL-SPEC

#4 THE TOOLS YOU KNOW AND LOVElanguage - Rubyeditor - emacs, vim, sublime, Rubymine, etc.Rakerspec (sorry DHH)guard<fill in the ruby tool> - remember it's just Ruby

#5 EASY INTEGRATION WITH RUBYopal-railsopal-sprockets (already shown in modules)it's Ruby

OPAL RAILShttps://github.com/opal/opal-rails

#6 NEW IN BROWSER TOOLSopal-irbopal-inspector

OPAL-IRBirb for opalhistoryreadline controlsmultiline edit (over all of history)send a link - live gist

OPAL-INSPECTORinspired by amber.js in browser Smalltalk like code browserchange the paradigm of developmentdevelop in browser w/better toolspersistent live Opal objects is similar to Smalltalk image

DEMOSopal-irbopal-inspectorSource Maps (head has broken it somewhat though)

QUICK LOOK AT CODEonly 440 lines for opal-inspector current statevery short, small classesdidn't need a framework

#7 A NEW FUTURE (HOPE)in browser dev, goodness from Smalltalk, Ruby and LispMachinesmeteor.js like same code on both sides

blurring front and back1 language…

THERE CAN ONLY BE ONE

May that language be Ruby/Opal

CALL TO ARMSthings are goodthey can be betterneed your help

HELPtry it outtalk, google group, ircdocumentcontribute, it's just Rubyhave fun

KISS JAVASCRIPT GOODBYE

Created by fkchang.