rsence-pre 2.3.0.25 → 2.3.0.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9f829d0320a69e26fffca9867960063c5d30859
4
- data.tar.gz: 9b101aa1465a3e5f81d0814e9d1d7b0f471e37d1
3
+ metadata.gz: 5961f0e8e0436d16a623ab61bd03408378ef18c5
4
+ data.tar.gz: 748f84c78b21acd52ffc24a1df92d40c4be29821
5
5
  SHA512:
6
- metadata.gz: 354bc014997bce241e953a63ad89246f115c308311667db9c6575fd0bb09f8b1f37927ad0d14ee41f3962ed08c20f8abc30276e7e802c9e58a253c83a4c7392d
7
- data.tar.gz: 07e49b798898bcdc8b0e0d3a7004425ae2a48b9610993af7006fec38301b04aec5193748291df5ce621347dbed5640f4daa8b11dd4b713cd3f11886a4871ef48
6
+ metadata.gz: d980561d4bed3accd01ad93ba47ed42e3545460304f07f37eb5cdd28277b3b7f7fd06ffb08ce421faceca7ed0fce71805daacbf29a3c31431254633c8cd402ec
7
+ data.tar.gz: ea1b4fbfbe85efc1a9449e4ca48e2d49178784fee6dcb41ee7c104b85cb4d3ce87a217a534c18e2b66d1518700ae5f80bd3b476737f126b7d89e9f40bf8b9511
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0.25.pre
1
+ 2.3.0.26.pre
@@ -37,6 +37,10 @@
37
37
  # Default HTML <body> contents
38
38
  :body: ''
39
39
  #
40
+ # The default language to use
41
+ # * Used in user_info[:lang] as the default
42
+ :lang: en
43
+ #
40
44
  # The settings for the main plugin
41
45
  :main_plugin:
42
46
  #
@@ -24,7 +24,7 @@ HTextControl = HControl.extend
24
24
  textIndent: 0
25
25
  fontSize: '10px'
26
26
  color: '#666'
27
- refreshAfter: 1
27
+ refreshAfter: 0.2 # 200ms
28
28
  refreshOnBlur: true
29
29
  refreshOnInput: true
30
30
  refreshOnIdle: true
data/lib/rsence/msg.rb CHANGED
@@ -171,6 +171,14 @@ module RSence
171
171
  @session[:user_info]
172
172
  end
173
173
 
174
+ # Getter for the user language
175
+ # @return [Hash] The current user language. Returns RSence.config[:lang] by default
176
+ def lang
177
+ uinfo = user_info
178
+ uinfo[:lang] = RSence.config[:lang] unless uinfo.has_key? :lang
179
+ uinfo[:lang]
180
+ end
181
+
174
182
  # @private used for automatic reload of page, when the plugins have been changed.
175
183
  def refresh_page?( plugin_incr )
176
184
  if plugin_incr != @session[:plugin_incr]
@@ -195,6 +203,13 @@ module RSence
195
203
  @session[:user_info] = user_info
196
204
  end
197
205
 
206
+ # Setter for the user language
207
+ # @param [String] lang The language to set. Use in login situations to store the user language.
208
+ # @return [nil]
209
+ def lang=(lang)
210
+ @session[:user_info][:lang] = lang
211
+ end
212
+
198
213
  # Returns the session id
199
214
  # @return [Number]
200
215
  def ses_id
@@ -1,3 +1,5 @@
1
+ # Interface for handling localized strings
2
+ require 'rsence/plugins/plugin_localization'
1
3
 
2
4
  module RSence
3
5
  module Plugins
@@ -16,6 +18,8 @@ module RSence
16
18
  # * {#gui_params +#gui_params+} -- Extend to define your own params for the gui data.
17
19
  #
18
20
  class GUIPlugin__ < Plugin__
21
+
22
+ include Localization
19
23
 
20
24
  # @private Class type identifier for the PluginManager.
21
25
  # @return [:GUIPlugin]
@@ -28,7 +32,7 @@ module RSence
28
32
  super
29
33
  yaml_src = false
30
34
  [ "#{@name}.yaml", 'gui.yaml',
31
- "gui/#{@name}.yaml", "gui/main.yaml"
35
+ "gui/#{@name}.yaml", 'gui/main.yaml'
32
36
  ].each do |yaml_name|
33
37
  yaml_src = file_read( yaml_name )
34
38
  break if yaml_src
