spiderfw 0.5.16 → 0.5.17

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ = 0.5.17
2
+ == 20 December, 2010
3
+ * Better assets compression; assets profiles
4
+ * Bugfixes
5
+
6
+
7
+
1
8
  = 0.5.16
2
9
  == 07 December, 2010
3
10
  * Added app update command
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.16
1
+ 0.5.17
@@ -1,6 +1,7 @@
1
1
  Spider::Template.define_named_asset 'jquery', [
2
- [:js, 'js/jquery/jquery-1.4.3.js', Spider::Components]
2
+ [:js, 'js/jquery/jquery-1.4.3.js', Spider::Components, {:cdn => 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'}]
3
3
  ]
4
+
4
5
  Spider::Template.define_named_asset 'spider', [
5
6
  [:js, 'js/inheritance.js', Spider::Components],
6
7
  [:js, 'js/spider.js', Spider::Components],
@@ -199,6 +199,7 @@ Spider.Widget = Class.extend({
199
199
  if (options.before) options.before();
200
200
  },
201
201
  success: function(res){
202
+ w.trigger('ajaxifyResponse', form);
202
203
  w.replaceHTML(res);
203
204
  w.removeLoading();
204
205
  if (options.onLoad) options.onLoad(form);
@@ -231,6 +232,7 @@ Spider.Widget = Class.extend({
231
232
  type: 'GET',
232
233
  dataType: 'html',
233
234
  success: function(res){
235
+ w.trigger('ajaxifyResponse', a);
234
236
  w.replaceHTML(res);
235
237
  w.removeLoading();
236
238
  if (options.onLoad) options.onLoad(a);
@@ -78,8 +78,10 @@ module Spider; module Forms
78
78
  @model = const_get_full(@model) if @model.is_a?(String)
79
79
  if @model.method_defined?(:to_subclass) # FIXME: this is a quick hack, standardize
80
80
  @obj ||= load
81
- @obj = @obj.to_subclass
82
- @model = @obj.class
81
+ if @obj
82
+ @obj = @obj.to_subclass
83
+ @model = @obj.class
84
+ end
83
85
  end
84
86
  if (@elements.is_a?(String))
85
87
  @elements = @elements.split(',').map{ |e| @model.elements[e.strip.to_sym] }.reject{ |i| i.nil? }
@@ -4,7 +4,7 @@
4
4
  <tpl:asset type="js" src="html_area.js" /><tpl:asset type="js" src="text_area.js" />
5
5
  <!--- <tpl:asset type="css" src="jwysiwyg/jquery.wysiwyg.css" />
6
6
  <tpl:asset type="js" src="jwysiwyg/jquery.wysiwyg.js" /> -->
7
- <tpl:asset type="js" src="ckeditor/ckeditor.js" />
7
+ <tpl:asset type="js" src="ckeditor/ckeditor.js" compressed="true"/>
8
8
  <tpl:asset type="js" src="ckeditor/adapters/jquery.js" />
9
9
  <div class="initial_html" style="display:none">{ @initial_html }</div>
10
10
  <div class="css" style="display:none">{ @css }</div>
@@ -109,6 +109,7 @@ class AppCommand < CmdParse::Command
109
109
  opt.on("--no-optional-gems", _("Don't install optional gem dependencies"), "-G"){ |g|
110
110
  @no_optional_gems = true
111
111
  }
112
+ opt.on("--ssh-user [USERNAME]", _("SSH user")){ |s| @ssh_user = s }
112
113
  end
113
114
  install.set_execution_block do |args|
114
115
  unless File.exist?('init.rb') && File.directory?('apps')
@@ -121,7 +122,8 @@ class AppCommand < CmdParse::Command
121
122
  begin
122
123
  require 'grit'
123
124
  use_git = true
124
- rescue
125
+ rescue => exc
126
+ puts exc.message
125
127
  puts "Grit not available; install Grit for Git support"
126
128
  end
127
129
  end
@@ -147,11 +149,13 @@ class AppCommand < CmdParse::Command
147
149
  puts _("The following apps will be installed as a dependency:")
148
150
  puts (deps - apps).inspect
149
151
  end
150
- Spider::AppManager.install(specs, Dir.pwd, {
152
+ options = {
151
153
  :use_git => use_git,
152
154
  :no_gems => @no_gems,
153
155
  :no_optional_gems => @no_optional_gems
154
- })
156
+ }
157
+ options[:ssh_user] = @ssh_user if @ssh_user
158
+ Spider::AppManager.install(specs, Dir.pwd, options)
155
159
  end
156
160
  self.add_command(install)
157
161
 
@@ -156,6 +156,8 @@ module Spider
156
156
  :default => lambda{ Spider.config.get('runmode') == 'production' ? true : false }, :type => Spider::DataTypes::Bool
157
157
  config_option 'css.cachebuster', _("Use cache busters for CSS urls"), :type => Symbol,
158
158
  :default => :soft, :choices => [false, :soft, :hard, :hardcopy]
159
+ config_option 'assets.use_cdn', _("Use a Content Delivery Network for assets if defined"), :type => Spider::Bool,
160
+ :default => lambda{ Spider.config.get('runmode') == 'production' ? true : false }
159
161
 
160
162
  config_option 'http_proxy', _("Proxy to use for http clients (http://user:pass@host:port)"), :type => String,
161
163
  :do => lambda{ |val| ENV['http_proxy'] = val }
@@ -39,6 +39,7 @@ module Spider
39
39
  b = @body.is_a?(String) ? StringIO.new(@body) : @body
40
40
  return nil unless b
41
41
  if block_given?
42
+ b.rewind
42
43
  while (buf = b.read(BUFSIZE))
43
44
  yield buf
44
45
  end
@@ -4,6 +4,7 @@ require 'locale'
4
4
 
5
5
  module Spider; module I18n
6
6
 
7
+ # Formats: short, medium, full, long
7
8
  class CLDR < Provider
8
9
 
9
10
  def initialize(locale)
@@ -376,6 +376,7 @@ module Spider; module Model
376
376
  end
377
377
  if (@subclasses)
378
378
  @subclasses.each do |sub|
379
+ next if sub == type && attributes[:added_reverse] && sub.elements[attributes[:reverse]].type == self # subclass ref to parent
379
380
  next if sub.elements[name] # if subclass already defined an element with this name, don't overwrite it
380
381
  sub.elements[name] = @elements[name].clone
381
382
  sub.elements_order << name
@@ -169,10 +169,10 @@ module Spider; module Model
169
169
 
170
170
  # Sets a comparison.
171
171
  def set(field, comparison, value)
172
- if (value.is_a?(QuerySet))
172
+ if value.is_a?(QuerySet)
173
173
  value = value.to_a
174
174
  end
175
- if (value.is_a?(Array))
175
+ if value.is_a?(Array) && comparison != 'between'
176
176
  or_cond = self.class.or
177
177
  value.uniq.each do |v|
178
178
  or_cond.set(field, comparison, v)
@@ -253,7 +253,7 @@ module Spider; module Model
253
253
  # Elements that are associated to this one externally.
254
254
  def association_elements
255
255
  els = @model.elements_array.select{ |el|
256
- mapped?(el) && !el.integrated? && !have_references?(el) && !(el.attributes[:added_reverse] && el.type == @model)
256
+ mapped?(el) && !el.integrated? && !have_references?(el) && !(el.attributes[:added_reverse] && el.type <= @model)
257
257
  }
258
258
  if @unit_of_work_task
259
259
  els = els.select{ |el| el.attributes[:junction] && !el.attributes[:keep_junction] }
@@ -404,6 +404,7 @@ module Spider; module Model
404
404
  # Deletes an object, or objects according to a condition.
405
405
  # Will not delete with null condition (i.e. all objects) unless force is true
406
406
  def delete(obj_or_condition, force=false)
407
+
407
408
  def prepare_delete_condition(obj)
408
409
  condition = Condition.and
409
410
  @model.primary_keys.each do |key|
@@ -882,6 +883,14 @@ module Spider; module Model
882
883
  condition = @model.prepare_condition(condition)
883
884
  basic_preprocess(condition)
884
885
  end
886
+ if @model.attributes[:integrated_models]
887
+ @model.attributes[:integrated_models].each do |im, iel|
888
+ if im.respond_to?(:prepare_condition)
889
+ condition = im.prepare_condition(condition)
890
+ basic_preprocess(condition)
891
+ end
892
+ end
893
+ end
885
894
 
886
895
  # Utility function to set conditions on
887
896
  def set_pks_condition(condition, el, val, prefix) # :nodoc:
@@ -6,7 +6,7 @@ module Spider; module Model; module Storage
6
6
  attr_accessor :instance_name
7
7
 
8
8
  def self.sequence_sync
9
- @sequence_sync ||= Sync.new
9
+ @sequence_sync ||= ::Sync.new
10
10
  end
11
11
 
12
12
  def self.base_types
@@ -96,7 +96,7 @@ module Spider; module Model; module Storage
96
96
  f.flock File::LOCK_UN
97
97
  f.close
98
98
  end
99
- self.class.sequence_sync.lock(Sync::UN)
99
+ self.class.sequence_sync.lock(::Sync::UN)
100
100
  return seq
101
101
  end
102
102
 
@@ -112,4 +112,4 @@ module Spider; module Model; module Storage
112
112
 
113
113
 
114
114
 
115
- end; end; end
115
+ end; end; end
@@ -194,10 +194,10 @@ module Spider; module Model; module Storage; module Db
194
194
  sql = "#{key} #{comp} NULL"
195
195
  else
196
196
  if comp.to_s.downcase == 'between'
197
- if (bound_vars)
198
- val0, val1 = value
199
- else
197
+ if bound_vars
200
198
  val0 = ":#{(curr[:bind_cnt] += 1)}"; val1 = ":#{(curr[:bind_cnt] += 1)}"
199
+ else
200
+ val0, val1 = value
201
201
  end
202
202
  sql = "#{key} #{comp} #{val0} AND #{val1}"
203
203
  else
@@ -263,6 +263,10 @@ module Spider; module Model; module Storage; module Db
263
263
  ##############################################################
264
264
  # Methods to get information from the db #
265
265
  ##############################################################
266
+
267
+ def post_execute
268
+ curr[:bind_cnt] = 0
269
+ end
266
270
 
267
271
  def list_tables
268
272
  return execute("SELECT TABLE_NAME FROM user_tables ORDER BY table_name").map{ |r| r['TABLE_NAME'] }
@@ -149,6 +149,7 @@ module Spider; module Model; module Storage; module Db; module Connectors
149
149
  query_finished
150
150
  cursor.close if cursor
151
151
  release if curr[:conn] && !in_transaction?
152
+ post_execute
152
153
  end
153
154
  end
154
155
 
@@ -92,6 +92,7 @@ module Spider; module Model; module Storage; module Db
92
92
  end
93
93
 
94
94
  def query_finished
95
+ return unless curr[:query_start] # happens if there was no db connection
95
96
  now = Time.now
96
97
  diff = now - curr[:query_start]
97
98
  diff = 0 if diff < 0 # ???
@@ -0,0 +1,13 @@
1
+ module Hpricot
2
+ class DocType
3
+ def output(out, opts = {})
4
+ out <<
5
+ if_output(opts) do
6
+ "<!DOCTYPE #{target}" +
7
+ (public_id ? " PUBLIC \"#{public_id}\"" : "") +
8
+ (system_id ? " SYSTEM #{html_quote(system_id)}" : "") + ">"
9
+ end
10
+ end
11
+ end
12
+
13
+ end
@@ -11,25 +11,33 @@ module Spider
11
11
  pre_setup(specs, options)
12
12
  specs.each do |spec|
13
13
  if spec.git_repo && options[:use_git]
14
- git_install(spec, home_path)
14
+ git_install(spec, home_path, options)
15
15
  else
16
- pack_install(spec, home_path)
16
+ pack_install(spec, home_path, options)
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
- def self.git_install(spec, home_path)
21
+ def self.git_install(spec, home_path, options={})
22
22
  require 'grit'
23
+ if ::File.exist?("apps/#{spec.id}")
24
+ puts _("%s already installed, skipping") % spec.id
25
+ return
26
+ end
23
27
  repo = Grit::Repo.new(home_path)
24
28
  puts _("Fetching %s from %s") % [spec.app_id, spec.git_repo]
25
- `#{Grit::Git.git_binary} submodule add #{spec.git_repo} apps/#{spec.id}`
29
+ repo_url = spec.git_repo
30
+ if options[:ssh_user] && repo_url =~ /ssh:\/\/([^@]+@)?(.+)/
31
+ repo_url = "ssh://#{options[:ssh_user]}@#{$2}"
32
+ end
33
+ `#{Grit::Git.git_binary} submodule add #{repo_url} apps/#{spec.id}`
26
34
  repo.git.submodule({}, "init")
27
35
  repo.git.submodule({}, "update")
28
36
  repo.add('.gitmodules', "apps/#{spec.id}")
29
37
  repo.commit_index(_("Added app %s") % spec.id)
30
38
  end
31
39
 
32
- def self.pack_install(spec, home_path)
40
+ def self.pack_install(spec, home_path, options={})
33
41
  require 'rubygems/package'
34
42
  client = AppServerClient.new(spec.app_server)
35
43
  print _("Fetching %s from server... ") % spec.app_id
@@ -82,14 +90,14 @@ module Spider
82
90
  pre_setup(specs, options)
83
91
  specs.each do |spec|
84
92
  if spec.git_repo && options[:use_git]
85
- git_update(spec, home_path)
93
+ git_update(spec, home_path, options)
86
94
  else
87
- pack_update(spec, home_path)
95
+ pack_update(spec, home_path, options)
88
96
  end
89
97
  end
90
98
  end
91
99
 
92
- def self.git_update(spec, home_path)
100
+ def self.git_update(spec, home_path, options={})
93
101
  require 'grit'
94
102
  home_repo = Grit::Repo.new(home_path)
95
103
  app_path = File.join(home_path, "apps/#{spec.id}")
@@ -116,7 +124,7 @@ module Spider
116
124
  home_repo.commit_index(_("Updated app %s") % spec.id)
117
125
  end
118
126
 
119
- def self.pack_update(spec, home_path)
127
+ def self.pack_update(spec, home_path, options={})
120
128
  require 'fileutils'
121
129
  require 'date'
122
130
  require 'time'
@@ -32,7 +32,6 @@ module Spider; module TemplateBlocks
32
32
  init, c = klass.compile_block(@el, id, @el.attributes.to_hash, options)
33
33
  return CompiledBlock.new(init, c)
34
34
  end
35
- init_params = self.class.attributes_to_init_params(@el.attributes.to_hash)
36
35
 
37
36
  html = ""
38
37
  @el.each_child do |ch|
@@ -43,7 +42,15 @@ module Spider; module TemplateBlocks
43
42
 
44
43
  template = nil
45
44
  overrides += @template.overrides_for(id)
45
+
46
+ asset_profiles = @el.get_attribute('sp:asset-profiles')
47
+ if asset_profiles
48
+ asset_profiles = asset_profiles.split(/,\s*/).map{ |pr| pr.to_sym }
49
+ @el.remove_attribute('sp:asset-profiles')
50
+ end
51
+
46
52
  template = klass.load_template(template_attr || klass.default_template)
53
+ template.asset_profiles = asset_profiles if asset_profiles
47
54
  if (overrides.length > 0)
48
55
  #template_name = klass.find_template(template_attr)
49
56
  template.add_overrides overrides
@@ -55,12 +62,19 @@ module Spider; module TemplateBlocks
55
62
 
56
63
  init = ""
57
64
  t_param = 'nil'
65
+ t_options = {}
66
+
67
+ t_options[:asset_profiles] = asset_profiles if asset_profiles
68
+
58
69
  if (template)
59
70
  # FIXME: the subtemplate shouldn't be loaded at this point
60
- init = "t = load_subtemplate('#{id}')\n"
71
+ init = "t = load_subtemplate('#{id}', #{t_options.inspect})\n"
61
72
  t_param = 't'
62
73
  end
63
74
  html.gsub!("'", "\\\\'")
75
+
76
+ init_params = self.class.attributes_to_init_params(@el.attributes.to_hash)
77
+
64
78
  init += "add_widget('#{id}', #{klass}.new(@request, @response), {#{init_params.join(', ')}}, '#{html}', #{t_param})\n"
65
79
  c = "yield :\"#{id}\"\n"
66
80
  return CompiledBlock.new(init, c)
@@ -19,53 +19,93 @@ module Spider
19
19
  super
20
20
  end
21
21
 
22
+ def only_asset_profiles(*profiles)
23
+ @only_asset_profiles = profiles
24
+ end
25
+
26
+ def no_asset_profiles(*profiles)
27
+ @no_asset_profiles = profiles
28
+ end
29
+
22
30
  def prepare_assets
23
31
  @template_assets = { :css => [], :js => [] }
32
+ assets = {:css => [], :js => []}
24
33
  seen = {}
25
- js = []
26
- css = []
27
- runtime = []
28
34
  js_messages = []
29
- all_assets.each do |res|
30
- is_runtime = res[:runtime] || res[:if_ie_lte] || res[:media]
31
- if is_runtime
32
- rntm = res[:runtime] || res[:src]
33
- next if seen[rntm]
34
- seen[rntm] = true
35
- runtime << res
36
- next
35
+ use_cdn = Spider.conf.get('assets.use_cdn')
36
+ compress_assets = {:js => {}, :css => {}}
37
+ cname = File.basename(@path, '.layout.shtml')
38
+ cname = File.basename(cname, '.shtml')
39
+ cname += "-#{@asset_set}" if @asset_set
40
+ pub_dest = nil
41
+ all_assets.each do |ass|
42
+ seen_check = ass[:runtime] || ass[:src]
43
+ next if !ass[:src] || ass[:src].empty?
44
+ next if seen[seen_check]
45
+ seen[seen_check] = true
46
+ type = ass[:type].to_sym
47
+ compress_config = case type
48
+ when :js
49
+ 'javascript.compress'
50
+ when :css
51
+ 'css.compress'
52
+ end
53
+ no_compress = @scene.__is_error_page || !Spider.conf.get(compress_config) || \
54
+ ass[:runtime] || ass[:if_ie_lte] || ass[:media] || (use_cdn && ass[:cdn])
55
+
56
+ if no_compress
57
+ if ass[:runtime]
58
+ assets[type] << Spider::Template.runtime_assets[ass[:runtime]].call(@request, @response, @scene)
59
+ else
60
+ assets[type] << ass
61
+ end
62
+ else
63
+ unless pub_dest
64
+ pub_dest = Spider::HomeController.pub_path+'/'+COMPILED_FOLDER
65
+ FileUtils.mkdir_p(pub_dest)
66
+ end
67
+ if comp = ass[:compressed_path]
68
+ name = File.basename(comp)
69
+ unless File.exist?(File.join(pub_dest, name))
70
+ File.cp(comp, pub_dest)
71
+ end
72
+ ass[:src] = Spider::HomeController.pub_url+'/'+COMPILED_FOLDER+'/'+name
73
+ assets[type] << ass
74
+ else
75
+ name = ass[:compress] || cname
76
+ unless compress_assets[type][name]
77
+ cpr = {:name => name, :assets => [], :cpr => true}
78
+ assets[type] << cpr
79
+ compress_assets[type][name] = cpr
80
+ end
81
+ compress_assets[type][name][:assets] << ass
82
+ end
37
83
  end
38
- next if !res[:src] || res[:src].empty?
39
- next if seen[res[:src]]
40
- seen[res[:src]] = true
41
- @template_assets[res[:type].to_sym] ||= []
42
- @template_assets[res[:type].to_sym] << res[:src]
43
- js << res if Spider.conf.get('javascript.compress') && res[:type].to_sym == :js
44
- css << res if Spider.conf.get('css.compress') && res[:type].to_sym == :css
45
- if res[:gettext] && res[:type].to_sym == :js
46
- msg_path = asset_gettext_messages_file(res[:path])
84
+ if ass[:gettext] && type == :js
85
+ msg_path = asset_gettext_messages_file(ass[:path])
47
86
  js_messages += JSON.parse(File.read(msg_path))
48
87
  end
49
88
  end
50
- if Spider.conf.get('javascript.compress') && !@scene.__is_error_page
51
- compressed = compress_javascript(js)
52
- @template_assets[:js] = compressed.map{ |c|
53
- Spider::HomeController.pub_url+'/'+COMPILED_FOLDER+'/'+c
54
- }
55
- end
56
- if Spider.conf.get('css.compress') && !@scene.__is_error_page
57
- combined = compress_css(css)
58
- @template_assets[:css] = combined.map{ |c|
59
- Spider::HomeController.pub_url+'/'+COMPILED_FOLDER+'/'+c
60
- }
89
+ assets[:js].each do |ass|
90
+ if ass[:cpr]
91
+ compressed = compress_javascript(ass)
92
+ @template_assets[:js] << Spider::HomeController.pub_url+'/'+COMPILED_FOLDER+'/'+compressed
93
+ else
94
+ ass[:src] = ass[:cdn] if ass[:cdn] && use_cdn
95
+ @template_assets[:js] << ass[:src]
96
+ end
61
97
  end
62
- runtime.each do |rt|
63
- if rt[:runtime]
64
- @template_assets[rt[:type]] << Spider::Template.runtime_assets[rt[:runtime]].call(@request, @response, @scene)
98
+ assets[:css].each do |ass|
99
+ if ass[:cpr]
100
+ compressed = compress_css(ass)
101
+ @template_assets[:css] << Spider::HomeController.pub_url+'/'+COMPILED_FOLDER+'/'+compressed
65
102
  else
66
- @template_assets[rt[:type]] << rt
103
+ ass[:src] = ass[:cdn] if ass[:cdn] && use_cdn
104
+ is_dyn = ass[:if_ie_lte] || ass[:media]
105
+ @template_assets[:css] << (is_dyn ? ass : ass[:src])
67
106
  end
68
107
  end
108
+
69
109
  @content[:yield_to] = @template
70
110
  @scene.assets = @template_assets
71
111
  @scene.extend(LayoutScene)
@@ -95,7 +135,14 @@ module Spider
95
135
  end
96
136
 
97
137
  def all_assets
98
- return @template.assets + self.assets
138
+ assets = @template.assets + self.assets
139
+ if @only_asset_profiles
140
+ assets = assets.select{ |ass| ass[:profiles] && !(ass[:profiles] & @only_asset_profiles).empty? }
141
+ end
142
+ if @no_asset_profiles
143
+ assets = assets.select{ |ass| !ass[:profiles] || (ass[:profiles] & @no_asset_profiles).empty? }
144
+ end
145
+ assets
99
146
  end
100
147
 
101
148
  COMPILED_FOLDER = '_c'
@@ -106,188 +153,155 @@ module Spider
106
153
  File.join(dir, "#{name}.i18n.json")
107
154
  end
108
155
 
109
- def compress_javascript(assets)
156
+ def compress_javascript(cpr)
110
157
  require 'yui/compressor'
111
- res = []
112
- compress = {}
113
- compressed = []
114
- cname = File.basename(@path, '.layout.shtml')
115
- cname += "-#{@asset_set}" if @asset_set
116
- assets.each do |ass|
117
- if ass[:compressed]
118
- compressed << ass[:compressed_path]
119
- else
120
- name = ass[:compress] || cname
121
- compress[name] ||= []
122
- compress[name] << ass
123
- end
124
- end
125
- pub_dest = Spider::HomeController.pub_path+'/'+COMPILED_FOLDER
126
- FileUtils.mkdir_p(pub_dest)
127
158
 
128
- compress.each do |name, ass|
129
-
130
- already_compressed = Dir.glob(pub_dest+'/'+name+'.*.js')
131
- unless already_compressed.empty?
132
- res << File.basename(already_compressed.first)
133
- next
159
+ pub_dest = Spider::HomeController.pub_path+'/'+COMPILED_FOLDER
160
+ name = cpr[:name]
161
+
162
+ already_compressed = Dir.glob(pub_dest+'/'+name+'.*.js')
163
+ unless already_compressed.empty?
164
+ return File.basename(already_compressed.first)
165
+ end
166
+
167
+ tmp_combined = Spider.paths[:tmp]+'/_'+name+'.js'
168
+ File.open(tmp_combined, 'w') do |f|
169
+ cpr[:assets].each.each do |a|
170
+ f.write IO.read(a[:path])+"\n"
134
171
  end
172
+ end
135
173
 
136
- tmp_combined = Spider.paths[:tmp]+'/_'+name+'.js'
137
- File.open(tmp_combined, 'w') do |f|
138
- ass.each do |a|
139
- f.write IO.read(a[:path])+"\n"
140
- end
141
- end
142
- version = 0
143
- curr = Dir.glob(pub_dest+"/._#{name}.*.js")
144
- unless curr.empty?
145
- curr.each do |f|
146
- name = File.basename(f)
147
- if name =~ /(\d+)\.js$/
148
- version = $1.to_i if $1.to_i > version
149
- File.unlink(f)
150
- end
174
+
175
+ version = 0
176
+ curr = Dir.glob(pub_dest+"/._#{name}.*.js")
177
+ unless curr.empty?
178
+ curr.each do |f|
179
+ name = File.basename(f)
180
+ if name =~ /(\d+)\.js$/
181
+ version = $1.to_i if $1.to_i > version
182
+ File.unlink(f)
151
183
  end
152
184
  end
153
- version += 1
154
- compiled_name = "#{name}.#{version}.js"
155
- combined = "#{pub_dest}/._#{compiled_name}"
185
+ end
186
+ version += 1
187
+ compiled_name = "#{name}.#{version}.js"
188
+ combined = "#{pub_dest}/._#{compiled_name}"
156
189
 
157
- dest = "#{pub_dest}/#{compiled_name}"
158
- File.cp(tmp_combined, combined)
159
- File.unlink(tmp_combined)
160
- compressor = YUI::JavaScriptCompressor.new("charset" => "UTF-8")
161
- io = open(combined, 'r')
162
- cjs = compressor.compress(io)
163
- open(dest, 'w') do |f|
164
- f << cjs
165
- end
166
- res << compiled_name
190
+ dest = "#{pub_dest}/#{compiled_name}"
191
+ File.cp(tmp_combined, combined)
192
+ File.unlink(tmp_combined)
193
+ compressor = YUI::JavaScriptCompressor.new("charset" => "UTF-8")
194
+ io = open(combined, 'r')
195
+ cjs = compressor.compress(io)
196
+ open(dest, 'w') do |f|
197
+ f << cjs
167
198
  end
199
+ return compiled_name
168
200
 
169
- compressed.uniq.each do |comp|
170
- name = File.basename(comp)
171
- unless File.exist?("#{pub_dest}/#{name}")
172
- File.cp(comp, pub_dest)
173
- end
174
- res << name
175
- end
176
- res
177
201
  end
178
202
 
179
- def compress_css(assets)
180
- res = []
181
- combine = {}
182
- cname = File.basename(@path, '.layout.shtml')
183
- cname += "-#{@asset_set}" if @asset_set
184
- assets.each do |ass|
185
- name = ass[:combine] || cname
186
- combine[name] ||= []
187
- combine[name] << ass
188
- end
203
+ def compress_css(cpr)
204
+
189
205
  pub_dest = Spider::HomeController.pub_path+'/'+COMPILED_FOLDER
190
- FileUtils.mkdir_p(pub_dest)
191
- combine.each do |name, ass|
192
- already_compressed = Dir.glob(pub_dest+'/'+name+'.*.css')
193
- unless already_compressed.empty?
194
- res << File.basename(already_compressed.first)
195
- next
196
- end
197
- tmp_combined = Spider.paths[:tmp]+'/_'+name+'.css'
206
+ name = cpr[:name]
207
+
208
+ already_compressed = Dir.glob(pub_dest+'/'+name+'.*.css')
209
+ unless already_compressed.empty?
210
+ return File.basename(already_compressed.first)
211
+ end
212
+
213
+ tmp_combined = Spider.paths[:tmp]+'/_'+name+'.css'
198
214
 
199
- File.open(tmp_combined, 'w') do |f|
200
- ass.each do |a|
201
- path = a[:path]
202
- src_dir = File.dirname(path)
203
- app = a[:app]
204
- if app
205
- app_relative_path = a[:app].relative_path
206
- app_path = app.path
207
- elsif path.index(Spider::SpiderController.pub_path) == 0
208
- app_relative_path = 'spider'
209
- app_path = Spider::SpiderController.pub_path
210
- end
215
+ File.open(tmp_combined, 'w') do |f|
216
+ cpr[:assets].each do |a|
217
+ path = a[:path]
218
+ src_dir = File.dirname(path)
219
+ app = a[:app]
220
+ if app
221
+ app_relative_path = a[:app].relative_path
222
+ app_path = app.path
223
+ elsif path.index(Spider::SpiderController.pub_path) == 0
224
+ app_relative_path = 'spider'
225
+ app_path = Spider::SpiderController.pub_path
226
+ end
211
227
 
212
- pub_app = "#{pub_dest}/#{app_relative_path}"
213
- FileUtils.mkdir_p(pub_app)
214
- src_files = Spider::ContentUtils.resolve_css_includes(path)
215
- src = ""
216
- src_files.each do |src_file|
217
- src += IO.read(src_file)+"\n"
218
- end
219
- src.gsub!(/^\s*@import(?:\surl\(|\s)(['"]?)([^\?'"\)\s]+)(\?(?:[^'"\)]*))?\1\)?(?:[^?;]*);?/i, "")
228
+ pub_app = "#{pub_dest}/#{app_relative_path}"
229
+ FileUtils.mkdir_p(pub_app)
230
+ src_files = Spider::ContentUtils.resolve_css_includes(path)
231
+ src = ""
232
+ src_files.each do |src_file|
233
+ src += IO.read(src_file)+"\n"
234
+ end
235
+ src.gsub!(/^\s*@import(?:\surl\(|\s)(['"]?)([^\?'"\)\s]+)(\?(?:[^'"\)]*))?\1\)?(?:[^?;]*);?/i, "")
220
236
 
221
- src.scan(/url\([\s"']*([^\)"'\s]*)[\s"']*\)/m).uniq.collect do |url|
222
- url = url.first
223
- next if url =~ %r{^/} || url =~ %r{^[a-z]+://}
224
- path = ""
225
- url_dest = File.expand_path(File.join(pub_app, url))
226
- url_src = File.expand_path(File.join(src_dir, url))
227
- unless url_src.index(app_path) == 0
228
- raise "Can't combine CSS if paths go outside app: #{url} in #{path}"
229
- end
230
- FileUtils.mkdir_p(File.dirname(url_dest))
231
- cachebuster = Spider.conf.get('css.cachebuster')
232
- new_url = "#{app_relative_path}/#{url}"
233
- if File.exist?(url_src)
234
- mtime = File.mtime(url_src).to_i
235
- if cachebuster && File.exist?(url_dest) && mtime > File.mtime(url_dest).to_i
236
- if cachebuster == :soft
237
+ src.scan(/url\([\s"']*([^\)"'\s]*)[\s"']*\)/m).uniq.collect do |url|
238
+ url = url.first
239
+ next if url =~ %r{^/} || url =~ %r{^[a-z]+://}
240
+ path = ""
241
+ url_dest = File.expand_path(File.join(pub_app, url))
242
+ url_src = File.expand_path(File.join(src_dir, url))
243
+ unless url_src.index(app_path) == 0
244
+ raise "Can't combine CSS if paths go outside app: #{url} in #{path}"
245
+ end
246
+ FileUtils.mkdir_p(File.dirname(url_dest))
247
+ cachebuster = Spider.conf.get('css.cachebuster')
248
+ new_url = "#{app_relative_path}/#{url}"
249
+ if File.exist?(url_src)
250
+ mtime = File.mtime(url_src).to_i
251
+ if cachebuster && File.exist?(url_dest) && mtime > File.mtime(url_dest).to_i
252
+ if cachebuster == :soft
253
+ File.cp(url_src, url_dest)
254
+ new_url += "?cb=#{mtime}"
255
+ elsif cachebuster == :hard || cachebuster == :hardcopy
256
+ url_dir = File.dirname(url)
257
+ url_ext = File.extname(url)
258
+ url_basename = File.basename(url, url_ext)
259
+ url_dest_dir = File.dirname(url_dest)
260
+ cb_file_name = "#{url_basename}-cb#{mtime}#{url_ext}"
261
+ new_url = "#{url_dir}/#{cb_file_name}"
262
+ if cachebuster == :hard
237
263
  File.cp(url_src, url_dest)
238
- new_url += "?cb=#{mtime}"
239
- elsif cachebuster == :hard || cachebuster == :hardcopy
240
- url_dir = File.dirname(url)
241
- url_ext = File.extname(url)
242
- url_basename = File.basename(url, url_ext)
243
- url_dest_dir = File.dirname(url_dest)
244
- cb_file_name = "#{url_basename}-cb#{mtime}#{url_ext}"
245
- new_url = "#{url_dir}/#{cb_file_name}"
246
- if cachebuster == :hard
247
- File.cp(url_src, url_dest)
248
- else
249
- File.cp(url_src, "#{url_dest_dir}/#{cb_file_name}")
250
- end
264
+ else
265
+ File.cp(url_src, "#{url_dest_dir}/#{cb_file_name}")
251
266
  end
252
- else
253
- File.cp(url_src, url_dest)
254
267
  end
255
268
  else
256
- Spider.logger.error("CSS referenced file not found: #{url_src}")
269
+ File.cp(url_src, url_dest)
257
270
  end
258
- src.gsub!(/\([\s"']*#{url}[\s"']*\)/m, "(#{new_url})")
271
+ else
272
+ Spider.logger.error("CSS referenced file not found: #{url_src}")
259
273
  end
260
- f.write(src+"\n")
274
+ src.gsub!(/\([\s"']*#{url}[\s"']*\)/m, "(#{new_url})")
261
275
  end
276
+ f.write(src+"\n")
262
277
  end
278
+ end
263
279
 
264
- version = 0
265
- curr = Dir.glob(pub_dest+"/._#{name}.*.css")
266
- unless curr.empty?
267
- curr.each do |f|
268
- name = File.basename(f)
269
- if name =~ /(\d+)\.js$/
270
- version = $1.to_i if $1.to_i > version
271
- File.unlink(f)
272
- end
280
+ version = 0
281
+ curr = Dir.glob(pub_dest+"/._#{name}.*.css")
282
+ unless curr.empty?
283
+ curr.each do |f|
284
+ currname = File.basename(f)
285
+ if currname =~ /(\d+)\.js$/
286
+ version = $1.to_i if $1.to_i > version
287
+ File.unlink(f)
273
288
  end
274
289
  end
275
- version += 1
276
- compiled_name = "#{name}.#{version}.css"
277
- combined = "#{pub_dest}/._#{compiled_name}"
290
+ end
291
+ version += 1
292
+ compiled_name = "#{name}.#{version}.css"
293
+ combined = "#{pub_dest}/._#{compiled_name}"
278
294
 
279
- dest = "#{pub_dest}/#{compiled_name}"
280
- File.cp(tmp_combined, combined)
281
- File.unlink(tmp_combined)
282
- compressor = YUI::CssCompressor.new("charset" => "UTF-8")
283
- io = open(combined, 'r')
284
- cjs = compressor.compress(io)
285
- open(dest, 'w') do |f|
286
- f << cjs
287
- end
288
- res << compiled_name
295
+ dest = "#{pub_dest}/#{compiled_name}"
296
+ File.cp(tmp_combined, combined)
297
+ File.unlink(tmp_combined)
298
+ compressor = YUI::CssCompressor.new("charset" => "UTF-8")
299
+ io = open(combined, 'r')
300
+ cjs = compressor.compress(io)
301
+ open(dest, 'w') do |f|
302
+ f << cjs
289
303
  end
290
- res
304
+ return compiled_name
291
305
  end
292
306
 
293
307
  end
@@ -296,6 +310,7 @@ module Spider
296
310
 
297
311
  def output_assets(type=nil)
298
312
  types = type ? [type] : self.assets.keys
313
+ use_cdn = Spider.conf.get('assets.use_cdn')
299
314
  if types.include?(:js)
300
315
  self.assets[:js].each do |ass|
301
316
  ass = {:src => ass} if ass.is_a?(String)
@@ -305,7 +320,7 @@ module Spider
305
320
  if types.include?(:css)
306
321
  self.assets[:css].each do |ass|
307
322
  ass = {:src => ass} if ass.is_a?(String)
308
- link = "<link rel=\"stylesheet\" href=\"#{ass[:src]}\""
323
+ link = "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{ass[:src]}\""
309
324
  link += " media=\"#{ass[:media]}\"" if ass[:media]
310
325
  link += ">\n"
311
326
  if ass[:if_ie_lte]
@@ -318,4 +333,5 @@ module Spider
318
333
 
319
334
  end
320
335
 
321
- end
336
+
337
+ end
@@ -1,4 +1,5 @@
1
1
  require 'hpricot'
2
+ require 'spiderfw/patches/hpricot'
2
3
  require 'spiderfw/templates/template_blocks'
3
4
  require 'spiderfw/cache/template_cache'
4
5
  begin
@@ -27,6 +28,7 @@ module Spider
27
28
  attr_accessor :assets
28
29
  attr_accessor :runtime_overrides
29
30
  attr_reader :overrides, :path, :subtemplates, :widgets
31
+ attr_accessor :asset_profiles
30
32
 
31
33
  @@registered = {}
32
34
  @@widget_plugins = {}
@@ -331,7 +333,7 @@ module Spider
331
333
  wt.load
332
334
  # sub_c = sub.compile(options.merge({:mode => :widget}))
333
335
  @assets = wt.compiled.assets + @assets
334
- end
336
+ end
335
337
 
336
338
  seen = {}
337
339
  # @assets.each_index do |i|
@@ -339,6 +341,7 @@ module Spider
339
341
  # if ass[:name]
340
342
  # end
341
343
  @assets.each do |ass|
344
+ ass[:profiles] = ((ass[:profiles] || []) + @asset_profiles).uniq if @asset_profiles
342
345
  next if seen[ass.inspect]
343
346
  res_init += "@assets << #{ass.inspect}\n"
344
347
  # res_init += "@assets << {
@@ -364,6 +367,9 @@ module Spider
364
367
  if attributes[:name]
365
368
  named = Spider::Template.get_named_asset(attributes[:name])
366
369
  raise "Can't find named asset #{attributes[:name]}" unless named
370
+ if attributes[:profiles]
371
+ named.each{ |nmdass| nmdass[:profiles] = attributes[:profiles] }
372
+ end
367
373
  return named.map{ |nmdass|
368
374
  parse_asset(nmdass[:type], nmdass[:src], nmdass)
369
375
  }.flatten
@@ -391,7 +397,7 @@ module Spider
391
397
  ass[:path] = res.path if res
392
398
  base_url = nil
393
399
  if controller.respond_to?(:pub_url)
394
- if src[0].chr == '/'
400
+ if src[0].chr == '/' && !(controller <= Spider::HomeController)
395
401
  # strips the app path from the src. FIXME: should probably be done somewhere else
396
402
  src = src[(2+controller.app.relative_path.length)..-1]
397
403
  end
@@ -406,17 +412,17 @@ module Spider
406
412
  processor = TemplateAssets.const_get(ass_info[:processor])
407
413
  ass = processor.process(ass)
408
414
  end
409
- if attributes['sp:if']
410
- ass[:if] = Spider::TemplateBlocks::Block.vars_to_scene(attributes['sp:if']).gsub("'", "\\'")
411
- end
412
415
  if attributes[:compressed]
413
416
  compressed_res = Spider.find_resource(type.to_sym, attributes[:compressed], @path, [owner_class, @definer_class])
414
417
  ass[:compressed_path] = compressed_res.path
415
418
  ass[:compressed] = base_url+attributes[:compressed]
416
419
  end
417
- [:gettext, :media, :if_ie_lte].each do |key|
420
+ [:gettext, :media, :if_ie_lte, :cdn].each do |key|
418
421
  ass[key] = attributes[key] if attributes.key?(key)
419
422
  end
423
+ if attributes[:profiles]
424
+ ass[:profiles] = attributes[:profiles].split(/,\s*/).map{ |p| p.to_sym }
425
+ end
420
426
  return [ass]
421
427
  end
422
428
 
@@ -685,10 +691,11 @@ module Spider
685
691
  end
686
692
 
687
693
 
688
- def load_subtemplate(id) # :nodoc:
694
+ def load_subtemplate(id, options={}) # :nodoc:
689
695
  load unless loaded?
690
696
  return nil unless @compiled.subtemplates[id]
691
697
  t = Template.new
698
+ t.asset_profiles = options[:asset_profiles] if options[:asset_profiles]
692
699
  t.compiled = @compiled.subtemplates[id]
693
700
  return t
694
701
  end
@@ -769,29 +776,7 @@ module Spider
769
776
  end
770
777
  end
771
778
 
772
- # Template assets.
773
- def conditional_assets
774
- res = []
775
- @assets.each do |ass|
776
- # FIXME: is this the best place to check if? Maybe it's better to do it when printing resources?
777
- res << ass unless ass[:if] && !ass[:if].empty? && !@scene.instance_eval(ass[:if])
778
- end
779
- return res
780
- end
781
-
782
- # # Assets for the template and contained widgets.
783
- # def all_assets
784
- # res = []
785
- # seen = {}
786
- # @widgets.each do |id, w|
787
- # # next if seen[w.class]
788
- # seen[w.class] = true
789
- # res += w.assets
790
- # end
791
- # res += assets
792
- # return res
793
- # end
794
-
779
+
795
780
  def with_widget(path, &proc)
796
781
  first, rest = path.split('/', 2)
797
782
  @widget_procs[first.to_sym] ||= []
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+
1
3
  module Spider
2
4
 
3
5
  def self.http_client
data/spider.gemspec CHANGED
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
  s.add_dependency("macaddr", [">= 1.0.0"])
42
42
  s.add_development_dependency("rake", ["> 0.7.3"])
43
43
  s.add_development_dependency("ruby-debug", ["> 0.9.3"])
44
- s.requirements << "Optional dependencies: json, openssl, sqlite3, webrick, mongrel, ruby-oci8 >2.0, mysql, yui-compressor, home_run"
44
+ s.requirements << "Optional dependencies: json, openssl, sqlite3, webrick, mongrel, ruby-oci8 >2.0, mysql, yui-compressor, home_run, cldr"
45
45
  # optional dependencies
46
46
  #
47
47
  end
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: 43
4
+ hash: 41
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 16
10
- version: 0.5.16
9
+ - 17
10
+ version: 0.5.17
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: 2010-12-07 00:00:00 +01:00
18
+ date: 2010-12-20 00:00:00 +01:00
19
19
  default_executable: spider
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -1029,6 +1029,7 @@ files:
1029
1029
  - lib/spiderfw/model/sync.rb
1030
1030
  - lib/spiderfw/model/type.rb
1031
1031
  - lib/spiderfw/model/unit_of_work.rb
1032
+ - lib/spiderfw/patches/hpricot.rb
1032
1033
  - lib/spiderfw/requires.rb
1033
1034
  - lib/spiderfw/resource.rb
1034
1035
  - lib/spiderfw/setup/app_manager.rb
@@ -1127,7 +1128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1127
1128
  - 0
1128
1129
  version: "0"
1129
1130
  requirements:
1130
- - "Optional dependencies: json, openssl, sqlite3, webrick, mongrel, ruby-oci8 >2.0, mysql, yui-compressor, home_run"
1131
+ - "Optional dependencies: json, openssl, sqlite3, webrick, mongrel, ruby-oci8 >2.0, mysql, yui-compressor, home_run, cldr"
1131
1132
  rubyforge_project:
1132
1133
  rubygems_version: 1.3.7
1133
1134
  signing_key: