spiderfw 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ = 0.6.9
2
+ == 28 July, 2011
3
+ * App installer now uses Git gem instead of Grit for better Windows compatibility
4
+ * Switched from GetText to FastGettext
5
+
1
6
  = 0.6.8
2
7
  == 26 July, 2011
3
8
  * Windows fix (no HUP trapping)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.8
1
+ 0.6.9
@@ -89,8 +89,8 @@ module Spider; module Auth
89
89
  model_name = parts[i..-2].join('_')+'_'
90
90
  self_name = self_parts[i..-2].join('_')+'_'
91
91
  end
92
- model_name += model.label_plural
93
- self_name += self.label_plural
92
+ model_name += model.label_plural_
93
+ self_name += self.label_plural_
94
94
  model_name.downcase!
95
95
  self_name.downcase!
96
96
  break
@@ -44,7 +44,6 @@ module Spider; module Components
44
44
  crud.table_widget = @custom_widgets[model][:table] if @custom_widgets[model][:table]
45
45
  crud.form_widget = @custom_widgets[model][:form] if @custom_widgets[model][:form]
46
46
  end
47
-
48
47
  @widgets[:switcher].add(model.label_plural, crud, _('Manage Data'))
49
48
  end
50
49
  if (@request.respond_to?(:user) && @request.user)
@@ -13,7 +13,7 @@ module Spider; module Master
13
13
  many :commands, Master::Command, :add_reverse => :server
14
14
  element_query :pending_commands, :commands, :condition => Spider::Model::Condition.new{ |c| c.status == 'pending' }
15
15
  many :resources, Master::Resource, :delete_cascade => true
16
- choice :customer, Master::Customer, :add_multiple_reverse => :server
16
+ choice :customer, Master::Customer, :add_multiple_reverse => :servers
17
17
  element :scout_plan_changed, DateTime, :hidden => true
18
18
  multiple_choice :admins, Master::Admin, :add_multiple_reverse => :server do
19
19
  element :receive_notifications, Bool, :default => true
@@ -98,7 +98,7 @@ module Spider
98
98
  context = []
99
99
  indents = {}
100
100
  prev_indent = ""
101
- curr = data
101
+ curr = data.dup
102
102
  curr_val = ""
103
103
  last_key = nil
104
104
  level = 0
@@ -90,6 +90,10 @@ module Spider
90
90
  Locale.init(:driver => :cgi)
91
91
  Locale.set_request(@request.params['lang'], @request.cookies['lang'], @request.env['HTTP_ACCEPT_LANGUAGE'], @request.env['HTTP_ACCEPT_CHARSET'])
92
92
  @request.locale = Locale.current[0]
93
+ l = @request.locale.to_s
94
+ l = $1 if l =~ /(\w\w)_+/
95
+ FastGettext.locale = l
96
+ FastGettext.text_domain = 'spider'
93
97
  if (action =~ /(.+)\.(\w+)$/) # strip extension, set format
94
98
  action = $1
95
99
  @request.format = $2.to_sym
@@ -94,7 +94,7 @@ module Spider; module ControllerMixins
94
94
  end
95
95
 
96
96
  def base_url
97
- self.class.base_url
97
+ HTTPMixin.base_url
98
98
  end
99
99
 
100
100
  def prepare_scene(scene)
@@ -210,11 +210,13 @@ module Spider; module ControllerMixins
210
210
  end
211
211
  init_widgets(template, layout)
212
212
  return template if done?
213
- if layout
214
- layout.render(scene)
215
- else
216
- template.render(scene)
217
- end
213
+ Spider::GetText.in_domain(self.class.app.short_name){
214
+ if layout
215
+ layout.render(scene)
216
+ else
217
+ template.render(scene)
218
+ end
219
+ }
218
220
  return template
219
221
  end
220
222
 
@@ -34,21 +34,21 @@ module Spider
34
34
  create(source_path, dest_path)
35
35
 
36
36
  begin
37
- require 'grit'
37
+ require 'git'
38
38
 
39
39
  cwd = Dir.getwd
40
40
  Dir.chdir(dest_path)
41
41
  begin
42
- repo = Grit::Repo.init(dest_path)
43
- repo.add('apps', 'config', 'init.rb', 'public')
42
+ repo = Git.init(dest_path)
43
+ repo.add(['apps', 'config', 'init.rb', 'public'])
44
44
  repo.add('.gitignore')
45
- repo.commit_index(_("Created repository"))
45
+ repo.commit(_("Created repository"))
46
46
  rescue => exc
