Permalink
Browse files

feature(developers): Devs can show loaded AMD modules in console

  • Loading branch information...
mrclay committed May 21, 2015
1 parent 19d6b84 commit 221bdf6a2ff41cd6f2ef63169363c4c127b7f993
@@ -45,7 +45,7 @@ public function filter($viewName, $content) {
$amdName = $this->getAmdName($viewName);
if (!empty($amdName)) {
$content = preg_replace('/^define\(([^\'"])/m', "define(\"$amdName\", \$1", $content, 1);
$content = preg_replace('/^(\s*)define\(([^\'"])/m', "\${1}define(\"$amdName\", \$2", $content, 1);
}
return $content;
@@ -13,6 +13,15 @@ public function testInsertsNamesForAnonymousModules() {
$this->assertEquals("// Comment\ndefine(\"my/mod\", {})", $filteredContent);
}
public function testAllowsWhitespacePrecedingDefine() {
$viewFilter = new \Elgg\Amd\ViewFilter();
$originalContent = "// Comment\n\t define({})";
$filteredContent = $viewFilter->filter('js/my/mod.js', $originalContent);
$this->assertEquals("// Comment\n\t define(\"my/mod\", {})", $filteredContent);
}
public function testLeavesNamedModulesAlone() {
$viewFilter = new \Elgg\Amd\ViewFilter();
@@ -31,6 +31,7 @@
'wrap_views',
'log_events',
'show_gear',
'show_modules',
];
foreach ($simple_settings as $setting) {
elgg_set_plugin_setting($setting, get_input($setting), 'developers');
@@ -23,6 +23,8 @@
'developers:help:screen_log' => "This displays elgg_log() and elgg_dump() output and a DB query count.",
'developers:label:show_strings' => "Show raw translation strings",
'developers:help:show_strings' => "This displays the translation strings used by elgg_echo().",
'developers:label:show_modules' => "Show AMD modules loaded in console",
'developers:help:show_modules' => "Streams loaded modules and values to your JavaScript console.",
'developers:label:wrap_views' => "Wrap views",
'developers:help:wrap_views' => "This wraps almost every view with HTML comments. Useful for finding the view creating particular HTML.
This can break non-HTML views in the default viewtype. See developers_wrap_views() for details.",
@@ -82,4 +84,6 @@
// status messages
'developers:settings:success' => 'Settings saved and caches flushed',
'developers:amd' => 'AMD',
);
View
@@ -53,6 +53,10 @@ function developers_process_settings() {
elgg_register_event_handler('init', 'system', 'developers_clear_strings', 1);
}
if (!empty($settings['show_modules'])) {
elgg_require_js('elgg/dev/amd_monitor');
}
if (!empty($settings['wrap_views'])) {
elgg_register_plugin_hook_handler('view', 'all', 'developers_wrap_views');
}
@@ -52,6 +52,13 @@
'readonly' => false,
),
'show_modules' => array(
'type' => 'checkbox',
'value' => 1,
'checked' => elgg_get_plugin_setting('show_modules', 'developers') == 1,
'readonly' => false,
),
'wrap_views' => array(
'type' => 'checkbox',
'value' => 1,
@@ -12,7 +12,7 @@ define(function(require) {
}).bind("loaded.jstree", function() {
$("#developers-inspect-results").fadeIn();
});
}
};
setupInspectTree();
});
@@ -0,0 +1,29 @@
!function(){
// http://stackoverflow.com/a/19043564/3779
var defined_modules = require.s.contexts._.defined;
define(function (require) {
var $ = require('jquery');
var elgg = require('elgg');
var known = {};
var count = 0;
function update() {
$.each(defined_modules, function (name, val) {
if (!known[name]) {
known[name] = 1;
count++;
console.log(count + ' ' + elgg.echo('developers:amd') + '(' + name + ')', val);
}
});
}
if (typeof Object.observe === 'function') {
Object.observe(defined_modules, update);
} else {
setInterval(update, 1000);
}
update();
});
}();

0 comments on commit 221bdf6

Please sign in to comment.