mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-12 02:50:58 +00:00
changed to showdown from markup. added validator overview
This commit is contained in:
parent
8767e766d1
commit
3d6a099d6e
14 changed files with 1496 additions and 1473 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
|
||||
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="true"/>
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <launchConfigurationWorkingSet editPageId="org.eclipse.ui.resourceWorkingSetPage" factoryID="org.eclipse.ui.internal.WorkingSetFactory" id="1262905463390_2" label="workingSet" name="workingSet"> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/angular.js/test" type="2"/> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/angular.js/src" type="2"/> </launchConfigurationWorkingSet>}"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/angular.js}/test.sh"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ var fs = require('fs'),
|
|||
spawn = require('child_process').spawn,
|
||||
mustache = require('mustache'),
|
||||
callback = require('callback'),
|
||||
markdown = require('markdown');
|
||||
Showdown = require('showdown').Showdown;
|
||||
|
||||
var documentation = {
|
||||
section:{},
|
||||
|
|
@ -99,7 +99,12 @@ function escapedHtmlTag(doc, name, value) {
|
|||
}
|
||||
|
||||
function markdownTag(doc, name, value) {
|
||||
doc[name] = markdown.toHTML(value.replace(/^#/gm, '##'));
|
||||
doc[name] = markdown(value.replace(/^#/gm, '##'));
|
||||
}
|
||||
|
||||
function markdown(text) {
|
||||
text = text.replace(/<angular\/>/gm, '<tt><angular/></tt>');
|
||||
return new Showdown.converter().makeHtml(text);
|
||||
}
|
||||
|
||||
var TAG = {
|
||||
|
|
@ -114,6 +119,8 @@ var TAG = {
|
|||
description: markdownTag,
|
||||
TODO: markdownTag,
|
||||
returns: markdownTag,
|
||||
paramDescription: markdownTag,
|
||||
exampleDescription: markdownTag,
|
||||
name: function(doc, name, value) {
|
||||
doc.name = value;
|
||||
doc.shortName = value.split(/\./).pop();
|
||||
|
|
@ -127,7 +134,8 @@ var TAG = {
|
|||
type: match[2],
|
||||
name: match[6] || match[5],
|
||||
'default':match[7],
|
||||
description:match[8]};
|
||||
description:value.replace(match[0], match[8])
|
||||
};
|
||||
doc.param.push(param);
|
||||
if (!doc.paramFirst) {
|
||||
doc.paramFirst = param;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
<h1><tt>{{name}}</tt></h1>
|
||||
<h2>Description</h2>
|
||||
{{{description}}}
|
||||
|
||||
<h2>Usage</h2>
|
||||
<h3>In HTML Template Binding</h3>
|
||||
<tt>
|
||||
|
|
@ -25,9 +28,6 @@ angular.filter.{{shortName}}({{paramFirst.name}}{{#paramRest}}, {{name}}{{/param
|
|||
<h3>CSS</h3>
|
||||
{{{css}}}
|
||||
|
||||
<h2>Description</h2>
|
||||
{{{description}}}
|
||||
|
||||
<WIKI:SOURCE style="display:block;">
|
||||
{{{example}}}
|
||||
</WIKI:SOURCE>
|
||||
|
|
@ -4,8 +4,8 @@
|
|||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="docs-data.js"></script>
|
||||
<script type="text/javascript" src="../angular.min.js" ng:autobind></script>
|
||||
<script type="text/javascript" src="http://angularjs.org/extensions/wiki_widgets.js"></script>
|
||||
<link rel="stylesheet" href="http://angularjs.org/extensions/wiki_widgets.css" type="text/css" media="screen" />
|
||||
<script type="text/javascript" src="wiki_widgets.js"></script>
|
||||
<link rel="stylesheet" href="wiki_widgets.css" type="text/css" media="screen" />
|
||||
<script type="text/javascript">
|
||||
function DocsController() {
|
||||
this.docs = NG_DOC;
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@
|
|||
|
||||
<WIKI:SOURCE style="display:block;">
|
||||
{{{example}}}
|
||||
</WIKI:SOURCE>
|
||||
</WIKI:SOURCE>
|
||||
|
|
|
|||
|
|
@ -6,21 +6,29 @@ var Script = process.binding('evals').Script;
|
|||
var collect = load('docs/collect.js');
|
||||
|
||||
describe('collect', function(){
|
||||
describe('markdown', function(){
|
||||
it('should replace angular in markdown', function(){
|
||||
expect(collect.markdown('<angular/>')).
|
||||
toEqual('<p><tt><angular/></tt></p>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('TAG', function(){
|
||||
var TAG = collect.TAG;
|
||||
var doc;
|
||||
beforeEach(function(){
|
||||
doc = {};
|
||||
});
|
||||
|
||||
describe('@param', function(){
|
||||
var doc;
|
||||
beforeEach(function(){
|
||||
doc = {};
|
||||
});
|
||||
it('should parse with no default', function(){
|
||||
TAG.param(doc, 'param',
|
||||
'{(number|string)} number Number to format.');
|
||||
'{(number|string)} number Number \n to format.');
|
||||
expect(doc.param).toEqual([{
|
||||
type : '(number|string)',
|
||||
name : 'number',
|
||||
'default' : undefined,
|
||||
description : 'Number to format.' }]);
|
||||
description : 'Number \n to format.' }]);
|
||||
});
|
||||
it('should parse with default', function(){
|
||||
TAG.param(doc, 'param',
|
||||
|
|
@ -32,7 +40,25 @@ describe('collect', function(){
|
|||
description : 'desc' }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('@describe', function(){
|
||||
it('should support pre blocks', function(){
|
||||
TAG.description(doc, 'description', '<pre>abc</pre>');
|
||||
expect(doc.description).toEqual('<pre>abc</pre>');
|
||||
});
|
||||
|
||||
describe('@example', function(){
|
||||
it('should not remove {{}}', function(){
|
||||
TAG.example(doc, 'example', 'text {{ abc }}');
|
||||
expect(doc.example).toEqual('text {{ abc }}');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
function load(path){
|
||||
|
|
|
|||
27
docs/validator.template
Normal file
27
docs/validator.template
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<h1><tt>{{name}}</tt></h1>
|
||||
|
||||
<h2>Description</h2>
|
||||
{{{description}}}
|
||||
|
||||
<h2>Usage</h2>
|
||||
<h3>In HTML Template Binding</h3>
|
||||
<tt>
|
||||
<input type="text" ng:validate="{{shortName}}{{#paramRest}}{{^default}}:{{name}}{{/default}}{{#default}}<i>[:{{name}}]</i>{{/default}}{{/paramRest}}"/>
|
||||
</tt>
|
||||
|
||||
<h3>Parameters</h3>
|
||||
<ul>
|
||||
{{#param}}
|
||||
<li><tt>{{name}}:{{#type}}{{type}}{{/type}}{{^type}}:*{{/type}}{{#default}}={{default}}{{/default}}</tt>: {{{description}}}</li>
|
||||
{{/param}}
|
||||
</ul>
|
||||
{{{paramDescription}}}
|
||||
|
||||
<h3>CSS</h3>
|
||||
{{{css}}}
|
||||
|
||||
<h2>Example</h2>
|
||||
{{{exampleDescription}}}
|
||||
<WIKI:SOURCE style="display:block;">
|
||||
{{{example}}}
|
||||
</WIKI:SOURCE>
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
<h1><tt>{{name}}</tt></h1>
|
||||
|
||||
<h2>Description</h2>
|
||||
{{{description}}}
|
||||
|
||||
<h2>Usage</h2>
|
||||
<h3>In HTML Template Binding</h3>
|
||||
<tt>
|
||||
|
|
@ -20,9 +24,6 @@
|
|||
<h3>CSS</h3>
|
||||
{{{css}}}
|
||||
|
||||
<h2>Description</h2>
|
||||
{{{description}}}
|
||||
|
||||
<WIKI:SOURCE style="display:block;">
|
||||
{{{example}}}
|
||||
</WIKI:SOURCE>
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
/usr/local/bin/node docs/specs.js --noColor && /usr/local/bin/node docs/collect.js
|
||||
node docs/specs.js --noColor && node docs/collect.js
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
6
lib/showdown/index.js
Normal file
6
lib/showdown/index.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
var fs = require('fs');
|
||||
|
||||
var filename = __dirname + '/showdown-0.9.js';
|
||||
var src = fs.readFileSync(filename);
|
||||
var Showdown = process.compile(src + '\nShowdown;', filename);
|
||||
exports.Showdown = Showdown;
|
||||
1296
lib/showdown/showdown-0.9.js
Normal file
1296
lib/showdown/showdown-0.9.js
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -93,6 +93,59 @@ var _undefined = undefined,
|
|||
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
|
||||
angularDirective = extensionMap(angular, 'directive'),
|
||||
angularWidget = extensionMap(angular, 'widget', lowercase),
|
||||
|
||||
/**
|
||||
* @ngdoc overview
|
||||
* @name angular.validator
|
||||
* @namespace Namespace for all filters.
|
||||
* @description
|
||||
* # Overview
|
||||
* Validators are a standard way to check the user input against a specific criteria. For
|
||||
* example, you might need to check that an input field contains a well-formed phone number.
|
||||
*
|
||||
* # Syntax
|
||||
* Attach a validator on user input widgets using the `ng:validate` attribute.
|
||||
*
|
||||
* <WIKI:SOURCE>
|
||||
* Change me: <input type="text" name="number" ng:validate="integer" value="123">
|
||||
* </WIKI:SOURCE>
|
||||
*
|
||||
* # Writing your own Validators
|
||||
* Writing your own validator is easy. To make a function available as a
|
||||
* validator, just define the JavaScript function on the `angular.validator`
|
||||
* object. <angular/> passes in the input to validate as the first argument
|
||||
* to your function. Any additional validator arguments are passed in as
|
||||
* additional arguments to your function.
|
||||
*
|
||||
* You can use these variables in the function:
|
||||
*
|
||||
* * `this` — The current scope.
|
||||
* * `this.$element` — The DOM element containing the binding. This allows the filter to manipulate
|
||||
* the DOM in addition to transforming the input.
|
||||
*
|
||||
* In this example we have written a upsTrackingNo validator.
|
||||
* It marks the input text "valid" only when the user enters a well-formed
|
||||
* UPS tracking number.
|
||||
*
|
||||
* <pre>
|
||||
* angular.validator('upsTrackingNo', function(input, format) {
|
||||
* var regexp = new RegExp("^" + format.replace(/9/g, '\\d') + "$");
|
||||
* return input.match(regexp) ? "" : "The format must match " + format;
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @example
|
||||
* <script>
|
||||
* angular.validator('upsTrackingNo', function(input, format) {
|
||||
* var regexp = new RegExp("^" + format.replace(/9/g, '\\d') + "$");
|
||||
* return input.match(regexp)?"":"The format must match " + format;
|
||||
* });
|
||||
* </script>
|
||||
* <input type="text" name="trackNo" size="40"
|
||||
* ng:validate="upsTrackingNo:'1Z 999 999 99 9999 999 9'"
|
||||
* value="1Z 123 456 78 9012 345 6"/>
|
||||
*
|
||||
*/
|
||||
angularValidator = extensionMap(angular, 'validator'),
|
||||
|
||||
|
||||
|
|
@ -139,13 +192,13 @@ var _undefined = undefined,
|
|||
* You can use these variables in the function:
|
||||
*
|
||||
* * `this` — The current scope.
|
||||
* * `$element` — The DOM element containing the binding. This allows the filter to manipulate
|
||||
* * `this.$element` — The DOM element containing the binding. This allows the filter to manipulate
|
||||
* the DOM in addition to transforming the input.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
<script type="text/javascript">
|
||||
angular.filter.reverse = function(input, uppercase, color) {
|
||||
angular.filter('reverse', function(input, uppercase, color) {
|
||||
var out = "";
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
out = input.charAt(i) + out;
|
||||
|
|
@ -157,7 +210,7 @@ var _undefined = undefined,
|
|||
this.$element.css('color', color);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
});
|
||||
</script>
|
||||
The following example filter reverses a text string. In addition, it conditionally makes the
|
||||
text upper-case (to demonstrate optional arguments) and assigns color (to demonstrate DOM
|
||||
|
|
@ -169,10 +222,6 @@ var _undefined = undefined,
|
|||
<span ng:non-bindable="true">{{"hello"|reverse:true:"blue"}}</span>:
|
||||
{{"hello"|reverse:true:"blue"}}
|
||||
|
||||
* @TODO: I completely dropped a mention of using the other option (setter method), it's
|
||||
* confusing to have two ways to do the same thing. I just wonder if we should prefer using the
|
||||
* setter way over direct assignment because in the future we might want to be able to intercept
|
||||
* filter registrations for some reason.
|
||||
*/
|
||||
angularFilter = extensionMap(angular, 'filter'),
|
||||
angularFormatter = extensionMap(angular, 'formatter'),
|
||||
|
|
|
|||
|
|
@ -84,6 +84,62 @@ extend(angularValidator, {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc validator
|
||||
* @name angular.validator.asynchronous
|
||||
* @description
|
||||
* Use asynchronous validator if the validation can not be computed
|
||||
* immediately, but is provided through a callback. The widget
|
||||
* automatically shows a spinning indicator while the validity of
|
||||
* the widget is computed. This validator caches the result.
|
||||
*
|
||||
* @param {string} value value to validate
|
||||
* @param {function(inputToValidate,validationDone)} validate function to call to validate the state
|
||||
* of the input.
|
||||
* @param {function(data)=} [update=noop] function to call when state of the
|
||||
* validator changes
|
||||
*
|
||||
* @paramDescription
|
||||
* The `validate` function (specified by you) is called as
|
||||
* `validate(inputToValidate, validationDone)`:
|
||||
*
|
||||
* * `inputToValidate`: value of the input box.
|
||||
* * `validationDone`: `function(error, data){...}`
|
||||
* * `error`: error text to display if validation fails
|
||||
* * `data`: data object to pass to update function
|
||||
*
|
||||
* The `update` function is optionally specified by you and is
|
||||
* called by <angular/> on input change. Since the
|
||||
* asynchronous validator caches the results, the update
|
||||
* function can be called without a call to `validate`
|
||||
* function. The function is called as `update(data)`:
|
||||
*
|
||||
* * `data`: data object as passed from validate function
|
||||
*
|
||||
* @css ng-input-indicator-wait
|
||||
*
|
||||
* @exampleDescription
|
||||
* <pre>
|
||||
* function myValidator (value, callback) {
|
||||
* // simulate delayed response, validate on even input length
|
||||
* setTimeout(function(){
|
||||
* callback(value.length % 2);
|
||||
* }, 2000);
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
* @example
|
||||
* <script>
|
||||
* function myValidator(value, callback) {
|
||||
* setTimeout(function(){
|
||||
* callback(value.length % 2);
|
||||
* }, 2000);
|
||||
* }
|
||||
* </script>
|
||||
* This input is validated asynchronously:
|
||||
* <input name="text" ng:validate="asynchronous:$window.myValidator">
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* cache is attached to the element
|
||||
* cache: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue