[HOW TO] Install gtk-webkit-ruby Gem

WebKit is an open source web browser engine. gtk-webkit-ruby is a Ruby Gem that provides Gtk Webkit bindings for ruby, making it possible to embed a webview (class that has the ability to render a webpage) in a Ruby-GNOME2 application.

In this article we'll see how to install it in any Ubuntu distribution.

Install

Open a terminal window and run:

sudo apt-get install ruby-gnome2-dev -y && sudo apt-get install libwebkitgtk-dev -y && sudo gem install gtk-webkit-ruby -y

Usage

Bellow are the main instructions that should be added to a program in order to render a webpage within a Ruby-GNOME2 application. Please note that this is not a runnable example.

require "gtk2"
require "webkit"

webview = WebKit::WebView.new
webview.show
webview.open(url) # url is a string

Note

While I was trying to install the Gem I encountered some errors that were caused by dependencies not being installed in my system: ruby-gnome2-dev and libwebkitgtk-dev. Below I pasted the error messages for future reference.

### ruby-gnome2-dev dependency error
$ sudo gem install gtk-webkit-ruby
Building native extensions.  This could take a while...
ERROR:  Error installing gtk-webkit-ruby:
 ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.8 extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
 --with-opt-dir
 --without-opt-dir
 --with-opt-include
 --without-opt-include=${opt-dir}/include
 --with-opt-lib
 --without-opt-lib=${opt-dir}/lib
 --with-make-prog
 --without-make-prog
 --srcdir=.
 --curdir
 --ruby=/usr/bin/ruby1.8
extconf.rb:2:in `require': no such file to load -- mkmf-gnome2 (LoadError)
 from extconf.rb:2


Gem files will remain installed in /var/lib/gems/1.8/gems/gtk-webkit-ruby-0.0.3 for inspection.
Results logged to /var/lib/gems/1.8/gems/gtk-webkit-ruby-0.0.3/ext/webkit/gem_make.out

### libwebkitgtk-dev dependency error

$ sudo gem install gtk-webkit-ruby
Building native extensions.  This could take a while...
ERROR:  Error installing gtk-webkit-ruby:
 ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.8 extconf.rb
checking for GCC... yes
checking for rb_define_alloc_func() in ruby.h... yes
checking for rb_block_proc() in ruby.h... yes
checking for new allocation framework... yes
checking for attribute assignment... yes
checking for gtk+-2.0... yes
checking for webkit-1.0... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
 --with-opt-dir
 --without-opt-dir
 --with-opt-include
 --without-opt-include=${opt-dir}/include
 --with-opt-lib
 --without-opt-lib=${opt-dir}/lib
 --with-make-prog
 --without-make-prog
 --srcdir=.
 --curdir
 --ruby=/usr/bin/ruby1.8
 --with-pkg-config
 --without-pkg-config
 --with-override-variables
 --without-override-variables


Gem files will remain installed in /var/lib/gems/1.8/gems/gtk-webkit-ruby-0.0.3 for inspection.
Results logged to /var/lib/gems/1.8/gems/gtk-webkit-ruby-0.0.3/ext/webkit/gem_make.out

References

gtk-webkit-ruby | RubyGems.org

Comments

  1. Another option: https://github.com/mvz/ruby-gir-ffi
    Painless install (gem), GirFFI.setup(:WebKit) and webkit is bound.

    Then to leverage HTML5 in ruby, ruby_js
    https://github.com/ppibburr/ruby_js
    Binds JavascriptCore to ruby, and allows JS to use ruby API's

    ReplyDelete

Post a Comment

Popular posts from this blog

[HOW TO] Create QR Codes in Xubuntu 12.04

[FIX] VLC is unable to open the MRL (smb://)

Add items to Xfce Applications Menu