@@ -68,7 +72,9 @@ module RSence
68
72
  #
69
73
  def gui_params( msg )
70
74
  return unless @gui
71
- { :values => @gui.values( get_ses( msg ) ) }
75
+ params = super
76
+ params[:values] = @gui.values( get_ses( msg ) )
77
+ params
72
78
  end
73
79
 
74
80
  # @private Method that implements +client_pkgs.yaml+ loading
@@ -498,7 +498,7 @@ module RSence
498
498
  end
499
499
  return values_clean unless values_clean.empty?
500
500
  else
501
- warn "Unsupported format of values.yaml, got: #{values_dirty.inspect}, expected Hash or Array."
501
+ warn "Unsupported format of #{bundle_path('values.yaml')}, got: #{values_dirty.inspect}, expected Hash or Array."
502
502
  end
503
503
  return false
504
504
  end
@@ -0,0 +1,153 @@
1
+ module RSence
2
+ module Plugins
3
+ module Localization
4
+ def read_strings( fn='strings.yaml' )
5
+ yaml_read( fn )
6
+ end
7
+ def fill_strs_raw_path( hash, path, val )
8
+ key = path.shift
9
+ if path.empty?
10
+ hash[key] = val
11
+ else
12
+ hash[key] = {} unless hash.has_key? key
13
+ fill_strs_raw_path( hash[key], path, val )
14
+ end
15
+ end
16
+ def parse_strs_raw( hash_out, hash_node_in, path )
17
+ hash_node_in.each do |key,val|
18
+ if val.class == Hash
19
+ child_path = path.dup
20
+ child_path.push( key )
21
+ parse_strs_raw( hash_out, val, child_path )
22
+ else
23
+ out_path = path.dup
24
+ out_path.unshift( key )
25
+ fill_strs_raw_path( hash_out, out_path, val )
26
+ end
27
+ end
28
+ end
29
+ def deep_merge_hash( src, tgt={} )
30
+ src.each do |key,val|
31
+ if val.class == Hash
32
+ tgt[key] = {} unless tgt.has_key? key and tgt[key].class == Hash
33
+ deep_merge_hash( src[key], tgt[key] )
34
+ else
35
+ if [String,Array].include? val.class
36
+ dupval = val.dup
37
+ else
38
+ dupval = val
39
+ end
40
+ tgt[key] = dupval unless tgt.has_key? key and tgt[key].class == val.class
41
+ end
42
+ end
43
+ end
44
+ def process_localized_strings( str_hash )
45
+ langs = str_hash.keys.sort { |a,b| (a > b) ? ( ( a.length > b.length ) ? 1 : -1 ) : -1 }
46
+ default_lang = RSence.config[:lang]
47
+ if langs.include? default_lang
48
+ default_hash = deep_merge_hash( str_hash[default_lang] )
49
+ else
50
+ warn "Warning in #{bundle_path} #process_localized_strings: No default language in localized, using '#{langs.first}' instead"
51
+ default_hash = deep_merge_hash( str_hash[langs.first] )
52
+ end
53
+ langs.each do |lang|
54
+ # create a new copy of the default hash
55
+ base_hash = deep_merge_hash( default_hash )
56
+ if lang.length == 5 and langs.include? lang[0..1]
57
+ # create a base of extended language from the base languge (eg. 'en' for 'en-US')
58
+ base_hash = deep_merge_hash( str_hash[lang[0..1]], base_hash )
59
+ end
60
+ # finally complete the language hash with the base
61
+ deep_merge_hash( base_hash, str_hash[lang] )
62
+ end
63
+ end
64
+ def read_localized_strings( fn='localized.yaml' )
65
+ strs_raw = read_strings( fn )
66
+ return nil unless strs_raw
67
+ str_hash = {}
68
+ if strs_raw
69
+ parse_strs_raw( str_hash, strs_raw, [] )
70
+ end
71
+ process_localized_strings( str_hash )
72
+ str_hash
73
+ end
74
+ def init_strings
75
+ [ 'strings.yaml', 'gui/strings.yaml' ].each do |yaml_name|
76
+ strs = read_strings( yaml_name )
77
+ @strings = strs
78
+ break if strs
79
+ end
80
+ end
81
+ def init_localized_strings
82
+ [ 'localized.yaml', 'gui/localized.yaml' ].each do |yaml_name|
83
+ strs = read_localized_strings( yaml_name )
84
+ @localized_strings = strs
85
+ break if strs
86
+ end
87
+ end
88
+ def init
89
+ super
90
+ init_strings
91
+ init_localized_strings
92
+ end
93
+ def gui_params( msg )
94
+ params = {}
95
+ if @strings
96
+ params[:strings] = strings()
97
+ end
98
+ if @localized_strings
99
+ params[:localized] = localized_strings( msg )
100
+ end
101
+ params
102
+ end
103
+ def strings_params_search( arr_path, params )
104
+ if arr_path.class == String
105
+ arr_path = arr_path.split('.')
106
+ elsif arr_path.class != Array
107
+ warn "Warning in #{bundle_path} #strings_params_search: Invalid string_path class #{arr_path.class.to_s}"
108
+ return nil
109
+ end
110
+ item = arr_path.shift
111
+ if params.class == Hash
112
+ if params.has_key?( item )
113
+ if arr_path.size == 0
114
+ return params[item]
115
+ else
116
+ return strings_params_search( arr_path, params[ item ] )
117
+ end
118
+ end
119
+ end
120
+ ''
121
+ end
122
+ def strings( string_path=nil )
123
+ return nil unless @strings
124
+ return @strings if string_path.nil?
125
+ strings_params_search( arr_path.dup, @strings )
126
+ end
127
+ def localized_strings( msg, string_path=nil )
128
+ return nil unless @localized_strings
129
+ if msg.class == String
130
+ lang = msg
131
+ else
132
+ lang = msg.lang
133
+ end
134
+ default_lang = RSence.config[:lang]
135
+ if @localized_strings.has_key?( lang )
136
+ search_obj = @localized_strings[lang]
137
+ elsif lang.length == 5 and lang[2] == '-' and @localized_strings.has_key?( lang[0..1] )
138
+ warn "Warning in #{bundle_path} #localized_strings: No '#{lang}' language, using variant '#{lang[0..1]}' instead" if RSence.args[:verbose]
139
+ lang = lang[0..1]
140
+ search_obj = @localized_strings[lang]
141
+ elsif @localized_strings.has_key?( default_lang )
142
+ warn "Warning in #{bundle_path} #localized_strings: No '#{lang}' language, using default '#{default_lang}' instead" if RSence.args[:verbose]
143
+ search_obj = @localized_strings[lang]
144
+ else
145
+ warn "Error in #{bundle_path} #localized_strings: No '#{lang}' language, no default '#{default_lang}' either"
146
+ return nil
147
+ end
148
+ return search_obj if string_path.nil?
149
+ strings_params_search( string_path, search_obj )
150
+ end
151
+ end
152
+ end
153
+ end
@@ -90,7 +90,9 @@ module RSence
90
90
  :_msg_unused => true,
