These are chat archives for opal/opal

18th
Jul 2015
Forrest Chang
@fkchang
Jul 18 2015 01:30
@catmando so I did implement some level of multiline handling, which broke on newer versions of opal than 0.6 - fixing now
for opal-irb that is
Mitch VanDuyn
@catmando
Jul 18 2015 03:28
@fkchang. Great! I use your irb all the time!
George Plymale II
@ylluminarious
Jul 18 2015 05:53
@elia @meh @adambeynon @vais hey, just noticed that the opal-browser and opal-jquery cdn's seem pretty outdated: opal/opal-cdn#7. i would update them and make a PR for it, but i'm not really sure how, so any help would be appreciated with this so that folks can use opal-jquery and opal-browser via the cdn again :)
Bernhard Weichel
@bwl21
Jul 18 2015 08:15
my opal 0.8.0 applications appears to be significantly faster than with 0.7.0 (about factor 2) - great. Thanks.
not counting loading time
Torsten Rüger
@rubydesign
Jul 18 2015 09:35
:clap:
Bernhard Weichel
@bwl21
Jul 18 2015 09:58

upgrading to 0.8.0 I face a problem with using opal in the static page version.

Compilation rake - task

  env = Sprockets::Environment.new
  Opal.append_path "."
  Opal.use_gem "vector2d"

  Opal.paths.each { |p| env.append_path(p) }

  File.open(ZUPFNOTER_JS, "w+") do |out|
    out << env["application"].to_s
  end

application.rb

require 'opal'
require 'opal-jquery'
require 'vector2d'
require 'math'

require 'consolelogger'
require 'harpnotes'
require 'abc_to_harpnotes'
require 'opal-raphael'
require 'opal-jspdf'
require 'opal-jszip'
require 'opal-abcjs'
require 'opal-musicaljs'
require 'raphael_engine'
require 'pdf_engine'
require 'command-controller'
require 'controller'
require 'controller-nw'
require 'controller_command_definitions'
require 'harpnote_player'
require 'text_pane'
require 'opal-dropboxjs'
require 'opal-jqconsole'
require 'confstack'
require 'opal-abc2svg'
require 'version'

puts "now starting zupfnoter"
puts "zupfnoter is now running"

I cannot see the two messages in JS console. It seems that Opal is not initialized. Is there any change betwee 0.7 and 0.8 with respect to static applications? It works with the following rackup

  # config.ru
  require 'bundler'
  Bundler.require

  #Opal::Processor.inline_operators_enabled = true
  run Opal::Server.new { |s|

    s.append_path 'public'
    s.append_path 'src'

    Opal.use_gem "vector2d"

    Opal.paths.each { |p| s.append_path(p) }


    #s.use_gem 'vector2d'

   # s.debug = true
    s.source_map = true

    s.main = 'application'

    s.index_path = 'index_opal.html.erb'
  }
