summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRory MacQueen <rorymacqueen@gmail.com>2013-07-26 16:13:19 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2013-07-26 18:25:10 -0700
commit0601bc0f891bf92a28c00895ab3d5d9fd37f37aa (patch)
tree1bd221335b76dcc05ac36e035747017abaca6cdd
parent4c3634f241f3b112e6fd58ad9361b6b5a84fc960 (diff)
Added function to utils file to directly fetch resource
[endlessm/eos-sdk#175]
-rw-r--r--wikipedia/src/presenters/domain_wiki_presenter.js23
-rw-r--r--wikipedia/src/utils.js15
2 files changed, 32 insertions, 6 deletions
diff --git a/wikipedia/src/presenters/domain_wiki_presenter.js b/wikipedia/src/presenters/domain_wiki_presenter.js
index 50346b3..a1ef9be 100644
--- a/wikipedia/src/presenters/domain_wiki_presenter.js
+++ b/wikipedia/src/presenters/domain_wiki_presenter.js
@@ -4,6 +4,16 @@ const GObject = imports.gi.GObject;
//Local Libraries
const Utils = imports.utils;
+const CategoryModel = imports.models.category_model;
+const ArticleModel = imports.models.article_model;
+
+
+function _resourceUriToPath(uri) {
+ if(uri.startsWith('resource://'))
+ return uri.slice('resource://'.length);
+ throw new Error('Resource URI did not start with "resource://"');
+}
+
const DomainWikiPresenter = new Lang.Class({
Name: "DomainWikiPresenter",
Extends: GObject.Object,
@@ -35,21 +45,22 @@ const DomainWikiPresenter = new Lang.Class({
},
initFromJsonFile: function(filename) {
- let app_content = JSON.parse(Utils.load_file (filename));
+ //filename = "../data/brazil_categories.json";
+ let app_content = JSON.parse(Utils.load_file_from_resource(filename));
this._application_name = app_content['app_name'];
this._image_uri = app_content['image_uri'];
this._lang_code = filename.substring(0, 2);
let categories = app_content['categories'];
let cat_length = categories.length
- categories = new Array();
+ let category_models = new Array();
for(let i = 0; i < cat_length; i++){
let category = categories[i];
- let categoryModel = initCategory(category);
+ let categoryModel = this.initCategory(category);
let articles = category['articles'];
- categoryModel.addArticles(initArticleModels(articles));
- categories.push(categoryModel);
+ categoryModel.addArticles(this.initArticleModels(articles));
+ category_models.push(categoryModel);
}
- this._domain_wiki_model.addCategories(categories);
+ this._domain_wiki_model.addCategories(category_models);
},
initCategory: function(category){
diff --git a/wikipedia/src/utils.js b/wikipedia/src/utils.js
index 099daf8..08c372f 100644
--- a/wikipedia/src/utils.js
+++ b/wikipedia/src/utils.js
@@ -37,6 +37,21 @@ const range = function(a, b, step) {
/*
* ...Taken from utils.js from the eos-weather branch...
*/
+function load_file_from_resource(filename) {
+ // Return the text stored in the file at filename
+ var file = Gio.file_new_for_uri(filename);
+ var fstream = file.read(null);
+ var dstream = new Gio.DataInputStream({
+ base_stream: fstream
+ });
+ var data = dstream.read_until("", null);
+ fstream.close(null);
+ return data[0];
+}
+
+/*
+ * ...Taken from utils.js from the eos-weather branch...
+ */
function load_file(filename) {
// Return the text stored in the file at filename
var file = Gio.file_new_for_path(filename);