<dragonkh>
so as a test I created a new test rails project using opal - and I can put some opal in the corresponding asset pipeline and it works
<dragonkh>
so my controller - flights has index - and my assets/flights.js.rb contains my opal code
<elia>
and of course it's already bundled with opal-jquery
<dragonkh>
so when I navigate to the index action on the flights controller -my alert pops up that I put in the flights.js.rb
<dragonkh>
hi elia :)
<dragonkh>
so my questions is:
<dragonkh>
in a regular index.html.erb view I currently use some jquery javascript in a script tag - in this case I have it inlined so I can dynamically use the values coming from erb e.g. <%= flight.id %> kind of thing
<dragonkh>
is there a way I can have opal code in my old school index.html.erb view? like I would normally have script tags?
<dragonkh>
I can see if I use the haml version - I can include :opal and put some in there - but I can;t see a way to do it with an erb template
<elia>
dragonkh, best way is to add an helper that will compile opal
<dragonkh>
can you give me some more details on that?
<dragonkh>
do you mean put opal code in a rails helper module? in the helpers directory? or a different kind of helper?
<dragonkh>
I'm a bit impatient tonight!! got an 8 month old daughter and I'm trying to use my time between feeds to get some coding done lol
<elia>
dragonkh, lol, my 3rd son is 8myo too
<dragonkh>
elia: ok cool - so using Opal.compile directly
<elia>
so welcome to CBDD (crying baby driven development)
<elia>
cc fkchang
<dragonkh>
hahah
<dragonkh>
yeah tell me about it!
<dragonkh>
ok cool the helper module is working fine
<dragonkh>
<%= opal_tag do %>
<dragonkh>
alert "hello"
<dragonkh>
<% end %>
<elia>
dragonkh, I learned to code one-handed dduring CBDD sessions –lol
<dragonkh>
heheh
<dragonkh>
elia: so how would I get a variable into the opal_tag? like say I want to find an element on the page using a dynamic variable that comes from my controller - e..g @name = 'skywalker' in the controller - adn I want to alert hello skywalker from opal ?
<elia>
dragonkh, if you're brave enough you can have a look at the var passing in opal templates
<elia>
basically I filter locals/ivars for the template through json and then inspect them into opal
<elia>
…or you use plain ERB and do something like: foo = "<%= @bar %>"
<elia>
but that could be confusing
<dragonkh>
hmm
<dragonkh>
this works:
<dragonkh>
<%= opal_tag do %>
<dragonkh>
alert "hello, <%= @name %>"
<dragonkh>
<% end %>
<dragonkh>
which is probably good enough
<elia>
dragonkh, if you come up with something handy let me know, I seldom use opal inside templates, and the few times I use the haml filter
<dragonkh>
it's purely because I have an existing rails app and I want it to use opal instead of coffeescript or js
<dragonkh>
it's looking promising though
<elia>
dragonkh, you have all my support (unsurprisingly)
<dragonkh>
right I have a couple more questions :) then :) before I go to bed
<dragonkh>
it's 00:37 here
<elia>
dragonkh, which TZ?
<dragonkh>
UK
<dragonkh>
GMT
<elia>
ha 1.37am here
<elia>
italy
<dragonkh>
hehe nice
<dragonkh>
so I also built a sprockets opal app - as a test
<dragonkh>
and used a config.ru and bundle exec rackup
<dragonkh>
in my app/application.rb - I can put opal code and in the index.html I can bring in the opal code with the javascript_tag_helper
<dragonkh>
so when I hit the index page of my app - I see my opal code running - which is great
<dragonkh>
so now I want to bring in a third party js library - this is where I hit problems
<dragonkh>
pure.js for example is a templating engine - it has only the render method eg. $('div.template').render(someJson, someDirective)
<dragonkh>
but opal-jquery always gives me back an Element when I find
<dragonkh>
render is not on the Element class
<dragonkh>
so I can't figure out how to do it
<elia>
Element has a class method named .expose which exposes native methods
<dragonkh>
$$['$'].(div.template) returns Element
<dragonkh>
so Element.expose(:render) ?
<elia>
probably adding Element.expose :render just after requiring pure will work
<elia>
yep
<dragonkh>
hmm I tried that but didn't seem to work - but I'll play around a but more tomorrow with it
<elia>
let me know, or tell adambeynon_
<elia>
how it goes
<dragonkh>
in opal - if I put my pure.min.js in the app folder - in the application.rb file - I can require 'pure.min' and it seems to bring in the pure.js library - is that the correct way to do it ?
<elia>
dragonkh, yes, it relies on sprockets for requires
<elia>
so it maps directly to //=require …
<dragonkh>
I see
<dragonkh>
I'm just looking at opal-haml
<dragonkh>
I see there used to be an opal-erb - which seems to be what I wanted - but also Adam has a post saying - its not longer needed because opal has the erb compiler
<dragonkh>
but I don't really understand how to use that - .opalerb files aren't going to work in the rails view
<elia>
dragonkh, actually not being a fan of erb I never used opal-erb and opal-rails lacks a test for that as a consequence
<elia>
I know that opal-erb has been merged into the stdlib
<elia>
but I'm not sure about how to make it work in opal-rails
<dragonkh>
I think that probably in an opal-sprockets app I could use index.opalerb and it would work - but that wont work in rails
<elia>
I imagine I'll need to try it :)
<dragonkh>
I'll have a play with it tomorrow as I'd really like to use opal-erb inside my rails views
<dragonkh>
I'll contribute it back if its any good
<elia>
dragonkh, quick fix: try requiring opal/erb inside an initializer
<dragonkh>
I don't know how my opal code should even look in the view though - inside erb tags perhaps? <%= Element.find('#name') %>
<elia>
dragonkh, i think so
<dragonkh>
hmm not working
<dragonkh>
maybe I can take the same approach as opal-haml with erb
<dragonkh>
so that it can work in the rails view
<dragonkh>
although the opal_tag helper seems to be working just fine - so maybe that will do me for what I need
<elia>
dragonkh, im out of ammo here, going to bed, be sure to ask adambeynon_ about opal-erb when he's around
<dragonkh>
elia: thanks for your help - I'll give you an update if I do anything exciting or have any more boring questions lol !!!
<dragonkh>
yeah I will ask him
<dragonkh>
time for bed too
<dragonkh>
great work on opal-rails :)
ryanstout has quit [Quit: ryanstout]
dragonkh has quit [Quit: Bye!]
elia has quit [Quit: Computer has gone to sleep.]
fkchang has quit [Ping timeout: 252 seconds]
Todd- has joined #opal
Todd has quit [Ping timeout: 272 seconds]
meh` has quit [Ping timeout: 252 seconds]
Liothen has quit [Remote host closed the connection]
Liothen has joined #opal
marcandr_ has joined #opal
marcandre has quit [Read error: Connection reset by peer]
kludge` has quit [Disconnected by services]
kludge` has joined #opal
Liothen has quit [*.net *.split]
Liothen has joined #opal
marcandr_ has quit [Remote host closed the connection]
fkchang has joined #opal
fkchang has quit [Ping timeout: 265 seconds]
DouweM has quit [Ping timeout: 252 seconds]
dfranciosi has joined #opal
elia has joined #opal
GitHub195 has joined #opal
<GitHub195>
opal/ng-percent-strings d33ae49 Elia Schito: Add a failing test for percent strings
<GitHub195>
[opal] elia created ng-percent-strings (+1 new commit): http://git.io/jRQzlg
GitHub195 has left #opal [#opal]
<elia>
adambeynon_, I wasn't able to find where the parser digests percent strings, so I added the failing spec (gh479)
<elia>
anyways it's an angular bug as you probably have noticed :P
<adambeynon_>
lol, I did
<adambeynon_>
btw, that new bot/logger is awesome
<elia>
adambeynon_, yeah
<elia>
!m [o__o]
<[o__o]>
You're doing good work, [o__o]!
<elia>
adambeynon_, should I ask whitequark to remove _whitelogger_ ?
kludge` has quit [Ping timeout: 260 seconds]
kludge` has joined #opal
<adambeynon_>
elia: yeh, can do
wmnnd has joined #opal
elia has quit [Quit: Computer has gone to sleep.]
elia has joined #opal
GitHub160 has joined #opal
GitHub160 has left #opal [#opal]
<GitHub160>
[opal] adambeynon pushed 1 new commit to ng-percent-strings: http://git.io/cV3B9g
<GitHub160>
opal/ng-percent-strings 37703ee Adam Beynon: Fix <> matching pair for string boundrys
<elia>
adambeynon_, I think we should add a :method option to dynamic_require_severity
<elia>
or let all requires go through Kernel.require anyway
<elia>
that would help both opal-node and in-browser (eg. opal-playground) and it's the right hook for dynamic requires (eg. with $.ajax(async:false))
<elia>
if we make kernel.require look into @loaded_files and add sprockets required files to it at compile time it should become a more consistent experience
<elia>
adambeynon_, thoughts?
travis-ci has joined #opal
<travis-ci>
[travis-ci] opal/opal#1674 (ng-percent-strings - 37703ee : Adam Beynon): The build was fixed.
<GitHub52>
[opal] elia deleted ng-percent-strings at 37703ee: http://git.io/BB8d9A
GitHub52 has joined #opal
GitHub52 has left #opal [#opal]
<elia>
adambeynon_, meh` perhaps the async require needs its own method, like async_require(&block) or something
<meh`>
elia, in opal-browser I have require_external stashed locally
<elia>
meh`, totally makes sense in the browser
DouweM has joined #opal
<meh`>
bah
<meh`>
we really need a way to fix the require order
<meh`>
running gems unmodified is a problem otherwise
dfranciosi has joined #opal
<meh`>
adambeynon_, ping
<adambeynon_>
meh`: sup
<meh`>
adambeynon_, this require situation is unbearable
<meh`>
nothing works out of the box because of the sprockets limitation
<meh`>
adambeynon_, we need to solve this
<meh`>
and I think the best way to go is monkeypatching sprockets
<meh`>
thoughts?
<adambeynon_>
meh`: it's not possible with sprockets
<meh`>
adambeynon_, it is if we monkeypatch it in opal/sprockets
<adambeynon_>
meh`: it's not because if file a requires file b, inside some method definition in the middle of the file, then the source for b would have to be injected in the middle of the output of a.rb
<adambeynon_>
And, there is no way to handle 2 files requiring the same dependency
<elia>
meh`, adambeynon_ I think the best way is to store "modules" a la node and require will load them
marcandre has joined #opal
<elia>
and make kernel.require respectful of an internal @loaded
<elia>
we already wrap any required file in a self executing function
<meh`>
adambeynon_, I don't see the problem sincerely
<meh`>
the issue is just sprockets ignores directives after the first line
<meh`>
we can monkeypatch this behaviour and still use the rest of sprockets
<elia>
meh`, the issue is that sprockets is not done at runtime
<adambeynon_>
elia: I tried that before. My problem was that we would always need some main.js to load the initial ruby file
<elia>
adambeynon_, im sure we can solve that one way or another
<elia>
eg a lazy main that is filled at the first "sprockets-require"
<meh`>
elia, it doesn't have to be at runtime
<meh`>
I tested that earlier
<meh`>
we need to solve this before 0.6
<meh`>
the limitation is only ignoring directives after the first line
<meh`>
it's extremely important
<meh`>
we can't just require a gem with the current behaviour
<meh`>
and having gems work out of the box is vital
<elia>
meh`, afaik requires are gathered from the whole file and then "executed" on the top
<meh`>
as long as there's an option to compile a file to a non module
barry_ has joined #opal
<adambeynon_>
meh`: I still dont know how to handle the "main" file though
<adambeynon_>
i.e. the first file to get run/loaded
DouweM has joined #opal
<meh`>
adambeynon_, you should be able to know which file started the whole require chain
<meh`>
in lissio there's a main
<meh`>
that you define
<meh`>
I think Opal::Server does the same thing
<meh`>
in short, it's already a given that the main file be told by the user
<adambeynon_>
meh`: that doesnt cover sinatra or rails apps
<meh`>
then back to my first proposal
<meh`>
you keep track of the chain
<meh`>
you know which file started it all
<elia>
adambeynon_, rails has a whitelist that defaults to application.js
<adambeynon_>
meh`: sprockets only asks you to compile what it needs. if you change 1 file, you only know about that 1 file
fkchang has joined #opal
GitHub100 has joined #opal
GitHub100 has left #opal [#opal]
<GitHub100>
opal-haml/master ff91c89 Adam Beynon: Add some specs for handling runtime attribute generation
<GitHub100>
[opal-haml] adambeynon pushed 1 new commit to master: http://git.io/_1c5-A
barry_ has quit [Remote host closed the connection]
barry_ has joined #opal
elia has quit [Read error: Operation timed out]
GitHub135 has joined #opal
<GitHub135>
opalrb.org/master d6bfcfb Adam Beynon: Introduction to haml templating
<GitHub135>
[opalrb.org] adambeynon pushed 1 new commit to master: http://git.io/tOevhA
GitHub135 has left #opal [#opal]
DrShoggoth has joined #opal
barry_ has quit [Remote host closed the connection]
barry_ has joined #opal
GitHub62 has joined #opal
<GitHub62>
opalrb.org/master 072bae8 Adam Beynon: Style cleanup
<GitHub62>
[opalrb.org] adambeynon pushed 1 new commit to master: http://git.io/myiAZA
GitHub62 has left #opal [#opal]
barry_ has quit [Ping timeout: 246 seconds]
wmnnd has quit [Quit: wmnnd]
GitHub92 has joined #opal
<GitHub92>
opalrb.org/master b47b091 Adam Beynon: Remove old pygment styles
<GitHub92>
[opalrb.org] adambeynon pushed 1 new commit to master: http://git.io/o-h8tw
GitHub92 has left #opal [#opal]
e_dub has quit [Quit: It's a hard knock life]
<fkchang>
I think this has potential, esp. w/notion of node.js type async IO, but in ruby http://isaiah.github.io/jubilee/ -- ryanstout would appreciate this
barry_ has joined #opal
dragonkh has joined #opal
<dragonkh>
evening
<dragonkh>
adambeynon_ if you are around I have a couple of questions about using opal in rails with erb instead of haml
<adambeynon_>
dragonkh: hi. Sure go ahead. Have you tried it yet?
barry_ has quit [Remote host closed the connection]
dfranciosi has quit [Remote host closed the connection]
e_dub has joined #opal
e_dub has quit [Ping timeout: 264 seconds]
e_dub has joined #opal
<e_dub>
adambeynon_, i think you forgot to link to the new haml docs page from anywhere
<adambeynon_>
hi e_dub: not quite ready to publish them yet. they have some 0.6.0 specific stuff in them
<adambeynon_>
hopefully 0.6.0 is close anyway
barry_ has joined #opal
<e_dub>
ah i see, ok, just saw the commit roll by earlier, then was browsing for it, then got stubborn, cloned it and grepped lol
barry_ has quit [Remote host closed the connection]
barry_ has joined #opal
<adambeynon_>
e_dub: :) Im trying to get the docs done before release
<adambeynon_>
they have been lacking until now
<dragonkh>
hi adambeynon_
GitHub18 has joined #opal
<GitHub18>
[opalrb.org] adambeynon pushed 1 new commit to master: http://git.io/RY0JXw
<GitHub18>
opalrb.org/master 3ac52ef Adam Beynon: Add docs on using ERB templates and listing registered
GitHub18 has left #opal [#opal]
<adambeynon_>
dragonkh: how are have you got with erb?
<adambeynon_>
just been writing up some more docs on them actually
<dragonkh>
adambeynon_ - I have some traditional views in my rails app - e.g. index.html.erb with some inline javascript - and I wanted to replace the js with opal in the view itself - but the only way I could figure out was to use this: https://gist.github.com/elia/8327282
<dragonkh>
elia didnt know much about the erb templating as he doesnt use it
<dragonkh>
and suggested asking you about it
<dragonkh>
I can't put a index.opalerb file in my rails app as its not recognised
<adambeynon_>
dragonkh: the only problem with that is the opal code will end up being recompiled on every template invocation
<adambeynon_>
dragonkh: haml offers a way to inline it once on the initial compile
<adambeynon_>
I dont think erb has a way to do that
<dragonkh>
adambeynon_ - the only reason I want to put the js in the view is to access a variable that is dynamic
<dragonkh>
adambeynon_ hmm I don't really want to convert my views to haml
<adambeynon_>
dragonkh: if it is just some variables, I would say to do it in javascript, which would have no overhead in template compilation, and then to access those variables from opal
<adambeynon_>
e.g. @variable = `window.MY_VAR_IN_TEMPLATE`
<dragonkh>
adambeynon_ - ah yeah I could do that
<adambeynon_>
dragonkh: the `.opalerb` vs `.erb` extension is tricky though
<adambeynon_>
I havent tried it, but symlinks might work
<adambeynon_>
dragonkh: this is another idea I had
<dragonkh>
I have a couple more questions around opal - for experimentation I tried to bring in pure.js - a js templating library - with some help from elia I got it working - but because it requires passing in data - it got a bit complex
<adambeynon_>
you can require that erb file which will add all the listed templates to your opal app
<dragonkh>
when passing in a simple directive its just a case of {:name => 'dragonkh'}.to_n
<dragonkh>
but that iterating directive is more complex
<adambeynon_>
chrome says "cant find server"
<dragonkh>
I'm probably not going to bother with pure.js though as I can achieve the same results just directly in ruby - but it was interesting to know if is possible to construct a parameter like that one
<adambeynon_>
oo, its loading now
<dragonkh>
I've recently moved to fibre - so im superfast :) (after 10 years of pitifully slow connection)
<dragonkh>
adambeynon_ - I quite like the approach of compiling the templates from the application.js.rb
e_dub has quit [Ping timeout: 264 seconds]
e_dub has joined #opal
<fkchang>
adambeynon_: so the jubilee link reminds me of the other thing I suggested, i.e. rack on top of opal-node so we could hopefully reuse stuff from the rack ecosystem. I'm going to probably experiement w/jubilee coz I have an experiment it's well suited, but I still think rack on opal-node wil be able to provide a lot of value of being able to reuse rack code. I think we should call it Node-Racking