Using Ruby to display in a browser a specially made HTML file with links as options, and pass back to Ruby which option link was selected

I use Ruby at home for my personal stuff (since the late 1990s), and
I'm reasonably familiar with it but I'm not an expert. I'd like to do
something which is way outside anything which I've done before, which
is:

(1) First something I can do: use Ruby to create an HTML file on my
home computer. The links are likely to only be to files on my home
computer, but they might also be to WWW pages and/or resources.

(2) Next something I've just found I can do: use Ruby to load that
file into an already running browser (Firefox or Chrome) so it
displays. I've just searched the WWW for command line options for
Firefox, and there are options to open a URL in a new window or tab; I
just tried it using using Kernel#system and it works as it looks like
it should.

(3) Now for the point of this: on the page loaded into the browser
will be several options, indicated by text/and or images, and I want
to be able to select one of those options, preferably by a left or
right mouse click, and then have the controlling Ruby program told
which option was selected. I might want to successively select several
options, and then finally select an option to tell Ruby to close the
browser tab being displayed.

(4) For example, one use will be to display some thumbnail images, and
select one of the thumbnail images and do something with it, for
example: rename it; move it; display its full size image from Ruby
using, for example, Kernel#system to run an image viewer, or - as I
just learned - to open a browser page.

(5) The tricky bit, which is something I can't - yet - do, is (3),
that is selecting one of the displayed options and then have the
controlling Ruby program told which option was selected.

(6) I've been toying with the idea of maybe using PHP or some
Javascript to do both (3) and carrying out an action based on the
selected option, or maybe using PHP or Javascript to do (3)and then
somehow pass an appropriate message back to Ruby about the type of
mouse click.

(7) Does anyone have any suggestions for a not too difficult way to do
this? I could maybe use something like AutoIt, which I've used in the
past to control a browser, but I found that a bit messy. I've wondered
about using something like Watir, but I'm not sure it can do what I
want, and even if it can I wonder if it might be a bit
over-complicated for what I'd like to do: but if complicated is the
only way to do it, I can live with that. I'm even OK with doing
something like using a (simple) web-hosting site as a server, but I'm
not at all sure that would be a good solution, because files to be
loaded as "WWW" pages in browser tabs are going to be created "on the
fly".

Thanks in advance for any assistance.

You could run your Ruby program as an HTTP server on your computer. Have your HTML page send requests to the server indicating what image was clicked, with what option, or whatever you want.

···

Sent from my iPhone

On Mar 28, 2020, at 1:02 PM, Colin Bartlett <colinb2r@googlemail.com> wrote:

I use Ruby at home for my personal stuff (since the late 1990s), and
I'm reasonably familiar with it but I'm not an expert. I'd like to do
something which is way outside anything which I've done before, which
is:

(1) First something I can do: use Ruby to create an HTML file on my
home computer. The links are likely to only be to files on my home
computer, but they might also be to WWW pages and/or resources.

(2) Next something I've just found I can do: use Ruby to load that
file into an already running browser (Firefox or Chrome) so it
displays. I've just searched the WWW for command line options for
Firefox, and there are options to open a URL in a new window or tab; I
just tried it using using Kernel#system and it works as it looks like
it should.

(3) Now for the point of this: on the page loaded into the browser
will be several options, indicated by text/and or images, and I want
to be able to select one of those options, preferably by a left or
right mouse click, and then have the controlling Ruby program told
which option was selected. I might want to successively select several
options, and then finally select an option to tell Ruby to close the
browser tab being displayed.

(4) For example, one use will be to display some thumbnail images, and
select one of the thumbnail images and do something with it, for
example: rename it; move it; display its full size image from Ruby
using, for example, Kernel#system to run an image viewer, or - as I
just learned - to open a browser page.

(5) The tricky bit, which is something I can't - yet - do, is (3),
that is selecting one of the displayed options and then have the
controlling Ruby program told which option was selected.

(6) I've been toying with the idea of maybe using PHP or some
Javascript to do both (3) and carrying out an action based on the
selected option, or maybe using PHP or Javascript to do (3)and then
somehow pass an appropriate message back to Ruby about the type of
mouse click.

