sproutcore 0.9.11 → 0.9.12

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 (88) hide show
  1. data/History.txt +98 -73
  2. data/Manifest.txt +2 -1
  3. data/README.txt +1 -1
  4. data/Rakefile +8 -8
  5. data/app_generators/sproutcore/USAGE +2 -3
  6. data/app_generators/sproutcore/sproutcore_generator.rb +12 -12
  7. data/app_generators/sproutcore/templates/README +26 -23
  8. data/app_generators/sproutcore/templates/{sc-config.rb → sc-config} +32 -17
  9. data/bin/sc-build +17 -17
  10. data/bin/sc-server +1 -1
  11. data/bin/sproutcore +3 -3
  12. data/clients/sc_test_runner/english.lproj/no_tests.rhtml +0 -1
  13. data/config/hoe.rb +9 -9
  14. data/config/requirements.rb +1 -1
  15. data/frameworks/sproutcore/HISTORY +14 -0
  16. data/frameworks/sproutcore/core.js +1 -1
  17. data/frameworks/sproutcore/english.lproj/theme.css +1 -0
  18. data/frameworks/sproutcore/foundation/binding.js +2 -2
  19. data/frameworks/sproutcore/foundation/timer.js +55 -22
  20. data/frameworks/sproutcore/lib/index.rhtml +2 -3
  21. data/frameworks/sproutcore/models/record.js +204 -63
  22. data/frameworks/sproutcore/tests/models/model.rhtml +360 -0
  23. data/frameworks/sproutcore/views/button/button.js +22 -1
  24. data/frameworks/sproutcore/views/collection/collection.js +6 -2
  25. data/frameworks/sproutcore/views/collection/list.js +1 -0
  26. data/frameworks/sproutcore/views/collection/source_list.js +1 -0
  27. data/frameworks/sproutcore/views/field/text_field.js +11 -2
  28. data/frameworks/sproutcore/views/inline_text_field.js +3 -2
  29. data/frameworks/sproutcore/views/menu_item.js +1 -0
  30. data/frameworks/sproutcore/views/pagination.js +1 -0
  31. data/frameworks/sproutcore/views/view.js +4 -1
  32. data/lib/sproutcore/build_tools/html_builder.rb +36 -36
  33. data/lib/sproutcore/build_tools/resource_builder.rb +55 -54
  34. data/lib/sproutcore/build_tools.rb +12 -12
  35. data/lib/sproutcore/bundle.rb +162 -164
  36. data/lib/sproutcore/bundle_manifest.rb +154 -107
  37. data/lib/sproutcore/generator_helper.rb +23 -23
  38. data/lib/sproutcore/helpers/capture_helper.rb +10 -10
  39. data/lib/sproutcore/helpers/static_helper.rb +39 -26
  40. data/lib/sproutcore/helpers/tag_helper.rb +10 -10
  41. data/lib/sproutcore/helpers/text_helper.rb +36 -36
  42. data/lib/sproutcore/helpers.rb +1 -1
  43. data/lib/sproutcore/jsdoc.rb +10 -10
  44. data/lib/sproutcore/jsmin.rb +14 -14
  45. data/lib/sproutcore/library.rb +135 -87
  46. data/lib/sproutcore/merb/bundle_controller.rb +77 -54
  47. data/lib/sproutcore/merb/router.rb +19 -12
  48. data/lib/sproutcore/merb.rb +1 -1
  49. data/lib/sproutcore/version.rb +1 -1
  50. data/lib/sproutcore/view_helpers.rb +121 -121
  51. data/lib/sproutcore.rb +5 -7
  52. data/sc-config.rb +6 -0
  53. data/sc_generators/client/README +1 -1
  54. data/sc_generators/client/USAGE +1 -2
  55. data/sc_generators/client/client_generator.rb +6 -6
  56. data/sc_generators/client/templates/core.js +2 -2
  57. data/sc_generators/client/templates/english.lproj/body.css +79 -81
  58. data/sc_generators/client/templates/english.lproj/strings.js +1 -2
  59. data/sc_generators/client/templates/main.js +6 -8
  60. data/sc_generators/controller/USAGE +1 -2
  61. data/sc_generators/controller/controller_generator.rb +7 -7
  62. data/sc_generators/controller/templates/controller.js +3 -3
  63. data/sc_generators/controller/templates/test.rhtml +1 -1
  64. data/sc_generators/framework/README +1 -2
  65. data/sc_generators/framework/USAGE +2 -3
  66. data/sc_generators/framework/framework_generator.rb +5 -5
  67. data/sc_generators/framework/templates/core.js +3 -3
  68. data/sc_generators/framework/templates/english.lproj/strings.js +1 -2
  69. data/sc_generators/language/USAGE +1 -2
  70. data/sc_generators/language/language_generator.rb +6 -6
  71. data/sc_generators/language/templates/strings.js +1 -2
  72. data/sc_generators/model/USAGE +1 -2
  73. data/sc_generators/model/model_generator.rb +7 -7
  74. data/sc_generators/model/templates/fixture.js +26 -26
  75. data/sc_generators/model/templates/model.js +5 -5
  76. data/sc_generators/model/templates/test.rhtml +2 -2
  77. data/sc_generators/test/USAGE +1 -2
  78. data/sc_generators/test/templates/test.rhtml +2 -2
  79. data/sc_generators/test/test_generator.rb +6 -6
  80. data/sc_generators/view/USAGE +1 -2
  81. data/sc_generators/view/templates/test.rhtml +2 -2
  82. data/sc_generators/view/templates/view.js +3 -3
  83. data/sc_generators/view/view_generator.rb +7 -7
  84. data/spec/spec.opts +1 -1
  85. data/spec/spec_helper.rb +1 -1
  86. data/spec/sproutcore_spec.rb +3 -3
  87. data/tasks/deployment.rake +4 -4
  88. metadata +4 -3
