knjrbfw 0.0.23 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/VERSION +1 -1
  2. data/knjrbfw.gemspec +7 -4
  3. data/lib/knj/autoload.rb +1 -61
  4. data/lib/knj/datarow.rb +7 -10
  5. data/lib/knj/datarow_custom.rb +12 -2
  6. data/lib/knj/datet.rb +107 -0
  7. data/lib/knj/eruby.rb +21 -12
  8. data/lib/knj/gettext_threadded.rb +1 -1
  9. data/lib/knj/http2.rb +27 -9
  10. data/lib/knj/image.rb +10 -0
  11. data/lib/knj/includes/require_info.rb +3 -3
  12. data/lib/knj/knj.rb +16 -9
  13. data/lib/knj/knj_controller.rb +10 -1
  14. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb +26 -9
  15. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb +11 -8
  16. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb +5 -0
  17. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_tables.rb +83 -26
  18. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb +3 -3
  19. data/lib/knj/knjdb/libknjdb.rb +19 -20
  20. data/lib/knj/knjdb/revision.rb +9 -2
  21. data/lib/knj/kvm.rb +100 -0
  22. data/lib/knj/locale_strings.rb +32 -3
  23. data/lib/knj/locales.rb +1 -4
  24. data/lib/knj/memory_analyzer.rb +335 -0
  25. data/lib/knj/objects/objects_sqlhelper.rb +2 -2
  26. data/lib/knj/objects.rb +44 -11
  27. data/lib/knj/opts.rb +8 -8
  28. data/lib/knj/os.rb +13 -0
  29. data/lib/knj/php.rb +18 -33
  30. data/lib/knj/process.rb +3 -0
  31. data/lib/knj/process_meta.rb +1 -1
  32. data/lib/knj/rhodes/mutex.rb +2 -1
  33. data/lib/knj/rhodes/rhodes.js +5 -1
  34. data/lib/knj/rhodes/rhodes.rb +15 -15
  35. data/lib/knj/rhodes/youtube_embed.erb +12 -0
  36. data/lib/knj/rhodes/youtube_open.erb +45 -0
  37. data/lib/knj/strings.rb +2 -1
  38. data/lib/knj/translations.rb +3 -3
  39. data/lib/knj/unix_proc.rb +15 -4
  40. data/lib/knj/web.rb +17 -247
  41. data/lib/knj/webscripts/image.rhtml +9 -3
  42. data/lib/knj/wref.rb +109 -70
  43. data/spec/datet_spec.rb +30 -0
  44. data/spec/http2_spec.rb +23 -0
  45. data/spec/php_spec.rb +3 -0
  46. metadata +20 -17
  47. data/lib/knj/rhodes/delegate.rb +0 -414
  48. data/lib/knj/rhodes/weakref.rb +0 -80
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.23
1
+ 0.0.24
data/knjrbfw.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjrbfw}
8
- s.version = "0.0.23"
8
+ s.version = "0.0.24"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = %q{2012-03-16}
12
+ s.date = %q{2012-04-26}
13
13
  s.description = %q{Including stuff for HTTP, SSH and much more.}
14
14
  s.email = %q{k@spernj.org}
