├── .rspec ├── lib ├── knj │ ├── .gitignore │ ├── autoload │ │ ├── wref.rb │ │ ├── cinch.rb │ │ ├── gd2.rb │ │ ├── tzinfo.rb │ │ ├── activesupport.rb │ │ ├── parsedate.rb │ │ ├── soap.rb │ │ ├── gtk2.rb │ │ ├── facebooker.rb │ │ ├── mysql.rb │ │ ├── tmail.rb │ │ ├── zip.rb │ │ ├── magick.rb │ │ ├── sqlite3.rb │ │ ├── xmlsimple.rb │ │ ├── erubis.rb │ │ ├── facets_dictionary.rb │ │ ├── gettext.rb │ │ ├── json.rb │ │ ├── rexml.rb │ │ ├── backups │ │ │ ├── parsedate.rb │ │ │ └── ping.rb │ │ └── ping.rb │ ├── erb │ │ ├── cache │ │ │ └── README │ │ ├── erb_fcgi_jruby.rb │ │ ├── apache_knjerb.conf │ │ ├── erb_1.9.rb │ │ ├── erb_cache_clean.rb │ │ ├── erb.rb │ │ ├── erb_jruby.rb │ │ ├── erb_fcgi.rb │ │ └── erb_fcgi_1.9.rb │ ├── php_parser │ │ ├── arguments.rb │ │ ├── tests │ │ │ ├── test_function.php │ │ │ ├── test.rb │ │ │ └── test_function_run.rb │ │ ├── php_parser.rb │ │ └── functions.rb │ ├── ironruby-gtk2 │ │ ├── iconsize.rb │ │ ├── gtk_menu.rb │ │ ├── gdk_event.rb │ │ ├── stock.rb │ │ ├── vbox.rb │ │ ├── gtk_cellrenderertext.rb │ │ ├── gtk_filechooserbutton.rb │ │ ├── gtk_menuitem.rb │ │ ├── entry.rb │ │ ├── gtk_statusicon.rb │ │ ├── gdk_eventbutton.rb │ │ ├── gdk_pixbuf.rb │ │ ├── glib.rb │ │ ├── gtk_treeselection.rb │ │ ├── image.rb │ │ ├── gtk_treeview.rb │ │ ├── gtk_combobox.rb │ │ ├── gtk_liststore.rb │ │ ├── tests │ │ │ ├── test_2.rb │ │ │ ├── test.glade │ │ │ └── test_ironruby_window.rb │ │ ├── button.rb │ │ ├── label.rb │ │ ├── window.rb │ │ ├── gtk_treeiter.rb │ │ ├── gtk_builder.rb │ │ ├── gtk_treeviewcolumn.rb │ │ ├── dialog.rb │ │ ├── gladexml.rb │ │ └── gtk2.rb │ ├── scripts │ │ ├── keepalive.rb │ │ ├── degulesider.rb │ │ ├── ip2location.rb │ │ ├── svn_merge.rb │ │ ├── upgrade_knjrbfw_checker.rb │ │ ├── filesearch.rb │ │ └── speed_test.rb │ ├── jruby-gtk2 │ │ ├── tests │ │ │ ├── test_trayicon.png │ │ │ ├── test_normal_window.rb │ │ │ ├── test_trayicon.rb │ │ │ └── test_glade_window.rb │ │ ├── checkbutton.rb │ │ ├── iconsize.rb │ │ ├── image.rb │ │ ├── cellrenderertext.rb │ │ ├── hbox.rb │ │ ├── stock.rb │ │ ├── statusicon.rb │ │ ├── window.rb │ │ ├── vbox.rb │ │ ├── progressbar.rb │ │ ├── builder │ │ │ ├── test_builder.rb │ │ │ ├── test_builder.ui │ │ │ └── test_builder.glade │ │ ├── eventbutton.rb │ │ ├── combobox.rb │ │ ├── builder.rb │ │ ├── menu.rb │ │ ├── dialog.rb │ │ ├── liststore.rb │ │ ├── treeview.rb │ │ └── gladexml.rb │ ├── win.rb │ ├── tests │ │ ├── test_degulesider.rb │ │ ├── compiler │ │ │ ├── compiler_test.rb │ │ │ └── compiler_test_file.rb │ │ ├── test_http2.rb │ │ ├── test_http2_proxy.rb │ │ └── test_mount.rb │ ├── rhodes │ │ ├── mutex.rb │ │ ├── rhodes.js │ │ ├── youtube_embed.erb │ │ └── youtube_open.erb │ ├── fs │ │ ├── drivers │ │ │ ├── filesystem.rb │ │ │ ├── ssh.rb │ │ │ └── ftp.rb │ │ └── fs.rb │ ├── filesystem.rb │ ├── libqt_window.rb │ ├── includes │ │ ├── require_info.rb │ │ └── appserver_cli.rb │ ├── jruby_compiler.rb │ ├── rand.rb │ ├── ip2location.rb │ ├── sysuser.rb │ ├── rsvgbin.rb │ ├── gettext_fallback.rb │ ├── knj_controller.rb │ ├── csv.rb │ ├── power_manager.rb │ ├── thread.rb │ ├── exchangerates.rb │ ├── youtube.rb │ ├── gtk2_msgbox.rb │ ├── nvidia_settings.rb │ ├── thread2.rb │ ├── notify.rb │ ├── x11vnc.rb │ ├── hash_methods.rb │ ├── mutexcl.rb │ ├── gtk2_window.rb │ ├── opts.rb │ ├── degulesider.rb │ ├── errors.rb │ ├── cpufreq.rb │ ├── gtk2_menu.rb │ ├── gtk2_statuswindow.rb │ ├── maemo │ │ └── fremantle-calendar │ │ │ └── fremantle-calendar.rb │ ├── event_filemod.rb │ ├── sms.rb │ ├── win_registry.rb │ ├── compiler.rb │ ├── iotop.rb │ ├── locale_strings.rb │ ├── mail.rb │ ├── libqt.rb │ ├── mailobj.rb │ ├── cmd_gen.rb │ ├── knj.rb │ ├── cmd_parser.rb │ ├── google_sitemap.rb │ ├── gettext_threadded.rb │ ├── autoload.rb │ ├── mount.rb │ ├── locales.rb │ ├── kvm.rb │ ├── event_handler.rb │ ├── facebook_connect.rb │ ├── win_tightvnc.rb │ ├── gtk2_cb.rb │ ├── amixer.rb │ ├── threadhandler.rb │ ├── unix_proc.rb │ └── webscripts │ │ └── image.rhtml └── knjrbfw.rb ├── Gemfile ├── .document ├── testfiles └── image.jpg ├── spec ├── autoload_spec.rb ├── locales_spec.rb ├── spec_helper.rb ├── amixer_spec.rb ├── cmd_parser_spec.rb ├── arrayext_spec.rb ├── strings_spec.rb ├── web_spec.rb └── knjrbfw_spec.rb ├── .github └── dependabot.yml ├── peak_flow.yml ├── README.rdoc ├── Rakefile ├── .gitignore ├── LICENSE.txt ├── knjrbfw.gemspec └── Gemfile.lock /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | -------------------------------------------------------------------------------- /lib/knj/.gitignore: -------------------------------------------------------------------------------- 1 | erb/cache/* 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | gemspec 3 | -------------------------------------------------------------------------------- /lib/knj/autoload/wref.rb: -------------------------------------------------------------------------------- 1 | Knj.gem_require(:Wref, :wref) -------------------------------------------------------------------------------- /lib/knj/autoload/cinch.rb: -------------------------------------------------------------------------------- 1 | require "rubygems" 2 | require "cinch" -------------------------------------------------------------------------------- /lib/knj/autoload/gd2.rb: -------------------------------------------------------------------------------- 1 | require "rubygems" 2 | require "gd2" -------------------------------------------------------------------------------- /lib/knj/autoload/tzinfo.rb: -------------------------------------------------------------------------------- 1 | require "rubygems" 2 | require "tzinfo" -------------------------------------------------------------------------------- /lib/knj/autoload/activesupport.rb: -------------------------------------------------------------------------------- 1 | require "rubygems" 2 | require "active_support" -------------------------------------------------------------------------------- /lib/knj/autoload/parsedate.rb: -------------------------------------------------------------------------------- 1 | require "#{$knjpath}autoload/backups/parsedate.rb" -------------------------------------------------------------------------------- /.document: -------------------------------------------------------------------------------- 1 | lib/**/*.rb 2 | bin/* 3 | - 4 | features/**/*.feature 5 | LICENSE.txt 6 | -------------------------------------------------------------------------------- /lib/knj/erb/cache/README: -------------------------------------------------------------------------------- 1 | This is where cache-files are stored for fast execution. 2 | -------------------------------------------------------------------------------- /testfiles/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaspernj/knjrbfw/HEAD/testfiles/image.jpg -------------------------------------------------------------------------------- /lib/knj/autoload/soap.rb: -------------------------------------------------------------------------------- 1 | module SOAP 2 | autoload :WSDLDriverFactory, "soap/wsdlDriver" 3 | end -------------------------------------------------------------------------------- /lib/knj/php_parser/arguments.rb: -------------------------------------------------------------------------------- 1 | class Knj::Php_parser 2 | def args 3 | 4 | end 5 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/iconsize.rb: -------------------------------------------------------------------------------- 1 | class Gtk::IconSize 2 | DIALOG = RealGtk::IconSize.Dialog 3 | end -------------------------------------------------------------------------------- /lib/knj/autoload/gtk2.rb: -------------------------------------------------------------------------------- 1 | require "gtk2" 2 | 3 | module Gtk 4 | autoload :MozEmbed, "gtkmozembed" 5 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_menu.rb: -------------------------------------------------------------------------------- 1 | class Gtk::Menu 2 | def popup(*paras) 3 | @ob.popup 4 | end 5 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gdk_event.rb: -------------------------------------------------------------------------------- 1 | class Gdk::Event 2 | BUTTON_PRESS = RealGdk::EventType.ButtonPress 3 | end -------------------------------------------------------------------------------- /lib/knj/scripts/keepalive.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | while true 4 | print "Keel-alive\n" 5 | sleep 1 6 | end -------------------------------------------------------------------------------- /lib/knj/autoload/facebooker.rb: -------------------------------------------------------------------------------- 1 | require "rubygems" 2 | require "#{File.dirname(__FILE__)}/json_autoload" 3 | require "facebooker" -------------------------------------------------------------------------------- /lib/knj/autoload/mysql.rb: -------------------------------------------------------------------------------- 1 | begin 2 | require "mysql" 3 | rescue LoadError 4 | require "rubygems" 5 | require "mysql" 6 | end -------------------------------------------------------------------------------- /lib/knj/autoload/tmail.rb: -------------------------------------------------------------------------------- 1 | begin 2 | require "tmail" 3 | rescue LoadError 4 | require "rubygems" 5 | require "tmail" 6 | end -------------------------------------------------------------------------------- /lib/knj/autoload/zip.rb: -------------------------------------------------------------------------------- 1 | begin 2 | require "zip/zip" 3 | rescue LoadError 4 | require "rubygems" 5 | require "zip" 6 | end -------------------------------------------------------------------------------- /lib/knj/autoload/magick.rb: -------------------------------------------------------------------------------- 1 | begin 2 | require "rmagick" 3 | rescue LoadError 4 | require "rubygems" 5 | require "rmagick" 6 | end -------------------------------------------------------------------------------- /lib/knj/autoload/sqlite3.rb: -------------------------------------------------------------------------------- 1 | begin 2 | require "sqlite3" 3 | rescue LoadError 4 | require "rubygems" 5 | require "sqlite3" 6 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/stock.rb: -------------------------------------------------------------------------------- 1 | module Gtk::Stock 2 | OK = RealGtk::Stock.Ok 3 | DIALOG_WARNING = RealGtk::Stock.DialogWarning 4 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/tests/test_trayicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaspernj/knjrbfw/HEAD/lib/knj/jruby-gtk2/tests/test_trayicon.png -------------------------------------------------------------------------------- /lib/knj/autoload/xmlsimple.rb: -------------------------------------------------------------------------------- 1 | begin 2 | require "xmlsimple" 3 | rescue LoadError 4 | require "rubygems" 5 | require "xmlsimple" 6 | end -------------------------------------------------------------------------------- /lib/knjrbfw.rb: -------------------------------------------------------------------------------- 1 | module Knj 2 | end 3 | 4 | $knjpath = "knj/" if !$knjpath 5 | $: << File.dirname(__FILE__) 6 | 7 | require "#{$knjpath}knj" -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/vbox.rb: -------------------------------------------------------------------------------- 1 | class Gtk::VBox 2 | def pack_start(widget, arg1 = false, arg2 = false) 3 | @ob.PackStart(widget.ob) 4 | end 5 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_cellrenderertext.rb: -------------------------------------------------------------------------------- 1 | class Gtk::CellRendererText 2 | def initialize(*paras) 3 | @ob = RealGtk::CellRendererText.new 4 | end 5 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_filechooserbutton.rb: -------------------------------------------------------------------------------- 1 | class Gtk::FileChooserButton 2 | def filename=(newfilename) 3 | @ob.set_filename(newfilename) 4 | end 5 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/checkbutton.rb: -------------------------------------------------------------------------------- 1 | class Gtk::CheckButton 2 | #nothing here yet... once there were something here... but that was a long long time ago... 3 | end -------------------------------------------------------------------------------- /lib/knj/win.rb: -------------------------------------------------------------------------------- 1 | module Knj::Win 2 | #Autoloader. 3 | def self.const_missing(name) 4 | require "#{$knjpath}knj/win_#{name.to_s.downcase}" 5 | end 6 | end -------------------------------------------------------------------------------- /lib/knj/autoload/erubis.rb: -------------------------------------------------------------------------------- 1 | module Erubis; end #bugfix 2 | 3 | begin 4 | require "erubis" 5 | rescue LoadError 6 | require "rubygems" 7 | require "erubis" 8 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_menuitem.rb: -------------------------------------------------------------------------------- 1 | Gtk.events["Gtk"]["MenuItem"] = { 2 | "activate" => "activated" 3 | } 4 | 5 | class Gtk::MenuItem 6 | #nothing here yet. 7 | end -------------------------------------------------------------------------------- /lib/knj/erb/erb_fcgi_jruby.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/jruby 2 | 3 | require "fcgi" 4 | FCGI.each_cgi do |fcgi| 5 | print "Content-Type: text/html\n\n" 6 | print "Hello world." 7 | end 8 | -------------------------------------------------------------------------------- /lib/knj/php_parser/tests/test_function.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/iconsize.rb: -------------------------------------------------------------------------------- 1 | class Gtk::IconSize 2 | DIALOG = org.gnome.gtk.IconSize::DIALOG 3 | BUTTON = org.gnome.gtk.IconSize::BUTTON 4 | MENU = org.gnome.gtk.IconSize::MENU 5 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/entry.rb: -------------------------------------------------------------------------------- 1 | Gtk.events["Gtk"]["Entry"] = { 2 | "activate" => "activate" 3 | } 4 | 5 | class Gtk::Entry 6 | def set_text(newtext) 7 | @ob.text = newtext 8 | end 9 | end -------------------------------------------------------------------------------- /lib/knj/autoload/facets_dictionary.rb: -------------------------------------------------------------------------------- 1 | require "rubygems" 2 | 3 | begin 4 | require "facets/dictionary" 5 | rescue LoadError 6 | require File.dirname(__FILE__) + "/backups/facets_dictionary" 7 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_statusicon.rb: -------------------------------------------------------------------------------- 1 | Gtk.events["Gtk"]["StatusIcon"] = { 2 | "activate" => "activate", 3 | "popup-menu" => "popup_menu" 4 | } 5 | 6 | class Gtk::StatusIcon 7 | #nothing here yet. 8 | end -------------------------------------------------------------------------------- /spec/autoload_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Autoload" do 4 | it "Wref" do 5 | require "#{File.dirname(__FILE__)}/../lib/knj/autoload/wref.rb" 6 | end 7 | end -------------------------------------------------------------------------------- /lib/knj/tests/test_degulesider.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "knj/autoload" 4 | 5 | dgs = Knj::Degulesider.new 6 | results = dgs.search( 7 | :where => "Engvej 3, 4970 Rødby" 8 | ) 9 | 10 | Php4r.print_r(results) -------------------------------------------------------------------------------- /lib/knj/rhodes/mutex.rb: -------------------------------------------------------------------------------- 1 | class Mutex 2 | def synchronize 3 | sleep 0.05 while @working 4 | @working = true 5 | 6 | begin 7 | yield 8 | ensure 9 | @working = false 10 | end 11 | end 12 | end -------------------------------------------------------------------------------- /lib/knj/erb/apache_knjerb.conf: -------------------------------------------------------------------------------- 1 | AddType text/html .rhtml 2 | 3 | ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 4 | 5 | 6 | AddType application/x-httpd-knj .rhtml 7 | Action application/x-httpd-knj "/cgi-bin/knjerb" 8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: bundler 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "01:00" 8 | timezone: Europe/Copenhagen 9 | open-pull-requests-limit: 99 10 | -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gdk_eventbutton.rb: -------------------------------------------------------------------------------- 1 | class Gdk::EventButton 2 | def initialize(*paras) 3 | #take no args. 4 | end 5 | 6 | def button 7 | #do nothing. 8 | end 9 | 10 | def time 11 | #do nothing. 12 | end 13 | end -------------------------------------------------------------------------------- /lib/knj/scripts/degulesider.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "knj/autoload" 4 | include Knj 5 | 6 | dgs = Degulesider.new 7 | res = dgs.search( 8 | :where => ARGV[0], 9 | :what => ARGV[1] 10 | ) 11 | 12 | print JSON.generate(res) -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/image.rb: -------------------------------------------------------------------------------- 1 | class Gtk::Image 2 | def initialize(arg1, arg2) 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | else 7 | @ob = Gtk.evalob("org.gnome.gtk.Image").new(arg1, arg2) 8 | end 9 | end 10 | end -------------------------------------------------------------------------------- /lib/knj/scripts/ip2location.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "knj/autoload" 4 | ip2loc = Knj::Ip2location.new 5 | 6 | data = ip2loc.lookup(ARGV[0]) 7 | 8 | if ARGV[1] == "json" 9 | print Php4r.json_encode(data) 10 | else 11 | Php4r.print_r(data) 12 | end -------------------------------------------------------------------------------- /lib/knj/autoload/gettext.rb: -------------------------------------------------------------------------------- 1 | #In some version just requiring gettext givet an error because you have to define the constant first... weird... 2 | module GetText; end 3 | 4 | begin 5 | require "gettext" 6 | rescue LoadError 7 | require "rubygems" 8 | require "gettext" 9 | end -------------------------------------------------------------------------------- /lib/knj/fs/drivers/filesystem.rb: -------------------------------------------------------------------------------- 1 | class Knj::Fs::Filesystem 2 | def self.args 3 | return [ 4 | { 5 | "title" => "Path", 6 | "name" => "texpath" 7 | } 8 | ] 9 | end 10 | 11 | def initialize(args) 12 | @args = args 13 | end 14 | end -------------------------------------------------------------------------------- /lib/knj/filesystem.rb: -------------------------------------------------------------------------------- 1 | class Knj::Filesystem 2 | def self.copy(args) 3 | FileUtils.rm(args[:to]) if args[:replace] and File.exist?(args[:to]) 4 | FileUtils.cp(args[:from], args[:to]) 5 | mod = File.lstat(args[:from]).mode & 0777 6 | File.chmod(mod, args[:to]) 7 | end 8 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/cellrenderertext.rb: -------------------------------------------------------------------------------- 1 | class Gtk::CellRendererText 2 | def initialize 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | end 7 | end 8 | 9 | def init(tcol) 10 | @ob = org.gnome.gtk.CellRendererText.new(tcol.ob) 11 | end 12 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/hbox.rb: -------------------------------------------------------------------------------- 1 | class Gtk::HBox 2 | def initialize(homogeneous = false, spacing = 0) 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | else 7 | @ob = Gtk.evalob("org.gnome.gtk.HBox").new(homogeneous, spacing) 8 | end 9 | end 10 | end -------------------------------------------------------------------------------- /lib/knj/rhodes/rhodes.js: -------------------------------------------------------------------------------- 1 | function knj_rhodes_html_links(args){ 2 | $.ajax({type: "POST", data: {"url": args.url}, url: "/app/Knj/html_links"}) 3 | } 4 | 5 | function knj_rhodes_youtube_open_in_app(args){ 6 | $.ajax({type: "POST", data: {"youtube_id": args.youtube_id}, url: "/app/Knj/youtube_open_in_app"}) 7 | } -------------------------------------------------------------------------------- /lib/knj/libqt_window.rb: -------------------------------------------------------------------------------- 1 | class QtWindow 2 | def self.doCenter(tha_window) 3 | qdw = Qt::DesktopWidget.new 4 | 5 | move_left = (qdw.width / 2) - (tha_window.width / 2) 6 | move_top = (qdw.height / 2) - (tha_window.height / 2) 7 | 8 | tha_window.move(move_left, move_top) 9 | end 10 | end -------------------------------------------------------------------------------- /peak_flow.yml: -------------------------------------------------------------------------------- 1 | rvm: true 2 | builds: 3 | build_1: 4 | environment: 5 | RUBY_VERSION: 2.7.8 6 | name: Ruby 2.7.8 7 | script: 8 | - bundle exec rspec 9 | build_2: 10 | environment: 11 | RUBY_VERSION: 3.2.2 12 | name: Ruby 3.2.2 13 | script: 14 | - bundle exec rspec 15 | -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/stock.rb: -------------------------------------------------------------------------------- 1 | class Gtk::Stock 2 | OK = org.gnome.gtk.Stock::OK 3 | YES = org.gnome.gtk.Stock::YES 4 | NO = org.gnome.gtk.Stock::NO 5 | DIALOG_WARNING = org.gnome.gtk.Stock::DIALOG_WARNING 6 | DIALOG_QUESTION = org.gnome.gtk.Stock::DIALOG_QUESTION 7 | DIALOG_INFO = org.gnome.gtk.Stock::DIALOG_INFO 8 | end -------------------------------------------------------------------------------- /lib/knj/tests/compiler/compiler_test.rb: -------------------------------------------------------------------------------- 1 | require "knj/knj" 2 | require "#{$knjpath}compiler" 3 | 4 | compiler = Knj::Compiler.new 5 | 6 | time_start = Time.new.to_f 7 | 8 | #0.upto(10000) do 9 | compiler.eval_file("compiler_test_file.rb") 10 | #end 11 | 12 | time_spent = Time.new.to_f - time_start 13 | print "#{time_spent}\n" -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/statusicon.rb: -------------------------------------------------------------------------------- 1 | Gtk.events << ["StatusIcon", "activate", org.gnome.gtk.StatusIcon::Activate, :onActivate, nil] 2 | Gtk.events << ["StatusIcon", "popup-menu", org.gnome.gtk.StatusIcon::PopupMenu, :onPopupMenu, nil] 3 | 4 | class Gtk::StatusIcon 5 | def pixbuf=(newpixbuf) 6 | @ob.from_pixbuf = newpixbuf.ob 7 | end 8 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/window.rb: -------------------------------------------------------------------------------- 1 | Gtk.events << ["Window", "destroy", org.gnome.gtk.Window::DeleteEvent, :onDeleteEvent, false] 2 | 3 | class Gtk::Window 4 | def destroy 5 | @ob.hide #destroy does not exist in the Java-version? - knj 6 | end 7 | 8 | def set_frame_dimensions(arg1, arg2, arg3, arg4) 9 | @ob.border_width = arg1 10 | end 11 | end -------------------------------------------------------------------------------- /lib/knj/includes/require_info.rb: -------------------------------------------------------------------------------- 1 | Knj::REQUIRE_INFO = {} 2 | 3 | class Object 4 | alias_method :require_knj, :require 5 | 6 | def require(path) 7 | stat = require_knj(path) 8 | 9 | if stat and !Knj::REQUIRE_INFO.key?(path) 10 | Knj::REQUIRE_INFO[path] = {:caller => caller} 11 | end 12 | 13 | return stat 14 | end 15 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gdk_pixbuf.rb: -------------------------------------------------------------------------------- 1 | class Gdk::Pixbuf 2 | def initialize(*args) 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | else 7 | @ob = Kernel.const_get("RealGdk").const_get("Pixbuf").method(:new).overload(System::String).call(System::String.new(args[0])) 8 | #method.call("") 9 | end 10 | end 11 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/vbox.rb: -------------------------------------------------------------------------------- 1 | class Gtk::VBox 2 | def initialize 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | else 7 | splitted = self.class.to_s.split("::") 8 | javaname = "org.gnome." + splitted.first.downcase + "." + splitted.last 9 | @ob = Gtk.evalob(javaname).new(false, 0) 10 | end 11 | end 12 | end -------------------------------------------------------------------------------- /lib/knj/jruby_compiler.rb: -------------------------------------------------------------------------------- 1 | class Knj::Jruby_compiler 2 | def initialize(args = {}) 3 | @args = args 4 | 5 | factory = javax.script.ScriptEngineManager.new 6 | engine = factory.getEngineByName("jruby") 7 | code = File.read(args[:path]) 8 | @script = engine.compile(code) 9 | end 10 | 11 | def run 12 | @script.eval 13 | end 14 | end -------------------------------------------------------------------------------- /lib/knj/autoload/json.rb: -------------------------------------------------------------------------------- 1 | require "rubygems" 2 | 3 | begin 4 | if RUBY_ENGINE == "jruby" 5 | require "json/pure" #normal json has utf-8 encoding problems - knj. 6 | else 7 | require "json/pure" 8 | 9 | #deactivated because of problems with utf-8 encoding. 10 | #require "json/ext" 11 | end 12 | rescue LoadError 13 | require "json/pure" 14 | end -------------------------------------------------------------------------------- /lib/knj/erb/erb_1.9.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby1.9 2 | 3 | knjdir = File.dirname(File.realpath(__FILE__)) + "/../" 4 | 5 | require knjdir + "autoload" 6 | require knjdir + "/erb/include" 7 | 8 | $knj_eruby = KnjEruby 9 | 10 | filename = ENV["PATH_TRANSLATED"] if ENV and ENV["PATH_TRANSLATED"] 11 | filename = ARGV[0] if ARGV and ARGV[0] 12 | 13 | KnjEruby.load(filename) -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/progressbar.rb: -------------------------------------------------------------------------------- 1 | class Gtk::ProgressBar 2 | def initialize 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | else 7 | splitted = self.class.to_s.split("::") 8 | javaname = "org.gnome." + splitted.first.downcase + "." + splitted.last 9 | @ob = Gtk.evalob(javaname).new 10 | end 11 | end 12 | end -------------------------------------------------------------------------------- /lib/knj/autoload/rexml.rb: -------------------------------------------------------------------------------- 1 | require "rexml/rexml" 2 | 3 | module REXML 4 | autoload :Document, "rexml/document" 5 | autoload :ParseException, "rexml/parseexception" 6 | end 7 | 8 | module REXML::Formatters 9 | autoload :Default, "rexml/formatters/default" 10 | autoload :Pretty, "rexml/formatters/pretty" 11 | autoload :Transitive, "rexml/formatters/transitive" 12 | end -------------------------------------------------------------------------------- /spec/locales_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Locales" do 4 | it "should do convertions of short formats" do 5 | Thread.current[:locale] = "en" 6 | res = Knj::Locales.lang 7 | raise "Result wasnt as expected: '#{res}'." if res["first"] != "en" or res["second"] != "GB" or res["full"] != "en_GB" 8 | end 9 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/glib.rb: -------------------------------------------------------------------------------- 1 | module GLib 2 | class Timeout 3 | def self.add(time, &block) 4 | Thread.new(time, block) do |time, block| 5 | begin 6 | sleep(time / 1000) 7 | block.call 8 | rescue Exception => e 9 | puts e.inspect 10 | puts e.backtrace 11 | end 12 | end 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/tests/test_normal_window.rb: -------------------------------------------------------------------------------- 1 | require "knj/autoload" 2 | 3 | button = Gtk::Button.new("Test") 4 | button.signal_connect("clicked") do 5 | print "Clicked!\n" 6 | end 7 | 8 | win = Gtk::Window.new("Trala") 9 | win.add(button) 10 | win.show_all 11 | 12 | win.signal_connect("destroy") do 13 | print "Destroy!\n" 14 | Gtk.main_quit 15 | end 16 | 17 | Gtk.main -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_treeselection.rb: -------------------------------------------------------------------------------- 1 | Gtk.events["Gtk"]["TreeSelection"] = { 2 | "changed" => "changed" 3 | } 4 | 5 | class Gtk::TreeSelection 6 | def selected_rows 7 | ret = [] 8 | sel_rows = @ob.GetSelectedRows 9 | sel_rows.each do |tpath| 10 | Gtk.takeob = tpath 11 | ret << Gtk::TreePath.new 12 | end 13 | 14 | return ret 15 | end 16 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/tests/test_trayicon.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/jruby 2 | 3 | require "knj/autoload" 4 | 5 | pixbuf = Gdk::Pixbuf.new("test_trayicon.png") 6 | 7 | icon = Gtk::StatusIcon.new 8 | icon.pixbuf = pixbuf 9 | 10 | icon.signal_connect("activate") do 11 | print "Activate\n" 12 | end 13 | 14 | icon.signal_connect("popup-menu") do 15 | print "Popup-menu\n" 16 | end 17 | 18 | Gtk.main -------------------------------------------------------------------------------- /lib/knj/php_parser/tests/test.rb: -------------------------------------------------------------------------------- 1 | require "knj/autoload" 2 | require "php4r" if !Kernel.const_defined?(:Php4r) 3 | require "#{$knjpath}php_parser/php_parser" 4 | 5 | module Knj::Php_parser::Functions 6 | def self.my_function(phpvar_arg) 7 | Php4r.print("Hejsa.\n") 8 | Php4r.print(phpvar_arg + "\n") 9 | end 10 | end 11 | Knj::Php_parser::Functions.my_function("Helloworld.") 12 | 13 | -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/image.rb: -------------------------------------------------------------------------------- 1 | class Gtk::Image 2 | def initialize(*paras) 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | else 7 | splitted = self.class.to_s.split("::") 8 | @ob = RealGtk.const_get(splitted.last).new(*paras) 9 | end 10 | 11 | if !@ob 12 | raise "Object was not spawned: #{self.class.to_s}" 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_treeview.rb: -------------------------------------------------------------------------------- 1 | class Gtk::TreeView 2 | def selection 3 | if !@selection 4 | Gtk.takeob = @ob.selection 5 | @selection = Gtk::TreeSelection.new 6 | end 7 | 8 | return @selection 9 | end 10 | 11 | def model=(newmodel) 12 | @model = newmodel 13 | @ob.model = newmodel.ob 14 | end 15 | 16 | def model 17 | return @model 18 | end 19 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/builder/test_builder.rb: -------------------------------------------------------------------------------- 1 | require "knj/autoload" 2 | 3 | class TestWindow 4 | def initialize 5 | @gui = Gtk::Builder.new 6 | @gui.add_from_file("test_builder.ui") 7 | @gui.connect_signals(){|h|method(h)} 8 | 9 | @gui["window1"].show_all 10 | end 11 | 12 | def on_window1_destroy 13 | Gtk.main_quit 14 | end 15 | end 16 | 17 | TestWindow.new 18 | 19 | Gtk.main -------------------------------------------------------------------------------- /lib/knj/rand.rb: -------------------------------------------------------------------------------- 1 | #This module is used to handel various random handeling. 2 | module Knj::Rand 3 | #Returns a random integer between the two integers given. 4 | def self.range(first, last) 5 | return first.to_i + rand(last.to_i - first.to_i) 6 | end 7 | 8 | #Returns a random element in the given array. 9 | def self.array(arr) 10 | key = rand(arr.length) 11 | return arr[key] 12 | end 13 | end -------------------------------------------------------------------------------- /lib/knj/php_parser/tests/test_function_run.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "knj/autoload" 4 | include Knj 5 | 6 | parser = Php_parser.new( 7 | "file" => File.dirname(__FILE__) + "/test_function.php" 8 | ) 9 | 10 | begin 11 | cont = parser.parse 12 | rescue RuntimeError => e 13 | print "Retcont:\n#{parser.retcont}\n\n" 14 | print "Cont:\n#{parser.cont}\n\n" 15 | 16 | raise e 17 | end 18 | 19 | print cont + "\n" -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_combobox.rb: -------------------------------------------------------------------------------- 1 | class Gtk::ComboBox 2 | def pack_start(widget, val) 3 | @ob.pack_start(widget.ob, val) 4 | @ob.add_attribute(widget.ob, "text", 0) 5 | end 6 | 7 | def add_attribute(*paras) 8 | #this should not do anything. 9 | end 10 | 11 | def model=(newmodel) 12 | @model = newmodel 13 | @ob.model = newmodel.ob 14 | end 15 | 16 | def model 17 | return @model 18 | end 19 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_liststore.rb: -------------------------------------------------------------------------------- 1 | class Gtk::ListStore 2 | def initialize(*args) 3 | args_cons = [] 4 | args.each do |col_name| 5 | args_cons << System::String.to_clr_type 6 | end 7 | 8 | @ob = RealGtk::ListStore.new(*args_cons) 9 | end 10 | 11 | def append 12 | Gtk.takeob = @ob.append 13 | retob = Gtk::TreeIter.new 14 | retob.liststore = self 15 | 16 | return retob 17 | end 18 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/tests/test_2.rb: -------------------------------------------------------------------------------- 1 | require "knj/autoload" 2 | 3 | class MainWindow 4 | def initialize 5 | button = Gtk::Button.new("Test") 6 | 7 | button.signal_connect("clicked") do 8 | Gtk.main_quit 9 | end 10 | 11 | win = Gtk::Window.new 12 | win.add button 13 | win.show_all 14 | end 15 | 16 | def on_button1_clicked(object, event) 17 | print "hmm\n" 18 | end 19 | end 20 | 21 | main_window = MainWindow.new 22 | Gtk.main -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 2 | $LOAD_PATH.unshift(File.dirname(__FILE__)) 3 | require 'rspec' 4 | require 'knjrbfw' 5 | 6 | # Requires supporting files with custom matchers and macros, etc, 7 | # in ./support/ and its subdirectories. 8 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} 9 | 10 | RSpec.configure do |config| 11 | config.expect_with(:rspec) { |c| c.syntax = :should } 12 | end 13 | -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/button.rb: -------------------------------------------------------------------------------- 1 | Gtk.events["Gtk"]["Button"] = { 2 | "clicked" => "clicked" 3 | } 4 | 5 | class Gtk::Button 6 | def initialize(title = "") 7 | if Gtk.takeob 8 | @ob = Gtk.takeob 9 | Gtk.takeob = nil 10 | else 11 | splitted = self.class.to_s.split("::") 12 | @ob = RealGtk.const_get(splitted.last).new(title) 13 | end 14 | 15 | if !@ob 16 | raise "Object was not spawned: #{self.class.to_s}" 17 | end 18 | end 19 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/label.rb: -------------------------------------------------------------------------------- 1 | class Gtk::Label 2 | def initialize(title = "") 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | else 7 | splitted = self.class.to_s.split("::") 8 | @ob = RealGtk.const_get(splitted.last).new(title) 9 | end 10 | 11 | if !@ob 12 | raise "Object was not spawned: #{self.class.to_s}" 13 | end 14 | end 15 | 16 | def label=(newlabel) 17 | @ob.label_prop = newlabel 18 | end 19 | end -------------------------------------------------------------------------------- /lib/knj/erb/erb_cache_clean.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "knj/autoload" 4 | include Knj 5 | Os.chdir_file(__FILE__) 6 | 7 | curtime = Time.new.to_i 8 | 9 | Dir.new("cache").each do |filename| 10 | if filename != "." and filename != ".." and filename != "README" 11 | fn = "cache/#{filename}" 12 | file = File.new(fn) 13 | mtime = file.mtime.to_i 14 | diftime = curtime - mtime 15 | 16 | if diftime >= (3600 * 48) 17 | File.delete(fn) 18 | end 19 | end 20 | end -------------------------------------------------------------------------------- /lib/knj/rhodes/youtube_embed.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |

