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
.
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: Class: ERB (Ruby 2.5.5)
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.
Yea, looks good!
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.
- 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: Generate Native Executable from .NET Core 3.1 Project - CodeProject). 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.
- 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 (GitHub - ruby/fiddle: A libffi wrapper for Ruby.) to wrap the native library and call it from ruby.
- I have tried wrapping the coreclr as a ruby c++ extension once… did not make it.
- Windows only… and… pretty old tech: register you dll as a COM object and then call it using Win32OLE.
Regarding
Creating a simple c# dll and access it from ruby
c#, ruby, winapi, dll
asked by KenGey on 07:43PM - 16 Jan 13 UTC
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
I have tried wrapping the coreclr as a ruby c++ extension once… did not make it.
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.
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.