@@ -1,37 +1,48 @@
1
1
  require 'yaml'
2
2
 
3
3
  module SproutCore
4
-
5
- # Describes a single library that can contain one or more clients and
6
- # frameworks. This class is used to automatically locate all installed
4
+
5
+ # Describes a single library that can contain one or more clients and
6
+ # frameworks. This class is used to automatically locate all installed
7
7
  # libraries and to register the clients within them.
8
- #
9
- # Libraries are chained, with the child library replacing the parent
10
- # library's settings. In general, the root library is always the current app
11
- # while its parent libraries are those found in the load path or explicitly
8
+ #
9
+ # Libraries are chained, with the child library replacing the parent
10
+ # library's settings. In general, the root library is always the current app
11
+ # while its parent libraries are those found in the load path or explicitly
12
12
  # stated in the configs.
13
13
  class Library
14
14
 
15
- # Creates a chained set of libraries from the passed location and the load path
15
+ # Creates a chained set of libraries from the passed location and the load
16
+ # path
16
17
  def self.library_for(root_path, opts = {})
17
-
18
+
18
19
  # Find libraries in the search paths, build chain
19
20
  root_path = File.expand_path(root_path)
21
+
22
+ # Walk up the root_path until we find a library
23
+ # If no library is found and we reach the top, then return nil.
24
+ while !is_library?(root_path)
25
+ new_root_path, removed_filename = File.split(root_path)
26
+ return nil if new_root_path == root_path
27
+ root_path = new_root_path
28
+ end
29
+
20
30
  paths = libraries_in($:).reject { |x| x == root_path }
21
31
  paths.unshift(root_path)
22
32
  ret = nil
23
-
33
+
24
34
  # Convert chain to library objects. The last path processed should be
25
35
  # the one passed in to this method.
26
- while path = paths.pop
36
+ while path = paths.pop
27
37
  ret = self.new(path, opts, ret)
28
38
  end
29
-
39
+
30
40
  # Return library object for root_path
31
- return ret
41
+ return ret
32
42
  end
33
-
34
- # Searches the array of paths, returning the array of paths that are actually libraries.
43
+
44
+ # Searches the array of paths, returning the array of paths that are
45
+ # actually libraries.
35
46
  #
36
47
  # ==== Params
37
48
  # paths<Array>:: Array of libraries.
@@ -43,81 +54,86 @@ module SproutCore
43
54
  end
44
55
  ret.flatten.compact.uniq
45
56
  end
46
-
47
- # Heuristically determine if a particular location is a library.
57
+
58
+ # Heuristically determines if the library is a path or not.
59
+ #
60
+ # ==== Params
61
+ # path:: the path to check
62
+ #
63
+ # ==== Returns
64
+ # true if path appears to be a library
65
+ #
48
66
  def self.is_library?(path)
