Class: Knj::Rhodes
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#gettext ⇒ Object
readonly
Returns the value of attribute gettext.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#ob ⇒ Object
readonly
Returns the value of attribute ob.
Class Method Summary collapse
Instance Method Summary collapse
- #_(str) ⇒ Object
- #callback(&block) ⇒ Object
- #callbacks(key) ⇒ Object
-
#initialize(args = {}) ⇒ Rhodes
constructor
A new instance of Rhodes.
- #inputs(*arr) ⇒ Object
- #session_key(key) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Rhodes
Returns a new instance of Rhodes.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/knj/rhodes/rhodes.rb', line 7 def initialize(args = {}) require "#{$knjpath}arrayext.rb" require "#{$knjpath}datet.rb" require "php4r" require "#{$knjpath}objects.rb" require "#{$knjpath}datarow.rb" require "#{$knjpath}event_handler.rb" require "#{$knjpath}hash_methods.rb" require "#{$knjpath}errors.rb" require "#{$knjpath}gettext_threadded.rb" require "#{$knjpath}locales.rb" require "#{$knjpath}locale_strings.rb" require "#{$knjpath}web.rb" if !Kernel.const_defined?("Mutex") print "Mutex not defined - loading alternative.\n" require "#{$knjpath}rhodes/mutex.rb" end require "#{$knjpath}opts.rb" require "#{$knjpath}knjdb/libknjdb.rb" require "#{$knjpath}knjdb/revision.rb" require "#{$knjpath}knjdb/drivers/sqlite3/knjdb_sqlite3.rb" require "#{$knjpath}knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb" require "#{$knjpath}knjdb/drivers/sqlite3/knjdb_sqlite3_columns.rb" require "#{$knjpath}knjdb/drivers/sqlite3/knjdb_sqlite3_indexes.rb" @args = args @callbacks = {} @callbacks_count = 0 @db = Knj::Db.new( :type => "sqlite3", :subtype => "rhodes", :path => "#{Rho::RhoApplication.get_user_path}rhodes_default.sqlite3", :return_keys => "symbols", :require => false, :index_append_table_name => true ) if @args[:schema] schema = @args[:schema] else schema = {"tables" => {}} end #Table used for options-module. schema["tables"]["Option"] = { "columns" => [ {"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true}, {"name" => "title", "type" => "varchar"}, {"name" => "value", "type" => "text"} ] } #Run database-revision. dbrev = Knj::Db::Revision.new dbrev.init_db("schema" => schema, "db" => @db) #Initialize options-module. Knj::Opts.init( "table" => "Option", "knjdb" => @db ) #Initialize objects-module. @ob = Knj::Objects.new( :db => @db, :class_path => "#{Rho::RhoApplication.get_base_app_path}app/models", :require => false, :module => @args[:module], :datarow => true ) #Initialize locales. @gettext = Knj::Gettext_threadded.new @gettext.load_dir("#{Rho::RhoApplication.get_base_app_path}app/locales") locale = "#{System.get_property("locale")}_#{System.get_property("country")}".downcase @args[:locale_default] = "en_GB" if !@args[:locale_default] langs = @gettext.langs.keys langs.each do |lang| if locale == lang.downcase @locale = lang break end end if !@locale langs.each do |lang| if locale.slice(0..2) == lang.downcase.slice(0..2) @locale = lang break end end end @locale = @args[:locale_default] if !@locale end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
5 6 7 |
# File 'lib/knj/rhodes/rhodes.rb', line 5 def args @args end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
5 6 7 |
# File 'lib/knj/rhodes/rhodes.rb', line 5 def db @db end |
#gettext ⇒ Object (readonly)
Returns the value of attribute gettext.
5 6 7 |
# File 'lib/knj/rhodes/rhodes.rb', line 5 def gettext @gettext end |
#locale ⇒ Object
Returns the value of attribute locale.
4 5 6 |
# File 'lib/knj/rhodes/rhodes.rb', line 4 def locale @locale end |
#ob ⇒ Object (readonly)
Returns the value of attribute ob.
5 6 7 |
# File 'lib/knj/rhodes/rhodes.rb', line 5 def ob @ob end |
Class Method Details
.html_links(args) ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'lib/knj/rhodes/rhodes.rb', line 147 def self.html_links(args) html_cont = "#{args[:html]}" html_cont.scan(/(<a([^>]+)href=\"(http.+?)\")/) do |match| html_cont = html_cont.gsub(match[0], "<a#{match[1]}href=\"javascript: knj_rhodes_html_links({url: '#{match[2]}'});\"") end return html_cont end |
Instance Method Details
#_(str) ⇒ Object
157 158 159 |
# File 'lib/knj/rhodes/rhodes.rb', line 157 def _(str) return @gettext.trans(@locale, str.to_s) end |
#callback(&block) ⇒ Object
169 170 171 172 173 174 |
# File 'lib/knj/rhodes/rhodes.rb', line 169 def callback(&block) count = @callbacks_count @callbacks_count += 1 @callbacks[count] = block return count end |
#callbacks(key) ⇒ Object
176 177 178 179 180 181 |
# File 'lib/knj/rhodes/rhodes.rb', line 176 def callbacks(key) block = @callbacks[key.to_i] raise "Block not found for key: '#{key}'." if !block @callbacks.delete(key.to_i) return block end |
#inputs(*arr) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/knj/rhodes/rhodes.rb', line 110 def inputs(*arr) html = "" arr.each do |data| value = "" data[:type] = :text if !data.key?(:type) if data.key?(:value) and data[:value].is_a?(Array) and data[:value][0] value = data[:value][0][data[:value][1]] elsif data.key?(:valthread_callbackue) value = data[:value] end extra_args = "" extra_args = " autofocus=\"autofocus\"" if data[:autofocus] css = {} if data[:type] == :textarea css["height"] = data[:height] if data.key?(:height) html << "<div data-role=\"fieldcontain\">" html << "<label for=\"#{data[:name]}\">#{data[:title]}</label>" html << "<textarea name=\"#{data[:name]}\" id=\"#{data[:name]}\"#{Knj::Web.style_html(css)}#{extra_args}>#{value}</textarea>" html << "</div>" else html << "<div data-role=\"fieldcontain\">" html << "<label for=\"#{data[:name]}\">#{data[:title]}</label>" html << "<input type=\"#{data[:type]}\" name=\"#{data[:name]}\" id=\"#{data[:name]}\" value=\"#{value}\"#{Knj::Web.style_html(css)}#{extra_args} />" html << "</div>" end end return html end |
#session_key(key) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/knj/rhodes/rhodes.rb', line 161 def session_key(key) if key == :locale return @locale end raise "No such key: '#{key}'." end |