decaf icon indicating copy to clipboard operation
decaf copied to clipboard

Include useful standard libraries (JSON, Set, Observable, etc.)

Open collin opened this issue 11 years ago • 12 comments

require 'set'
>>> "NoMethodError: undefined method `require' for #<Window:0x007f9ff2c33108>"
Kernel.require 'set'
>>> "LoadError: cannot load such file -- set"
Kernel.require 'observable'
>>> "LoadError: cannot load such file -- observable"

I get something like net/http not being available, as the DOM provides interfaces. But things like Set and Observable ought to be available, no?

collin avatar May 06 '13 07:05 collin

Good point. It would be nice to have modules like Set, Observable, and JSON. The problem is figuring out where to load them from. Either the files can be distributed in the application bundle and loaded from there, or they can be compiled and linked statically with the project. I believe I'd like to link them statically, since then we can ensure that everything works. Then, the problem is deciding which libraries to include. Any thoughts?

By the way, this brings up a security issue. I thought I had undefined require along with methods like exit!, but apparently not all the way. This commit should take care of that.

timimahoney avatar May 06 '13 15:05 timimahoney

Taking a quick peek at lib/ from ruby...

  • set
  • observable
  • json
  • uri
  • ostruct
  • securerandom
  • base64
  • csv
  • delegator
  • erb
  • forwardable

Probably others but that's what jumped out the most in quick look at 'lib/'. Probably okay to miss things as long as a clear way to include stdlib code is introduced so missing bits can be added later, right?

collin avatar May 06 '13 17:05 collin

Also, to go off topic on this ticket. Absolutely loving being able to play around with the DOM in Ruby. Match made in heaven.

collin avatar May 06 '13 20:05 collin

I'll look into including some or all of these libraries soon. I never knew about OpenStruct, and that might be a nice format to convert JSON to.

Anyway, I'm glad you like it! Making anything cool?

timimahoney avatar May 07 '13 14:05 timimahoney

I'm playing with porting concepts I use in a personal js app framework to ruby https://github.com/collin/AlphaSimprini.rb/blob/master/app/assets/javascripts/alpha_simprini/core/view.rb

So far it's a dream.

collin avatar May 09 '13 01:05 collin

Nice! I agree that it's kind of a dream to use Ruby in the browser.

Back to the topic, I'm putting out a new binary soon, but it doesn't have the standard libraries. I'll work on adding these libraries for the next major update.

timimahoney avatar May 10 '13 16:05 timimahoney

I would love if you could include/load Math library by default, there is no pure ruby version Math library available

senthilnayagam avatar May 16 '13 12:05 senthilnayagam

@senthilnayagam Do you mean this Math library? If so, it's already in there. Try Math.cos(Math::PI).

timimahoney avatar May 16 '13 16:05 timimahoney

Thanks you saved my day :)

senthilnayagam avatar May 17 '13 05:05 senthilnayagam

is there a way to load a local ruby script in the web pages context.

this way I can include my favourite scripts to automate testing, or crawling the pages, there are some javascript based tools like phantomjs which does this with javascript, but a ruby option would be awesome

senthilnayagam avatar Jul 25 '13 07:07 senthilnayagam

also some way to remotely connect to decaf instance like how pry-remote does with DRB, this way we can script it from a normal ruby script

senthilnayagam avatar Jul 25 '13 07:07 senthilnayagam

I'm not quite sure what you're looking for in the past two comments. Could you elaborate?

timimahoney avatar Jul 27 '13 23:07 timimahoney