/*** BEGIN LICENSE BLOCK {{{ Copyright (c) 2008 suVene distributable under the terms of an MIT-style license. http://www.opensource.jp/licenses/mit-license.html }}} END LICENSE BLOCK ***/ // PLUGIN_INFO//{{{ var PLUGIN_INFO = {NAME} change notice framework. 変更通知フレームワーク。 suVene 0.1.7 MIT 2.0pre 2.0pre https://github.com/vimpr/vimperator-plugins/raw/master/notifier.js ; //}}} (function() { if (!liberator.plugins.libly) { liberator.log("notifier: needs _libly.js"); return; } if (liberator.plugins.notifier && liberator.plugins.notifier._self) { liberator.plugins.notifier._self.stop(function() { liberator.plugins.notifier._self = bootstrap(); }); } else { liberator.plugins.notifier = {}; liberator.plugins.notifier._self = bootstrap(); } function bootstrap() { var libly = liberator.plugins.libly; var $U = libly.$U; var logger = $U.getLogger("notifier"); var Loader = function() {//{{{ this.initialize.apply(this, arguments); }; Loader.prototype = { initialize: function(name) { liberator.plugins.notifier[name] = this; this.name = name; this.plugins = []; this.load(name); }, load: function(name) { io.getRuntimeDirectories("plugin/notifier").forEach(function(dir) { $U.readDirectory(io.expandPath(dir.path), "^" + name + "_", function(f) { try { io.source(f.path, true) logger.log("plugin load success: " + f.leafName); } catch (e) { logger.log("plugin load failed: " + f.leafName); } }); }); }, register: function(baseClass, pluginExtends) { this.plugins.push(new baseClass(pluginExtends)); }, unregister: function(plugin) { var ret = []; this.plugins.forEach(function(p) { if (p != plugin) ret.push(p); }); this.plugins = ret; }, getPlugins: function() { return this.plugins; } }; //}}} var Message = function() {//{{{ this.initialize.apply(this, arguments); }; Message.prototype = { initialize: function(title, message, link, options) { try { if (typeof title == "undefined" || title == null) throw "title is undefined."; if (typeof message == "undefined" || message == null) throw "message is undefined."; this.title = title;
var seqCount = 0;
var usedIds = {};
var makeUnique = {
  'index.html': true,
  'style.css': true,
  'script.js': true,
  'unit.js': true,
  'spec.js': true,
  'scenario.js': true
}

function ids(list) {
  return list.map(function(item) { return item.id; }).join(' ');
};


exports.Example = function(scenarios) {
  this.module = '';
  this.deps = ['angular.js'];
  this.html = [];
  this.css = [];
  this.js = [];
  this.unit = [];
  this.scenario = [];
  this.scenarios = scenarios;
}

exports.Example.prototype.setModule = function(module) {
  if (module) {
    this.module = module;
  }
};

exports.Example.prototype.addDeps = function(deps) {
  deps && deps.split(/[\s\,]/).forEach(function(dep) {
    if (dep) {
      this.deps.push(dep);
    }
  }, this);
};

exports.Example.prototype.addSource = function(name, content) {
  var ext = name == 'scenario.js' ? 'scenario' : name.split('.')[1],
      id = name;

  if (makeUnique[name] && usedIds[id]) {
    id = name + '-' + (seqCount++);
  }
  usedIds[id] = true;
  
  this[ext].push({name: name, content: content, id: id});
  if (name.match(/\.js$/) && name !== 'spec.js' && name !== 'unit.js' && name != 'scenario.js') {
    this.deps.push(name);
  }
  if (ext == 'scenario') {
    this.scenarios.push(content);
  }
};

exports.Example.prototype.toHtml = function() {
  return '<h1>Source</h1>\n' +
          this.toHtmlEdit() +
          this.toHtmlTabs() +
          '<h1>Demo</h1>\n' +
          this.toHtmlEmbed();
};


exports.Example.prototype.toHtmlEdit = function() {
  var out = [];
  out.push('<div source-edit="' + this.module + '"');
  out.push(' source-edit-deps="' + this.deps.join(' ') + '"');
  out.push(' source-edit-html="' + ids(this.html) + '"');
  out.push(' source-edit-css="' + ids(this.css) + '"');
  out.push(' source-edit-js="' + ids(this.js) + '"');
  out.push(' source-edit-unit="' + ids(this.unit) + '"');
  out.push(' source-edit-scenario="' + ids(this.scenario) + '"');
  out.push('></div>\n');
  return out.join('');
};

exports.Example.prototype.toHtmlTabs = function() {
  var out = [],
      self = this;

  out.push('<div class="tabbable">');
  htmlTabs(this.html);
  htmlTabs(this.css);
  htmlTabs(this.js);
  htmlTabs(this.unit);
  htmlTabs(this.scenario);
  out.push('</div>');
  return out.join('');

  function htmlTabs(sources) {
    sources.forEach(function(source) {
      var wrap = '',
          isCss = source.name.match(/\.css$/),
          name = source.name;

      if (name === 'index.html') {
        wrap = ' ng-html-wrap="' + self.module + ' ' + self.deps.join(' ') + '"';
      }
      if (name == 'scenario.js') name = 'End to end test';

      out.push(
        '<div class="tab-pane" title="' + name + '">\n' +
          '<pre class="prettyprint linenums" ng-set-text="' + source.id + '"' + wrap + '></pre>\n' +
          (isCss
             ? ('<style type="text/css" id="' + source.id + '">' + source.content + '</style>\n')
             : ('<script type="text/ng-template" id="' + source.id + '">' + source.content + '</script>\n') ) +
        '</div>\n');
    });
  }
};

exports.Example.prototype.toHtmlEmbed = function() {
  var out = [];
  out.push('<div class="well doc-example-live"');
  out.push(' ng-embed-app="' + this.module + '"');
  out.push(' ng-set-html="' + this.html[0].id + '"');
  out.push(' ng-eval-javascript="' + ids(this.js) + '">');
  out.push('</div>');
  return out.join('');
};