49
- has_it = %w(clients frameworks sc-config.rb).map do |x|
50
- File.exists?(File.join(path, x))
67
+ ['sc-config.rb', 'sc-config'].each do |filename|
68
+ return true if File.exists?(File.join(path, filename))
51
69
  end
52
- return false unless has_it.pop
53
- has_it.each { |x| return true if x }
54
70
  return false
55
71
  end
56
-
72
+
57
73
  # The root path for this library
58
74
  attr_reader :root_path
59
-
75
+
60
76
  # The raw environment hash loaded from disk. Generally use computed_environment,
61
77
  # which combines the parent.
62
78
  attr_reader :environment
63
-
79
+
64
80
  # The parent library, used for load order dependency
65
81
  attr_accessor :next_library
66
-
82
+
67
83
  # Any proxy info stored for development
68
84
  attr_accessor :proxies
69
-
70
- # The client directories found in this library. This usually maps directly to a
85
+
86
+ # The client directories found in this library. This usually maps directly to a
71
87
  # client name but it may not if you have set up some other options.
72
88
  def client_directories
73
89
  return @client_dirs unless @client_dirs.nil?
74
- client_path = File.join(@root_path, 'clients')
90
+ client_path = File.join(@root_path, 'clients')
75
91
  if File.exists?(client_path)
76
- @client_dirs = Dir.entries(client_path).reject do |x|
92
+ @client_dirs = Dir.entries(client_path).reject do |x|
77
93
  (/^\./ =~ x) || !File.directory?(File.join(client_path,x))
78
94
  end
79
95
  else
80
96
  @client_dirs = []
81
97
  end
82
-
98
+
83
99
  return @client_dirs
84
100
  end
85
101
 
86
102
  # The framework directories found in this library
87
103
  def framework_directories
88
104
  return @framework_dirs unless @framework_dirs.nil?
89
- framework_path = File.join(@root_path, 'frameworks')
105
+ framework_path = File.join(@root_path, 'frameworks')
90
106
  if File.exists?(framework_path)
91
- @framework_dirs = Dir.entries(framework_path).reject do |x|
107
+ @framework_dirs = Dir.entries(framework_path).reject do |x|
92
108
  (/^\./ =~ x) || !File.directory?(File.join(framework_path,x))
93
109
  end
94
110
  else
95
111
  @framework_dirs = []
96
112
  end
97
-
113
+
98
114
  return @framework_dirs
99
115
  end
100
116
 
101
- # Returns all of the client names known to the current environment, including
117
+ # Returns all of the client names known to the current environment, including
102
118
  # through parent libraries.
103
119
  def client_names
104
120
  return @cache_client_names unless @cache_client_names.nil?
105
-
121
+
106
122
  ret = next_library.nil? ? [] : next_library.client_directories
107
123
  ret += client_directories
108
124
  return @cache_client_names = ret.compact.uniq.sort
109
125
  end
110
-
126
+
111
127
  # Returns all of the framework names known to the current environment, including
112
128
  # through parent libraries.
113
129
  def framework_names
114
130
  return @cache_framework_names unless @cache_framework_names.nil?
115
-
131
+
116
132
  ret = next_library.nil? ? [] : next_library.framework_directories
117
133
  ret += framework_directories
118
134
  return @cache_framework_names = ret.compact.uniq.sort
119
- end
120
-
135
+ end
136
+
121
137
  # ==== Returns
122
138
  # A hash of all bundle names mapped to root url. This method is optimized for frequent
123
139
  # requests so you can use it to route incoming requests.
@@ -127,28 +143,28 @@ module SproutCore
127
143
  bundles.each { |b| ret[b.url_root] = b; ret[b.index_root] = b }
128
144
  return @cached_bundles_by_url = ret
129
145
  end
130
-
146
+
131
147
  # ==== Returns
132
148
  # A bundle for the specified name. If the bundle has not already been created, then
133
149
  # it will be created.
134
150
  def bundle_for(bundle_name)
135
151
  bundle_name = bundle_name.to_sym
136
152
  @bundles ||= {}
137
- return @bundles[bundle_name] ||= Bundle.new(bundle_name, environment_for(bundle_name))
153
+ return @bundles[bundle_name] ||= Bundle.new(bundle_name, environment_for(bundle_name))
138
154
  end
139
-
140
- # ==== Returns
155
+
156
+ # ==== Returns
141
157
  # All of the bundles for registered clients