(7) Does anyone have any suggestions for a not too difficult way to do
this? I could maybe use something like AutoIt, which I've used in the
past to control a browser, but I found that a bit messy. I've wondered
about using something like Watir, but I'm not sure it can do what I
want, and even if it can I wonder if it might be a bit
over-complicated for what I'd like to do: but if complicated is the
only way to do it, I can live with that. I'm even OK with doing
something like using a (simple) web-hosting site as a server, but I'm
not at all sure that would be a good solution, because files to be
loaded as "WWW" pages in browser tabs are going to be created "on the
fly".

Thanks in advance for any assistance.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Why in the name of all that's holy would you consider using PHP
when you're already working in Ruby?

Yes, some of what you're talking about will require JavaScript on
the client (browser) side, but building out the server side in Ruby
is well-trod ground.

From simple http://sinatrarb.com/ to complex https://rubyonrails.org/
and lots between...

···

On Sat, Mar 28, 2020 at 10:02 AM Colin Bartlett <colinb2r@googlemail.com> wrote:

(6) I've been toying with the idea of maybe using PHP or some
Javascript to do both (3) and carrying out an action based on the
selected option, or maybe using PHP or Javascript to do (3)and then
somehow pass an appropriate message back to Ruby about the type of
mouse click.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Hi Colin,

these days browser security clamps down hard on local access (via
Javascript or otherwise) even from locally loaded HTML files. There could
be many technical ways to achieve your goals but the browser just won't let
them happen.

I would say that Daniel's recommended approach of running a local HTTP
server is the Ruby way to do this.
There are a few small web app frameworks:

Sinatra, Hanami, Roda are good ways to get a small project off the group
with minimal dependencies.

