From 86f84d5350d7a9d9c53957d6e10833f18987828d Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 11 Jan 2017 17:49:41 +0000 Subject: [PATCH] Add config file API --- src/app.js | 2 ++ src/app/config.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/app/config.js diff --git a/src/app.js b/src/app.js index 65b678983a3..e8aa0a0280b 100644 --- a/src/app.js +++ b/src/app.js @@ -11,6 +11,7 @@ var GistHandler = require('./app/gist-handler') var gistHandler = new GistHandler() var Storage = require('./app/storage') +var Config = require('./app/config') var Editor = require('./app/editor') var Renderer = require('./app/renderer') var Compiler = require('./app/compiler') @@ -40,6 +41,7 @@ var run = function () { var self = this this.event = new EventManager() var storage = new Storage() + var config = new Config(storage) function loadFiles (files) { for (var f in files) { diff --git a/src/app/config.js b/src/app/config.js new file mode 100644 index 00000000000..02f36d377a2 --- /dev/null +++ b/src/app/config.js @@ -0,0 +1,28 @@ +'use strict' + +var CONFIG_FILE = '.browser-solidity.json' + +function Config (storage) { + this.items = {} + + // load on instantiation + var config = storage.get(CONFIG_FILE) + if (config) { + this.items = JSON.parse(config) + } + + this.exists = function (key) { + return this.items[key] !== undefined + } + + this.get = function (key) { + return this.items[key] + } + + this.set = function (key, content) { + this.items[key] = content + storage.set(CONFIG_FILE, JSON.stringify(this.items)) + } +} + +module.exports = Config