Elia Schito
@elia
Jul 18 2015 10:33
@bwl21 you need to add out << Opal::Processor.load_asset_code(env, 'application')
Bernhard Weichel
@bwl21
Jul 18 2015 10:55
@elia: thanks so much. It works. Is there anything I could contribute to the documentation with that respect?
Bernhard Weichel
@bwl21
Jul 18 2015 11:36
in fact, I did not really understand "Delegate dependency management directly to Sprockets (when used) making sourcemaps swift again. This means code generated by sprockets will always need to be bootstrapped via Opal.load or Opal.require. Luckily Opal::Processor.load_asset_code(sprockets, name) does just that in the right way." But i guess this is the hint to read ... :-)
Bernhard Weichel
@bwl21
Jul 18 2015 12:11
@elia, @vais, I tried to update static_applications.html.md accordingly, but found the commit 20851b3 by @vais. Does that mean it is no longer recommended to use Sprockets::Environment to build static apps?
Bernhard Weichel
@bwl21
Jul 18 2015 12:18
Or do we have two different methods to build static applications (Sprockets and Opal builder). I tried both with 0.8.0 and both worked well.
Vais Salikhov
@vais
Jul 18 2015 12:48
@bwl21 can you post a link to that commit? I can't find 20851b3 :confused:
Vais Salikhov
@vais
Jul 18 2015 12:53
@elia the more I think about the docs and opalrb.org, the more I think it should follow volt's example. Not that volt's site is perfect (it's completely unfinished), but the idea is nice and simple. Documentation and Libraries sections should be merged into a single documentation section that is a GitBook updated live from a repo https://github.com/opal/docs, which will be known as :sparkles: The Opal Book :sparkles:, and which will be the authoritative source of information for any and all things Opal, organized into a neat collection of chapters. Am I dreaming??
Bernhard Weichel
@bwl21
Jul 18 2015 13:06
@vais: opal/opalrb.org@20851b3
Vais Salikhov
@vais
Jul 18 2015 13:13
@bwl21 yeah, I see now (I was looking for that commit in opal/opal which explains why I couldn't find it). I'm not sure if this applies to 0.8, that was me updating some old instructions that no longer worked under 0.7. @elia fixed a bunch of stuff re Sprockets since then, I have not really been following the details. tldr - @elia can answer that question better than me :sweat_smile:
Bernhard Weichel
@bwl21
Jul 18 2015 13:15
so let us wait for @elia to tell, if we document both approaches. If yes, I can prepare it.
@vais is there any reason that you use File.binwrite instead of File.write?
Vais Salikhov
@vais
Jul 18 2015 13:39
@bwl21 because I often run Ruby on Windows, and there File.write and File.binwrite do not do quite the same thing. File.binwrite does what you think File.write will do. This does not only apply to class methods, but to instance methods of IO as well, so when you open a file for writing, 'w', you should do 'wb' instead, and 'rb' for reading. 'b' stands for binary. Ruby ignores this on other platforms. :sweat:
Elia Schito
@elia
Jul 18 2015 13:41
@bwl21 @vais I'd say that the preferred approach to build static files is Opal::Builder, nonetheless adding docs to clarify how to use load_assed_code is important.
Bernhard Weichel
@bwl21
Jul 18 2015 13:43
@vais: does this apply also if you only write textual content using File.puts? I never experienced problems with that. I am mostly on OSX but also have ruby scripts on Win.
@elia, so I will prepare a PR on static_applications.html.md
Elia Schito
@elia
Jul 18 2015 13:43
@bwl21 Anywhere you'd exepected to find info on load_asset_code please send a PR to fix it or point that out (e.g. with an issue) so someone can fix it
@bwl21 great!
@vais started stuff for gitbooks (no idea what I'm doing) :D
Vais Salikhov
@vais
Jul 18 2015 13:51
@bwl21 well, there's no class method File.puts, you mean IO#puts, but that's writing to an IO that is already open in one mode or another, so you don't need to worry about that.
@elia that means you are doing it right :)
Mmm... :sparkles: The Opal Book :sparkles:
Bernhard Weichel
@bwl21
Jul 18 2015 13:53
@vais so I will use File.open("build.js", w) { | f | f.puts .. } for sake of consistency.
also in the PR on static_applications.html.md
Vais Salikhov
@vais
Jul 18 2015 13:54
For the sake of correctness, use File.open("build.js", "wb") { | f | f.puts ... } :wink2:
@bwl21 let's try this again: File.open("build.js", "wb") { | f | f.write ... } because puts adds a new line.
Here's a better version: File.binwrite(string) :smile:
Last attempt: File.binwrite("build.js", javascript) :sweat_smile:
Oh, wait, that what we started with! Maybe just don't worry about Windows users, nobody else does anyway :trollface:
Elia Schito
@elia
Jul 18 2015 13:59
I need to start using File.binwrite by default, @vais you remember if it works on older rubies too?
Bernhard Weichel
@bwl21
Jul 18 2015 13:59
@vais no problem with this. But i'd like to understand. The resulting JS is still a text file where the new line at the end does not hurt. IMHO it is a bit less confusing to output a text using text methods. I anticipate that in when the file is opened with "w" it even maintains the line ending of the platform.
Vais Salikhov
@vais
Jul 18 2015 14:01
@elia it was a new feature starting with 1.9.3 - I cannot find any reference to File.binread/binwrite in 1.8.7
Elia Schito
@elia
Jul 18 2015 14:02
ha! old habits! :)
Bernhard Weichel
@bwl21
Jul 18 2015 14:02
I tried both f.puts and f.binwrite on OSX, both worked. Personally I prefer File.open(){} over static methods.
Vais Salikhov
@vais
Jul 18 2015 14:03
@bwl21 don't worry about it, IO is a pretty deep rabbit hole that I have not fully explored, and honestly, not sure that I want to. Any one of these ways basically works. Static methods are there for your convenience. What is this, nodejs?!
I mean preferring the long-form with a callback (shudder)
Bernhard Weichel
@bwl21
Jul 18 2015 14:06

@elia does sourcemaps also work with static applications? This would be a reason to expose both approachaces in the docs. Opal::Builder is simpler. This is how I wrote it up to noe

* using Sprockets

    Dependency management is delegated directly to Sprockets.
    This means code generated by sprockets will always need to be bootstrapped 
    via `Opal.load` or `Opal.require`. Luckily `Opal::Processor.load_asset_code(sprockets, name)`
    does just that in the right way.

    ```ruby
    # Rakefile
    require 'opal'

    desc "Build our app to build.js"
    task :build do

      env = Sprockets::Environment.new

      Opal::Processor.source_map_enabled = true
      Opal.append_path "app"

      Opal.paths.each { |p| env.append_path(p) }

      File.open("build.js", "w+") do |out|
        out << env["application"].to_s
        out << Opal::Processor.load_asset_code(env, 'application')
      end
    end
  • using Opal::Builder

      # Rakefile
      require 'opal'
    
      desc "Build our app to build.js"
      task :build do
        Opal.append_path "app"
        File.binwrite "build.js", Opal::Builder.build("application").to_s
      end

```

Elia Schito
@elia
Jul 18 2015 14:08
@bwl21 for static apps writing the whole app to a single file would brake source maps regardless of using sprockets
Bernhard Weichel
@bwl21
Jul 18 2015 14:08
I also would like to illustrate useage of Opal.use_gem
Elia Schito
@elia
Jul 18 2015 14:08
So I don't think neither of the forms would have working sourcemaps
Bernhard Weichel
@bwl21
Jul 18 2015 14:09
But then we could illustrate both approaches, but not justify the usage of Sprockets to build static applications.
Vais Salikhov
@vais
Jul 18 2015 14:23
@bwl21 based on what @elia said re sourcemaps and static apps (i.e., basically, "pick one or the other"), what value do you see in demonstrating the long route with Sprockets::Environment? (Not a rhetorical question, I am genuinely confused now).
Bernhard Weichel
@bwl21
Jul 18 2015 14:44
Being confused AS well, I try to keep my applications running and also to understand why they work. @elia is there a specific use case to use sprockets for static applications? If not, we should not document it. I observed slight differences in the generated js, butvdud not understand the details.
Elia Schito
@elia
Jul 18 2015 14:48
I think a use case is if you need anything in the sprockets ecosystem like processors or libs
Ryan Stout
@ryanstout
Jul 18 2015 20:58
@elia you around by chance?
Torsten Rüger
@rubydesign
Jul 18 2015 21:07
@vais sorry i wasn’t here for your book initiative. But that is definately a good idea and i will help (as i can). Especially with outline and review. As you noticed in my volt post i am not a native english speaker. But yes let the :sparkles: The Opal Book :sparkles: commence.
by another way, is @meh around: i was looking into lissio today and it looks like it has definate potential. But what’s the story, abandoned? superseded? The docs are such that one (me) would need help to get started.
meh.
@meh
Jul 18 2015 21:11
dancinglightning, I'm here
the story is I'm bad at writing documentation and refuse to publicize my work
it's not abandoned by any means, I use it
dancinglightning, also I think the build system is still broken on 0.8 but I need help from @elia or @adambeynon to fix it and they haven't had the time to look into it yet
Mitch VanDuyn
@catmando
Jul 18 2015 21:12
@fkchang bundler 1.10 has inline gem files. I am thinking this could be leveraged into a server where you request an gem, and it returns the opal files. Just a thought from yesterdays conversation.
Torsten Rüger
@rubydesign
Jul 18 2015 21:14
@meh good and hmm news: would you be willing to answer questions and fix issues. possibly give me commit rights if i promise to do just docs?
meh.
@meh
Jul 18 2015 21:15
dancinglightning, I'd rather still get pull requests, I like going over every change, even in projects that aren't mine :P
dancinglightning, but yeah, go ahead if you have any questions or find bugs
Torsten Rüger
@rubydesign
Jul 18 2015 21:25
@meh the commit was not about bugs. just getting your answers down so the effort is not wasted. I take that as a yes you will fix and answer ? So what do you mean by build system? Currently i can’t even install the gem and so i’m grounded. Could you push a new gem version that is maybe 0.7 compatible ?
meh.
@meh
Jul 18 2015 21:26
dancinglightning, what's the error for the gem?
mh
Torsten Rüger
@rubydesign
Jul 18 2015 21:29
@meh ERROR: Could not find a valid gem 'lissio' (>= 0) in any repository
try it
meh.
@meh
Jul 18 2015 21:29
yeah you'd have to use --pre
I'm pushing some stables, they've been in beta for way too long anyway
Torsten Rüger
@rubydesign
Jul 18 2015 21:30
@meh ok. thanks
bedtime. i’ll try tomorrow what you pushed
meh.
@meh
Jul 18 2015 21:31
sure
night