47
47
  puts "Unable to init Git repo, please init manually"
48
48
  end
49
49
  Dir.chdir(cwd)
50
50
  rescue LoadError
51
- puts "Grit not installed, cannot init repo"
51
+ puts "git gem not installed, cannot init repo"
52
52
  end
53
53
  end
54
54
 
@@ -1,8 +1,24 @@
1
- # def _(s)
2
- # s
3
- # end
1
+ require 'fast_gettext'
2
+ require 'locale'
3
+ include FastGettext::Translation
4
+ FastGettext.add_text_domain('spider', :path => File.join($SPIDER_PATH, 'data', 'locale'))
5
+ FastGettext.text_domain = 'spider'
6
+ l = Locale.current[0].to_s
7
+ l = $1 if l =~ /(\w\w)_+/
8
+ FastGettext.locale = l
4
9
 
5
- require 'gettext'
6
- include GetText
7
- bindtextdomain('spider')
8
- GetText.set_output_charset('utf-8')
10
+ module Spider
11
+
12
+ module GetText
13
+
14
+ def self.in_domain(domain, &block)
15
+ prev_text_domain = FastGettext.text_domain
16
+ FastGettext.text_domain = domain if FastGettext.translation_repositories.key?(domain)
17
+ v = yield
18
+ FastGettext.text_domain = prev_text_domain
19
+ v
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -99,7 +99,11 @@ module Spider; module Model
99
99
  @subclasses ||= []
100
100
  @subclasses << subclass
101
101
  each_element do |el|
102
- subclass.add_element(el.clone) unless el.attributes[:local_pk]
102
+ unless el.attributes[:local_pk]
103
+ cl_el = el.clone
104
+ cl_el.definer_model = el.definer_model
105
+ subclass.add_element(cl_el)
106
+ end
103
107
  end
104
108
  subclass.instance_variable_set("@mapper_modules", @mapper_modules.clone) if @mapper_modules
105
109
  subclass.instance_variable_set("@extended_models", @extended_models.clone) if @extended_models
@@ -116,7 +120,7 @@ module Spider; module Model
116
120
  def self.app
117
121
  return @app if @app
118
122
  app = self
119
- while (!app.include?(Spider::App))
123
+ while !app.include?(Spider::App)
120
124
  app = app.parent_module
121
125
  end
122
126
  @app = app
@@ -527,6 +531,7 @@ module Spider; module Model
527
531
  def self.add_element(el)
528
532
  @elements ||= {}
529
533
  @elements[el.name] = el
534
+ el.definer_model ||= self
530
535
  @elements_order ||= []
531
536
  if (el.attributes[:element_position])
532
537
  @elements_order.insert(el.attributes[:element_position], el.name)
@@ -880,13 +885,29 @@ module Spider; module Model
880
885
  def self.label(sing=nil, plur=nil)
881
886
  @label = sing if sing
882
887
  @label_plural = plur if plur
883
- _(@label || self.name || '')
888
+ unless sing
889
+ Spider::GetText.in_domain(self.app.short_name){
890
+ _(@label || self.name || '')
891
+ }
892
+ end
884
893
  end
885
894
 
886
895
  # Sets/retrieves the plural form for the label
887
896
  def self.label_plural(val=nil)
888
897
  @label_plural = val if (val)
889
- _(@label_plural || self.name || '')
898
+ unless val
899
+ Spider::GetText.in_domain(self.app.short_name){
900
+ _(@label_plural || self.name || '')
901
+ }
902
+ end
903
+ end
904
+
905
+ def self.label_
906
+ @label
907
+ end
908
+
909
+ def self.label_plural_
910
+ @label_plural
890
911
  end
891
912
 
892
913
  def self.auto_primary_keys?
@@ -7,6 +7,7 @@ module Spider; module Model
7
7
  class Element
8
8
  attr_reader :name
9
9
  attr_accessor :attributes
10
+ attr_accessor :definer_model
10
11
 
11
12
  def initialize(name, type, attributes={})
12
13
  @name = name
@@ -145,7 +146,16 @@ module Spider; module Model
145
146
 
146
147
  # Label. Will use the :label attribute, or return the name split by '_' with each word capitalized.
147
148
  def label