With the continued maturation of Opal (https://opalrb.com), there is a new
option. It may be feasible to build your app into the web page.
<https://opalrb.com/&gt;
Again being a locally loaded page your access to local resources is
restricted. but if your application and data are self-contained you may
like this approach. It can also be combined with the local HTTP server
approach.

-gf-

···

On Sat, Mar 28, 2020 at 1:25 PM Daniel Wood <dwooddev@gmail.com> wrote:

You could run your Ruby program as an HTTP server on your computer. Have
your HTML page send requests to the server indicating what image was
clicked, with what option, or whatever you want.

Sent from my iPhone

> On Mar 28, 2020, at 1:02 PM, Colin Bartlett <colinb2r@googlemail.com> > wrote:
>
> I use Ruby at home for my personal stuff (since the late 1990s), and
> I'm reasonably familiar with it but I'm not an expert. I'd like to do
> something which is way outside anything which I've done before, which
> is:
>
> (1) First something I can do: use Ruby to create an HTML file on my
> home computer. The links are likely to only be to files on my home
> computer, but they might also be to WWW pages and/or resources.
>
> (2) Next something I've just found I can do: use Ruby to load that
> file into an already running browser (Firefox or Chrome) so it
> displays. I've just searched the WWW for command line options for
> Firefox, and there are options to open a URL in a new window or tab; I
> just tried it using using Kernel#system and it works as it looks like
> it should.
>
> (3) Now for the point of this: on the page loaded into the browser
> will be several options, indicated by text/and or images, and I want
> to be able to select one of those options, preferably by a left or
> right mouse click, and then have the controlling Ruby program told
> which option was selected. I might want to successively select several
> options, and then finally select an option to tell Ruby to close the
> browser tab being displayed.
>
> (4) For example, one use will be to display some thumbnail images, and
> select one of the thumbnail images and do something with it, for
> example: rename it; move it; display its full size image from Ruby
> using, for example, Kernel#system to run an image viewer, or - as I
> just learned - to open a browser page.
>
> (5) The tricky bit, which is something I can't - yet - do, is (3),
> that is selecting one of the displayed options and then have the
> controlling Ruby program told which option was selected.
>
> (6) I've been toying with the idea of maybe using PHP or some
> Javascript to do both (3) and carrying out an action based on the
> selected option, or maybe using PHP or Javascript to do (3)and then
> somehow pass an appropriate message back to Ruby about the type of
> mouse click.
>
> (7) Does anyone have any suggestions for a not too difficult way to do
> this? I could maybe use something like AutoIt, which I've used in the
> past to control a browser, but I found that a bit messy. I've wondered
> about using something like Watir, but I'm not sure it can do what I
> want, and even if it can I wonder if it might be a bit
> over-complicated for what I'd like to do: but if complicated is the
> only way to do it, I can live with that. I'm even OK with doing
> something like using a (simple) web-hosting site as a server, but I'm
> not at all sure that would be a good solution, because files to be
> loaded as "WWW" pages in browser tabs are going to be created "on the
> fly".
>
> Thanks in advance for any assistance.
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

I used Flammarion (GitHub - zach-capalbo/flammarion: The nifty ruby gui toolkit.) to do most
of what you require. I have written scripts to control our Websphere
installations through a Chrome base menu system.

It hasn't been updated in a while but it is serves my needs.

It took a while to explore and experiment but it was worth the effort.

···

On Sat, Mar 28, 2020 at 1:02 PM Colin Bartlett <colinb2r@googlemail.com> wrote:

I use Ruby at home for my personal stuff (since the late 1990s), and
I'm reasonably familiar with it but I'm not an expert. I'd like to do
something which is way outside anything which I've done before, which
is:

(1) First something I can do: use Ruby to create an HTML file on my
home computer. The links are likely to only be to files on my home
computer, but they might also be to WWW pages and/or resources.

(2) Next something I've just found I can do: use Ruby to load that
file into an already running browser (Firefox or Chrome) so it
displays. I've just searched the WWW for command line options for
Firefox, and there are options to open a URL in a new window or tab; I
just tried it using using Kernel#system and it works as it looks like
it should.

(3) Now for the point of this: on the page loaded into the browser
will be several options, indicated by text/and or images, and I want
to be able to select one of those options, preferably by a left or
right mouse click, and then have the controlling Ruby program told
which option was selected. I might want to successively select several
options, and then finally select an option to tell Ruby to close the
browser tab being displayed.

(4) For example, one use will be to display some thumbnail images, and
select one of the thumbnail images and do something with it, for
example: rename it; move it; display its full size image from Ruby
using, for example, Kernel#system to run an image viewer, or - as I
just learned - to open a browser page.

(5) The tricky bit, which is something I can't - yet - do, is (3),
that is selecting one of the displayed options and then have the
controlling Ruby program told which option was selected.

(6) I've been toying with the idea of maybe using PHP or some
Javascript to do both (3) and carrying out an action based on the
selected option, or maybe using PHP or Javascript to do (3)and then
somehow pass an appropriate message back to Ruby about the type of
mouse click.

(7) Does anyone have any suggestions for a not too difficult way to do
this? I could maybe use something like AutoIt, which I've used in the
past to control a browser, but I found that a bit messy. I've wondered
about using something like Watir, but I'm not sure it can do what I
want, and even if it can I wonder if it might be a bit
over-complicated for what I'd like to do: but if complicated is the
only way to do it, I can live with that. I'm even OK with doing
something like using a (simple) web-hosting site as a server, but I'm
not at all sure that would be a good solution, because files to be
loaded as "WWW" pages in browser tabs are going to be created "on the
fly".

Thanks in advance for any assistance.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Quoting Colin Bartlett (colinb2r@googlemail.com)

(7) Does anyone have any suggestions for a not too difficult way to do
this?

I am a web-skeptic to say the least, but as part of my job I sometimes
have to offer to somebody the way to access data or services from
their browser.

Once the somebody accepts to have from her/his browser the lamest of
all possible experiences, I obtain what I need by using Webrick, the
web server that's included in the official ruby distribution. You have
to learn how to use it, as for all useful tools, but then you get to
write, for each element in your web site's page hierarchy, a nice ruby
method that composes the needed HTML, and feeds it back to the
client's browser.

I add a homeopatic dose of CSS and, of course, no javascript at all.

The methods give you access to the results of browser-based choices
contained in HTML forms you have previously submitted, of course. The
simplicity is awesome.

Naturally, you must not be afraid about reading/writing pure HTML...

If you often happen to run across this sort of challenges, it might be
worth investing some time and energy into learning Webrick.

Carlo

···

Subject: Using Ruby to display in a browser a specially made HTML file with links as options, and pass back to Ruby which option link was selected
  Date: Sat 28 Mar 20 05:01:34PM +0000

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

Carlo E. Prelz <fluido@fluido.as> writes:

Once the somebody accepts to have from her/his browser the lamest of
all possible experiences, I obtain what I need by using Webrick, the
web server that's included in the official ruby distribution.

This is actually a pretty nice idea, especially if the OP does not want
to depend on any RubyGems. In that case, I would also add that Ruby's
stdlib contains a library called "erb" which eases the output of HTML
quite a bit.

If depending on RubyGems is okay, there are endless possibilities. Since
what the OP wants to do sounds simple in web terms, I would suggest use
of the "sinatra" gem in that case: https://sinatrarb.com

Since the OP is concerned mostly with user interfacing, he sohuld also
consider writing a real GUI application rather than a web page as "the
lamest of all possible experiences", to quote the preceeding post. With
Tk sadly gone from the stdlib, all possibilities to write a GUI with
Ruby however involve RubyGems. There are several options for doing this
with Ruby, including Gtk3, Shoes, Fxruby, Tk, and more.

But indeed, the most simple option is probably Webrick with erb.

···

--
Blog: https://mg.guelker.eu

Thanks for the link to Flammarion
<https://github.com/zach-capalbo/flammarion&gt;\. Its local web app + server +
browser launcher combo looks interesting. Now I'm looking for a nail to hit
with this hammer :slight_smile: .

-gf-

···

On Sat, Mar 28, 2020 at 10:05 PM Michael Gaunnac <mlgaunnac@gmail.com> wrote:

I used Flammarion (GitHub - zach-capalbo/flammarion: The nifty ruby gui toolkit.) to do most
of what you require. I have written scripts to control our Websphere
installations through a Chrome base menu system.

It hasn't been updated in a while but it is serves my needs.

It took a while to explore and experiment but it was worth the effort.

On Sat, Mar 28, 2020 at 1:02 PM Colin Bartlett <colinb2r@googlemail.com> > wrote:

I use Ruby at home for my personal stuff (since the late 1990s), and
I'm reasonably familiar with it but I'm not an expert. I'd like to do
something which is way outside anything which I've done before, which
is:

(1) First something I can do: use Ruby to create an HTML file on my
home computer. The links are likely to only be to files on my home
computer, but they might also be to WWW pages and/or resources.

(2) Next something I've just found I can do: use Ruby to load that
file into an already running browser (Firefox or Chrome) so it
displays. I've just searched the WWW for command line options for
Firefox, and there are options to open a URL in a new window or tab; I
just tried it using using Kernel#system and it works as it looks like
it should.

(3) Now for the point of this: on the page loaded into the browser
will be several options, indicated by text/and or images, and I want
to be able to select one of those options, preferably by a left or
right mouse click, and then have the controlling Ruby program told
which option was selected. I might want to successively select several
options, and then finally select an option to tell Ruby to close the
browser tab being displayed.

(4) For example, one use will be to display some thumbnail images, and
select one of the thumbnail images and do something with it, for
example: rename it; move it; display its full size image from Ruby
using, for example, Kernel#system to run an image viewer, or - as I
just learned - to open a browser page.

(5) The tricky bit, which is something I can't - yet - do, is (3),
that is selecting one of the displayed options and then have the
controlling Ruby program told which option was selected.

(6) I've been toying with the idea of maybe using PHP or some
Javascript to do both (3) and carrying out an action based on the
selected option, or maybe using PHP or Javascript to do (3)and then
somehow pass an appropriate message back to Ruby about the type of
mouse click.

(7) Does anyone have any suggestions for a not too difficult way to do
this? I could maybe use something like AutoIt, which I've used in the
past to control a browser, but I found that a bit messy. I've wondered
about using something like Watir, but I'm not sure it can do what I
want, and even if it can I wonder if it might be a bit
over-complicated for what I'd like to do: but if complicated is the
only way to do it, I can live with that. I'm even OK with doing
something like using a (simple) web-hosting site as a server, but I'm
not at all sure that would be a good solution, because files to be
loaded as "WWW" pages in browser tabs are going to be created "on the
fly".

Thanks in advance for any assistance.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;