Skip to content

Commit

Permalink
refactor(gen): switch to ng-annotate
Browse files Browse the repository at this point in the history
Closes #17.
  • Loading branch information
balthazar committed Sep 6, 2014
1 parent 176d26d commit ea55b62
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 91 deletions.
169 changes: 84 additions & 85 deletions dist/ng-markdown.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,29 @@
var converter = Markdown.getSanitizingConverter();
var editor;
var preview;
var postfix = '';
var suffix = '';
var prefix = 'wmd-';
var helpHandler = null;
var strings = {};

//Test attributes
if (attrs.sanitized === 'false') {
converter = new Markdown.Converter();
}
if (attrs.suffix) {
postfix = attrs.suffix;
suffix = attrs.suffix;
}
if (attrs.prefix) {
prefix = attrs.prefix;
}
if (attrs.helpHandler) {
helpHandler = scope.helpHandler;
}
if (attrs.customStrings) {
strings = scope.customStrings;
}

editor = new Markdown.Editor(converter, suffix, prefix, helpHandler, strings);

if (attrs.preConversion) {
converter.hooks.chain('preConversion', scope.preConversion);
}
Expand Down Expand Up @@ -89,18 +97,11 @@
if (attrs.insertImageDialog) {
editor.hooks.set('insertImageDialog', scope.insertImageDialog);
}
if (attrs.helpHandler) {
helpHandler = scope.helpHandler;
}
if (attrs.customStrings) {
strings = scope.customStrings;
}

preview = angular.element(document.querySelector('.' + prefix + 'preview' + postfix));
preview = angular.element(document.querySelector('.' + prefix + 'preview' + suffix));

element.addClass(prefix + 'input' + postfix);
element.addClass(prefix + 'input' + suffix);

editor = new Markdown.Editor(converter, postfix, prefix, helpHandler, strings);
editor.run();

scope.refresh = function () {
Expand All @@ -116,7 +117,7 @@
};

