[gnome-weather] package: add support for loading JS from a GResource
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-weather] package: add support for loading JS from a GResource
- Date: Wed, 15 Jan 2014 21:56:11 +0000 (UTC)
commit 9f779d096134f6fd140fbfd5c4afdf17d7d96d86
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Wed Jan 15 21:35:54 2014 +0100
package: add support for loading JS from a GResource
Load two resources by default, ${name}.data and ${name}.src, from
a gresource file in datadir. If the latter exists, set up gjs to
import modules from there.
src/package.js | 27 ++++++++++++++++++++-------
1 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/src/package.js b/src/package.js
index 4a77679..8a79c87 100644
--- a/src/package.js
+++ b/src/package.js
@@ -55,6 +55,10 @@ function _runningFromSource() {
return binary.equal(sourceBinary);
}
+function _makeNamePath(name) {
+ return '/' + name.replace('.', '/', 'g');
+}
+
/**
* init:
* @params: package parameters
@@ -131,12 +135,27 @@ function init(params) {
girpath = GLib.build_filenamev([pkglibdir, 'girepository-1.0']);
pkgdatadir = GLib.build_filenamev([datadir, name]);
localedir = GLib.build_filenamev([datadir, 'locale']);
- moduledir = pkgdatadir;
+
+ try {
+ let resource = Gio.Resource.load(GLib.build_filenamev([pkg.pkgdatadir,
+ pkg.name + '.src.gresource']));
+ resource._register();
+
+ moduledir = 'resource://' + _makeNamePath(pkg.name) + '/js';
+ } catch(e) {
+ moduledir = pkgdatadir;
+ }
}
imports.searchPath.unshift(moduledir);
GIRepository.Repository.prepend_search_path(girpath);
GIRepository.Repository.prepend_library_path(libpath);
+
+ try {
+ let resource = Gio.Resource.load(GLib.build_filenamev([pkg.pkgdatadir,
+ pkg.name + '.data.gresource']));
+ resource._register();
+ } catch(e) { }
}
/**
@@ -242,12 +261,6 @@ function initSubmodule(name) {
}
}
-function initResources() {
- let resource = Gio.Resource.load(GLib.build_filenamev([pkg.pkgdatadir,
- pkg.name + '.gresource']));
- resource._register();
-}
-
// Launcher support
function _launcherUsage(flags) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]