Skip to content

Commit 588448d

Browse files
committed
Adds localized loading.ejs file support
1 parent 9a1aa9b commit 588448d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

lib/appbuilder.js

+46-1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ BT.AppBuilder = SC.Object.extend({
239239
return require('path').basename(this.get('path'));
240240
}.property('path'),
241241

242+
lprojDirNames: function () {
243+
var language = this.get('language'),
244+
ret = [];
245+
246+
BT.LANGUAGE_MAP[language].forEach(function(lang) {
247+
ret.push(lang + '.lproj');
248+
}, this);
249+
ret.push(language + '.lproj');
250+
251+
return ret;
252+
}.property('language').cacheable(),
253+
242254
bootstrap: function () {
243255
var ret = [];
244256

@@ -264,7 +276,40 @@ BT.AppBuilder = SC.Object.extend({
264276

265277
contentForBody: "", // empty for now...
266278

267-
contentForLoading: '<p class="loading">Loading...</p>',
279+
contentForLoading: function () {
280+
// return an ejs generated template, never ever cache this
281+
var ejs = require('ejs'),
282+
pathlib = require('path'),
283+
fslib = require('fs'),
284+
lprojDirNames = this.get('lprojDirNames'),
285+
locPath, templatePath;
286+
287+
for (var i = 0, len = lprojDirNames.get('length'); i < len; i++) {
288+
var lprojDirName = lprojDirNames.objectAt(i);
289+
locPath = pathlib.join(BT.projectPath, 'apps', this.get('name'), lprojDirName, "loading.ejs");
290+
if (fslib.statSync(locPath).isFile()) {
291+
templatePath = locPath;
292+
break;
293+
}
294+
}
295+
if (!templatePath) {
296+
locPath = pathlib.join(BT.projectPath, 'apps', this.get('name'), "loading.ejs");
297+
if (fslib.statSync(locPath).isFile()) templatePath = locPath;
298+
}
299+
if (!templatePath) templatePath = pathlib.join(BT.btPath, "templates", "loading.ejs");
300+
301+
var template = fslib.readFileSync(templatePath),
302+
ret;
303+
304+
try {
305+
ret = ejs.render(template.toString());
306+
}
307+
catch (er) {
308+
SC.Logger.log("Problem compiling the Html template: " + require('util').inspect(er));
309+
SC.Logger.log("ret: " + require('util').inspect(ret));
310+
}
311+
return ret;
312+
}.property('language').cacheable(),
268313

269314
contentForResources: "", // empty for now
270315

templates/loading.ejs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p class="loading">Loading...</p>

0 commit comments

Comments
 (0)