148
- return self.attributes[:label] ? _(self.attributes[:label]) : Inflector.underscore_to_upcasefirst(@name.to_s)
149
+ prev_text_domain = nil
150
+ if @definer_model && @definer_model != Spider::Model::Managed
151
+ prev_text_domain = FastGettext.text_domain
152
+ FastGettext.text_domain = @definer_model.app.short_name
153
+ end
154
+ l = self.attributes[:label] ? _(self.attributes[:label]) : Inflector.underscore_to_upcasefirst(@name.to_s)
155
+ if prev_text_domain
156
+ FastGettext.text_domain = prev_text_domain
157
+ end
158
+ l
149
159
  end
150
160
 
151
161
  def to_s
@@ -18,9 +18,11 @@ module Spider; module Model
18
18
  self.data = val if (val)
19
19
  d = @data
20
20
  if self.translate?
21
- @data.each do |k, v|
22
- d[k] = _(v)
23
- end
21
+ Spider::GetText.in_domain(self.app.short_name){
22
+ @data.each do |k, v|
23
+ d[k] = _(v)
24
+ end
25
+ }
24
26
  end
25
27
  d
26
28
  end
@@ -6,11 +6,13 @@ module Spider; module Model
6
6
  def initialize(name, owner, integrated_element, integrated_element_element, attributes={})
7
7
  @name = name
8
8
  @owner = owner
9
+ el = @owner.elements[integrated_element]
10
+ @definer_model = el.model.elements[integrated_element_element].definer_model
9
11
  @integrated_element = integrated_element
10
12
  @integrated_element_element = integrated_element_element
11
13
  @attributes = ({
12
14
  :integrated => true,
13
- :integrated_from => @owner.elements[@integrated_element],
15
+ :integrated_from => el,
14
16
  :integrated_from_element => @integrated_element_element
15
17
  }).merge(attributes)
16
18
  end
@@ -34,11 +34,11 @@ module Spider
34
34
  use_git = false
35
35
  unless options[:no_git]
36
36
  begin
37
- require 'grit'
37
+ require 'git'
38
38
  use_git = true
39
39
  rescue => exc
40
40
  puts exc.message
41
- puts "Grit not available; install Grit for Git support"
41
+ puts "git gem not available; install git gem for Git support"
42
42
  end
43
43
  end
44
44
 
@@ -74,7 +74,7 @@ module Spider
74
74
  :no_optional_gems => options[:no_optional_gems]
75
75
  }
76
76
  i_options[:ssh_user] = options[:ssh_user] if options[:ssh_user]
77
- inst_specs = specs.reject!{ |s| existent.include? s.app_id }
77
+ inst_specs = specs.reject{ |s| existent.include? s.app_id }
78
78
  Spider::AppManager.install(inst_specs, Dir.pwd, i_options)
79
79
  unless options[:no_activate]
80
80
  require 'spiderfw/spider'
@@ -93,10 +93,10 @@ module Spider
93
93
  use_git = false
94
94
  unless options[:no_git]
95
95
  begin
96
- require 'grit'
96
+ require 'git'
97
97
  use_git = true
98
98
  rescue
99
- puts "Grit not available; install Grit for Git support"
99
+ puts "git gem not available; install git gem for Git support"
100
100
  end
101
101
  end
102
102
  if options[:all]
@@ -131,7 +131,8 @@ module Spider
131
131
  def self.install(specs, home_path, options)
132
132
  options[:use_git] = true unless options[:use_git] == false
133
133
  options[:home_path] = home_path
134
- specs = [specs] unless specs.is_a?(Array)
134
+ specs = [specs] if specs && !specs.is_a?(Array)
135
+ specs ||= []
135
136
  pre_setup(specs, options)
136
137
  specs.each do |spec|
137
138
  if spec.git_repo && options[:use_git]
@@ -144,22 +145,25 @@ module Spider
144
145
  end
145
146
 
146
147
  def self.git_install(spec, home_path, options={})
147
- require 'grit'
148
+ require 'git'
148
149
  if ::File.exist?("apps/#{spec.id}")
149
150
  puts _("%s already installed, skipping") % spec.id
150
151
  return
151
152
  end
152
- repo = Grit::Repo.new(home_path)
153
+ repo = Git.open(home_path)
153
154
  puts _("Fetching %s from %s") % [spec.app_id, spec.git_repo]
154
155
  repo_url = spec.git_repo
155
156
  if options[:ssh_user] && repo_url =~ /ssh:\/\/([^@]+@)?(.+)/
156
157
  repo_url = "ssh://#{options[:ssh_user]}@#{$2}"
157
158
  end
