{"id":73,"date":"2010-07-07T10:48:43","date_gmt":"2010-07-07T10:48:43","guid":{"rendered":"http:\/\/www.arnorehn.de\/blog\/?p=73"},"modified":"2016-08-07T11:58:19","modified_gmt":"2016-08-07T09:58:19","slug":"and-the-bindings-keep-rocking-writing-ruby-kio-slaves","status":"publish","type":"post","link":"https:\/\/www.arnorehn.de\/blog\/2010\/07\/07\/and-the-bindings-keep-rocking-writing-ruby-kio-slaves\/","title":{"rendered":"And the bindings keep rocking: Writing Ruby KIO slaves"},"content":{"rendered":"<p>It seems like I got into a hacking frenzy after yesterday&#8217;s Ruby plugins for Kate. Today I sat down and took another look at the KRubyPluginFactory to implement KIO slave support.<\/p>\n<p>So here it is, our very first Ruby Hello World KIO slave:<\/p>\n<pre class=\"brush:ruby\"># kate: space-indent on; indent-width 2;\r\n\r\nrequire 'korundum4'\r\nrequire 'kio'\r\n\r\nmodule Rubytest\r\n\r\n  class Main &lt; KIO::SlaveBase\r\n\r\n    def initialize protocol, pool_sock, app_sock\r\n      super protocol, pool_sock, app_sock\r\n    end\r\n\r\n    def get url\r\n      mimeType 'text\/plain'\r\n\r\n      data Qt::ByteArray.new('Hello World from our first Ruby KIO slave!')\r\n\r\n      finished\r\n    end\r\n\r\n  end\r\n\r\nend<\/pre>\n<p>We&#8217;ll also need a rubytest.protocol file that describes our new protocol:<\/p>\n<pre>[Protocol]\r\nexec=krubypluginfactory\r\ninput=none\r\noutput=filesystem\r\nprotocol=rubytest\r\nreading=true<\/pre>\n<p>To test it, you just have to type rubytest:\/ into konqi&#8217;s addressbar and you should see nice hello world greeting.<\/p>\n<p>Some more info on the structure of a Ruby kio slave: the Ruby script always has to be named &#8216;main.rb&#8217; and the SlaveBase derived class always &#8216;Main&#8217;. The module name is the camelized form of the protocol (so a protocol &#8216;foo_bar&#8217; would map to a module name &#8216;FooBar&#8217;). The script has to reside in &lt;kde prefix&gt;\/share\/apps\/kio_&lt;protocol name&gt;.<br \/>\nThe .protocol file itself should be installed to &lt;kde prefix&gt;\/share\/kde4\/services.<\/p>\n<p>As with the Kate plugin, I packaged this example in a <a href=\"http:\/\/www.arnorehn.de\/blog\/wp-content\/uploads\/2010\/07\/kio_rubytest.tar.gz\">tarball<\/a>. It ships a Makefile and can easily be installed to your home directory with &#8216;make install&#8217;.<br \/>\nI committed this feature to both trunk and the 4.5 branch &#8211; so you can soon start coding your own KIO slaves in Ruby! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It seems like I got into a hacking frenzy after yesterday&#8217;s Ruby plugins for Kate. Today I sat down and took another look at the KRubyPluginFactory to implement KIO slave support. So here it is, our very first Ruby Hello World KIO slave: # kate: space-indent on; indent-width 2; require &#8216;korundum4&#8217; require &#8216;kio&#8217; module Rubytest [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-kde"],"_links":{"self":[{"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":6,"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":158,"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions\/158"}],"wp:attachment":[{"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.arnorehn.de\/blog\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}