142
158
  def client_bundles
143
159
  @cached_client_bundles ||= client_names.map { |x| bundle_for(x) }
144
160
  end
145
161
 
146
- # ==== Returns
162
+ # ==== Returns
147
163
  # All of the bundles for registered frameworks
148
164
  def framework_bundles
149
165
  @cached_framework_bundles ||= framework_names.map { |x| bundle_for(x) }
150
166
  end
151
-
167
+
152
168
  # ==== Returns
153
169
  # All known bundles, both framework & client
154
170
  def bundles
@@ -157,9 +173,9 @@ module SproutCore
157
173
 
158
174
  # Reloads the manifest for all bundles.
159
175
  def reload_bundles!
160
- bundles.each { |b| b.reload! }
176
+ bundles.each { |b| b.reload! }
161
177
  end
162
-
178
+
163
179
  # Build all of the bundles in the library. This can take awhile but it is the simple
164
180
  # way to get all of your code onto disk in a deployable state
165
181
  def build(*languages)
@@ -167,14 +183,14 @@ module SproutCore
167
183
  bundle.build(*languages)
168
184
  end
169
185
  end
170
-
186
+
171
187
  # Returns the computed environment for a particular client or framework.
172
- # This will go up the chain of parent libraries, retrieving and merging
173
- # any known environment settings. The returned options are suitable for
188
+ # This will go up the chain of parent libraries, retrieving and merging
189
+ # any known environment settings. The returned options are suitable for
174
190
  # passing to the ClientBuilder for registration.
175
191
  #
176
192
  # The process here is:
177
- #
193
+ #
178
194
  # 1. merge together the :all configs.
179
195
  # 2. Find the deepest config for the bundle specifically and merge that.
180
196
  #
@@ -195,60 +211,89 @@ module SproutCore
195
211
  # base environment and fill in some useful defaults...
196
212
  ret = base_env.dup.merge(config_env).merge(bundle_location)
197
213
  ret[:required] = [:sproutcore] if ret[:required].nil?
198
-
214
+
199
215
  # Add local library so we get proper deployment paths, etc.
200
216
  ret[:library] = self
201
-
217
+
202
218
  # Done! return...
203
- return ret
219
+ return ret
204
220
  end
205
221
 
206
222
  # Returns a re-written proxy URL for the passed URL or nil if no proxy
207
223
  # is registered. The URL should NOT include a hostname.
208
- #
224
+ #
209
225
  # === Returns
210
226
  # the converted proxy_url and the proxy options or nil if no match
211
227
  #
212
- def proxy_url_for(url)
213
-
228
+ def proxy_url_for(url)
229
+
214
230
  # look for a matching proxy.
215
231
  matched = nil
216
232
  matched_url = nil
217
-
233
+
218
234
  @proxies.each do |proxy_url, opts|
219
235
  matched_url = proxy_url
220
236
  matched = opts if url =~ /^#{proxy_url}/
221
237
  break if matched
222
238
  end
223
-
239
+
224
240
  # If matched, rewrite the URL
225
241
  if matched
226
-
242
+
227
243
  # rewrite the matched_url if needed...
228
244
  if matched[:url]
