Dev: Expose highlight, beautify and createCfg util

This commit is contained in:
surunzi
2017-01-15 11:28:49 +08:00
parent fb7fc34d2f
commit f14c219acc
10 changed files with 44 additions and 30 deletions

View File

@@ -1,7 +1,6 @@
import Logger from './Logger.es6'
import Tool from '../DevTools/Tool.es6'
import util from '../lib/util'
import config from '../lib/config.es6'
export default class Console extends Tool
{
@@ -18,7 +17,7 @@ export default class Console extends Tool
this._appendTpl();
this._initLogger();
this._exposeLogger();
this._initConfig(parent);
this._initCfg(parent);
this._bindEvent(parent);
}
show()
@@ -177,9 +176,9 @@ export default class Console extends Tool
this._$inputBtns.show();
}
_initConfig(parent)
_initCfg(parent)
{
let cfg = this.config = config.create('eruda-console'),
let cfg = this.config = util.createCfg('console'),
sources = parent.get('sources'),
logger = this._logger;

View File

@@ -1,7 +1,6 @@
import NavBar from './NavBar.es6'
import util from '../lib/util'
import Tool from './Tool.es6'
import config from '../lib/config.es6'
export default class DevTools extends util.Emitter
{
@@ -18,7 +17,7 @@ export default class DevTools extends util.Emitter
this._appendTpl();
this._initNavBar();
this._initConfig();
this._initCfg();
}
show()
{
@@ -99,9 +98,9 @@ export default class DevTools extends util.Emitter
return this;
}
_initConfig()
_initCfg()
{
var cfg = this.config = config.create('eruda-dev-tools');
var cfg = this.config = util.createCfg('dev-tools');
cfg.set(util.defaults(cfg.get(), {
transparency: '95%',

View File

@@ -4,7 +4,6 @@ import stringify from '../lib/stringify.es6'
import Highlight from './Highlight.es6'
import Select from './Select.es6'
import util from '../lib/util'
import config from '../lib/config.es6'
export default class Elements extends Tool
{
@@ -34,7 +33,7 @@ export default class Elements extends Tool
this._highlight = new Highlight(this._parent.$parent);
this._select = new Select();
this._bindEvent();
this._initConfig();
this._initCfg();
}
show()
{
@@ -259,9 +258,9 @@ export default class Elements extends Tool
this._lastHtml = html;
this._$showArea.html(html);
}
_initConfig()
_initCfg()
{
let cfg = this.config = config.create('eruda-elements');
let cfg = this.config = util.createCfg('elements');
cfg.set(util.defaults(cfg.get(), {overrideEventTarget: true}));

View File

@@ -1,6 +1,5 @@
import util from '../lib/util'
import Draggabilly from 'draggabilly'
import config from '../lib/config.es6'
export default class EntryBtn extends util.Emitter
{
@@ -13,7 +12,7 @@ export default class EntryBtn extends util.Emitter
this._$parent = $parent;
this._appendTpl();
this._makeDraggable();
this._initConfig();
this._initCfg();
this._setPos();
this._bindEvent();
}
@@ -75,9 +74,9 @@ export default class EntryBtn extends util.Emitter
{
this._draggabilly = new Draggabilly(this._$el.get(0), {containment: true});
}
_initConfig()
_initCfg()
{
var cfg = this.config = config.create('eruda-home-button');
var cfg = this.config = util.createCfg('home-button');
cfg.set(util.defaults(cfg.get(), {
rememberPos: true,
@@ -92,4 +91,4 @@ var getDefPos = () =>
x: window.innerWidth - 50,
y: window.innerHeight - 50
};
};
};

View File

@@ -1,7 +1,6 @@
import Tool from '../DevTools/Tool.es6'
import Request from './Request.es6'
import util from '../lib/util'
import config from '../lib/config.es6'
export default class Network extends Tool
{
@@ -27,7 +26,7 @@ export default class Network extends Tool
this._parent = parent;
this._bindEvent();
this._initConfig();
this._initCfg();
}
show()
{
@@ -285,9 +284,9 @@ export default class Network extends Tool
this._resourceTimingData = data;
}
_initConfig()
_initCfg()
{
var cfg = this.config = config.create('eruda-network');
var cfg = this.config = util.createCfg('network');
cfg.set(util.defaults(cfg.get(), {
disablePerformance: false,
@@ -354,4 +353,4 @@ function formatTime(time)
if (time < 1000) return time + 'ms';
return (time / 1000).toFixed(1) + 's';
}
}

View File

@@ -1,6 +1,5 @@
import Tool from '../DevTools/Tool.es6'
import util from '../lib/util'
import config from '../lib/config.es6'
export default class Resources extends Tool
{
@@ -28,7 +27,7 @@ export default class Resources extends Tool
this.refresh();
this._bindEvent();
this._initConfig();
this._initCfg();
}
refresh()
{
@@ -273,9 +272,9 @@ export default class Resources extends Tool
};
}
}
_initConfig()
_initCfg()
{
let cfg = this.config = config.create('eruda-resources');
let cfg = this.config = util.createCfg('resources');
cfg.set(util.defaults(cfg.get(), {
hideErudaSetting: true

View File

@@ -3,7 +3,6 @@ import util from '../lib/util'
import beautify from 'js-beautify'
import highlight from '../lib/highlight.es6'
import JsonViewer from '../lib/JsonViewer.es6'
import config from '../lib/config.es6'
export default class Sources extends Tool
{
@@ -25,7 +24,7 @@ export default class Sources extends Tool
this._parent = parent;
this._bindEvent();
this._initConfig();
this._initCfg();
}
set(type, val)
{
@@ -139,9 +138,9 @@ export default class Sources extends Tool
this._rawTpl = require('./raw.hbs');
this._iframeTpl = require('./iframe.hbs');
}
_initConfig()
_initCfg()
{
let cfg = this.config = config.create('eruda-sources');
let cfg = this.config = util.createCfg('sources');
cfg.set(util.defaults(cfg.get(), {
'showLineNum': true,

View File

@@ -11,6 +11,7 @@ import Sources from './Sources/Sources.es6'
import Settings from './Settings/Settings.es6'
import util from './lib/util'
import config from './lib/config.es6'
import extraUtil from './lib/extraUtil.es6'
module.exports = {
init({el, tool} = {})
@@ -122,3 +123,6 @@ module.exports = {
devTools.showTool(util.last(tool) || 'settings');
}
};
extraUtil(util);

15
src/lib/extraUtil.es6 Normal file
View File

@@ -0,0 +1,15 @@
import highlight from './highlight.es6'
import beautify from 'js-beautify'
import config from './config.es6'
export default function (util)
{
Object.assign(util, {
highlight,
beautify,
createCfg(name)
{
return config.create('eruda-' + name);
}
});
};

View File

@@ -4,6 +4,8 @@ import util from '../lib/util'
export default function highlight(str, lang)
{
lang = lang || 'js';
str = str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
lang = language[lang];