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.
- data/History.txt +98 -73
- data/Manifest.txt +2 -1
- data/README.txt +1 -1
- data/Rakefile +8 -8
- data/app_generators/sproutcore/USAGE +2 -3
- data/app_generators/sproutcore/sproutcore_generator.rb +12 -12
- data/app_generators/sproutcore/templates/README +26 -23
- data/app_generators/sproutcore/templates/{sc-config.rb → sc-config} +32 -17
- data/bin/sc-build +17 -17
- data/bin/sc-server +1 -1
- data/bin/sproutcore +3 -3
- data/clients/sc_test_runner/english.lproj/no_tests.rhtml +0 -1
- data/config/hoe.rb +9 -9
- data/config/requirements.rb +1 -1
- data/frameworks/sproutcore/HISTORY +14 -0
- data/frameworks/sproutcore/core.js +1 -1
- data/frameworks/sproutcore/english.lproj/theme.css +1 -0
- data/frameworks/sproutcore/foundation/binding.js +2 -2
- data/frameworks/sproutcore/foundation/timer.js +55 -22
- data/frameworks/sproutcore/lib/index.rhtml +2 -3
- data/frameworks/sproutcore/models/record.js +204 -63
- data/frameworks/sproutcore/tests/models/model.rhtml +360 -0
- data/frameworks/sproutcore/views/button/button.js +22 -1
- data/frameworks/sproutcore/views/collection/collection.js +6 -2
- data/frameworks/sproutcore/views/collection/list.js +1 -0
- data/frameworks/sproutcore/views/collection/source_list.js +1 -0
- data/frameworks/sproutcore/views/field/text_field.js +11 -2
- data/frameworks/sproutcore/views/inline_text_field.js +3 -2
- data/frameworks/sproutcore/views/menu_item.js +1 -0
- data/frameworks/sproutcore/views/pagination.js +1 -0
- data/frameworks/sproutcore/views/view.js +4 -1
- data/lib/sproutcore/build_tools/html_builder.rb +36 -36
- data/lib/sproutcore/build_tools/resource_builder.rb +55 -54
- data/lib/sproutcore/build_tools.rb +12 -12
- data/lib/sproutcore/bundle.rb +162 -164
- data/lib/sproutcore/bundle_manifest.rb +154 -107
- data/lib/sproutcore/generator_helper.rb +23 -23
- data/lib/sproutcore/helpers/capture_helper.rb +10 -10
- data/lib/sproutcore/helpers/static_helper.rb +39 -26
- data/lib/sproutcore/helpers/tag_helper.rb +10 -10
- data/lib/sproutcore/helpers/text_helper.rb +36 -36
- data/lib/sproutcore/helpers.rb +1 -1
- data/lib/sproutcore/jsdoc.rb +10 -10
- data/lib/sproutcore/jsmin.rb +14 -14
- data/lib/sproutcore/library.rb +135 -87
- data/lib/sproutcore/merb/bundle_controller.rb +77 -54
- data/lib/sproutcore/merb/router.rb +19 -12
- data/lib/sproutcore/merb.rb +1 -1
- data/lib/sproutcore/version.rb +1 -1
- data/lib/sproutcore/view_helpers.rb +121 -121
- data/lib/sproutcore.rb +5 -7
- data/sc-config.rb +6 -0
- data/sc_generators/client/README +1 -1
- data/sc_generators/client/USAGE +1 -2
- data/sc_generators/client/client_generator.rb +6 -6
- data/sc_generators/client/templates/core.js +2 -2
- data/sc_generators/client/templates/english.lproj/body.css +79 -81
- data/sc_generators/client/templates/english.lproj/strings.js +1 -2
- data/sc_generators/client/templates/main.js +6 -8
- data/sc_generators/controller/USAGE +1 -2
- data/sc_generators/controller/controller_generator.rb +7 -7
- data/sc_generators/controller/templates/controller.js +3 -3
- data/sc_generators/controller/templates/test.rhtml +1 -1
- data/sc_generators/framework/README +1 -2
- data/sc_generators/framework/USAGE +2 -3
- data/sc_generators/framework/framework_generator.rb +5 -5
- data/sc_generators/framework/templates/core.js +3 -3
- data/sc_generators/framework/templates/english.lproj/strings.js +1 -2
- data/sc_generators/language/USAGE +1 -2
- data/sc_generators/language/language_generator.rb +6 -6
- data/sc_generators/language/templates/strings.js +1 -2
- data/sc_generators/model/USAGE +1 -2
- data/sc_generators/model/model_generator.rb +7 -7
- data/sc_generators/model/templates/fixture.js +26 -26
- data/sc_generators/model/templates/model.js +5 -5
- data/sc_generators/model/templates/test.rhtml +2 -2
- data/sc_generators/test/USAGE +1 -2
- data/sc_generators/test/templates/test.rhtml +2 -2
- data/sc_generators/test/test_generator.rb +6 -6
- data/sc_generators/view/USAGE +1 -2
- data/sc_generators/view/templates/test.rhtml +2 -2
- data/sc_generators/view/templates/view.js +3 -3
- data/sc_generators/view/view_generator.rb +7 -7
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/sproutcore_spec.rb +3 -3
- data/tasks/deployment.rake +4 -4
- metadata +4 -3
data/lib/sproutcore/bundle.rb
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
require 'sproutcore/build_tools'
|
|
2
2
|
|
|
3
3
|
module SproutCore
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
# A bundle can map a directory of source files to an output format optimized
|
|
6
|
-
# for delivery on the web. It can also return the URLs to use for a
|
|
7
|
-
# particular client. A Bundle cannot actually build resources for you, but
|
|
6
|
+
# for delivery on the web. It can also return the URLs to use for a
|
|
7
|
+
# particular client. A Bundle cannot actually build resources for you, but
|
|
8
8
|
# it works in concert with the ResourceBuilder to help you with that.
|
|
9
9
|
#
|
|
10
|
-
# When you create a bundle, you must pass the name of the client and the
|
|
11
|
-
# library the bundle belongs to. The library is used to generate default
|
|
10
|
+
# When you create a bundle, you must pass the name of the client and the
|
|
11
|
+
# library the bundle belongs to. The library is used to generate default
|
|
12
12
|
# paths for most resources and to find other bundles.
|
|
13
13
|
#
|
|
14
14
|
# You must provide the following properties to every build:
|
|
15
|
-
#
|
|
15
|
+
#
|
|
16
16
|
# bundle_name:: A name used to identify the client for required URLs, etc.
|
|
17
17
|
# library:: The root URL of the library holding the client
|
|
18
18
|
#
|
|
19
|
-
# The following properties are also required, but have defaults you can rely
|
|
19
|
+
# The following properties are also required, but have defaults you can rely
|
|
20
20
|
# use:
|
|
21
21
|
#
|
|
22
22
|
# bundle_type:: :framework|:client (default :client)
|
|
23
23
|
# required_bundles:: Names of required frameworks. (default: none)
|
|
24
|
-
# stylesheet_libs:: URLs to requires CSS not managed by the build system.
|
|
24
|
+
# stylesheet_libs:: URLs to requires CSS not managed by the build system.
|
|
25
25
|
# (default: none)
|
|
26
|
-
# javascript_libs:: URLS to requires JavaScript notn managed by the build
|
|
26
|
+
# javascript_libs:: URLS to requires JavaScript notn managed by the build
|
|
27
27
|
# system (def:non)
|
|
28
28
|
#
|
|
29
|
-
# The following properties are required for the build process but can be
|
|
29
|
+
# The following properties are required for the build process but can be
|
|
30
30
|
# generated automatically using other properties you specify:
|
|
31
31
|
#
|
|
32
32
|
# source_root:: The directory containing the source files
|
|
@@ -38,47 +38,47 @@ module SproutCore
|
|
|
38
38
|
# url_root:: The url that can be used to reach the built resources
|
|
39
39
|
# default: /:url_prefix/:bundle_name
|
|
40
40
|
#
|
|
41
|
-
# index_root:: The root url that can be used to reach retrieve the
|
|
41
|
+
# index_root:: The root url that can be used to reach retrieve the
|
|
42
42
|
# index.html. default: /:index_prefix/:bundle_name
|
|
43
43
|
#
|
|
44
|
-
# If you do not want to specify all of these options, you can provide the
|
|
44
|
+
# If you do not want to specify all of these options, you can provide the
|
|
45
45
|
# following defaults and the rest will be inferred:
|
|
46
|
-
#
|
|
47
|
-
# library_root:: The root URL for the library. This is computed from
|
|
46
|
+
#
|
|
47
|
+
# library_root:: The root URL for the library. This is computed from
|
|
48
48
|
# the library if you pass one.
|
|
49
49
|
#
|
|
50
50
|
# public_root:: The root directory accessible to the web browser.
|
|
51
51
|
# default: :library_root/public
|
|
52
52
|
#
|
|
53
|
-
# url_prefix:: The prefix to put in front of all resource requests.
|
|
53
|
+
# url_prefix:: The prefix to put in front of all resource requests.
|
|
54
54
|
# default: static
|
|
55
|
-
#
|
|
55
|
+
#
|
|
56
56
|
# index_prefix:: The prefix to put in front of all index.html request.
|
|
57
57
|
# default: ''
|
|
58
58
|
#
|
|
59
|
-
# preferred_language:: The default language to use for this bundle.
|
|
59
|
+
# preferred_language:: The default language to use for this bundle.
|
|
60
60
|
# Defaults to :en
|
|
61
61
|
#
|
|
62
|
-
# build_mode:: Determines whether the JS & CSS resources should be
|
|
62
|
+
# build_mode:: Determines whether the JS & CSS resources should be
|
|
63
63
|
# combined or linked directly
|
|
64
64
|
#
|
|
65
65
|
# layout: Path to the layout resource. This should be of the form
|
|
66
|
-
# bundle_name:relative_path/to/client. Default:
|
|
67
|
-
# sproutcore:lib/index.html
|
|
68
|
-
#
|
|
69
|
-
class Bundle
|
|
66
|
+
# bundle_name:relative_path/to/client. Default:
|
|
67
|
+
# sproutcore:lib/index.html
|
|
68
|
+
#
|
|
69
|
+
class Bundle
|
|
70
70
|
|
|
71
71
|
LONG_LANGUAGE_MAP = { :english => :en, :french => :fr, :german => :de, :japanese => :ja, :spanish => :es, :italian => :it }
|
|
72
72
|
SHORT_LANGUAGE_MAP = { :en => :english, :fr => :french, :de => :german, :ja => :japanese, :es => :spanish, :it => :italian }
|
|
73
73
|
|
|
74
|
-
# The default build mode for bundles. This should be set once before you
|
|
75
|
-
# start using bundles. You can override this when you create a specific
|
|
74
|
+
# The default build mode for bundles. This should be set once before you
|
|
75
|
+
# start using bundles. You can override this when you create a specific
|
|
76
76
|
# bundle, but that should not be the typical behavior
|
|
77
77
|
def self.build_mode; @build_mode || :development; end
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
def self.build_mode=(new_mode); @build_mode = new_mode; end
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
attr_reader :bundle_name, :bundle_type, :required_bundles, :preferred_language
|
|
83
83
|
attr_reader :javascript_libs, :stylesheet_libs
|
|
84
84
|
attr_reader :library, :public_root, :url_prefix, :index_prefix, :build_prefix
|
|
@@ -89,9 +89,9 @@ module SproutCore
|
|
|
89
89
|
def library_root
|
|
90
90
|
@library_root ||= library.nil? ? nil : library.root_path
|
|
91
91
|
end
|
|
92
|
-
|
|
93
|
-
# ==== Returns
|
|
94
|
-
# All bundles required directly or indirectly by this bundles. These are
|
|
92
|
+
|
|
93
|
+
# ==== Returns
|
|
94
|
+
# All bundles required directly or indirectly by this bundles. These are
|
|
95
95
|
# returned in their proper load order.
|
|
96
96
|
#
|
|
97
97
|
def all_required_bundles(seen=nil)
|
|
@@ -106,16 +106,16 @@ module SproutCore
|
|
|
106
106
|
raise "Cannot locate required bundle '#{name}' for #{bundle_name}" if b.nil?
|
|
107
107
|
ret += b.all_required_bundles(seen)
|
|
108
108
|
end
|
|
109
|
-
ret << self
|
|
109
|
+
ret << self
|
|
110
110
|
return ret
|
|
111
111
|
end
|
|
112
|
-
|
|
113
|
-
# ==== Returns
|
|
112
|
+
|
|
113
|
+
# ==== Returns
|
|
114
114
|
# True if the build_mode is not development to minify the JS.
|
|
115
115
|
def minify?
|
|
116
|
-
build_mode
|
|
116
|
+
library.minify_build_modes.include?(build_mode)
|
|
117
117
|
end
|
|
118
|
-
|
|
118
|
+
|
|
119
119
|
# ==== Returns
|
|
120
120
|
# The computed path to the layout rhtml.
|
|
121
121
|
def layout_path
|
|
@@ -126,30 +126,30 @@ module SproutCore
|
|
|
126
126
|
# Get the bundle. If bundle_name is nil, self
|
|
127
127
|
layout_bundle = bundle_name.nil? ? self : library.bundle_for(bundle_name.to_sym)
|
|
128
128
|
return nil if layout_bundle.nil?
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
# Now look for an entry with that name. This will use the primary language
|
|
131
131
|
# since we do not support localized layouts.
|
|
132
132
|
entry = layout_bundle.entry_for(entry_name, :hidden => :include)
|
|
133
|
-
|
|
133
|
+
|
|
134
134
|
# If the entry was not found, then we don't have a layout. Oh no!
|
|
135
135
|
if entry.nil?
|
|
136
136
|
raise "Could not find layout named #{entry_name} in bundle #{layout_bundle.bundle_name}!"
|
|
137
137
|
end
|
|
138
|
-
|
|
138
|
+
|
|
139
139
|
# The return value if the source_path of the entry.
|
|
140
140
|
@layout_path = entry.source_path
|
|
141
141
|
end
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
# Returns the root URL to the current library.
|
|
144
144
|
def initialize(bundle_name, opts ={})
|
|
145
|
-
|
|
145
|
+
|
|
146
146
|
# You must provide the following properties to every build:
|
|
147
|
-
# bundle_name:: A name used to identify the client for required
|
|
147
|
+
# bundle_name:: A name used to identify the client for required
|
|
148
148
|
# URLs, etc.
|
|
149
149
|
@bundle_name = bundle_name.to_sym
|
|
150
150
|
|
|
151
|
-
# The following are not required by the build system, but they can be
|
|
152
|
-
# used to automatically construct the key paths listed below. Often
|
|
151
|
+
# The following are not required by the build system, but they can be
|
|
152
|
+
# used to automatically construct the key paths listed below. Often
|
|
153
153
|
# times defaults will do the right thing
|
|
154
154
|
#
|
|
155
155
|
# library:: The root URL of the library holding the client
|
|
@@ -157,7 +157,7 @@ module SproutCore
|
|
|
157
157
|
@library_root = opts[:library_root]
|
|
158
158
|
raise "Bundles must belong to a library or have a library_root" if library_root.nil?
|
|
159
159
|
|
|
160
|
-
# The following properties are also required, but have defaults you can
|
|
160
|
+
# The following properties are also required, but have defaults you can
|
|
161
161
|
# rely use:
|
|
162
162
|
# bundle_type:: :framework|:client (default :client)
|
|
163
163
|
@bundle_type = (opts[:bundle_type] || opts[:type] || :client).to_sym
|
|
@@ -170,21 +170,21 @@ module SproutCore
|
|
|
170
170
|
|
|
171
171
|
# javacript_libs:: External required libraries.
|
|
172
172
|
@javascript_libs = opts[:javascript_libs] || opts[:js_libs] || []
|
|
173
|
-
|
|
173
|
+
|
|
174
174
|
# stylesheet_libs:: External required stylesheet library
|
|
175
175
|
@stylesheet_libs = opts[:stylesheet_libs] || opts[:css_libs] || []
|
|
176
|
-
|
|
176
|
+
|
|
177
177
|
# public_root:: The root directory accessible to the web browser.
|
|
178
178
|
@public_root = normalize_path(opts[:public_root] || 'public')
|
|
179
|
-
|
|
179
|
+
|
|
180
180
|
@make_resources_relative = opts[:resources_relative] || false
|
|
181
|
-
|
|
182
|
-
# url_prefix:: The prefix to put in front of all resource requests.
|
|
181
|
+
|
|
182
|
+
# url_prefix:: The prefix to put in front of all resource requests.
|
|
183
183
|
@url_prefix = opts[:url_prefix] || opts[:resources_at] || opts[:at] || (make_resources_relative ? '../..' : 'static')
|
|
184
|
-
|
|
184
|
+
|
|
185
185
|
# build_prefix:: The prefix to put in front of the built files directory. Generally if you are using absolute paths you want your build_prefix to match the url_prefix. If you are using relative paths, you don't want a build prefix.
|
|
186
186
|
@build_prefix = opts[:build_prefix] || (make_resources_relative ? '' : url_prefix)
|
|
187
|
-
|
|
187
|
+
|
|
188
188
|
# index_prefix:: The prefix to put in front of all index.html request.
|
|
189
189
|
@index_prefix = opts[:index_prefix] || opts[:index_at] || ''
|
|
190
190
|
|
|
@@ -195,26 +195,26 @@ module SproutCore
|
|
|
195
195
|
|
|
196
196
|
# build_root:: The directory that should contain the built files.
|
|
197
197
|
@build_root = normalize_path(opts[:build_root] || File.join(public_root, build_prefix.to_s, bundle_name.to_s))
|
|
198
|
-
|
|
198
|
+
|
|
199
199
|
# url_root:: The url that can be used to reach the built resources
|
|
200
|
-
|
|
200
|
+
|
|
201
201
|
# Note that if the resources are relative, we don't want to include a
|
|
202
202
|
# '/' at the front. Using nil will cause it to be removed during
|
|
203
203
|
# compact.
|
|
204
204
|
@url_root = opts[:url_root] || [
|
|
205
|
-
(make_resources_relative ? nil : ''),
|
|
206
|
-
(url_prefix.nil? || url_prefix.size==0) ? nil : url_prefix,
|
|
205
|
+
(make_resources_relative ? nil : ''),
|
|
206
|
+
(url_prefix.nil? || url_prefix.size==0) ? nil : url_prefix,
|
|
207
207
|
bundle_name.to_s].compact.join('/')
|
|
208
208
|
|
|
209
209
|
# index_root:: The root url that can be used to reach retrieve the index.html.
|
|
210
210
|
@index_root = opts[:index_root] || ['',(index_prefix.nil? || index_prefix.size==0) ? nil : index_prefix, bundle_name.to_s].compact.join('/')
|
|
211
|
-
|
|
211
|
+
|
|
212
212
|
# build_mode:: The build mode to use when combining resources.
|
|
213
213
|
@build_mode = opts[:build_mode] || SproutCore::Bundle.build_mode
|
|
214
|
-
|
|
214
|
+
|
|
215
215
|
# layout: Path to the layout resource. This should be of the form
|
|
216
216
|
@layout = opts[:layout] || 'sproutcore:lib/index.rhtml'
|
|
217
|
-
|
|
217
|
+
|
|
218
218
|
reload!
|
|
219
219
|
end
|
|
220
220
|
|
|
@@ -237,27 +237,27 @@ module SproutCore
|
|
|
237
237
|
entries = entries_for(:javascript, opts)
|
|
238
238
|
BuildTools::JavaScriptResourceBuilder.sort_entries_by_load_order(entries, opts[:language], self)
|
|
239
239
|
end
|
|
240
|
-
|
|
241
|
-
# This method returns the manifest entries for resources of the specified
|
|
240
|
+
|
|
241
|
+
# This method returns the manifest entries for resources of the specified
|
|
242
242
|
# type.
|
|
243
|
-
#
|
|
243
|
+
#
|
|
244
244
|
# ==== Params
|
|
245
245
|
# type:: must be one of :javascript, :stylesheet, :resource, :html, 3
|
|
246
246
|
# :fixture, :test
|
|
247
|
-
#
|
|
247
|
+
#
|
|
248
248
|
# ==== Options
|
|
249
249
|
# language:: The language to use. Defaults to preferred language.
|
|
250
250
|
# hidden:: Can be :none|:include|:only
|
|
251
251
|
#
|
|
252
252
|
def entries_for(resource_type, opts={})
|
|
253
253
|
with_hidden = opts[:hidden] || :none
|
|
254
|
-
|
|
254
|
+
|
|
255
255
|
language = opts[:language] || preferred_language
|
|
256
256
|
mode = opts[:build_mode] || build_mode
|
|
257
257
|
manifest = manifest_for(language, mode)
|
|
258
258
|
|
|
259
259
|
ret = manifest.entries_for(resource_type)
|
|
260
|
-
|
|
260
|
+
|
|
261
261
|
case with_hidden
|
|
262
262
|
when :none
|
|
263
263
|
ret = ret.reject { |x| x.hidden }
|
|
@@ -266,7 +266,7 @@ module SproutCore
|
|
|
266
266
|
end
|
|
267
267
|
return ret
|
|
268
268
|
end
|
|
269
|
-
|
|
269
|
+
|
|
270
270
|
# Returns the manifest entry for a resource with the specified name.
|
|
271
271
|
#
|
|
272
272
|
# ==== Params
|
|
@@ -278,7 +278,7 @@ module SproutCore
|
|
|
278
278
|
#
|
|
279
279
|
def entry_for(resource_name, opts={})
|
|
280
280
|
with_hidden = opts[:hidden] || :none
|
|
281
|
-
|
|
281
|
+
|
|
282
282
|
language = opts[:language] || preferred_language
|
|
283
283
|
mode = opts[:build_mode] || build_mode
|
|
284
284
|
manifest = manifest_for(language, mode)
|
|
@@ -294,17 +294,17 @@ module SproutCore
|
|
|
294
294
|
return ret
|
|
295
295
|
end
|
|
296
296
|
|
|
297
|
-
# Returns the entry for the specified URL. This will extract the language
|
|
297
|
+
# Returns the entry for the specified URL. This will extract the language
|
|
298
298
|
# from the URL and try to get the entry from both the manifest in the
|
|
299
299
|
# current build mode and in the production build mode (if one is
|
|
300
300
|
# provided)
|
|
301
301
|
#
|
|
302
|
-
# ==== Params
|
|
302
|
+
# ==== Params
|
|
303
303
|
# url<String>:: The url
|
|
304
304
|
#
|
|
305
305
|
# ==== Options
|
|
306
306
|
# hidden:: Use :include,:none,:only to control hidden options
|
|
307
|
-
# language:: Explicitly include the language. Leave this out to
|
|
307
|
+
# language:: Explicitly include the language. Leave this out to
|
|
308
308
|
# autodetect from URL.
|
|
309
309
|
#
|
|
310
310
|
def entry_for_url(url, opts={})
|
|
@@ -316,22 +316,22 @@ module SproutCore
|
|
|
316
316
|
entries(opts).each do |entry|
|
|
317
317
|
return entry if entry.url == url
|
|
318
318
|
end
|
|
319
|
-
|
|
319
|
+
|
|
320
320
|
# try production is necessary...
|
|
321
|
-
if (build_mode != :production)
|
|
321
|
+
if (build_mode != :production)
|
|
322
322
|
opts[:build_mode] = :production
|
|
323
323
|
entries(opts).each do |entry|
|
|
324
324
|
return entry if entry.url == url
|
|
325
325
|
end
|
|
326
326
|
end
|
|
327
|
-
|
|
327
|
+
|
|
328
328
|
return nil # not found!
|
|
329
329
|
end
|
|
330
|
-
|
|
331
|
-
# Helper method. This will normalize a URL into one that can map directly
|
|
332
|
-
# to an entry in the bundle. If the URL is of a format that cannot be
|
|
330
|
+
|
|
331
|
+
# Helper method. This will normalize a URL into one that can map directly
|
|
332
|
+
# to an entry in the bundle. If the URL is of a format that cannot be
|
|
333
333
|
# converted, returns nil.
|
|
334
|
-
#
|
|
334
|
+
#
|
|
335
335
|
# ==== Params
|
|
336
336
|
# url<String>:: The URL
|
|
337
337
|
#
|
|
@@ -373,24 +373,24 @@ module SproutCore
|
|
|
373
373
|
return ret
|
|
374
374
|
end
|
|
375
375
|
|
|
376
|
-
# Does a deep search of the entries, looking for a resource that is a
|
|
377
|
-
# close match of the specified resource. This does not need to match the
|
|
376
|
+
# Does a deep search of the entries, looking for a resource that is a
|
|
377
|
+
# close match of the specified resource. This does not need to match the
|
|
378
378
|
# filename exactly and it can omit the extension
|
|
379
379
|
def find_resource_entry(filename, opts={}, seen=nil)
|
|
380
380
|
extname = File.extname(filename)
|
|
381
381
|
rootname = filename.gsub(/#{extname}$/,'')
|
|
382
382
|
entry_extname = entry_rootname = nil
|
|
383
|
-
|
|
383
|
+
|
|
384
384
|
ret = entries_for(:resource, opts.merge(:hidden => :none)).reject do |entry|
|
|
385
385
|
entry_extname = File.extname(entry.filename)
|
|
386
386
|
entry_rootname = entry.filename.gsub(/#{entry_extname}$/,'')
|
|
387
|
-
|
|
387
|
+
|
|
388
388
|
ext_match = (extname.nil? || extname.size == 0) || (entry_extname == extname)
|
|
389
389
|
!(ext_match && (/#{rootname}$/ =~ entry_rootname))
|
|
390
390
|
end
|
|
391
|
-
|
|
391
|
+
|
|
392
392
|
ret = ret.first
|
|
393
|
-
|
|
393
|
+
|
|
394
394
|
if ret.nil?
|
|
395
395
|
seen = Set.new if seen.nil?
|
|
396
396
|
seen << self
|
|
@@ -400,49 +400,49 @@ module SproutCore
|
|
|
400
400
|
return ret unless ret.nil?
|
|
401
401
|
end
|
|
402
402
|
end
|
|
403
|
-
return ret
|
|
403
|
+
return ret
|
|
404
404
|
end
|
|
405
|
-
|
|
406
|
-
# Builds the passed array of entries. If the entry is already built, then
|
|
405
|
+
|
|
406
|
+
# Builds the passed array of entries. If the entry is already built, then
|
|
407
407
|
# this method does nothing unless force => true
|
|
408
408
|
#
|
|
409
|
-
# The exact action taken by this method varies by resource type. Some
|
|
409
|
+
# The exact action taken by this method varies by resource type. Some
|
|
410
410
|
# resources will simply be copied. Others will actually be compiled.
|
|
411
411
|
#
|
|
412
412
|
# ==== Params
|
|
413
413
|
#
|
|
414
414
|
# entries:: The entries to build
|
|
415
|
-
#
|
|
415
|
+
#
|
|
416
416
|
# ==== Options
|
|
417
|
-
#
|
|
418
|
-
# force:: If true then the entry will be built again, even if it already
|
|
417
|
+
#
|
|
418
|
+
# force:: If true then the entry will be built again, even if it already
|
|
419
419
|
# exists.
|
|
420
420
|
# hidden:: Set to :none, :include, or :only
|
|
421
421
|
#
|
|
422
422
|
def build_entries(entries, opts={})
|
|
423
|
-
|
|
423
|
+
|
|
424
424
|
with_hidden = opts[:hidden] || :none
|
|
425
|
-
|
|
426
|
-
# First, start an "already seen" set.
|
|
425
|
+
|
|
426
|
+
# First, start an "already seen" set.
|
|
427
427
|
created_seen = @seen.nil?
|
|
428
|
-
@seen ||=
|
|
429
|
-
|
|
428
|
+
@seen ||= []
|
|
429
|
+
|
|
430
430
|
# Now, process the entries, adding them to the seen set.
|
|
431
431
|
entries.each do |entry|
|
|
432
|
-
|
|
432
|
+
|
|
433
433
|
# skip if hidden, already seen, or already built (unless forced)
|
|
434
434
|
if entry.hidden? && with_hidden == :none
|
|
435
435
|
SC.logger.debug("~ Skipping Entry: #{entry.filename} because it is hidden") and next
|
|
436
436
|
end
|
|
437
|
-
|
|
437
|
+
|
|
438
438
|
if !entry.hidden? && with_hidden == :only
|
|
439
439
|
SC.logger.debug("~ Skipping Entry: #{entry.filename} because it is not hidden") and next
|
|
440
440
|
end
|
|
441
441
|
|
|
442
442
|
# Nothing interesting to log here.
|
|
443
443
|
next if @seen.include?(entry)
|
|
444
|
-
@seen << entry
|
|
445
|
-
|
|
444
|
+
@seen << entry
|
|
445
|
+
|
|
446
446
|
# Do not build if file exists and source paths are not newer.
|
|
447
447
|
if !opts[:force] && File.exists?(entry.build_path)
|
|
448
448
|
source_mtime = entry.source_path_mtime
|
|
@@ -450,9 +450,9 @@ module SproutCore
|
|
|
450
450
|
SC.logger.debug("~ Skipping Entry: #{entry.filename} because it has not changed") and next
|
|
451
451
|
end
|
|
452
452
|
end
|
|
453
|
-
|
|
454
453
|
|
|
455
|
-
|
|
454
|
+
|
|
455
|
+
# OK, looks like this is ready to be built.
|
|
456
456
|
# if the entry is served directly from source
|
|
457
457
|
if entry.use_source_directly?
|
|
458
458
|
SC.logger.debug("~ No Build Required: #{entry.filename} (will be served directly)")
|
|
@@ -461,36 +461,36 @@ module SproutCore
|
|
|
461
461
|
BuildTools.send("build_#{entry.type}".to_sym, entry, self)
|
|
462
462
|
end
|
|
463
463
|
end
|
|
464
|
-
|
|
464
|
+
|
|
465
465
|
# Clean up the seen set when we exit.
|
|
466
466
|
@seen = nil if created_seen
|
|
467
467
|
end
|
|
468
|
-
|
|
469
|
-
# Easy singular form of build_entries(). Take same parameters except for
|
|
468
|
+
|
|
469
|
+
# Easy singular form of build_entries(). Take same parameters except for
|
|
470
470
|
# a single entry instead of an array.
|
|
471
471
|
def build_entry(entry, opts={})
|
|
472
472
|
build_entries([entry], opts)
|
|
473
473
|
end
|
|
474
474
|
|
|
475
|
-
# Invoked by build tools when they build a dependent entry. This will add
|
|
476
|
-
# the entry to the list of seen entries during a build so that it will not
|
|
475
|
+
# Invoked by build tools when they build a dependent entry. This will add
|
|
476
|
+
# the entry to the list of seen entries during a build so that it will not
|
|
477
477
|
# be rebuilt.
|
|
478
478
|
def did_build_entry(entry)
|
|
479
479
|
@seen << entry unless @seen.nil?
|
|
480
480
|
end
|
|
481
|
-
|
|
481
|
+
|
|
482
482
|
# This will perform a complete build for the named language
|
|
483
483
|
def build_language(language)
|
|
484
484
|
SC.logger.info("~ Language: #{language}")
|
|
485
485
|
build_entries(entries(:language => language))
|
|
486
486
|
SC.logger.debug("~ Done.\n")
|
|
487
487
|
end
|
|
488
|
-
|
|
489
|
-
# This will perform a complete build for all languages that have a
|
|
490
|
-
# matching lproj. You can also pass in an array of languages you would
|
|
488
|
+
|
|
489
|
+
# This will perform a complete build for all languages that have a
|
|
490
|
+
# matching lproj. You can also pass in an array of languages you would
|
|
491
491
|
# like to build
|
|
492
492
|
def build(*languages)
|
|
493
|
-
|
|
493
|
+
|
|
494
494
|
# Get the installed languages (and the preferred language, just in case)
|
|
495
495
|
languages = languages.flatten
|
|
496
496
|
languages = installed_languages if languages.nil? || languages.size == 0
|
|
@@ -501,12 +501,12 @@ module SproutCore
|
|
|
501
501
|
SC.logger.debug("~ Build Root: #{build_root}")
|
|
502
502
|
|
|
503
503
|
languages.uniq.each { |lang| build_language(lang) }
|
|
504
|
-
|
|
505
|
-
# After build is complete, try to copy the index.html file of the
|
|
504
|
+
|
|
505
|
+
# After build is complete, try to copy the index.html file of the
|
|
506
506
|
# preferred language to the build_root
|
|
507
507
|
index_entry = entry_for('index.html', :language => preferred_language)
|
|
508
508
|
if index_entry && File.exists?(index_entry.build_path)
|
|
509
|
-
|
|
509
|
+
|
|
510
510
|
# If we are publishing relative resources, then the default
|
|
511
511
|
# index.html needs to just redirect to the default language.
|
|
512
512
|
if make_resources_relative
|
|
@@ -521,8 +521,8 @@ module SproutCore
|
|
|
521
521
|
f = File.open(File.join(build_root, 'index.html'), 'w+')
|
|
522
522
|
f.write(file)
|
|
523
523
|
f.close
|
|
524
|
-
|
|
525
|
-
# Otherwise, just copy the contents of the index.html for the
|
|
524
|
+
|
|
525
|
+
# Otherwise, just copy the contents of the index.html for the
|
|
526
526
|
# preferred language.
|
|
527
527
|
else
|
|
528
528
|
FileUtils.mkdir_p(build_root)
|
|
@@ -530,13 +530,13 @@ module SproutCore
|
|
|
530
530
|
end
|
|
531
531
|
end
|
|
532
532
|
end
|
|
533
|
-
|
|
533
|
+
|
|
534
534
|
######################################################
|
|
535
535
|
## RUBY HELPERS
|
|
536
536
|
##
|
|
537
537
|
|
|
538
538
|
# ==== Returns
|
|
539
|
-
# Array of path to helper files that need to be loaded into memory
|
|
539
|
+
# Array of path to helper files that need to be loaded into memory
|
|
540
540
|
# before any HTML from the bundle can be rendered.
|
|
541
541
|
#
|
|
542
542
|
def helper_paths
|
|
@@ -556,8 +556,8 @@ module SproutCore
|
|
|
556
556
|
break
|
|
557
557
|
end
|
|
558
558
|
end
|
|
559
|
-
|
|
560
|
-
return ret
|
|
559
|
+
|
|
560
|
+
return ret
|
|
561
561
|
end
|
|
562
562
|
|
|
563
563
|
# ==== Returns
|
|
@@ -568,25 +568,25 @@ module SproutCore
|
|
|
568
568
|
|
|
569
569
|
# Oops...file has been deleted!
|
|
570
570
|
return '' if !File.exists?(path)
|
|
571
|
-
|
|
571
|
+
|
|
572
572
|
@_cached_helper_contents ||= {}
|
|
573
|
-
cached = @_cached_helper_contents[path]
|
|
574
|
-
|
|
573
|
+
cached = @_cached_helper_contents[path]
|
|
574
|
+
|
|
575
575
|
return cached[:contents] if cached && (cached[:mtime] == File.mtime(path))
|
|
576
|
-
|
|
576
|
+
|
|
577
577
|
# Not cached, build it.
|
|
578
578
|
cached = { :mtime => File.mtime(path), :contents => File.read(path) }
|
|
579
579
|
@_cached_helper_contents[path] = cached
|
|
580
|
-
|
|
581
|
-
return cached[:contents]
|
|
580
|
+
|
|
581
|
+
return cached[:contents]
|
|
582
582
|
end
|
|
583
|
-
|
|
583
|
+
|
|
584
584
|
######################################################
|
|
585
585
|
## LOCALIZATION
|
|
586
586
|
##
|
|
587
|
-
|
|
587
|
+
|
|
588
588
|
# Returns all of the strings.js entries for this bundle and any required
|
|
589
|
-
# bundles. The return array is in the order the entries should be
|
|
589
|
+
# bundles. The return array is in the order the entries should be
|
|
590
590
|
# processed to build the strings hash.
|
|
591
591
|
#
|
|
592
592
|
# ==== Options
|
|
@@ -596,29 +596,29 @@ module SproutCore
|
|
|
596
596
|
opts[:hidden] = true # include hidden files for prod mode.
|
|
597
597
|
all_required_bundles.map { |q| q.entry_for('strings.js', opts) }.compact
|
|
598
598
|
end
|
|
599
|
-
|
|
599
|
+
|
|
600
600
|
# This will load a strings resource and convert it into a hash of key
|
|
601
601
|
# value pairs.
|
|
602
602
|
def strings_for_entry(strings_entry)
|
|
603
603
|
source_path = strings_entry.source_path
|
|
604
604
|
return {} if !File.exists?(source_path)
|
|
605
|
-
|
|
605
|
+
|
|
606
606
|
# read the file in and strip out comments...
|
|
607
607
|
str = File.read(source_path)
|
|
608
608
|
str = str.gsub(/\/\/.*$/,'').gsub(/\/\*.*\*\//m,'')
|
|
609
|
-
|
|
609
|
+
|
|
610
610
|
# Now build the hash
|
|
611
611
|
ret = {}
|
|
612
|
-
str.scan(/['"](.+)['"]\s*:\s*['"](.+)['"],?\s*$/) do |x,y|
|
|
612
|
+
str.scan(/['"](.+)['"]\s*:\s*['"](.+)['"],?\s*$/) do |x,y|
|
|
613
613
|
# x & y are JS strings that must be evaled as such..
|
|
614
614
|
#x = eval(%("#{x}"))
|
|
615
615
|
y = eval(%[<<__EOF__\n#{y}\n__EOF__]).chop
|
|
616
|
-
ret[x] = y
|
|
616
|
+
ret[x] = y
|
|
617
617
|
end
|
|
618
|
-
|
|
618
|
+
|
|
619
619
|
return ret
|
|
620
620
|
end
|
|
621
|
-
|
|
621
|
+
|
|
622
622
|
# Strings the string hash for the current bundle. If this strings hash
|
|
623
623
|
# has not been loaded yet, it will be loaded now.
|
|
624
624
|
#
|
|
@@ -626,93 +626,93 @@ module SproutCore
|
|
|
626
626
|
# language: optional language. otherwise preferred language is used.
|
|
627
627
|
#
|
|
628
628
|
def strings_hash(opts={})
|
|
629
|
-
|
|
629
|
+
|
|
630
630
|
build_mode = opts[:build_mode] ||= build_mode
|
|
631
631
|
language = opts[:language] ||= preferred_language
|
|
632
632
|
key = [build_mode.to_s, language.to_s].join(':').to_sym
|
|
633
|
-
|
|
633
|
+
|
|
634
634
|
@strings_hash ||= {}
|
|
635
635
|
if @strings_hash[key].nil?
|
|
636
|
-
ret = {}
|
|
636
|
+
ret = {}
|
|
637
637
|
strings_entries(opts).each do |entry|
|
|
638
638
|
ret.merge! strings_for_entry(entry)
|
|
639
639
|
end
|
|
640
|
-
@strings_hash[key] = ret
|
|
640
|
+
@strings_hash[key] = ret
|
|
641
641
|
end
|
|
642
|
-
|
|
642
|
+
|
|
643
643
|
return @strings_hash[key]
|
|
644
644
|
end
|
|
645
|
-
|
|
645
|
+
|
|
646
646
|
######################################################
|
|
647
647
|
## MANIFESTS
|
|
648
648
|
##
|
|
649
649
|
|
|
650
|
-
# Invoke this method whenever you think the bundle's contents on disk
|
|
651
|
-
# might have changed this will throw away any cached information in
|
|
652
|
-
# bundle. This is generally a cheap operation so it is OK to call it
|
|
650
|
+
# Invoke this method whenever you think the bundle's contents on disk
|
|
651
|
+
# might have changed this will throw away any cached information in
|
|
652
|
+
# bundle. This is generally a cheap operation so it is OK to call it
|
|
653
653
|
# often, though it will be less performant overall.
|
|
654
654
|
def reload!
|
|
655
655
|
@manifests = {}
|
|
656
656
|
@strings_hash = {}
|
|
657
657
|
end
|
|
658
|
-
|
|
659
|
-
# Returns the bundle manifest for the specified language and build mode.
|
|
658
|
+
|
|
659
|
+
# Returns the bundle manifest for the specified language and build mode.
|
|
660
660
|
# The manifest will be created if it does not yet exist.
|
|
661
661
|
def manifest_for(language, build_mode)
|
|
662
662
|
manifest_key = [build_mode.to_s, language.to_s].join(':').to_sym
|
|
663
663
|
@manifests[manifest_key] ||= BundleManifest.new(self, language.to_sym, build_mode.to_sym)
|
|
664
664
|
end
|
|
665
|
-
|
|
665
|
+
|
|
666
666
|
# ==== Returns
|
|
667
667
|
# Languages installed in the source directory
|
|
668
668
|
#
|
|
669
669
|
def installed_languages
|
|
670
|
-
ret = Dir.glob(File.join(source_root,'*.lproj')).map do |x|
|
|
670
|
+
ret = Dir.glob(File.join(source_root,'*.lproj')).map do |x|
|
|
671
671
|
x.match(/([^\/]+)\.lproj$/).to_a[1]
|
|
672
672
|
end
|
|
673
673
|
ret << preferred_language
|
|
674
674
|
ret.compact.map { |x| LONG_LANGUAGE_MAP[x.to_sym] || x.to_sym }.uniq
|
|
675
675
|
end
|
|
676
|
-
|
|
677
|
-
# Finds the actual lproj directory (in the source) for the language code.
|
|
678
|
-
# If the named language does not exist, returns the lproj for the
|
|
676
|
+
|
|
677
|
+
# Finds the actual lproj directory (in the source) for the language code.
|
|
678
|
+
# If the named language does not exist, returns the lproj for the
|
|
679
679
|
# preferred language.
|
|
680
680
|
def lproj_for(language)
|
|
681
|
-
|
|
681
|
+
|
|
682
682
|
# try language as passed in.
|
|
683
683
|
ret = "#{language}.lproj"
|
|
684
684
|
return ret if File.exists?(File.join(source_root,ret))
|
|
685
|
-
|
|
685
|
+
|
|
686
686
|
# failed, try to map to long language
|
|
687
687
|
if long_language = SHORT_LANGUAGE_MAP[language.to_sym]
|
|
688
688
|
ret = "#{long_language}.lproj"
|
|
689
689
|
return ret if File.exists?(File.join(source_root,ret))
|
|
690
690
|
end
|
|
691
|
-
|
|
691
|
+
|
|
692
692
|
# failed, try to map to short language
|
|
693
693
|
if short_language = LONG_LANGUAGE_MAP[language.to_sym]
|
|
694
694
|
ret = "#{short_language}.lproj"
|
|
695
695
|
return ret if File.exists?(File.join(source_root,ret))
|
|
696
696
|
end
|
|
697
|
-
|
|
698
|
-
# failed, return using preferred_language unless this is the preferred
|
|
697
|
+
|
|
698
|
+
# failed, return using preferred_language unless this is the preferred
|
|
699
699
|
# language
|
|
700
700
|
ret = (language != preferred_language) ? lproj_for(preferred_language) : nil
|
|
701
701
|
return ret unless ret.nil?
|
|
702
|
-
|
|
703
|
-
# Super-ultra massive fail. Possible that no localized resources exist
|
|
702
|
+
|
|
703
|
+
# Super-ultra massive fail. Possible that no localized resources exist
|
|
704
704
|
# at all. Return english.lproj and hope for the best
|
|
705
|
-
return 'english.lproj'
|
|
705
|
+
return 'english.lproj'
|
|
706
706
|
end
|
|
707
|
-
|
|
707
|
+
|
|
708
708
|
# Used by the bundle manifest. Only true if bundle_type is client
|
|
709
709
|
def can_have_html?
|
|
710
710
|
return bundle_type == :client
|
|
711
711
|
end
|
|
712
|
-
|
|
712
|
+
|
|
713
713
|
protected
|
|
714
|
-
|
|
715
|
-
# Converts the named path to a fully qualified path name using the library
|
|
714
|
+
|
|
715
|
+
# Converts the named path to a fully qualified path name using the library
|
|
716
716
|
# root, if it does not begin with a slash
|
|
717
717
|
def normalize_path(path)
|
|
718
718
|
File.expand_path(path, library_root)
|
|
@@ -721,5 +721,3 @@ module SproutCore
|
|
|
721
721
|
end
|
|
722
722
|
|
|
723
723
|
end
|
|
724
|
-
|
|
725
|
-
|