scope.$on('refreshMarkdown', function (event, message) {
if (!message || message === '' || message === (prefix + postfix)) {
if (!message || message === '' || message === (prefix + suffix)) {
scope.refresh();
}
});
Expand Down Expand Up @@ -1519,91 +1520,89 @@ else

(function () {

var util = {},
position = {},
ui = {},
doc = window.document,
re = window.RegExp,
nav = window.navigator,
SETTINGS = { lineLength: 72 },

uaSniffed = {
isIE: /msie/.test(nav.userAgent.toLowerCase()),
isIE_5or6: /msie 6/.test(nav.userAgent.toLowerCase()) || /msie 5/.test(nav.userAgent.toLowerCase()),
isOpera: /opera/.test(nav.userAgent.toLowerCase())
};

var defaultsStrings = {
bold: "Strong <strong> Ctrl+B",
boldexample: "strong text",

italic: "Emphasis <em> Ctrl+I",
italicexample: "emphasized text",

link: "Hyperlink <a> Ctrl+L",
linkdescription: "enter link description here",
linkdialog: "<p><b>Insert Hyperlink</b></p><p>http://example.com/ \"optional title\"</p>",

quote: "Blockquote <blockquote> Ctrl+Q",
quoteexample: "Blockquote",

code: "Code Sample <pre><code> Ctrl+K",
codeexample: "enter code here",

image: "Image <img> Ctrl+G",
imagedescription: "enter image description here",
imagedialog: "<p><b>Insert Image</b></p><p>http://example.com/images/diagram.jpg \"optional title\"</p>",

olist: "Numbered List <ol> Ctrl+O",
ulist: "Bulleted List <ul> Ctrl+U",
litem: "List item",

heading: "Heading <h1>/<h2> Ctrl+H",
headingexample: "Heading",

hr: "Horizontal Rule <hr> Ctrl+R",

undo: "Undo - Ctrl+Z",
redo: "Redo - Ctrl+Y",
redomac: "Redo - Ctrl+Shift+Z",

help: "Markdown Editing Help"
};

var imageDefaultText = "http://";
var linkDefaultText = "http://";
var prefixName;
var suffixName;

// The helpFunction is the help function handler, fired when a user click on
// the help button. It will not be created if null function is given.
//
// If given, strings can modify all the properties as defaultStrings above.
//
// The constructed editor object has the methods:
// - getConverter() returns the markdown converter object that was passed to the constructor
// - run() actually starts the editor; should be called after all necessary plugins are registered. Calling this more than once is a no-op.
// - refreshPreview() forces the preview to be updated. This method is only available after run() was called.
var util = {},
position = {},
ui = {},
doc = window.document,
re = window.RegExp,
nav = window.navigator,
SETTINGS = { lineLength: 72 },
uaSniffed = {
isIE: /msie/.test(nav.userAgent.toLowerCase()),
isIE_5or6: /msie 6/.test(nav.userAgent.toLowerCase()) || /msie 5/.test(nav.userAgent.toLowerCase()),
isOpera: /opera/.test(nav.userAgent.toLowerCase())
};

var defaultsStrings = {
bold: "Strong <strong> Ctrl+B",
boldexample: "strong text",

italic: "Emphasis <em> Ctrl+I",
italicexample: "emphasized text",

link: "Hyperlink <a> Ctrl+L",
linkdescription: "enter link description here",
linkdialog: "<p><b>Insert Hyperlink</b></p><p>http://example.com/ \"optional title\"</p>",

quote: "Blockquote <blockquote> Ctrl+Q",
quoteexample: "Blockquote",

code: "Code Sample <pre><code> Ctrl+K",
codeexample: "enter code here",

image: "Image <img> Ctrl+G",
imagedescription: "enter image description here",
imagedialog: "<p><b>Insert Image</b></p><p>http://example.com/images/diagram.jpg \"optional title\"</p>",

olist: "Numbered List <ol> Ctrl+O",
ulist: "Bulleted List <ul> Ctrl+U",
litem: "List item",

heading: "Heading <h1>/<h2> Ctrl+H",
headingexample: "Heading",

hr: "Horizontal Rule <hr> Ctrl+R",

undo: "Undo - Ctrl+Z",
redo: "Redo - Ctrl+Y",
redomac: "Redo - Ctrl+Shift+Z",

help: "Markdown Editing Help"
};

var imageDefaultText = 'http://',
linkDefaultText = 'http://',
prefixName,
suffixName;

// The helpFunction is the help function handler, fired when a user click on
// the help button. It will not be created if null function is given.
//
// If given, strings can modify all the properties as defaultStrings above.
//
// The constructed editor object has the methods:
// - getConverter() returns the markdown converter object that was passed to the constructor
// - run() actually starts the editor; should be called after all necessary plugins are registered. Calling this more than once is a no-op.
// - refreshPreview() forces the preview to be updated. This method is only available after run() was called.
Markdown.Editor = function (markdownConverter, idPostfix, idPrefix, helpFunction, strings) {
strings = strings || {};
var getString = function (identifier) { return strings[identifier] || defaultsStrings[identifier]; };

idPostfix = idPostfix || "";
suffixName = idPostfix;
prefixName = idPrefix;
suffixName = idPostfix;
prefixName = idPrefix;

var hooks = this.hooks = new Markdown.HookCollection();
hooks.addNoop("onPreviewRefresh"); // called with no arguments after the preview has been refreshed
hooks.addNoop("postBlockquoteCreation"); // called with the user's selection *after* the blockquote was created; should return the actual to-be-inserted text
hooks.addFalse("insertImageDialog"); /* called with one parameter: a callback to be called with the URL of the image. If the application creates
hooks.addNoop('onPreviewRefresh'); // called with no arguments after the preview has been refreshed
hooks.addNoop('postBlockquoteCreation'); // called with the user's selection *after* the blockquote was created; should return the actual to-be-inserted text
hooks.addFalse('insertImageDialog'); /* called with one parameter: a callback to be called with the URL of the image. If the application creates
* its own image insertion dialog, this hook should return true, and the callback should be called with the chosen
* image url (or null if the user cancelled). If this hook returns false, the default dialog will be used.
*/

this.getConverter = function () { return markdownConverter; };

var that = this,
panels;
var that = this, panels;

this.run = function () {
if (panels)
Expand Down
6 changes: 3 additions & 3 deletions dist/ng-markdown.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var pkg = require('./package.json'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
ngmin = require('gulp-ngmin'),
annotate = require('gulp-ng-annotate'),
cssmin = require('gulp-minify-css'),
rename = require("gulp-rename"),
gutil = require('gulp-util'),
Expand Down Expand Up @@ -32,7 +32,7 @@ gulp.task('js', function () {
.pipe(jshint.reporter('default'))
.pipe(concat('ng-markdown.js'))
.pipe(gulp.dest('dist'))
.pipe(ngmin())
.pipe(annotate())
.on('error', handleError)
.pipe(uglify({ mangle: false }))
.pipe(rename({ suffix: '.min' }))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"gulp-coveralls": "~0.1.2",
"gulp-jshint": "^1.5.3",
"gulp-minify-css": "^0.3.7",
"gulp-ngmin": "^0.3.0",
"gulp-ng-annotate": "^0.3.0",
"gulp-protractor": "0.0.11",
"gulp-rename": "^1.2.0",
"gulp-ruby-sass": "^0.7.1",
Expand Down

0 comments on commit ea55b62

Please sign in to comment.