15
15
  s.extra_rdoc_files = [
@@ -173,6 +173,7 @@ Gem::Specification.new do |s|
173
173
  "lib/knj/knjdb/libknjdb_row.rb",
174
174
  "lib/knj/knjdb/libknjdb_sqlite3_ironruby.rb",
175
175
  "lib/knj/knjdb/revision.rb",
176
+ "lib/knj/kvm.rb",
176
177
  "lib/knj/libqt.rb",
177
178
  "lib/knj/libqt_window.rb",
178
179
  "lib/knj/locale_strings.rb",
@@ -180,6 +181,7 @@ Gem::Specification.new do |s|
180
181
  "lib/knj/maemo/fremantle-calendar/fremantle-calendar.rb",
181
182
  "lib/knj/mail.rb",
182
183
  "lib/knj/mailobj.rb",
184
+ "lib/knj/memory_analyzer.rb",
183
185
  "lib/knj/mount.rb",
184
186
  "lib/knj/mutexcl.rb",
185
187
  "lib/knj/notify.rb",
@@ -200,11 +202,11 @@ Gem::Specification.new do |s|
200
202
  "lib/knj/process_meta.rb",
201
203
  "lib/knj/rand.rb",
202
204
  "lib/knj/retry.rb",
203
- "lib/knj/rhodes/delegate.rb",
204
205
  "lib/knj/rhodes/mutex.rb",
205
206
  "lib/knj/rhodes/rhodes.js",
206
207
  "lib/knj/rhodes/rhodes.rb",
207
- "lib/knj/rhodes/weakref.rb",
208
+ "lib/knj/rhodes/youtube_embed.erb",
209
+ "lib/knj/rhodes/youtube_open.erb",
208
210
  "lib/knj/rsvgbin.rb",
209
211
  "lib/knj/scripts/degulesider.rb",
210
212
  "lib/knj/scripts/filesearch.rb",
@@ -244,6 +246,7 @@ Gem::Specification.new do |s|
244
246
  "lib/knjrbfw.rb",
245
247
  "spec/amixer_spec.rb",
246
248
  "spec/cmd_parser_spec.rb",
249
+ "spec/datet_spec.rb",
247
250
  "spec/db_spec.rb",
248
251
  "spec/db_spec_encoding_test_file.txt",
249
252
  "spec/http2_spec.rb",
data/lib/knj/autoload.rb CHANGED
@@ -2,71 +2,10 @@ $knjpath = File.dirname(__FILE__) + "/" if !$knjpath
2
2
  require "#{$knjpath}/knj"
3
3
 
4
4
  module Knj
5
- autoload :Amixer, $knjpath + "amixer"
6
- autoload :ArrayExt, $knjpath + "arrayext"
7
- autoload :Datestamp, $knjpath + "datestamp"
8
- autoload :Datet, $knjpath + "datet"
9
- autoload :Cmd_gen, $knjpath + "cmd_gen"
10
- autoload :Cmd_parser, $knjpath + "cmd_parser"
11
- autoload :Compiler, $knjpath + "compiler"
12
- autoload :Cpufreq, $knjpath + "cpufreq"
13
- autoload :Csv, $knjpath + "csv"
14
- autoload :Datarow, $knjpath + "datarow"
15
- autoload :Db, $knjpath + "knjdb/libknjdb"
16
5
  autoload :Db_row, $knjpath + "knjdb/libknjdb_row"
17
- autoload :Degulesider, $knjpath + "degulesider"
18
- autoload :Errors, $knjpath + "errors"
19
- autoload :Eruby, $knjpath + "eruby"
20
- autoload :Event_filemod, $knjpath + "event_filemod"
21
- autoload :Event_handler, $knjpath + "event_handler"
22
- autoload :Exchangerates, $knjpath + "exchangerates"
23
- autoload :Facebook_connect, $knjpath + "facebook_connect"
24
6
  autoload :Fs, $knjpath + "fs/fs"
25
- autoload :Filesystem, $knjpath + "filesystem"
26
- autoload :Gettext_threadded, $knjpath + "gettext_threadded"
27
- autoload :Hash_methods, $knjpath + "hash_methods"
28
- autoload :Http, $knjpath + "http"
29
- autoload :Http2, $knjpath + "http2"
30
- autoload :Image, $knjpath + "image"
31
- autoload :Ip2location, $knjpath + "ip2location"
32
- autoload :Jruby_compiler, $knjpath + "jruby_compiler"
33
- autoload :Locales, $knjpath + "locales"
34
- autoload :Objects, $knjpath + "objects"
35
- autoload :Opts, $knjpath + "opts"
36
- autoload :Mail, $knjpath + "mail"
37
- autoload :Mailobj, $knjpath + "mailobj"
38
- autoload :Mutexcl, $knjpath + "mutexcl"
39
- autoload :Mount, $knjpath + "mount"
40
- autoload :Mplayer, $knjpath + "mplayer"
41
- autoload :Notify, $knjpath + "notify"
42
- autoload :Nvidia_settings, $knjpath + "nvidia_settings"
43
- autoload :Web, $knjpath + "web"
44
- autoload :Google_sitemap, $knjpath + "google_sitemap"
45
- autoload :Process, $knjpath + "process"
46
- autoload :Process_meta, $knjpath + "process_meta"
47
- autoload :Sms, $knjpath + "sms"
48
- autoload :Os, $knjpath + "os"
49
- autoload :Gtk2, $knjpath + "gtk2"
50
- autoload :Php, $knjpath + "php"
51
7
  autoload :Php_parser, $knjpath + "php_parser/php_parser"
52
- autoload :Power_manager, $knjpath + "power_manager"
53
- autoload :Rand, $knjpath + "rand"
54
- autoload :Retry, $knjpath + "retry"
55
- autoload :RSVGBIN, $knjpath + "rsvgbin"
56
- autoload :Strings, $knjpath + "strings"
57
8
  autoload :SSHRobot, $knjpath + "sshrobot/sshrobot"
58
- autoload :Sysuser, $knjpath + "sysuser"
59
- autoload :Table_writer, $knjpath + "table_writer"
60
- autoload :Thread, $knjpath + "thread"
61
- autoload :Thread2, $knjpath + "thread2"
62
- autoload :Threadpool, $knjpath + "threadpool"
63
- autoload :Threadhandler, $knjpath + "threadhandler"
64
- autoload :Translations, $knjpath + "translations"
65
- autoload :X11VNC, $knjpath + "x11vnc"
66
- autoload :Unix_proc, $knjpath + "unix_proc"
67
- autoload :YouTube, $knjpath + "youtube"
68
- autoload :Win, $knjpath + "win"
69
- autoload :Wref, $knjpath + "wref"
70
9
  autoload :Wref_map, $knjpath + "wref"
71
10
  end
72
11
 
@@ -84,6 +23,7 @@ autoload :IPAddr, "ipaddr"
84
23
  autoload :JSON, $knjpath + "autoload/json"
85
24
  autoload :GD2, $knjpath + "autoload/gd2"
86
25
  autoload :Magick, $knjpath + "autoload/magick"
26
+ autoload :Monitor, "monitor"
87
27
  autoload :Mutex, "thread"
88
28
  autoload :Mysql, $knjpath + "autoload/mysql"
89
29
  autoload :Open3, "open3"
data/lib/knj/datarow.rb CHANGED
@@ -212,15 +212,8 @@ class Knj::Datarow
212
212
  def self.load_columns(d)
213
213
  @ob = d.ob if !@ob
214
214
 
215
- if !@classname
216
- if match = self.name.match(/($|::)([A-z\d_]+?)$/)
217
- @classname = match[2].to_sym
218
- else
219
- @classname = self.name.to_sym
220
- end
221
- end
222
-
223
- @mutex = Mutex.new if !@mutex
215
+ @classname = self.name.split("::").last if !@classname
216
+ @mutex = Monitor.new if !@mutex
224
217
 
225
218
  @mutex.synchronize do
226
219
  inst_methods = self.instance_methods(false)
@@ -532,7 +525,7 @@ class Knj::Datarow
532
525
  raise "Key was not a symbol: '#{key.class.name}'." if !key.is_a?(Symbol)
533
526
  raise "No data was loaded on the object? Maybe you are trying to call a deleted object?" if !@data
534
527
  return @data[key] if @data.key?(key)
535
- raise "No such key: '#{key}'."
528
+ raise "No such key: '#{key}' on '#{self.class.name}'."
536
529
  end
537
530
 
538
531
  #Writes/updates a keys value on the object.
@@ -543,10 +536,14 @@ class Knj::Datarow
543
536
 
544
537
  #Returns the objects ID.
545
538
  def id
539
+ raise "This object has been deleted." if self.deleted?
546
540
  raise "No data on object." if !@data
547
541
  return @data[:id]
548
542
  end
549
543
 
544
+ #This enable Knj::Wref to not return the wrong object.
545
+ alias __object_unique_id__ id
546
+
550
547
  #Tries to figure out, and returns, the possible name or title for the object.
551
548
  def name
552
549
  if @data.key?(:title)
@@ -72,10 +72,10 @@ class Knj::Datarow_custom
72
72
  if data.is_a?(Hash)
73
73
  @data = Knj::ArrayExt.hash_sym(data)
74
74
  else
75
- data = d.data
76
75
  raise "No 'data_from_id'-event connected to class." if !self.class.events.connected?(:data_from_id)
77
76
  data = self.class.events.call(:data_from_id, Knj::Hash_methods.new(:id => data))
78
77
  raise "No data was received from the event: 'data_from_id'." if !data
78
+ raise "Data expected to be a hash but wasnt: '#{data.class.name}'." if !data.is_a?(Hash)
79
79
  @data = Knj::ArrayExt.hash_sym(data)
80
80
  end
81
81
  end
@@ -84,15 +84,25 @@ class Knj::Datarow_custom
84
84
  return self.class.events.call(:update, Knj::Hash_methods.new(:object => self, :data => data))
85
85
  end
86
86
 
87
+ #Returns a key from the hash that this object is holding or raises an error if it doesnt exist.
87
88
  def [](key)
88
- raise "No such key: '#{key}'." if !@data or !@data.key?(key)
89
+ if !@data
90
+ raise "No data spawned on object."
91
+ end
92
+
93
+ if !@data.key?(key)
94
+ raise "No such key: '#{key}'. Available keys are: '#{@data.keys.sort.join(", ")}'."
95
+ end
96
+
89
97
  return @data[key]
90
98
  end
91
99
 
100
+ #Returns the ID of the object.
92
101
  def id
93
102
  return self[:id]
94
103
  end
95
104
 
105
+ #Returns the name of the object, which can be taken from various data or various defined methods.
96
106
  def name
97
107
  if @data.key?(:title)
98
108
  return @data[:title]
data/lib/knj/datet.rb CHANGED
@@ -272,6 +272,7 @@ class Knj::Datet
272
272
 
273
273
  def add_something(val)
274
274
  val = -val if @addmode == "-"
275
+ return self.add_years(val) if @mode == :years
275
276
  return self.add_hours(val) if @mode == :hours
276
277
  return self.add_days(val) if @mode == :days
277
278
  return self.add_months(val) if @mode == :months
@@ -309,6 +310,11 @@ class Knj::Datet
309
310
  return self
310
311
  end
311
312
 
313
+ def years
314
+ @mode = :years
315
+ return self
316
+ end
317
+
312
318
  def stamp(args)
313
319
  vars = {:year => @time.year, :month => @time.month, :day => @time.day, :hour => @time.hour, :min => @time.min, :sec => @time.sec}
314
320
 
@@ -621,4 +627,105 @@ class Knj::Datet
621
627
  def localtime_str
622
628
  return "#{"%04d" % @time.year}-#{"%02d" % @time.month}-#{"%02d" % @time.day} #{"%02d" % @time.hour}:#{"%02d" % @time.min}:#{"%02d" % @time.sec} #{self.offset_str}"
623
629
  end
630
+
631
+ #Returns a human readable string based on the difference from the current time and date.
632
+ def ago_str(args = {})
633
+ args = {
634
+ :year_ago_str => "%s year ago",
635
+ :years_ago_str => "%s years ago",
636
+ :month_ago_str => "%s month ago",
637
+ :months_ago_str => "%s months ago",
638
+ :day_ago_str => "%s day ago",
639
+ :days_ago_str => "%s days ago",
640
+ :hour_ago_str => "%s hour ago",
641
+ :hours_ago_str => "%s hours ago",
642
+ :min_ago_str => "%s minute ago",
643
+ :mins_ago_str => "%s minutes ago",
644
+ :sec_ago_str => "%s second ago",
645
+ :secs_ago_str => "%s seconds ago",
646
+ :right_now_str => "right now"
647
+ }.merge(args)
648
+
649
+ secs_ago = Time.now.to_i - @time.to_i
650
+ mins_ago = secs_ago.to_f / 60.0
651
+ hours_ago = mins_ago / 60.0
652
+ days_ago = hours_ago / 24.0
653
+ months_ago = days_ago / 30.0
654
+ years_ago = months_ago / 12.0
655
+
656
+ if years_ago > 0.9 and years_ago < 1.5
657
+ return sprintf(args[:year_ago_str], years_ago.to_i)
658
+ elsif years_ago >= 1.5
659
+ return sprintf(args[:years_ago_str], years_ago.to_i)
660
+ elsif months_ago > 0.9 and months_ago < 1.5
661
+ return sprintf(args[:month_ago_str], months_ago.to_i)
662
+ elsif months_ago >= 1.5
663
+ return sprintf(args[:months_ago_str], months_ago.to_i)
664
+ elsif days_ago > 0.9 and days_ago < 1.5
665
+ return sprintf(args[:day_ago_str], days_ago.to_i)
666
+ elsif days_ago >= 1.5
667
+ return sprintf(args[:days_ago_str], days_ago.to_i)
668
+ elsif hours_ago > 0.9 and hours_ago < 1.5
669
+ return sprintf(args[:hour_ago_str], hours_ago.to_i)
670
+ elsif hours_ago >= 1.5
671
+ return sprintf(args[:hours_ago_str], hours_ago.to_i)
672
+ elsif mins_ago > 0.9 and mins_ago < 1.5
673
+ return sprintf(args[:min_ago_str], mins_ago.to_i)
674
+ elsif mins_ago >= 1.5
675
+ return sprintf(args[:mins_ago_str], mins_ago.to_i)
676
+ elsif secs_ago >= 0.1 and secs_ago < 1.5
677
+ return sprintf(args[:sec_ago_str], secs_ago.to_i)
678
+ elsif secs_ago >= 1.5
679
+ return sprintf(args[:secs_ago_str], secs_ago.to_i)
680
+ end
681
+
682
+ return args[:right_now_str]
683
+ end
684
+
685
+ def human_str(args = {})
686
+ args = {
687
+ :time => true,
688
+ :number_endings => {
689
+ 0 => "th",
690
+ 1 => "st",
691
+ 2 => "nd",
692
+ 3 => "rd",
693
+ 4 => "th",
694
+ 5 => "th",
695
+ 6 => "th",
696
+ 7 => "th",
697
+ 8 => "th",
698
+ 9 => "th"
699
+ }
700
+ }.merge(args)
701
+
702
+ now = Time.now
703
+
704
+ #Generate normal string.
705
+ date_str = ""
706
+
707
+ if now.day != @time.day and now.month == @time.month and now.year == @time.year
708
+ last_digit = @time.day.to_s[-1, 1].to_i
709
+
710
+ if ending = args[:number_endings][last_digit]
711
+ #ignore.
712
+ else
713
+ ending = "."
714
+ end
715
+
716
+ date_str << "#{@time.day}#{ending} "
717
+ elsif now.day != @time.day or now.month != @time.month or now.year != @time.year
718
+ date_str << "#{@time.day}/#{@time.month} "
719
+ end
720
+
721
+ if now.year != @time.year
722
+ date_str << "#{@time.year} "
723
+ end
724
+
725
+ if args[:time]
726
+ date_str << "#{@time.hour}:#{"%02d" % @time.min}"
727
+ end
728
+
729
+ return date_str
730
+ end
624
731
  end
data/lib/knj/eruby.rb CHANGED
@@ -4,8 +4,7 @@ class Knj::Eruby
4
4
  def initialize(args = {})
5
5
  @args = args
6
6
 
7
- require "tmpdir"
8
- @tmpdir = "#{Dir.tmpdir}/knj_erb"
7
+ @tmpdir = "#{Knj::Os.tmpdir}/knj_erb"
9
8
  Dir.mkdir(@tmpdir, 0777) if !File.exists?(@tmpdir)
10
9
 
11
10
 
@@ -20,7 +19,8 @@ class Knj::Eruby
20
19
  @cache_mode = :code_eval
21
20
  #@cache_mode = :compile_knj
22
21
  elsif RUBY_VERSION.slice(0..2) == "1.9" and RubyVM::InstructionSequence.respond_to?(:compile_file)
23
- @cache_mode = :inseq
22
+ @cache_mode = :code_eval
23
+ #@cache_mode = :inseq
24
24
  #@cache_mode = :compile_knj
25
25
  end
26
26
 
@@ -45,6 +45,7 @@ class Knj::Eruby
45
45
  begin
46
46
  if !File.exists?(cachename) or filetime > cachetime
47
47
  Knj::Eruby::Handler.load_file(filename, {:cachename => cachename})
48
+ File.chmod(0777, cachename)
48
49
  cachetime = File.mtime(cachename)
49
50
  reload_cache = true
50
51
  elsif !@cache.key?(cachename)
@@ -55,8 +56,15 @@ class Knj::Eruby
55
56
  when :compile_knj
56
57
  @compiler.eval_file(:filepath => cachename, :fileident => filename)
57
58
  when :code_eval
59
+ if @args[:binding_callback]
60
+ binding_use = @args[:binding_callback].call
61
+ else
62
+ eruby_binding = Knj::Eruby::Binding.new
63
+ binding_use = eruby_binding.get_binding
64
+ end
65
+
58
66
  @cache[cachename] = File.read(cachename) if reload_cache
59
- eval(@cache[cachename], nil, filename)
67
+ eval(@cache[cachename], binding_use, filename)
60
68
  when :inseq
61
69
  if reload_cache or @cache[cachename][:time] < cachetime
62
70
  @cache[cachename] = {
@@ -212,13 +220,8 @@ class Knj::Eruby
212
220
  print "\n\n<pre>\n\n"
213
221
  print "<b>#{Knj::Web.html(e.class.name)}: #{Knj::Web.html(e.message)}</b>\n\n"
214
222
 
215
- #Lets hide all the stuff in what is not the users files to make it easier to debug.
216
- bt = e.backtrace
217
- #to = bt.length - 9
218
- #bt = bt[0..to]
219
-
220
- bt.each do |line|
221
- print Knj::Web.html(line) + "\n"
223
+ e.backtrace.each do |line|
224
+ print "#{Knj::Web.html(line)}\n"
222
225
  end
223
226
 
224
227
  print "</pre>"
@@ -228,7 +231,7 @@ class Knj::Eruby
228
231
  print "<b>#{Knj::Web.html(e.class.name)}: #{Knj::Web.html(e.message)}</b>\n\n"
229
232
 
230
233
  e.backtrace.each do |line|
231
- print Knj::Web.html(line) + "\n"
234
+ print "#{Knj::Web.html(line)}\n"
232
235
  end
233
236
 
234
237
  print "</pre>"
@@ -237,4 +240,10 @@ end
237
240
 
238
241
  class Knj::Eruby::Handler < Erubis::Eruby
239
242
  include Erubis::StdoutEnhancer
243
+ end
244
+
245
+ class Knj::Eruby::Binding
246
+ def get_binding
247
+ return binding
248
+ end
240
249
  end
@@ -29,7 +29,7 @@ class Knj::Gettext_threadded
29
29
  pofn = "#{dir}/#{file}/#{fname}/#{pofile}"
30
30
 
31
31
  cont = nil
32
- File.open(pofn, {:encoding => @args[:encoding]}) do |fp|
32
+ File.open(pofn, "r", {:encoding => @args[:encoding]}) do |fp|
33
33
  cont = fp.read.encode("utf-8")
34
34
  end
35
35
 
data/lib/knj/http2.rb CHANGED
@@ -1,10 +1,11 @@
1
+ require "#{$knjpath}web"
2
+
1
3
  class Knj::Http2
2
4
  attr_reader :cookies
3
5
 
4
6
  def initialize(args = {})
5
7
  args = {:host => args} if args.is_a?(String)
6
8
  raise "Arguments wasnt a hash." if !args.is_a?(Hash)
7
- require "#{$knjpath}web"
8
9
 
9
10
  @args = args
10
11
  @cookies = {}
@@ -135,6 +136,7 @@ class Knj::Http2
135
136
  def get(addr, args = {})
136
137
  begin
137
138
  @mutex.synchronize do
139
+ args[:addr] = addr
138
140
  header_str = "GET /#{addr} HTTP/1.1#{@nl}"
139
141
  header_str << self.header_str(self.default_headers(args), args)
140
142
  header_str << "#{@nl}"
@@ -149,8 +151,7 @@ class Knj::Http2
149
151
  return resp
150
152
  end
151
153
  rescue Knj::Errors::Retry => e
152
- print "Redirecting to: #{e.message}\n"
153
-
154
+ print "Redirecting to: #{e.message}\n" if @debug
154
155
  return self.get(e.message, args)
155
156
  end
156
157
  end
@@ -191,14 +192,31 @@ class Knj::Http2
191
192
  return headers
192
193
  end
193
194
 
195
+ def self.post_convert_data(pdata)
196
+ praw = ""
197
+
198
+ if pdata.is_a?(Hash)
199
+ pdata.each do |key, val|
200
+ praw << "&" if praw != ""
201
+ praw << "#{Knj::Web.urlenc(Knj::Http2.post_convert_data(key))}=#{Knj::Web.urlenc(Knj::Http2.post_convert_data(val))}"
202
+ end
203
+ elsif pdata.is_a?(Array)
204
+ count = 0
205
+ pdata.each do |val|
206
+ count += 1
207
+ praw << "#{count}=#{Knj::Web.urlenc(Knj::Http2.post_convert_data(val))}"
208
+ end
209
+ else
210
+ return pdata.to_s
211
+ end
212
+
213
+ return praw
214
+ end
215
+
194
216
  def post(addr, pdata = {}, args = {})
195
217
  begin
196
218
  @mutex.synchronize do
197
- praw = ""
198
- pdata.each do |key, val|
199
- praw << "&" if praw != ""
200
- praw << "#{Knj::Web.urlenc(key)}=#{Knj::Web.urlenc(val)}"
201
- end
219
+ praw = Knj::Http2.post_convert_data(pdata)
202
220
 
203
221
  header_str = "POST /#{addr} HTTP/1.1#{@nl}"
204
222
  header_str << self.header_str(self.default_headers(args).merge("Content-Length" => praw.length), args)
@@ -360,7 +378,7 @@ class Knj::Http2
360
378
  return http.get(uri.path)
361
379
  end
362
380
  elsif resp.args[:code].to_s == "500"
363
- raise "500 - Internal server error."
381
+ raise "500 - Internal server error: '#{args[:addr]}':\n\n#{resp.body}"
364
382
  elsif resp.args[:code].to_s == "403"
365
383
  raise Knj::Errors::NoAccess
366
384
  else
data/lib/knj/image.rb CHANGED
@@ -152,4 +152,14 @@ class Knj::Image
152
152
 
153
153
  pic.matte = true
154
154
  end
155
+
156
+ #Returns the width relative to the height.
157
+ def self.width_for_height(orig_width, orig_height, new_height)
158
+ return (orig_width.to_f / (orig_height.to_f / new_height.to_f)).to_i
159
+ end
160
+
161
+ #Returns the height relative to the width.
162
+ def self.height_for_width(orig_width, orig_height, new_width)
163
+ return (orig_height.to_f / (orig_width.to_f / new_width.to_f)).to_i
164
+ end
155
165
  end
@@ -1,4 +1,4 @@
1
- $knj_require_info = {}
1
+ Knj::REQUIRE_INFO = {}
2
2
 
3
3
  class Object
4
4
  alias_method :require_knj, :require
@@ -6,8 +6,8 @@ class Object
6
6
  def require(path)
7
7
  stat = require_knj(path)
8
8
 
9
- if stat and !$knj_require_info.key?(path)
10
- $knj_require_info[path] = {:caller => caller}
9
+ if stat and !Knj::REQUIRE_INFO.key?(path)
10
+ Knj::REQUIRE_INFO[path] = {:caller => caller}
11
11
  end
12
12
 
13
13
  return stat
data/lib/knj/knj.rb CHANGED
@@ -1,13 +1,20 @@
1
- if $knjpath
2
- autoload_path = "#{$knjpath}autoload.rb"
3
- else
4
- $knjpath = "knj/"
5
- autoload_path = "#{File.dirname(__FILE__)}/autoload.rb"
6
- end
7
-
8
- require autoload_path if $knjautoload != false
1
+ $knjpath = "knj/" if !$knjpath
9
2
 
10
3
  module Knj
4
+ CONFIG = {}
5
+
6
+ def self.const_missing(name)
7
+ if name == "db"
8
+ filepath = "#{$knjpath}/knjdb/libknjdb"
9
+ else
10
+ filepath = "#{$knjpath}#{name.to_s.downcase}"
11
+ end
12
+
13
+ require filepath
14
+ raise "Constant still not defined: '#{name}'." if !Knj.const_defined?(name)
15
+ return Knj.const_get(name)
16
+ end
17
+
11
18
  def self.appserver_cli(filename)
12
19
  Knj::Os.chdir_file(filename)
13
20
  require "#{$knjpath}/includes/appserver_cli.rb"
@@ -15,7 +22,7 @@ module Knj
15
22
 
16
23
  def self.dirname(filepath)
17
24
  raise "Filepath does not exist: #{filepath}" if !File.exists?(filepath)
18
- return Knj::Php.realpath(File.dirname(filepath))
25
+ return File.realpath(File.dirname(filepath))
19
26
  end
20
27
 
21
28
  #Returns the path of the knjrbfw-framework.
@@ -8,9 +8,18 @@ class KnjController < Rho::RhoController
8
8
  def html_links
9
9
  System.open_url(@params["url"])
10
10
  end
11
-
11
+
12
12
  def callback
13
13
  block = $rhodes.callbacks(@params["callback_id"])
14
14
  block.call(:params => @params)
15
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
16
25
  end