229
245
  url = url.gsub(/^#{matched_url}/, matched[:url])
230
246
  end
231
-
232
- # prepend the hostname and protocol
247
+
248
+ # prepend the hostname and protocol
233
249
  url = [(matched[:protocol] || 'http'), '://', matched[:to], url].join('')
234
-
250
+
235
251
  # otherwise nil
236
- else
252
+ else
237
253
  url = nil
238
254
  end
239
-
255
+
240
256
  return [url, matched]
241
-
257
+
258
+ end
259
+
260
+ # ==== Returns
261
+ # The current minification settings.
262
+ #
263
+ def minify_build_modes
264
+ env = base_environment || {}
265
+ [(env[:minify_javascript] || :production)].flatten
242
266
  end
243
-
244
- protected
245
267
 
246
- # Load the library at the specified path. Loads the sc-config.rb if it
247
- # exists and then detects all clients and frameworks in the library. If
248
- # you pass any options, those will overlay any :all options you specify in
268
+ # ==== Returns
269
+ # The build modes wherein javascript should be combined.
270
+ def combine_javascript_build_modes
271
+ env = base_environment || {}
272
+ [(env[:combine_javascript] || :production)].flatten
273
+ end
274
+
275
+ # ==== Returns
276
+ # The build modes wherein javascript should be combined.
277
+ def combine_stylesheets_build_modes
278
+ env = base_environment || {}
279
+ [(env[:combine_stylesheets] || [:development, :production])].flatten
280
+ end
281
+
282
+ # ==== Returns
283
+ # The build modes where fixtures should be included.
284
+ def include_fixtures_build_modes
285
+ env = base_environment || {}
286
+ [(env[:include_fixtures] || :development)].flatten
287
+ end
288
+
289
+ protected
290
+
291
+ # Load the library at the specified path. Loads the sc-config.rb if it
292
+ # exists and then detects all clients and frameworks in the library. If
293
+ # you pass any options, those will overlay any :all options you specify in
249
294
  # your sc-config file.
250
- #
251
- # You cannot create a library directly using this method. Instead is
295
+ #
296
+ # You cannot create a library directly using this method. Instead is
252
297
  # library_in()
253
298
  #
254
299
  def initialize(rp, opts = {}, next_lib = nil)
@@ -258,20 +303,22 @@ module SproutCore
258
303
  @proxies = {}
259
304
  load_environment!(opts)
260
305
  end
261
-
306
+
262
307
  # Internal method loads the actual environment. Get the ruby file and
263
308
  # eval it in the context of the library object.
264
309
  def load_environment!(opts=nil)
265
- env_path = File.join(root_path, 'sc-config.rb')
310
+ env_path = File.join(root_path, 'sc-config')
311
+ env_path = File.join(root_path, 'sc-config.rb') if !File.exists?(env_path)
312
+
266
313
  @environment = {}
267
314
  if File.exists?(env_path)
268
315
  f = File.read(env_path)
269
316
  eval(f) # execute the config file as if it belongs.
270
317
  end
271
-
318
+
272
319
  # Override any all options with load_opts
273
320
  (@environment[:all] ||= {}).merge!(@load_opts)
274
-
321
+
275
322
  end
276
323
 
277
324
  # This can be called from within a configuration file to actually setup
@@ -280,7 +327,7 @@ module SproutCore
280
327
  # ==== Params
281
328
  # bundle_name: the bundle these settings are for or :all for every bundle.
282
329
  # opts: optional set of parameters to merge into this bundle environment
283
- #
330
+ #
284
331
  # ==== Yields
285
332
  # If block is given, yield to the block, passing an options hash the block
286
333
  # can work on.
@@ -290,7 +337,7 @@ module SproutCore
290
337
  env.merge!(opts) unless opts.nil?
291
338
  yield(env) if block_given?
292
339
  end
293
-
340
+
294
341
  # Adds a proxy to the local library. This does NOT inherit from parent
295
342
  # libraries.
296
343
  #
@@ -305,27 +352,28 @@ module SproutCore
305
352
  def proxy(url, opts={})
306
353
  @proxies[url] = opts
307
354
  end
308
-
309
- # ==== Returns
355
+
356
+ # ==== Returns
310
357
  # the first :all environment config...
311
358
  def base_environment
312
359
  environment[:all] || (next_library.nil? ? {} : next_library.base_environment)
313
360
  end
314
-
361
+
362
+
315
363
  # ==== Returns
316
364
  # the first config found for the specified bundle
317
365
  def bundle_environment_for(bundle_name)
318
366
  bundle_name = bundle_name.to_sym
319
367
  return environment[bundle_name] || (next_library.nil? ? {} : next_library.bundle_environment_for(bundle_name))
320
368
  end
321
-
369
+
322
370
  # ==== Returns
323
371
  # path info for the bundle. Used by bundle object.
324
372
  def bundle_location_for(bundle_name)
325
373
  bundle_name = bundle_name.to_sym
326
374
  is_local_client = client_directories.include?(bundle_name.to_s)
327
375
  is_local_framework = framework_directories.include?(bundle_name.to_s)
328
-
376
+
329
377
  ret = nil
330
378
  if is_local_client || is_local_framework
331
379
  bundle_type = is_local_framework ? :framework : :client
@@ -337,10 +385,10 @@ module SproutCore
337
385
  else
338
386
  ret = next_library.nil? ? nil : next_library.bundle_location_for(bundle_name)
339
387
  end
340
-
388
+
341
389
  return ret
342
390
  end
343
-
391
+
344
392
  end
345
-
393
+
346
394
  end