From 6b8ed42670039f53d2b20dc1079f742840f62ae9 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 10 Nov 2010 12:02:49 -0800 Subject: Added Directives --- docs/collect.js | 14 +- docs/directive.template | 37 ++++ docs/doc_widgets.js | 4 +- docs/index.html | 30 +-- docs/spec/collectSpec.js | 4 +- src/Angular.js | 29 ++- src/directives.js | 560 +++++++++++++++++++++++++++++++++++++++++++++++ src/filters.js | 4 +- 8 files changed, 655 insertions(+), 27 deletions(-) create mode 100644 docs/directive.template diff --git a/docs/collect.js b/docs/collect.js index 2d43669a..08bb6be3 100644 --- a/docs/collect.js +++ b/docs/collect.js @@ -127,7 +127,8 @@ function escapedHtmlTag(doc, name, value) { } function markdownTag(doc, name, value) { - doc[name] = markdown(value.replace(/^#/gm, '##')); + doc[name] = markdown(value.replace(/^#/gm, '##')). + replace(/\
/gmi, '');
}
function markdown(text) {
@@ -135,6 +136,14 @@ function markdown(text) {
return new Showdown.converter().makeHtml(text);
}
+function markdownNoP(text) {
+ var lines = markdown(text).split(NEW_LINE);
+ var last = lines.length - 1;
+ lines[0] = lines[0].replace(/^/, '');
+ lines[last] = lines[last].replace(/<\/p>$/, '');
+ return lines.join('\n');
+}
+
var TAG = {
ngdoc: valueTag,
example: escapedHtmlTag,
@@ -149,6 +158,7 @@ var TAG = {
returns: markdownTag,
paramDescription: markdownTag,
exampleDescription: markdownTag,
+ element: valueTag,
name: function(doc, name, value) {
doc.name = value;
var match = value.match(/^angular[\.\#](([^\.]+)\.(.*)|(.*))/);
@@ -163,7 +173,7 @@ var TAG = {
type: match[2],
name: match[6] || match[5],
'default':match[7],
- description:value.replace(match[0], match[8])
+ description:markdownNoP(value.replace(match[0], match[8]))
};
doc.param.push(param);
if (!doc.paramFirst) {
diff --git a/docs/directive.template b/docs/directive.template
new file mode 100644
index 00000000..84b87ca7
--- /dev/null
+++ b/docs/directive.template
@@ -0,0 +1,37 @@
+
{{name}}
+Description
+{{{description}}}
+
+Usage
+In HTML Template Binding
+
+
+<{{element}} {{shortName}}="{{paramFirst.name}}">
+ ...
+</{{element}}>
+
+
+
+Parameters
+abc'); - expect(doc.description).toEqual('
abc'); + TAG.description(doc, 'description', '
abc'); + expect(doc.description).toEqual('
abc'); }); describe('@example', function(){ diff --git a/src/Angular.js b/src/Angular.js index e6e7be8d..a1477e35 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -17,7 +17,7 @@ var lowercase = function (value){ return isString(value) ? value.toLowerCase() : /** * @ngdoc - * @name angular#uppercase + * @name angular.uppercase * @function * * @description Converts string to uppercase. @@ -150,6 +150,21 @@ var _undefined = undefined, * }; * }); * + * + * @example + * + *
{{data}}
*
*
* @scenario
* it('should store reverse', function(){
- * expect(element('.doc-example input:first').val()).toEqual('+ * Google + *+ * + * The above gets translated to bellow during bootstrap time. + *
+ * Google + *+ * + * @element ANY + * @param {string} attribute_json a JSON key-value pairs representing + * the attributes to replace. Each key matches the attribute + * which needs to be replaced. Each value is a text template of + * the attribute with embedded + * {{expression}}s. Any number of + * key-value pairs can be specified. + * + * @exampleDescription + * Try it here: enter text in text box and click Google. + * @example + Google for: + + Google + * + * @scenario + it('should check ng:bind-attr', function(){ + expect(using('.doc-example-live').element('a').attr('href')). + toBe('http://www.google.com/search?q=AngularJS'); + using('.doc-example-live').input('query').enter('google'); + expect(using('.doc-example-live').element('a').attr('href')). + toBe('http://www.google.com/search?q=google'); + }); + */ angularDirective("ng:bind-attr", function(expression){ return function(element){ var lastValue = {}; @@ -146,8 +378,82 @@ angularDirective("ng:bind-attr", function(expression){ }; }); +/** + * @ngdoc directive + * @name angular.directive.ng:non-bindable + * + * @description + * Sometimes it is necessary to write code which looks like + * bindings but which should be left alone by
list={{list}}
+ * @scenario
+ it('should check ng:submit', function(){
+ expect(binding('list')).toBe('list=[]');
+ element('.doc-example-live form input').click();
+ this.addFutureAction('submit from', function($window, $document, done) {
+ $window.angular.element(
+ $document.elements('.doc-example-live form')).
+ trigger('submit');
+ done();
+ });
+ expect(binding('list')).toBe('list=["hello"]');
+ });
+ */
/**
* Enables binding angular expressions to onsubmit events.
*
@@ -243,6 +601,32 @@ angularDirective("ng:submit", function(expression, element) {
});
+/**
+ * @ngdoc directive
+ * @name angular.directive.ng:watch
+ *
+ * @description
+ * The `ng:watch` allows you watch a variable and then execute
+ * an evaluation on variable change.
+ *
+ * @element ANY
+ * @param {expression} expression to eval.
+ *
+ * @exampleDescription
+ * Notice that the counter is incremented
+ * every time you change the text.
+ * @example
+