<%=_"YouTube embedded"%>

4 | 5 | <%=_("Back")%> 6 |
7 |
8 |
9 | 10 |
11 |
12 |
-------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/eventbutton.rb: -------------------------------------------------------------------------------- 1 | class Gdk::EventButton 2 | def initialize(eventtype) 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | else 7 | splitted = self.class.to_s.split("::") 8 | classname = splitted[splitted.length - 1] 9 | class_spawn = Gtk.evalob("org.gnome.gdk." + classname) 10 | #@ob = class_spawn.new 11 | end 12 | end 13 | 14 | def button 15 | return 2 16 | end 17 | 18 | def time 19 | return 0 20 | end 21 | end -------------------------------------------------------------------------------- /lib/knj/erb/erb.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | def File::realpath(path) 4 | if File.symlink?(path) 5 | return self.realpath(File.readlink(path)) 6 | end 7 | 8 | return path 9 | end 10 | 11 | knjdir = File.dirname(File.realpath(__FILE__)) + "/../" 12 | 13 | require knjdir + "autoload" 14 | require knjdir + "erb/include" 15 | 16 | $knj_eruby = KnjEruby 17 | 18 | filename = ENV["PATH_TRANSLATED"] if ENV and ENV["PATH_TRANSLATED"] 19 | filename = ARGV[0] if ARGV and ARGV[0] 20 | 21 | KnjEruby.load(filename) -------------------------------------------------------------------------------- /lib/knj/tests/test_http2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby1.9.1 2 | 3 | Dir.chdir(File.dirname(__FILE__)) 4 | require "../../knjrbfw.rb" 5 | 6 | require "../autoload" 7 | 8 | http = Http2.new(:host => "www.partyworm.dk", :port => 80, :ssl => false) 9 | resp = http.get(:url => "/?show=frontpage") 10 | resp = http.get(:url => "/?show=login") 11 | 12 | #print "Wee!\n" 13 | #exit 14 | 15 | http = Http2.new(:host => "mexico.balance4u.com", :port => 443, :ssl => true) 16 | resp = http.get(:url => "/") 17 | 18 | Php4r.print_r(http.cookies) -------------------------------------------------------------------------------- /lib/knj/erb/erb_jruby.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/jruby 2 | 3 | def File::realpath(path) 4 | if File.symlink?(path) 5 | return self.realpath(File.readlink(path)) 6 | end 7 | 8 | return path 9 | end 10 | 11 | knjdir = File.dirname(File.realpath(__FILE__)) + "/../" 12 | 13 | require knjdir + "autoload" 14 | require "erubis" 15 | require knjdir + "/erb/include" 16 | 17 | $knj_eruby = KnjEruby 18 | 19 | filename = ENV["PATH_TRANSLATED"] if ENV and ENV["PATH_TRANSLATED"] 20 | filename = ARGV[0] if ARGV and ARGV[0] 21 | 22 | KnjEruby.load(filename) -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/window.rb: -------------------------------------------------------------------------------- 1 | Gtk.events["Gtk"]["Window"] = { 2 | "destroy" => "destroyed" 3 | } 4 | 5 | class Gtk::Window 6 | def initialize(title = "") 7 | if Gtk.takeob 8 | @ob = Gtk.takeob 9 | Gtk.takeob = nil 10 | else 11 | splitted = self.class.to_s.split("::") 12 | @ob = RealGtk.const_get(splitted.last).new(title) 13 | end 14 | 15 | if !@ob 16 | raise "Object was not spawned: #{self.class.to_s}" 17 | end 18 | end 19 | 20 | def add(widget) 21 | @ob.add(widget.ob) 22 | end 23 | end -------------------------------------------------------------------------------- /lib/knj/ip2location.rb: -------------------------------------------------------------------------------- 1 | class Knj::Ip2location 2 | def initialize(args = {}) 3 | @args = args 4 | @http = Knj::Http.new( 5 | "host" => "www.ip2location.com", 6 | "port" => 80 7 | ) 8 | end 9 | 10 | def lookup(ip) 11 | raise "Invalid IP: #{ip}." if !ip.to_s.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) 12 | 13 | html = @http.get("/#{ip}")["data"] 14 | ret = {} 15 | 16 | html.scan(/(.+?)<\/span>/) do |match| 17 | ret[match[0]] = match[1] 18 | end 19 | 20 | return ret 21 | end 22 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/tests/test.glade: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | button 9 | True 10 | True 11 | True 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/knj/fs/drivers/ssh.rb: -------------------------------------------------------------------------------- 1 | class Knj::Fs::Ssh 2 | def self.args 3 | return [ 4 | { 5 | "title" => "Hostname", 6 | "name" => "texhostname" 7 | }, 8 | { 9 | "title" => "Port", 10 | "name" => "texport" 11 | }, 12 | { 13 | "title" => "Username", 14 | "name" => "texusername" 15 | }, 16 | { 17 | "title" => "Password", 18 | "name" => "texpassword", 19 | "type" => "password" 20 | } 21 | ] 22 | end 23 | 24 | def initialize(args) 25 | @args = args 26 | raise "Stub!" 27 | end 28 | end -------------------------------------------------------------------------------- /lib/knj/sysuser.rb: -------------------------------------------------------------------------------- 1 | class Knj::Sysuser 2 | def initialize(data) 3 | @data = data 4 | end 5 | 6 | def self.list(paras = {}) 7 | cont = File.read("/etc/passwd") 8 | 9 | list = [] 10 | cont.split("\n").each do |line| 11 | linearr = line.split(":") 12 | 13 | list << Knj::Sysuser.new( 14 | "nick" => linearr[0], 15 | "home" => linearr[5], 16 | "shell" => linearr[6] 17 | ) 18 | end 19 | 20 | return list 21 | end 22 | 23 | def [](key) 24 | raise "No such key: " + key if !@data.key?(key) 25 | return @data[key] 26 | end 27 | end -------------------------------------------------------------------------------- /lib/knj/rsvgbin.rb: -------------------------------------------------------------------------------- 1 | class Knj::RSVGBIN 2 | def self.test_version 3 | test_version = %x[rsvg-convert -v] 4 | if !test_version.match(/^rsvg-convert version [0-9\.]+$/) 5 | raise "No valid version of rsvg-bin was found." 6 | end 7 | end 8 | 9 | def self.png_content_from_file(file_from) 10 | RSVGBIN.test_version 11 | return %x[rsvg-convert #{Strings.unixsafe(file_from)}] 12 | end 13 | 14 | def self.convert_file(file_from, file_to) 15 | RSVGBIN.test_version 16 | 17 | png_content = RSVGBIN.png_content_from_file(file_from) 18 | Php.file_put_contents(file_to, png_content) 19 | end 20 | end -------------------------------------------------------------------------------- /lib/knj/gettext_fallback.rb: -------------------------------------------------------------------------------- 1 | #A fallback GetText implementation that basically returns the given strings, but can be useful for using methods that uses GetText without using an actual GetText implementation. 2 | module GetText 3 | #Returns the given string. 4 | def self._(string) 5 | return string 6 | end 7 | 8 | #Returns the given string. 9 | def _(string) 10 | return string 11 | end 12 | 13 | #Returns the given string. 14 | def gettext(string) 15 | return string 16 | end 17 | 18 | #Doesnt do anything. 19 | def bindtextdomain(temp1 = nil, temp2 = nil, temp3 = nil) 20 | #nothing here. 21 | end 22 | end -------------------------------------------------------------------------------- /lib/knj/scripts/svn_merge.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require "knj/autoload" 4 | 5 | path_to = ARGV[0] 6 | 7 | Dir.glob(File.join("**", ".svn")).each do |dir| 8 | newdir = path_to + "/" + dir 9 | 10 | #print dir + "\n" 11 | #print newdir + "\n" 12 | 13 | if File.exist?(newdir) 14 | print "Remove: " + newdir.to_s + "\n" 15 | FileUtils.rm_r(newdir) 16 | end 17 | 18 | begin 19 | #print "Move: " + dir + "\n" 20 | #FileUtils.mv(dir, newdir) 21 | 22 | print "Copy: " + dir + "\n" 23 | FileUtils.cp_r(dir, newdir) 24 | rescue => e 25 | print "Failed: " + e.message + "\n" 26 | end 27 | 28 | #print "\n" 29 | end -------------------------------------------------------------------------------- /lib/knj/php_parser/php_parser.rb: -------------------------------------------------------------------------------- 1 | class Knj::Php_parser 2 | attr_reader :cont, :retcont 3 | 4 | def initialize(args) 5 | @args = args 6 | @cont = File.read(@args["file"]) 7 | 8 | if !args.key?("require_requirements") or args["require_requirements"] 9 | @retcont = "require \"knj/autoload\"\n" 10 | @retcont << "require \"php4r\"\n" 11 | @retcont << "require \"knj/php_parser/php_parser\"\n" 12 | @retcont << "\n" 13 | else 14 | @retcont = "" 15 | end 16 | end 17 | end 18 | 19 | require File.dirname(__FILE__) + "/functions.rb" 20 | 21 | module Knj::Php_parser::Functions 22 | #nothing here. 23 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_treeiter.rb: -------------------------------------------------------------------------------- 1 | class Gtk::TreeIter 2 | def initialize(*paras) 3 | if Gtk.takeob 4 | print "TreeIter from takeob.\n" 5 | @ob = Gtk.takeob 6 | Gtk.takeob = nil 7 | else 8 | print "TreeIter from constructor.\n" 9 | @ob = RealGtk::TreeIter.new(*paras) 10 | end 11 | end 12 | 13 | def liststore=(newliststore) 14 | @liststore = newliststore 15 | end 16 | 17 | def []=(key, value) 18 | return @liststore.ob.method(:set_value).overload(RealGtk::TreeIter, Fixnum, System::String).call(@ob, key, value) 19 | end 20 | 21 | def [](key) 22 | return @liststore.ob.get_value(@ob, key) 23 | end 24 | end -------------------------------------------------------------------------------- /lib/knj/includes/appserver_cli.rb: -------------------------------------------------------------------------------- 1 | require "knj/autoload" 2 | require "#{$knjpath}web" 3 | 4 | class Appserver_cli 5 | def self.loadfile(filepath) 6 | require filepath 7 | end 8 | 9 | def self._(str) 10 | return str 11 | end 12 | 13 | def self.gettext 14 | return self 15 | end 16 | 17 | def self.lang_opts 18 | return [] 19 | end 20 | end 21 | 22 | def _kas 23 | return Appserver_cli 24 | end 25 | 26 | def _db 27 | return $db 28 | end 29 | 30 | def _ob 31 | return $ob 32 | end 33 | 34 | autoinc_cli_path = "../include/autoinclude_cli.rb" 35 | if File.exist?(autoinc_cli_path) 36 | require autoinc_cli_path 37 | else 38 | require "../include/autoinclude.rb" 39 | end -------------------------------------------------------------------------------- /lib/knj/knj_controller.rb: -------------------------------------------------------------------------------- 1 | #This files makes the framework able to receive calls from the Rhodes framework from RhoMobile. 2 | class KnjController < Rho::RhoController 3 | #GET /Server 4 | def index 5 | render 6 | end 7 | 8 | def html_links 9 | System.open_url(@params["url"]) 10 | end 11 | 12 | def callback 13 | block = $rhodes.callbacks(@params["callback_id"]) 14 | block.call(:params => @params) 15 | end 16 | 17 | def youtube_embed 18 | @iframe_height = System.get_property("screen_height").to_i - 40 19 | render :file => "Knj/rhodes/youtube_embed.erb" 20 | end 21 | 22 | def youtube_open 23 | render :file => "Knj/rhodes/youtube_open.erb" 24 | end 25 | end -------------------------------------------------------------------------------- /lib/knj/csv.rb: -------------------------------------------------------------------------------- 1 | #Contains various methods for handeling CSV-stuff. 2 | class Knj::Csv 3 | #Converts a given array to a CSV-string. 4 | #===Examples 5 | # str = Knj::Csv.arr_to_csv([1, 2, 3], ";", "'") #=> "'1';'2';'3'\n" 6 | def self.arr_to_csv(arr, del, encl) 7 | raise "No delimiter given." if !del 8 | raise "No enclosure given." if !encl 9 | 10 | str = "" 11 | first = true 12 | arr.each do |val| 13 | if first 14 | first = false 15 | else 16 | str << del 17 | end 18 | 19 | val = val.to_s.encode("utf-8").gsub(del, "").gsub(encl, "") 20 | str << "#{encl}#{val}#{encl}" 21 | end 22 | 23 | str << "\n" 24 | 25 | return str 26 | end 27 | end -------------------------------------------------------------------------------- /lib/knj/fs/drivers/ftp.rb: -------------------------------------------------------------------------------- 1 | class Knj::Fs::Ftp 2 | def self.args 3 | return [ 4 | { 5 | "title" => "Hostname", 6 | "name" => "texhost" 7 | }, 8 | { 9 | "title" => "Port", 10 | "name" => "texport" 11 | }, 12 | { 13 | "title" => "Username", 14 | "name" => "texusername" 15 | }, 16 | { 17 | "title" => "Password", 18 | "name" => "texpassword", 19 | "type" => "password" 20 | }, 21 | { 22 | "title" => "Passive?", 23 | "name" => "chepassive", 24 | "type" => "checkbox" 25 | } 26 | ] 27 | end 28 | 29 | def initialize(args) 30 | @args = args 31 | raise "Stub!" 32 | end 33 | end -------------------------------------------------------------------------------- /lib/knj/tests/test_http2_proxy.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby1.9.1 2 | 3 | require "#{File.dirname(__FILE__)}/../../knjrbfw.rb" 4 | require "knj/autoload" 5 | 6 | proxy_settings = Marshal.load(File.read("#{File.dirname(__FILE__)}/test_http2_proxy_settings.marshal")) 7 | 8 | http = Http2.new( 9 | :host => "www.partyworm.dk", 10 | :proxy => proxy_settings 11 | ) 12 | 13 | urls = [ 14 | "?show=users_search", 15 | "?show=users_online", 16 | "?show=drinksdb", 17 | "?show=forum&fid=9&tid=1917&page=0" 18 | ] 19 | urls = ["robots.txt"] 20 | 21 | 0.upto(105) do |count| 22 | url = urls[rand(urls.size)] 23 | print "Doing request #{count} of 200 (#{url}).\n" 24 | res = http.get(:url => url) 25 | raise "Body was empty." if res.body.to_s.length <= 0 26 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/combobox.rb: -------------------------------------------------------------------------------- 1 | class Gtk::ComboBox 2 | def pack_start(widget, arg1, arg2 = false) 3 | #widget is useually a Gtk::CellRendererText which is started by this way in Java GTK. 4 | @renderer = widget 5 | widget.init(self) 6 | 7 | if self.model 8 | widget.text = self.model.dcol[0] 9 | @renderer_set = true 10 | end 11 | end 12 | 13 | def add_attribute(arg1, arg2, arg3) 14 | #do nothing - this method does not exist on Java GTK's ComboBox. 15 | end 16 | 17 | def model=(newmodel) 18 | @model = newmodel 19 | @ob.model = newmodel.ob 20 | 21 | if !@renderer_set 22 | @renderer.text = self.model.dcol[0] 23 | end 24 | end 25 | 26 | def model 27 | return @model 28 | end 29 | end -------------------------------------------------------------------------------- /lib/knj/tests/test_mount.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | Dir.chdir(File.dirname(__FILE__)) 4 | require "../autoload" 5 | 6 | print "Listing all mounts.\n" 7 | mounts = Knj::Mount.list 8 | mounts.each do |mount| 9 | Php4r.print_r(mount.data) 10 | print "Access: #{mount.access?}\n\n" 11 | end 12 | 13 | mounts = Knj::Mount.list("from_search" => "test_dir") 14 | mounts.each do |mount| 15 | print "Unmounting test_dir.\n" 16 | mount.umount 17 | end 18 | 19 | print "Mount binding test_dir to test_dir_to.\n" 20 | Knj::Mount.mount( 21 | "from" => "test_dir", 22 | "to" => "test_dir_to", 23 | "bind" => true 24 | ) 25 | 26 | mounts = Knj::Mount.list("from_search" => "test_dir") 27 | mounts.each do |mount| 28 | print "Unmounting test_dir.\n" 29 | mount.umount 30 | end -------------------------------------------------------------------------------- /lib/knj/power_manager.rb: -------------------------------------------------------------------------------- 1 | class Knj::Power_manager 2 | def initialize(args = {}) 3 | @args = args 4 | 5 | if !File.exist?("/proc/acpi/ac_adapter") 6 | raise "Could not find the proc-acpi folder." 7 | end 8 | 9 | Dir.new("/proc/acpi/ac_adapter").each do |file| 10 | next if file == "." or file == ".." 11 | fn = "/proc/acpi/ac_adapter/#{file}" 12 | 13 | if File.directory?(fn) 14 | @ac_folder = Php4r.realpath(fn) 15 | break 16 | end 17 | end 18 | 19 | raise "Could not register ac-folder." if !@ac_folder 20 | end 21 | 22 | def state 23 | cont = File.read("#{@ac_folder}/state") 24 | 25 | if match = cont.match(/state:\s*(.+)\s*/) 26 | return match[1] 27 | end 28 | 29 | raise "Could not figure out state." 30 | end 31 | end -------------------------------------------------------------------------------- /lib/knj/thread.rb: -------------------------------------------------------------------------------- 1 | #This class behaves like a normal thread - but it shows error-messages and tracebacks. Normal threads dont do that. 2 | class Knj::Thread < Thread 3 | attr_accessor :data 4 | 5 | #Initializes the thread and passes any given arguments to the thread-block. 6 | def initialize(*args) 7 | raise "No block was given." unless block_given? 8 | 9 | super(*args) do 10 | begin 11 | yield(*args) 12 | rescue SystemExit, Interrupt 13 | raise 14 | rescue Exception => e 15 | print "#{Knj::Errors.error_str(e)}\n\n" 16 | end 17 | end 18 | 19 | @data = {} 20 | end 21 | 22 | #Returns a key from the data-hash. 23 | def [](key) 24 | return @data[key] 25 | end 26 | 27 | #Sets a key on the data-hash. 28 | def []=(key, value) 29 | return @data[key] = value 30 | end 31 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/builder.rb: -------------------------------------------------------------------------------- 1 | class Gtk::Builder 2 | def initialize 3 | 4 | end 5 | 6 | def add_from_file(filename) 7 | cont = File.read(filename).gsub("", "").gsub("", "") 8 | cont = cont.gsub("", "") 9 | cont = cont.gsub("", "") 10 | cont = cont.gsub("", "") 11 | cont = cont.gsub("", "") 12 | cont = cont.gsub("", "") 13 | 14 | @glade = GladeXML.new(cont) 15 | end 16 | 17 | def connect_signals(&block) 18 | @glade.block = block 19 | @glade.auto_connect(@glade.data) 20 | end 21 | 22 | def [](key) 23 | return @glade[key] 24 | end 25 | 26 | alias get_object [] 27 | end -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | = knjrbfw 2 | 3 | Description goes here. 4 | 5 | == Contributing to knjrbfw 6 | 7 | * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet 8 | * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it 9 | * Fork the project 10 | * Start a feature/bugfix branch 11 | * Commit and push until you are happy with your contribution 12 | * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. 13 | * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. 14 | 15 | == Copyright 16 | 17 | Copyright (c) 2011 Kasper Johansen. See LICENSE.txt for 18 | further details. 19 | 20 | -------------------------------------------------------------------------------- /spec/amixer_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Amixer" do 4 | it "should load by using autoload" do 5 | if Knj::Os.os == "linux" 6 | require "knjrbfw" 7 | $amixer = Knj::Amixer.new 8 | end 9 | end 10 | 11 | it "should register various devices" do 12 | if Knj::Os.os == "linux" 13 | $devices = $amixer.devices 14 | end 15 | end 16 | 17 | it "should register various mixers and do various operations on them" do 18 | if Knj::Os.os == "linux" 19 | $devices.each do |name, device| 20 | mixers = device.mixers 21 | 22 | if device.active?(:stream => "PLAYBACK") 23 | mixers.each do |name, mixer| 24 | next if !mixer.volume? 25 | mixer.vol_add -5 26 | mixer.vol_add 3 27 | end 28 | end 29 | end 30 | end 31 | end 32 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_builder.rb: -------------------------------------------------------------------------------- 1 | class Gtk::Builder 2 | def initialize 3 | 4 | end 5 | 6 | def add_from_file(filename) 7 | cont = File.read(filename).gsub("", "").gsub("", "") 8 | cont = cont.gsub("", "") 9 | cont = cont.gsub("", "") 10 | cont = cont.gsub("", "") 11 | cont = cont.gsub("", "") 12 | cont = cont.gsub("", "") 13 | 14 | @glade = GladeXML.new(cont) 15 | end 16 | 17 | def connect_signals(&block) 18 | @glade.block = block 19 | @glade.auto_connect(@glade.data) 20 | end 21 | 22 | def [](key) 23 | return @glade[key] 24 | end 25 | 26 | alias get_object [] 27 | 28 | def objects 29 | return [] 30 | end 31 | end -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'rubygems' 4 | require 'bundler' 5 | begin 6 | Bundler.setup(:default, :development) 7 | rescue Bundler::BundlerError => e 8 | $stderr.puts e.message 9 | $stderr.puts "Run `bundle install` to install missing gems" 10 | exit e.status_code 11 | end 12 | require 'rake' 13 | 14 | require 'rspec/core' 15 | require 'rspec/core/rake_task' 16 | RSpec::Core::RakeTask.new(:spec) do |spec| 17 | spec.pattern = FileList['spec/**/*_spec.rb'] 18 | end 19 | 20 | RSpec::Core::RakeTask.new(:rcov) do |spec| 21 | spec.pattern = 'spec/**/*_spec.rb' 22 | spec.rcov = true 23 | end 24 | 25 | task :default => :spec 26 | 27 | require 'rdoc/task' 28 | Rake::RDocTask.new do |rdoc| 29 | version = File.exist?('VERSION') ? File.read('VERSION') : "" 30 | 31 | rdoc.rdoc_dir = 'rdoc' 32 | rdoc.title = "knjrbfw #{version}" 33 | rdoc.rdoc_files.include('README*') 34 | rdoc.rdoc_files.include('lib/**/*.rb') 35 | end 36 | -------------------------------------------------------------------------------- /lib/knj/fs/fs.rb: -------------------------------------------------------------------------------- 1 | class Knj::Fs 2 | @drivers = [] 3 | drivers_path = Php4r.realpath("#{File.dirname(__FILE__)}/drivers") 4 | Dir.new(drivers_path).each do |file| 5 | fn = "#{drivers_path}/#{file}" 6 | next if file == "." or file == ".." or File.directory?(fn) 7 | 8 | class_name = Php4r.ucwords(file.slice(0..-4)).to_sym 9 | print "Classname: #{class_name}\n" 10 | autoload class_name, fn 11 | 12 | @drivers << { 13 | :name => file.slice(0..-4), 14 | :args => const_get(class_name).args 15 | } 16 | end 17 | 18 | def self.drivers 19 | return @drivers 20 | end 21 | 22 | def initialize(args = {}) 23 | @args = args 24 | end 25 | 26 | def spawn_driver 27 | class_name = Php4r.ucwords(@args[:driver]) 28 | @driver = self.class.const_get(class_name).new(:fs => self, :args => @args) 29 | end 30 | end 31 | 32 | class Knj::Fs::File 33 | def initialize 34 | 35 | end 36 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/gtk_treeviewcolumn.rb: -------------------------------------------------------------------------------- 1 | class Gtk::TreeViewColumn 2 | def initialize(title, renderer, *paras) 3 | @title = title 4 | @renderer = renderer 5 | 6 | if Gtk.takeob 7 | @ob = Gtk.takeob 8 | if !@ob 9 | raise "Gtk.takeob was not set correctly: " + @ob.class.to_s 10 | end 11 | 12 | Gtk.takeob = nil 13 | else 14 | splitted = self.class.to_s.split("::") 15 | realclass = "Real#{splitted.first}" 16 | classob = Kernel.const_get(realclass).const_get(splitted.last) 17 | 18 | if !classob 19 | raise "Class does not exist: " + realclass + "::" + splitted.last 20 | end 21 | 22 | @ob = classob.new 23 | 24 | if !@ob 25 | raise "Object was not spawned: #{self.class.to_s}, #{@ob.class.to_s}, #{realclass}::#{splitted.last}" 26 | end 27 | 28 | @ob.pack_start(renderer.ob, true) 29 | #@ob.add_attribute(renderer.ob, "text", 0) 30 | end 31 | end 32 | end -------------------------------------------------------------------------------- /lib/knj/exchangerates.rb: -------------------------------------------------------------------------------- 1 | class Knj::Exchangerates 2 | attr_reader :rates 3 | 4 | def initialize(args = {}) 5 | @rates = {} 6 | end 7 | 8 | def base=(data) 9 | @base = data[:locale].to_s 10 | self.add_rate(data) 11 | end 12 | 13 | def add_rate(data) 14 | if !data[:locale] or data[:locale].to_s.length <= 0 15 | raise "Invalid locale given." 16 | end 17 | 18 | @rates[data[:locale].to_s] = data 19 | end 20 | 21 | def value(locale, floatval) 22 | floatval = floatval.to_f 23 | locale = locale.to_s 24 | 25 | raise "No such locale: '#{locale}' in '#{@rates.keys.join(",")}'." if !@rates.key?(locale) 26 | 27 | base_rate = @rates[@base][:rate].to_f 28 | cur_rate = @rates[locale][:rate].to_f 29 | 30 | if base_rate == cur_rate 31 | return floatval 32 | elsif cur_rate < base_rate 33 | diff = 1 + (base_rate - cur_rate) 34 | return floatval * diff 35 | else 36 | return floatval / cur_rate 37 | end 38 | end 39 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/menu.rb: -------------------------------------------------------------------------------- 1 | class Gtk::Menu 2 | def initialize 3 | if Gtk.takeob 4 | @ob = Gtk.takeob 5 | Gtk.takeob = nil 6 | else 7 | splitted = self.class.to_s.split("::") 8 | classname = splitted[splitted.length - 1] 9 | class_spawn = Gtk.evalob("org.gnome.gtk." + classname) 10 | @ob = class_spawn.new 11 | end 12 | end 13 | 14 | def popup(arg1, arg2, event_button, event_time) 15 | @ob.popup 16 | end 17 | 18 | def prepend(object) 19 | @ob.prepend(object.ob) 20 | end 21 | end 22 | 23 | class Gtk::MenuItem 24 | def initialize(title) 25 | if Gtk.takeob 26 | @ob = Gtk.takeob 27 | Gtk.takeob = nil 28 | else 29 | splitted = self.class.to_s.split("::") 30 | classname = splitted[splitted.length - 1] 31 | class_spawn = Gtk.evalob("org.gnome.gtk." + classname) 32 | 33 | if title 34 | @ob = class_spawn.new(title) 35 | else 36 | @ob = class_spawn.new 37 | end 38 | end 39 | end 40 | end -------------------------------------------------------------------------------- /lib/knj/youtube.rb: -------------------------------------------------------------------------------- 1 | class Knj::YouTube 2 | def self.all_videos(data, params = {}, opts = {}) 3 | params[:per_page] = 50 4 | 5 | ret_arr = [] 6 | go_through_pages = true 7 | page = 1 8 | while go_through_pages 9 | #print "Getting page #{page.to_s}\n" 10 | 11 | newparams = Marshal.load(Marshal.dump(params)) 12 | newparams[:page] = page 13 | videos = data["youtube"].videos_by(newparams) 14 | 15 | videos.videos.each do |video| 16 | if data["check_stop"] and data["check_stop"].respond_to?("check_stop_parsing") 17 | if data["check_stop"].check_stop_parsing(video) 18 | go_through_pages = false 19 | break 20 | end 21 | end 22 | 23 | ret_arr << video 24 | end 25 | 26 | status = videos.next_page 27 | break if !status 28 | 29 | page += 1 30 | break if data["pages"] and page > data["pages"].to_i 31 | end 32 | 33 | return ret_arr 34 | end 35 | end -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # rcov generated 2 | coverage 3 | 4 | # rdoc generated 5 | rdoc 6 | 7 | # yard generated 8 | doc 9 | .yardoc 10 | 11 | # bundler 12 | .bundle 13 | 14 | *.gem 15 | 16 | # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: 17 | # 18 | # * Create a file at ~/.gitignore 19 | # * Include files you want ignored 20 | # * Run: git config --global core.excludesfile ~/.gitignore 21 | # 22 | # After doing this, these files will be ignored in all your git projects, 23 | # saving you from having to 'pollute' every project you touch with them 24 | # 25 | # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line) 26 | # 27 | # For MacOS: 28 | # 29 | #.DS_Store 30 | 31 | # For TextMate 32 | #*.tmproj 33 | #tmtags 34 | 35 | # For emacs: 36 | #*~ 37 | #\#* 38 | #.\#* 39 | 40 | # For vim: 41 | #*.swp 42 | 43 | # For redcar: 44 | #.redcar 45 | 46 | # For rubinius: 47 | #*.rbc 48 | 49 | lib/knj/tests/test_http2_proxy_settings.marshal 50 | -------------------------------------------------------------------------------- /lib/knj/scripts/upgrade_knjrbfw_checker.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "knj/autoload" 4 | 5 | mode = ARGV[0] 6 | 7 | if mode.to_s.length <= 0 8 | print "No mode was given.\n" 9 | exit 10 | elsif mode != "dev" and mode != "original" 11 | print "Invalid mode: #{mode}\n" 12 | exit 13 | end 14 | 15 | checks = [ 16 | "/usr/share/php/knjphpframework", 17 | "/usr/lib/ruby/1.8/knjrbfw" 18 | ] 19 | 20 | checks.each do |dir| 21 | dev_name = dir + "_dev" 22 | original_name = dir + "_original" 23 | 24 | if mode == "dev" 25 | if File.exist?(dir) and File.symlink?(dir) 26 | #do nothing. 27 | elsif File.exist?(dir) and !File.exist?(original_name) 28 | File.rename(dir, original_name) 29 | File.rename(dev_name, dir) 30 | end 31 | elsif mode == "original" 32 | if File.exist?(dir) and File.exist?(original_name) and File.symlink?(dir) 33 | File.rename(dir, dev_name) 34 | File.rename(original_name, dir) 35 | else 36 | #do nothing. 37 | end 38 | else 39 | raise "No such mode: #{mode}" 40 | end 41 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/tests/test_ironruby_window.rb: -------------------------------------------------------------------------------- 1 | require "gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" 2 | require "glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" 3 | 4 | RealGtk = Gtk 5 | RealGtk::Application.init 6 | 7 | Gtk = Class.new do 8 | class Window 9 | def initialize(title = "") 10 | @ob = RealGtk::Window.new(title) 11 | end 12 | 13 | def add(widget) 14 | @ob.add(widget.ob) 15 | end 16 | 17 | def show_all 18 | @ob.show_all 19 | end 20 | end 21 | 22 | class Button 23 | def initialize(title = nil) 24 | @ob = RealGtk::Button.new(title) 25 | end 26 | 27 | def ob 28 | return @ob 29 | end 30 | 31 | def signal_connect(signal, &block) 32 | @ob.send(signal) do |sender, e| 33 | block.call 34 | end 35 | end 36 | end 37 | 38 | def self.main 39 | RealGtk::Application.run 40 | end 41 | 42 | def self.main_quit 43 | RealGtk::Application.quit 44 | end 45 | end 46 | 47 | require "test_2.rb" -------------------------------------------------------------------------------- /spec/cmd_parser_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Cmd_parser" do 4 | it "should be able to parse various strings" do 5 | require "knjrbfw" 6 | require "knj/cmd_parser" 7 | require "php4r" if !Kernel.const_defined?(:Php4r) 8 | 9 | strs = [ 10 | "-rw-r--r-- 1 admin administ 186.3M Aug 30 18:09 b4u_synoptik_2011_08_30_17_57_32.sql.gz\n", 11 | "-rw-r--r-- 1 admin administ 2 Nov 21 18:12 test\n", 12 | "-rw-r--r-- 1 kaspernj kaspernj 279943393 2011-07-27 09:28 dbdump_2011_07_27_03_07_36.sql\n", 13 | "-rw-rw-r-- 1 kaspernj kaspernj 58648 2011-10-28 18:33 2011-11-28 - Programmerings aften hos Anders - mad - 600 kr.pdf\n", 14 | "-rw-r--r-- 1 www-data www-data 4,0K 2011-05-16 23:21 dbbackup_2011_05_16-23:21:10.sql.gz\n" 15 | ] 16 | 17 | strs.each do |str| 18 | res = Knj::Cmd_parser.lsl(str) 19 | 20 | res.each do |file| 21 | raise "Byte was not numeric in: '#{str}'." if !(Float(file[:size]) rescue false) 22 | end 23 | end 24 | end 25 | end -------------------------------------------------------------------------------- /lib/knj/gtk2_msgbox.rb: -------------------------------------------------------------------------------- 1 | #This class holds various methods for message-box-functionality and debugging. 2 | class Knj::Gtk2::Msgbox 3 | #This hash contains various data like the currently shown message-box. 4 | DATA = {} 5 | 6 | #Returns the label of the currently shown message-box. 7 | def self.cur_label 8 | raise "No message-box currentl shown." if !Knj::Gtk2::Msgbox::DATA[:current] 9 | return Knj::Gtk2::Msgbox::DATA[:current].children.first.children.first.children.last.label 10 | end 11 | 12 | #Send a response to the currently shown message-box. 13 | def self.cur_respond(response) 14 | raise "No message-box currentl shown." if !Knj::Gtk2::Msgbox::DATA[:current] 15 | id = Knj::Gtk2::Msgbox::DATA[:current].__id__ 16 | Knj::Gtk2::Msgbox::DATA[:current].response(response) 17 | Thread.pass while Knj::Gtk2::Msgbox::DATA[:current] and Knj::Gtk2::Msgbox::DATA[:current].__id__ == id 18 | nil 19 | end 20 | 21 | #Returns true if a message-box is currently shown. 22 | def self.shown? 23 | return true if Knj::Gtk2::Msgbox::DATA[:current] 24 | return false 25 | end 26 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/tests/test_glade_window.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/jruby 2 | 3 | require "knj/autoload" 4 | require "#{$knjpath}gtk2_tv" 5 | 6 | class WinAppEdit 7 | def initialize 8 | print "Loading Glade.\n" 9 | @glade = GladeXML.new("test_glade_window.glade"){|h|method(h)} 10 | print "Done loading glade.\n" 11 | 12 | @glade["tvTest"].selection.signal_connect("changed") do 13 | print "test\n" 14 | end 15 | 16 | @glade["tvTest"].init(["ID", "Title"]) 17 | @glade["tvTest"].append(["Test1", "Test2"]) 18 | 19 | @glade["window"].show_all 20 | end 21 | 22 | def on_tvTest_row_activated 23 | #print "Test\n" 24 | end 25 | 26 | def on_btnSave_clicked(arg1) 27 | print arg1.to_s + "\n" 28 | print "Save clicked.\n" 29 | 30 | val = @glade["tvTest"].sel 31 | Php4r.print_r(val) 32 | end 33 | 34 | def on_btnCancel_clicked 35 | print "Cancel clicked.\n" 36 | end 37 | 38 | def on_window_destroy 39 | print "Destroyed!\n" 40 | Gtk.main_quit 41 | end 42 | end 43 | 44 | print "Starting app.\n" 45 | WinAppEdit.new 46 | 47 | Gtk.main -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Kasper Johansen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /lib/knj/nvidia_settings.rb: -------------------------------------------------------------------------------- 1 | class Knj::Nvidia_settings 2 | attr_reader :data 3 | 4 | def initialize(data = {}) 5 | @data = data 6 | @power_mizer_modes = { 7 | "adaptive" => 0, 8 | "performance" => 1 9 | } 10 | end 11 | 12 | def self.list(args = {}) 13 | res = Knj::Os.shellcmd("nvidia-settings -q gpus") 14 | ret = [] 15 | 16 | res.scan(/\[gpu:(\d+)\]/) do |gpu| 17 | ret << Knj::Nvidia_settings.new(args.merge({ 18 | "gpu_no" => gpu[0] 19 | })) 20 | end 21 | 22 | return ret 23 | end 24 | 25 | def power_mizer_mode=(newval) 26 | raise "No such power-mizer-mode." if @power_mizer_modes[newval] == nil 27 | 28 | cmd = "nvidia-settings -a [gpu:#{@data["gpu_no"]}]/GPUPowerMizerMode=#{@power_mizer_modes[newval]}" 29 | res = Knj::Os.shellcmd(cmd) 30 | 31 | if res.index("assigned value") == nil 32 | raise res.strip 33 | end 34 | end 35 | 36 | def extra_args 37 | str = "" 38 | 39 | if @data["display"] 40 | str << " --display #{@data["display"]}" 41 | end 42 | 43 | return str 44 | end 45 | end -------------------------------------------------------------------------------- /lib/knj/thread2.rb: -------------------------------------------------------------------------------- 1 | class Knj::Thread2 2 | def initialize(args = {}, &block) 3 | @args = args 4 | @block = block if block_given? 5 | @callbacks = {} 6 | end 7 | 8 | def connect(signal, &block) 9 | @callbacks[signal] = [] if !@callbacks.key?(signal) 10 | @callbacks[signal] << block 11 | end 12 | 13 | def call(signal, *args) 14 | return false if !@callbacks.key?(signal) 15 | @callbacks[signal].each do |block| 16 | block.call(*args) 17 | end 18 | 19 | return {:count => count} 20 | end 21 | 22 | def run 23 | Thread.new do 24 | abort_on_exception = true 25 | call(:on_run) 26 | 27 | begin 28 | @block.call 29 | rescue SystemExit 30 | call(:on_exit) 31 | exit 32 | rescue => e 33 | call(:on_error, e) 34 | 35 | if !@args.key?(:print_error) or @args[:print_error] 36 | print "Error: " 37 | puts e.inspect 38 | print "\n" 39 | puts e.backtrace 40 | print "\n\n" 41 | end 42 | end 43 | 44 | call(:on_done) 45 | end 46 | end 47 | end -------------------------------------------------------------------------------- /lib/knj/notify.rb: -------------------------------------------------------------------------------- 1 | #This class can be used to send notify-messages through the notify-binary (notify-send or kdialog). 2 | class Knj::Notify 3 | #Call this method to show notifications. 4 | #===Examples 5 | # Knj::Notify.send("msg" => "Hello world!", "time" => 5) 6 | def self.send(args) 7 | begin 8 | toolkit = Knj::Os.toolkit 9 | rescue 10 | toolkit = "" 11 | end 12 | 13 | if toolkit == "kde" 14 | cmd = "kdialog --passivepopup #{Knj::Strings.unixsafe(args["msg"])}" 15 | 16 | if args["title"] 17 | cmd << " --title #{Knj::Strings.unixsafe(args["msg"])}" 18 | end 19 | 20 | if args["time"] 21 | cmd << " #{Knj::Strings.unixsafe(args["time"])}" 22 | end 23 | 24 | system(cmd) 25 | else 26 | cmd = "notify-send" 27 | 28 | if args["time"] 29 | raise "Time is not numeric." if !(Float(args["time"]) rescue false) 30 | cmd << " -t #{args["time"]}" 31 | end 32 | 33 | cmd << " #{Knj::Strings.unixsafe(args["title"])} #{Knj::Strings.unixsafe(args["msg"])}" 34 | system(cmd) 35 | end 36 | end 37 | end -------------------------------------------------------------------------------- /lib/knj/erb/erb_fcgi.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | def File::realpath(path) 4 | if File.symlink?(path) 5 | return self.realpath(File.readlink(path)) 6 | end 7 | 8 | return path 9 | end 10 | 11 | require File.dirname(File.realpath(__FILE__)) + "/../autoload" 12 | 13 | $_FCGI_COUNT = 0 14 | require File.dirname(File.realpath(__FILE__)) + "/include" 15 | $knj_eruby = KnjEruby 16 | FCGI.each_cgi do |fcgi| 17 | $_FCGI_COUNT += 1 18 | $_CGI = fcgi 19 | $_FCGI = fcgi 20 | 21 | loadfp = File.dirname(__FILE__) + "/" + File.basename(__FILE__).slice(0..-6) + ".rhtml" 22 | 23 | begin 24 | KnjEruby.fcgi = fcgi 25 | KnjEruby.load(loadfp) 26 | 27 | if KnjEruby.connects["exit"] 28 | KnjEruby.connects["exit"].each do |block| 29 | block.call 30 | end 31 | end 32 | 33 | if $_FCGI_EXIT 34 | #Kill self! Need to start a new thread because the app as to finish. Give it 0.1 second to do that before killing it. 35 | Thread.new do 36 | sleep 0.5 37 | Process.kill(9, Process.pid) 38 | end 39 | end 40 | rescue Exception => e 41 | puts e.inspect 42 | puts e.backtrace 43 | end 44 | end -------------------------------------------------------------------------------- /lib/knj/erb/erb_fcgi_1.9.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby1.9 2 | 3 | def File::realpath(path) 4 | if File.symlink?(path) 5 | return self.realpath(File.readlink(path)) 6 | end 7 | 8 | return path 9 | end 10 | 11 | require File.dirname(File.realpath(__FILE__)) + "/../autoload" 12 | 13 | $_FCGI_COUNT = 0 14 | require File.dirname(File.realpath(__FILE__)) + "/include" 15 | $knj_eruby = KnjEruby 16 | FCGI.each_cgi do |fcgi| 17 | $_FCGI_COUNT += 1 18 | $_CGI = fcgi 19 | $_FCGI = fcgi 20 | 21 | loadfp = File.dirname(__FILE__) + "/" + File.basename(__FILE__).slice(0..-6) + ".rhtml" 22 | 23 | begin 24 | KnjEruby.fcgi = fcgi 25 | KnjEruby.load(loadfp) 26 | 27 | if KnjEruby.connects["exit"] 28 | KnjEruby.connects["exit"].each do |block| 29 | block.call 30 | end 31 | end 32 | 33 | if $_FCGI_EXIT 34 | #Kill self! Need to start a new thread because the app as to finish. Give it 0.1 second to do that before killing it. 35 | Thread.new do 36 | sleep 0.5 37 | Process.kill(9, Process.pid) 38 | end 39 | end 40 | rescue Exception => e 41 | puts e.inspect 42 | puts e.backtrace 43 | end 44 | end -------------------------------------------------------------------------------- /lib/knj/x11vnc.rb: -------------------------------------------------------------------------------- 1 | class Knj::X11VNC 2 | def initialize(args = {}) 3 | @args = ArrayExt.hash_sym(args) 4 | @open = true 5 | 6 | cmd = "x11vnc -q" 7 | cmd << " -shared" if @args[:shared] or !@args.key?(:shared) 8 | cmd << " -forever" if @args[:forever] or !@args.key?(:forever) 9 | cmd << " -rfbport #{@args[:port]}" if @args[:port] 10 | cmd << " -nolookup" if @args[:nolookup] or !@args.key?(:nolookup) 11 | 12 | print cmd + "\n" 13 | 14 | @thread = Knj::Thread.new do 15 | IO.popen(cmd) do |process| 16 | @pid = process.pid 17 | process.sync 18 | 19 | while read = process.read 20 | break if read.length == 0 21 | #print read 22 | end 23 | 24 | @open = false 25 | @pid = nil 26 | @thread = nil 27 | end 28 | end 29 | 30 | Kernel.at_exit do 31 | self.close 32 | end 33 | end 34 | 35 | def open? 36 | return @open 37 | end 38 | 39 | def close 40 | return nil if !@thread 41 | 42 | Process.kill("HUP", @pid) if @pid 43 | @thread.exit if @thread 44 | @thread = nil 45 | @open = false 46 | @pid = nil 47 | end 48 | end -------------------------------------------------------------------------------- /lib/knj/hash_methods.rb: -------------------------------------------------------------------------------- 1 | #A normal hash that uses 'method_missing' to be able to call keys by using methods. It is heavily used by Knj::Objects and have some pre-defined methods because of it to optimize performance. 2 | #===Examples 3 | # hm = Knj::Hash_methods(:test => "Test") 4 | # print hm.test 5 | class Knj::Hash_methods < Hash 6 | #Spawns the object and takes a hash as argument. 7 | def initialize(hash = {}) 8 | self.update(hash) 9 | end 10 | 11 | #Returns the db-key. 12 | def db 13 | return self[:db] 14 | end 15 | 16 | #Returns the ob-key. 17 | def ob 18 | return self[:ob] 19 | end 20 | 21 | #Returns the args-key. 22 | def args 23 | return self[:args] 24 | end 25 | 26 | #Returns the data-key. 27 | def data 28 | return self[:data] 29 | end 30 | 31 | def to_hash 32 | h = {} 33 | self.each do |key, val| 34 | h[k] = val 35 | end 36 | 37 | return h 38 | end 39 | 40 | #Proxies methods into the hash as keys. 41 | def method_missing(method, *args) 42 | method = method.to_sym 43 | return self[method] if self.key?(method) 44 | 45 | raise "No such method '#{method}' on class '#{self.class.name}'" 46 | end 47 | end -------------------------------------------------------------------------------- /lib/knj/jruby-gtk2/dialog.rb: -------------------------------------------------------------------------------- 1 | Gtk.events << ["Dialog", "response", org.gnome.gtk.Dialog::Response, :onResponse, nil] 2 | 3 | class Gtk::Dialog 4 | RESPONSE_OK = org.gnome.gtk.ResponseType::OK 5 | RESPONSE_YES = org.gnome.gtk.ResponseType::YES 6 | RESPONSE_NO = org.gnome.gtk.ResponseType::NO 7 | RESPONSE_CANCEL = org.gnome.gtk.ResponseType::CANCEL 8 | RESPONSE_CLOSE = org.gnome.gtk.ResponseType::CLOSE 9 | RESPONSE_DELETE_EVENT = org.gnome.gtk.ResponseType::DELETE_EVENT 10 | MODAL = true 11 | 12 | def initialize(title = nil, win_parent = nil, modal = nil, *buttons) 13 | if Gtk.takeob 14 | @ob = Gtk.takeob 15 | Gtk.takeob = nil 16 | else 17 | @ob = Gtk.evalob("org.gnome.gtk.Dialog").new(title, win_parent, modal) 18 | 19 | buttons.each do |button| 20 | self.add_button(button[0], button[1]) 21 | end 22 | 23 | self.signal_connect("response") do 24 | self.destroy 25 | end 26 | end 27 | end 28 | 29 | def vbox 30 | return self 31 | end 32 | 33 | def has_separator=(newval) 34 | # FIXME: No way to do this in Java-GTK? 35 | end 36 | 37 | def destroy 38 | if @ob 39 | @ob.hide 40 | end 41 | 42 | @ob = nil 43 | end 44 | end -------------------------------------------------------------------------------- /lib/knj/mutexcl.rb: -------------------------------------------------------------------------------- 1 | class Knj::Mutexcl 2 | def initialize(args = {}) 3 | @args = args 4 | raise "No ':modes' given in arguments." if !@args.key?(:modes) 5 | @mutex = Mutex.new 6 | @blocked = {} 7 | @args[:modes].each do |mode, data| 8 | data[:blocks].each do |block| 9 | @blocked[block] = { 10 | :mutex => Mutex.new, 11 | :count => 0 12 | } 13 | end 14 | end 15 | end 16 | 17 | def self.rw 18 | return Knj::Mutexcl.new( 19 | :modes => { 20 | :reader => {:blocks => [:writer]}, 21 | :writer => {:blocks => [:writer, :reader]} 22 | } 23 | ) 24 | end 25 | 26 | def sync(mode) 27 | raise "No such mode: '#{mode}'." if !@args[:modes].key?(mode) 28 | 29 | while @blocked[mode][:count].to_i > 0 30 | STDOUT.print "Sleeping because blocked '#{mode}' (#{@blocked[mode][:count]}).\n" 31 | sleep 0.1 32 | end 33 | 34 | @mutex.synchronize do 35 | @args[:modes][mode][:blocks].each do |block| 36 | @blocked[block][:count] += 1 37 | end 38 | end 39 | 40 | begin 41 | yield 42 | ensure 43 | @args[:modes][mode][:blocks].each do |block| 44 | @blocked[block][:count] -= 1 45 | end 46 | end 47 | end 48 | end -------------------------------------------------------------------------------- /lib/knj/gtk2_window.rb: -------------------------------------------------------------------------------- 1 | Knj.gem_require(:wref) 2 | 3 | #Containing various helper methods for Gtk2-windows. 4 | class Knj::Gtk2::Window 5 | @@uniques = Wref::Map.new 6 | 7 | #Used to make a window-instance unique. If it already exists when unique! is called, then it will pass focus to the existing window instead of yielding the block, which should contain code to create the window. 8 | #===Examples 9 | #This should only create a single window. 10 | # Knj::Gtk2::Window.unique!("my_window") do 11 | # Gtk::Window.new 12 | # end 13 | # 14 | # Knj::Gtk2::Window.unique!("my_window") do 15 | # Gtk::Window.new 16 | # end 17 | def self.unique!(id) 18 | instance = @@uniques.get!(id) 19 | 20 | if instance and !instance.gui["window"].destroyed? 21 | instance.gui["window"].present 22 | else 23 | obj = yield 24 | @@uniques[id] = obj 25 | end 26 | end 27 | 28 | #Returns the object if it hasnt been destroyed. 29 | #===Examples 30 | # Knj::Gtk2::Window.get("my_window") #=> nil 31 | # Knj::Gtk2::Window.get("my_window") #=> Gtk::Builder-object 32 | def self.get(id) 33 | instance = @@uniques.get!(id) 34 | 35 | if instance and !instance.gui["window"].destroyed? 36 | return instance 37 | end 38 | 39 | return nil 40 | end 41 | end -------------------------------------------------------------------------------- /lib/knj/ironruby-gtk2/dialog.rb: -------------------------------------------------------------------------------- 1 | class Gtk::Dialog 2 | RESPONSE_OK = RealGtk::ResponseType.Ok 3 | RESPONSE_YES = RealGtk::ResponseType.Yes 4 | RESPONSE_NO = RealGtk::ResponseType.No 5 | RESPONSE_CANCEL = RealGtk::ResponseType.Cancel 6 | RESPONSE_CLOSE = RealGtk::ResponseType.Close 7 | RESPONSE_DELETE_EVENT = RealGtk::ResponseType.DeleteEvent 8 | MODAL = 0 9 | 10 | def initialize(*paras) 11 | if Gtk.takeob 12 | @ob = Gtk.takeob 13 | Gtk.takeob = nil 14 | else 15 | splitted = self.class.to_s.split("::") 16 | @ob = RealGtk.const_get(splitted.last).new(*paras) 17 | end 18 | 19 | if paras.length > 3 20 | 3.upto(paras.length) do |count| 21 | data = paras[count] 22 | 23 | if data.is_a?(Array) 24 | @ob.method(:add_button).overload(System::String, RealGtk::ResponseType).call(data[0], data[1]) 25 | elsif data.is_a?(NilClass) 26 | #do nothing. 27 | else 28 | #raise "Unhandeled data: #{data.class.to_s}" 29 | end 30 | end 31 | end 32 | 33 | if !@ob 34 | raise "Object was not spawned: #{self.class.to_s}" 35 | end 36 | end 37 | 38 | def vbox 39 | Gtk.takeob = @ob.VBox 40 | conv_widget = Gtk::VBox.new 41 | 42 | return conv_widget 43 | end 44 | end -------------------------------------------------------------------------------- /knjrbfw.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = "knjrbfw" 3 | s.version = "0.0.116" 4 | 5 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 6 | s.require_paths = ["lib"] 7 | s.authors = ["Kasper Stöckel"] 8 | s.description = "Including stuff for HTTP, SSH and much more." 9 | s.email = "k@spernj.org" 10 | s.extra_rdoc_files = [ 11 | "LICENSE.txt", 12 | "README.rdoc" 13 | ] 14 | s.files = Dir["{include,lib}/**/*"] + ["Rakefile"] 15 | s.homepage = "http://github.com/kaspernj/knjrbfw" 16 | s.licenses = ["MIT"] 17 | s.rubygems_version = "2.4.0" 18 | s.summary = "A framework with lots of stuff for Ruby." 19 | 20 | s.add_runtime_dependency("wref", ">= 0.0.8") 21 | s.add_runtime_dependency("tsafe", ">= 0") 22 | s.add_runtime_dependency("datet", ">= 0") 23 | s.add_runtime_dependency("http2", ">= 0") 24 | s.add_runtime_dependency("php4r", ">= 0") 25 | s.add_runtime_dependency("ruby_process", ">= 0") 26 | s.add_development_dependency("rspec", ">= 0") 27 | s.add_development_dependency("bundler", ">= 0") 28 | s.add_development_dependency("jeweler", ">= 0") 29 | s.add_development_dependency("sqlite3", ">= 0") 30 | s.add_development_dependency("rmagick", ">= 0") 31 | s.add_development_dependency("array_enumerator", ">= 0") 32 | end 33 | -------------------------------------------------------------------------------- /lib/knj/scripts/filesearch.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "knj/autoload" 4 | include Knj 5 | 6 | begin 7 | options = {} 8 | OptionParser.new do |opts| 9 | opts.banner = "Usage: example.rb [options]" 10 | 11 | opts.on("-f FINDTHIS", "--find", "Search for this string.") do |f| 12 | options[:find] = f 13 | end 14 | 15 | opts.on("-b BYTES", "--bytes BYTES", "Return this number of bytes and finding the string.") do |b| 16 | options[:bytes] = b.to_i 17 | end 18 | 19 | opts.on("--filepath FILEPATH", "The file that should be searched.") do |fp| 20 | options[:filepath] = fp 21 | end 22 | end.parse! 23 | rescue OptionParser::InvalidOption => e 24 | Php.die(e.message + "\n") 25 | end 26 | 27 | cont = "" 28 | readstr = "" 29 | retcont = "" 30 | File.open(options[:filepath], "r") do |fp| 31 | loop do 32 | break if fp.eof 33 | 34 | prevcont = String.new(readstr) 35 | readstr = fp.read(1024) 36 | cont = prevcont + readstr 37 | 38 | if ind = cont.index(options[:find]) 39 | read_size = options[:bytes] - (cont.length - ind) 40 | 41 | if read_size > 0 42 | cont += fp.read(read_size) 43 | end 44 | 45 | retcont = cont.slice(ind, options[:bytes]) 46 | break 47 | end 48 | end 49 | end 50 | 51 | print retcont + "\n" -------------------------------------------------------------------------------- /lib/knj/opts.rb: -------------------------------------------------------------------------------- 1 | module Knj::Opts 2 | CONFIG = { 3 | "table" => "options" 4 | } 5 | 6 | def self.init(arr_opts) 7 | arr_opts.each do |pair| 8 | if pair[0] == "knjdb" or pair[0] == "table" 9 | Knj::Opts::CONFIG[pair[0]] = pair[1] 10 | end 11 | end 12 | end 13 | 14 | def self.get(title) 15 | db = Knj::Opts::CONFIG["knjdb"] 16 | value = db.select(Knj::Opts::CONFIG["table"], {"title" => title}, {"limit" => 1}).fetch 17 | 18 | if !value 19 | return "" 20 | else 21 | return value["value"] if value.key?("value") 22 | return value[:value] if value.key?(:value) 23 | raise "Could not figure out of value." 24 | end 25 | end 26 | 27 | def self.set(title, value) 28 | db = Knj::Opts::CONFIG["knjdb"] 29 | result = db.select(Knj::Opts::CONFIG["table"], {"title" => title}, {"limit" => 1}).fetch 30 | 31 | if !result 32 | db.insert(Knj::Opts::CONFIG["table"], { 33 | "title" => title, 34 | "value" => value 35 | }) 36 | else 37 | id = nil 38 | id = result["id"] if result.key?("id") 39 | id = result[:id] if result.key?(:id) 40 | raise "Could not figure out of ID." if !id 41 | 42 | db.update(Knj::Opts::CONFIG["table"], {"value" => value}, {"id" => id}) 43 | end 44 | end 45 | end -------------------------------------------------------------------------------- /lib/knj/degulesider.rb: -------------------------------------------------------------------------------- 1 | class Knj::Degulesider 2 | def initialize(args = {}) 3 | @args = args 4 | @http = Knj::Http.new( 5 | "host" => "www.degulesider.dk" 6 | ) 7 | end 8 | 9 | def search(sargs) 10 | url = "/search/#{Php4r.urlencode(sargs[:where])}/-/1/" 11 | 12 | html = @http.get(url) 13 | ret = [] 14 | 15 | tbody_match = html["data"].match(//) do |match| 17 | res = {} 18 | 19 | if title_match = match[1].match(/

(.+)<\/a><\/h2>/) 20 | res[:name] = title_match[1] 21 | end 22 | 23 | if phone_match = match[1].match(/