Cross-platform Generate xlsx Document

That would be the easy part. I was thinking about changing the html to include the javascript and css from linked files. That require a bit of parsing.

It’s called the scope operator.
And when it has no namespace preceding it, it refers to the toplevel ObjectSpace.

1 Like

Well a HEREDOC or a double quoted string can do it (using string interpolation.)

Within Ruby …

js_text = IO.read(File.join(__dir__,"dialog.js"))
css_text = IO.read(File.join(__dir__,"dialog.css"))

html = %[
<!DOCTYPE html>
<html>
  <head>
    <script>
      #{js_text}
    </script>
    <style>
      #{css_text}
    </style>
  </head>
  <body>

  </body>
</html>
]

Note that when we do this, all the code is loaded into the Ruby process’ memory.
When you let the CEF dialog load directly from html, js and css files, the code will be in the CEF instances memory (which happens anyway.)

Thanks for all your help. I’ll have to come back here for a refresher when I get ready to package my app.

There also is a standard templating library that can build your HTML text using <%= #Ruby code %> tags within the html.

It is sort of like how PHP is parsed on web servers.

See: https://ruby-doc.org/stdlib-2.5.5/libdoc/erb/rdoc/ERB.html
and the internal comments in “erb.rb”.

The YARD documenter uses it to build the doc web pages. ruby.sketchup.com uses YARD.

Thanks again everyone for your all your help. The performance seems to be pretty good.

2 Likes

Yea, looks good!

:+1:

Can you shed some light on the process? Perhaps an example or tutorial.
I’m about where you were 7 years ago when you posted this.

The solution lists several links. The one that looks the most useful is UnmanagedExports, but I really have no idea how to get all the parts and pieces working and use it in Ruby. (I would be willing to pay for a sample project or tutorial)

There are a few ways to use C# together with ruby, side by side.

  1. You can create a c# console application and compile to both a windows and an osx executable and execute those from Ruby and wait for their completions (see: https://www.codeproject.com/Articles/5262251/Generate-Native-Executable-from-NET-Core-3-1-Proje). You can pass arguments to the process, just like you can to an ordinary function. You could see this approach the same as contemporary lambdas used in webservices.
  2. Instead of an executable one can also compile C# into a library (dll on windows or dylib on osx) and export some functions (see: https://github.com/dotnet/corert/tree/master/samples/NativeLibrary). You can then use Fiddle (https://github.com/ruby/fiddle) to wrap the native library and call it from ruby.
  3. I have tried wrapping the coreclr as a ruby c++ extension once… did not make it.
  4. Windows only… and… pretty old tech: register you dll as a COM object and then call it using Win32OLE.

Regarding

Back then I ended up crafting a COM object. The biggest disadvantage was that this was Windows only. But, on the other hand, one gained also power over things such as WPF… from ruby :slight_smile:

1 Like

A valuable book for adding Ruby bindings for a library is the book …
Extending Ruby 1.9: Writing Extensions in C
There’s a PDF link in the Ruby Resources downloadable book list.

Thanks Dan. I have done a few ruby c++ extensions, going from geometric calculations to running native HTTP and Websocket servers directly in SketchUp using native threads. But, wrapping the coreclr… that was a bit over the top of my head.