158
- `#{Grit::Git.git_binary} submodule add #{repo_url} apps/#{spec.id}`
159
- repo.git.submodule({}, "init")
160
- repo.git.submodule({}, "update")
161
- repo.add('.gitmodules', "apps/#{spec.id}")
162
- repo.commit_index(_("Added app %s") % spec.id)
159
+
160
+ Dir.chdir(home_path) do
161
+ `git submodule add #{repo_url} apps/#{spec.id}`
162
+ `git submodule init`
163
+ `git submodule update`
164
+ end
165
+ repo.add(['.gitmodules', "apps/#{spec.id}"])
166
+ repo.commit(_("Added app %s") % spec.id)
163
167
  end
164
168
 
165
169
  def self.pack_install(spec, home_path, options={})
@@ -223,30 +227,29 @@ module Spider
223
227
  end
224
228
 
225
229
  def self.git_update(spec, home_path, options={})
226
- require 'grit'
227
- home_repo = Grit::Repo.new(home_path)
230
+ require 'git'
231
+ home_repo = Git.open(home_path)
228
232
  app_path = File.join(home_path, "apps/#{spec.id}")
229
- app_repo = Grit::Repo.new(app_path)
233
+ app_repo = Git.open(app_path)
230
234
  puts _("Updating %s from %s") % [spec.app_id, spec.git_repo]
231
235
  Dir.chdir(app_path) do
232
- app_repo.git.checkout({}, "master")
236
+ app_repo.branch('master').checkout
233
237
  end
234
- cmd = "#{Grit::Git.git_binary} --git-dir='#{app_path}/.git' pull"
235
238
  response = err = nil
236
239
  Dir.chdir(app_path) do
237
- response, err = app_repo.git.wild_sh(cmd)
240
+ `git --git-dir='#{app_path}/.git' pull origin master`
238
241
  end
239
242
  if response =~ /Aborting/
240
243
  puts err
241
244
  return
242
245
  end
243
246
  Dir.chdir(app_path) do
244
- app_repo.git.reset({:hard => true}, 'HEAD')
245
- app_repo.git.checkout
247
+ app_repo.reset('HEAD', :hard => true)
248
+ app_repo.branch('master').checkout
246
249
  end
247
250
 
248
251
  home_repo.add("apps/#{spec.id}")
249
- home_repo.commit_index(_("Updated app %s") % spec.id)
252
+ home_repo.commit(_("Updated app %s") % spec.id)
250
253
  end
251
254
 
252
255
  def self.pack_update(spec, home_path, options={})
@@ -83,15 +83,15 @@ module Spider
83
83
  end
84
84
 
85
85
  def init_apps
86
- @apps.each do |name, mod|
87
- mod.app_init if mod.respond_to?(:app_init)
88
- end
89
- GetText::LocalePath.memoize_clear # since new paths have been added to GetText
90
86
  @apps.each do |name, mod|
91
87
  if File.directory?(File.join(mod.path, 'po'))
92
- GetText.bindtextdomain(mod.short_name)
88
+ Spider.logger.debug("Adding text domain #{mod.short_name}")
89
+ FastGettext.add_text_domain(mod.short_name, :path => File.join(mod.path, 'data', 'locale'))
93
90
  end
94
91
  end
92
+ @apps.each do |name, mod|
93
+ mod.app_init if mod.respond_to?(:app_init)
94
+ end
95
95
  end
96
96
 
97
97
  def init_done?
@@ -365,7 +365,6 @@ module Spider
365
365
  last_name = File.basename(path)
366
366
  app_files = ['_init.rb', last_name+'.rb', 'cmd.rb']
367
367
  app_files.each{ |f| require File.join(relative_path, f) if File.exist?(File.join(path, f)) }
368
- GetText::LocalePath.add_default_rule(File.join(path, "data/locale/%{lang}/LC_MESSAGES/%{name}.mo"))
369
368
  end
370
369
 
371
370
 
@@ -249,7 +249,9 @@ module Spider
249
249
  super
250
250
  @is_target = false
251
251
  @widgets = {}
252
- @attributes = WidgetAttributes.new(self)
252
+ Spider::GetText.in_domain(self.class.app.short_name){
253
+ @attributes = WidgetAttributes.new(self)
254
+ }
253
255
  @id_path = []
254
256
  @widget_attributes = {}
255
257
  locale = @request.locale.language
@@ -317,13 +319,15 @@ module Spider
317
319
  end
318
320
 
319
321
  def widget_before(action='')