91
91
 
92
92
  # user info, map to your own user management code
93
- :user_info => {},
93
+ :user_info => {
94
+ :lang => RSence.config[:lang]
95
+ },
94
96
 
95
97
  # sequence number of session, incremented by each restore
96
98
  :ses_seq => 0,
@@ -130,9 +132,6 @@ module RSence
130
132
  end
131
133
 
132
134
  def refresh_ses( msg, ses_data, ses_id, ses_key, ses_seed )
133
- ## Perform old-session cleanup before extending another
134
- # expire_sessions
135
-
136
135
  # new time-out
137
136
  ses_data[:timeout] = Time.now.to_i + @config[:timeout_secs]
138
137
 
@@ -238,9 +237,6 @@ module RSence
238
237
  ### Returns the current session data, if the session is valid.
239
238
  ### Otherwise stops the client and returns false.
240
239
  def check_ses( msg, ses_key, ses_seed=false )
241
-
242
- ## Perform old-session cleanup while checking for another
243
- # expire_sessions
244
240
 
245
241
  # first, check if the session key exists (sync)
246
242
  if @session_keys.has_key?( ses_key )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsence-pre
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0.25
4
+ version: 2.3.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Riassence Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-03 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rsence-deps
@@ -72,6 +72,7 @@ files:
72
72
  - lib/rsence/plugins/guiparser.rb
73
73
  - lib/rsence/plugins/plugin.rb
74
74
  - lib/rsence/plugins/plugin_base.rb
75
+ - lib/rsence/plugins/plugin_localization.rb
75
76
  - lib/rsence/plugins/plugin_plugins.rb
76
77
  - lib/rsence/plugins/plugin_sqlite_db.rb
77
78
  - lib/rsence/plugins/servlet.rb