320
- #Spider.logger.debug("Widget #{self} widget_before(#{action})")
321
- widget_init(action)
322
- return unless active?
323
- #Spider.logger.debug("Preparing widget #{self}")
324
- prepare_scene(@scene)
325
- prepare
326
- @before_done = true
322
+ Spider::GetText.in_domain(self.class.app.short_name){
323
+ widget_init(action)
324
+ if active?
325
+ prepare_scene(@scene)
326
+ prepare
327
+ @before_done = true
328
+ end
329
+ }
330
+
327
331
  end
328
332
 
329
333
 
@@ -425,7 +429,7 @@ module Spider
425
429
 
426
430
  # Instantiates this widget's own subwidgets.
427
431
  def load_widgets(template=@template)
428
- if (self.class.scene_attributes)
432
+ if self.class.scene_attributes
429
433
  self.class.scene_attributes.each do |name|
430
434
  @scene[name] = instance_variable_get("@#{name}")
431
435
  end
@@ -472,7 +476,7 @@ module Spider
472
476
 
473
477
  def run(action='')
474
478
  @widgets.each do |wname, w|
475
- w.run if w.run?
479
+ w.do_run if w.run?
476
480
  end
477
481
  if (@parent)
478
482
  @parent.after_widget(@id.to_sym)
@@ -489,33 +493,43 @@ module Spider
489
493
  end
490
494
 
491
495
  def index
492
- run
496
+ do_run
493
497
  render
494
498
  end
495
499
 
500
+ def do_run
501
+ Spider::GetText.in_domain(self.class.app.short_name){
502
+ run
503
+ }
504
+ end
505
+
496
506
  def render
497
- prepare_scene(@scene)
498
- set_scene_vars(@scene)
499
- @template.render(@scene) unless @is_target_ancestor && !@is_target
507
+ Spider::GetText.in_domain(self.class.app.short_name){
508
+ prepare_scene(@scene)
509
+ set_scene_vars(@scene)
510
+ @template.render(@scene) unless @is_target_ancestor && !@is_target
511
+ }
500
512
  end
501
513
 
502
514
  def execute(action='', *params)
503
515
  Spider.logger.debug("Widget #{self} executing #{action}")
504
- widget_execute = @request.params['_we']
505
- if (@is_target)
506
- if (widget_execute)
507
- super(widget_execute, *params)
516
+ Spider::GetText.in_domain(self.class.app.short_name){
517
+ widget_execute = @request.params['_we']
518
+ if (@is_target)
519
+ if (widget_execute)
520
+ super(widget_execute, *params)
521
+ else
522
+ do_run
523
+ render
524
+ end
525
+ elsif (@_widget)
526
+ @_widget.set_action(widget_execute)
527
+ @_widget.before(@_widget_rest, *params)
528
+ @_widget.execute(@_widget_rest, *params)
508
529
  else
509
- run
510
- render
530
+ super
511
531
  end
512
- elsif (@_widget)
513
- @_widget.set_action(widget_execute)
514
- @_widget.before(@_widget_rest, *params)
515
- @_widget.execute(@_widget_rest, *params)
516
- else
517
- super
518
- end
532
+ }
519
533
  end
520
534
 
521
535
  def try_rescue(exc)
@@ -751,7 +765,7 @@ module Spider
751
765
  end
752
766
 
753
767
  def set_scene_vars(scene)
754
- if (self.class.scene_attributes) # Repeat for new instance variables
768
+ if self.class.scene_attributes # Repeat for new instance variables
755
769
  self.class.scene_attributes.each do |name|
756
770
  @scene[name] = instance_variable_get("@#{name}")
757
771
  end
data/spider.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.executables = ['spider']
29
29
  s.default_executable = 'spider'
30
30
  s.add_dependency("cmdparse", ["> 2.0.0"])
31
- s.add_dependency("gettext", ["> 2.0.0"])
31
+ s.add_dependency("fast_gettext", [">= 0.5.13"])
32
32
  s.add_dependency("hpricot", ["> 0.8"])
33
33
  s.add_dependency("json_pure", ["> 1.1"])
34
34
  s.add_dependency("uuidtools", ["> 2.1"])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spiderfw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 8
10
- version: 0.6.8
9
+ - 9
10
+ version: 0.6.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ivan Pirlik
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-26 00:00:00 +02:00
18
+ date: 2011-07-28 00:00:00 +02:00
19
19
  default_executable: spider
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -35,19 +35,19 @@ dependencies:
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: gettext
38
+ name: fast_gettext
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ">"
43
+ - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 15
45
+ hash: 17
46
46
  segments:
47
- - 2
48
- - 0
49
47
  - 0
50
- version: 2.0.0
48
+ - 5
49
+ - 13
50
+ version: 0.5.13
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency