Compare commits

...

120 Commits

Author SHA1 Message Date
Igor Minar 9b53b25f15 cutting the 0.9.4 total-recall release 2010-11-18 22:40:01 -08:00
Igor Minar 3fbfa357ca updated release notes for the 0.9.4 total-recall release 2010-11-18 22:40:00 -08:00
Igor Minar 50ef1f8e35 don't escape $ in hashpath either 2010-11-18 22:40:00 -08:00
Igor Minar 66c0bfaa8e don't escape ! and : in hashPath
This is a temporary fix for Issue #158
2010-11-18 20:51:31 -08:00
Igor Minar 1719b0aca5 fix all closure compilation warnings due to invalid function types 2010-11-18 17:03:43 -08:00
Igor Minar 7ee102eecf add a feedback link to the doc pages 2010-11-18 16:53:11 -08:00
Igor Minar fc7f11d03b add @workInProgress tag and mark all @ngdocs as work in progress 2010-11-18 16:28:42 -08:00
Igor Minar 3c7874b07b don't encode page.name (hash) in docs.js
see discussion in https://github.com/angular/angular.js/pull/158"
2010-11-18 11:56:10 -08:00
Igor Minar 7f339a1782 escape code in ng:bind-attr jsdoc 2010-11-18 11:33:09 -08:00
Igor Minar 72a5f007d8 most of the documentation for angular.scope and friends 2010-11-18 02:35:30 -08:00
Igor Minar 63380bbbda title for index.html should not show raw binding while the app bootstraps 2010-11-18 02:35:30 -08:00
Igor Minar c635b69f5c fix docs and examples for ng:format, ng:required and ng:validate 2010-11-18 02:35:30 -08:00
Igor Minar 522ec1a9ec move attribute widgets to widgets.js file
- move @ng:repeat to widgets.js and its specs to widgetsSpecs.js
- move @ng:non-bindable to widgets.js and its specs to widgetsSpecs.js
- make widget.template suitable for attribute widgets
- fix up the js docs for attribute widgets
2010-11-18 02:35:29 -08:00
Igor Minar 9cb57772a4 fix docs for angular.directive and ng:autobind 2010-11-18 02:35:29 -08:00
Igor Minar d54f09ef29 add spec for incrementing headings 2010-11-18 02:35:29 -08:00
Igor Minar 65989c6f0d add support for {@link} tags within @description and remove implicit linking
use as:
- foo {@link bar}
- foo {@link bar desc}

I'm removing implicit linking because it unintentionally links stuff and
generally interferes with other conversions. We have to link stuff explicitely
from now on.
2010-11-18 02:35:29 -08:00
Igor Minar 4491bbdede docs linkifying regexp should not mess up links alreaded converete by markdown 2010-11-18 02:35:28 -08:00
Igor Minar a6978b201b make @param type and description non-optional 2010-11-18 02:35:28 -08:00
Igor Minar 28e72cbe6b CSS, Parameters, Returns template changes
- make css section optional
- make returns section optional
- change format of the parameters section
- properly format the Returns section
2010-11-18 02:34:55 -08:00
Igor Minar 916dadd8ec adjust spacing of headings in the main doc div 2010-11-18 02:34:54 -08:00
Igor Minar e509ec37f5 fixing angular.lowercase and angular.upppercase jsdocs + api 2010-11-18 02:34:54 -08:00
Igor Minar ee0e9a4452 adding support for @param.optional 2010-11-18 02:34:54 -08:00
Igor Minar 9d36368ff9 fixing angular.filter.number jsdocs 2010-11-18 02:34:54 -08:00
Igor Minar d4bcee0799 toJson and fromJson jsdocs 2010-11-18 02:34:54 -08:00
Igor Minar dd687e2bf5 @returns description should support markdown 2010-11-18 02:34:53 -08:00
Igor Minar 4c69d694d7 make @returns type non-optional 2010-11-18 02:34:53 -08:00
Igor Minar ff7c738c21 fix ng docs for angular, angular.lowercase and uppercase 2010-11-18 02:34:53 -08:00
Igor Minar 51a22cf435 group utility methods/objects while sorting stuff for the side bar 2010-11-18 02:34:53 -08:00
Igor Minar c2c60ab49a remove extra returns tag 2010-11-18 02:34:53 -08:00
Igor Minar 71c2f24fc6 remove extra toolbar directive and support multiple pre's in describe 2010-11-18 02:34:52 -08:00
Igor Minar fc78738cc6 scope docs + lowercase doc fix 2010-11-18 02:34:52 -08:00
Igor Minar c7052f098d add support for @deprecated ng:doc annotation + show warnings in templates 2010-11-18 02:34:31 -08:00
Igor Minar 7d6f5f986e add function.template 2010-11-18 02:34:30 -08:00
Igor Minar beeb5ff908 fix regexp for @param parsing in ng:docs
There is an extra + in the regexp which causes exponential increase in time
needed to parse a @param annotation when the length of default value increases
linearly.
2010-11-16 14:44:35 -08:00
Misko Hevery b2d63ac48b Changed error handling so that better stack traces are displayed in the ng-errors 2010-11-16 14:19:55 -08:00
Igor Minar 4af32de84a docs should use ng:include onload 2010-11-16 13:45:45 -08:00
Igor Minar a130bb899d add onload attribute to ng:include 2010-11-16 11:35:43 -08:00
Vojta Jina cc749760fd Added basic Services, which support @memberOf and @methodOf 2010-11-15 21:55:37 -08:00
Misko Hevery b467a50bc7 generate keyword for searches; improved layout of doc 2010-11-15 12:28:08 -08:00
Misko Hevery a1652057a5 changed to ! notation for indexable apps 2010-11-15 10:04:17 -08:00
Misko Hevery 7e6f999221 added remaining directives and search box. 2010-11-15 10:04:17 -08:00
Igor Minar 625cc7609c fix code name in the change log 2010-11-12 16:18:11 -08:00
Igor Minar c51273b1fb Add test coverage analysis.
- jstd upgrade to head from 2010-11-11
- coverage plugin from the same head as jstd
- test-coverage.sh and server-coverage.sh scripts
- jstd configuration

Generate html by installing lconv (brew or port) and run:

genhtml tmp/lcov/jsTestDriver.conf-coverage.dat

to generate html docs.
2010-11-12 16:13:53 -08:00
Igor Minar 0a8b3161b1 $watch should optionally skip listener exec
- if initRun param is set to false, listener doesn't execute
- the oldValue should equal newValue during the initial execution
- added docs
- added specs
2010-11-11 16:39:01 -08:00
Igor Minar ba554eeb1b preparations for 0.9.4 total-recall iteration 2010-11-11 16:38:23 -08:00
Igor Minar 5f0af2cd0e cutting the 0.9.3 cold-resistance release 2010-11-10 22:15:16 -08:00
Igor Minar 7411b24812 updating the release notes for 0.9.3 release 2010-11-10 22:14:16 -08:00
Igor Minar ae5f6f48b4 scenario repeater should match only visible stuff 2010-11-10 21:04:44 -08:00
Igor Minar c5b2bf083c Make ng:repeat expose $position.
- $position is a textual representation of the position of
  repeated item ('first', 'middle', 'last')
- added specs for $index
2010-11-10 21:04:44 -08:00
Misko Hevery 0499c47270 added ng:switch-when-default; changed $watch to always fire on init. (may be backward incompatible) 2010-11-10 21:01:17 -08:00
Misko Hevery 43a4ff4cdf Example snippets now have full html snippets 2010-11-10 21:01:05 -08:00
Misko Hevery 6b8ed42670 Added Directives 2010-11-10 12:02:49 -08:00
Elliott Sprehn c57df3dc77 Make the docs look a little nicer 2010-11-10 11:01:30 -08:00
Igor Minar 6d53808475 improve jsdocs
- improve json filter example
- improve filter overview doc
- improving validator overview jsdocs
- simplify number filter examples and make them live + add specs
- various doc fixes
2010-11-09 22:33:27 -08:00
Misko Hevery a7e8a503fd proper trimming of leading whitespace; url restriction to angular.* 2010-11-09 22:27:37 -08:00
Igor Minar 324694a58b Better example widget
- syntax highlighting
- tabless design
- rename widget to doc:example
- rename widget files (wiki_widget.* -> doc_widget.*)
- example section is now optional
2010-11-09 22:27:31 -08:00
Igor Minar effcd340e9 updating watchr-docs.rb 2010-11-09 21:44:51 -08:00
Igor Minar 264f960800 added spec for auto bootstrap with #autobind 2010-11-09 19:58:42 -08:00
Elliott Sprehn 257e97a65f Support substring matching of bindings with repeater(). Closes #123 2010-11-09 13:39:12 -08:00
Misko Hevery c048f0d8e8 Added formatter documentation. 2010-11-09 09:15:29 -08:00
Elliott Sprehn 96e37a0866 Add key/value jQuery methods in a loop. Support 'css' method.
Closes #134
2010-11-09 08:02:49 -08:00
Vojta Jina 5062d32621 Updated parser tests to use jasmine expects
And some formatting as well and a bit of rafactor...
2010-11-09 07:38:03 -08:00
Vojta Jina d458f31711 Updated filters tests to use jasmine expects
And some small formatting...
2010-11-09 07:38:03 -08:00
Igor Minar fc9ce9ec07 make angular.String.toDate consider all time fractions as optional 2010-11-08 22:49:30 -08:00
Igor Minar da17c61444 angular.Date.toString should use toISOString if available 2010-11-08 22:49:30 -08:00
Igor Minar e5c135ac50 Support ISO 8601 extended datetime format troughout angular.
Support ISO 8601 extended format datetime strings (YYYY-MM-DDTHH:mm:ss.SSSZ) as defined
  in EcmaScript 5 throughout angular. This means that the following apis switched from
  YYYY-MM-DDTHH:mm:ssZ to YYYY-MM-DDTHH:mm:ss.SSSZ (note the added millis) when representing dates:
  - angular.Date.toString
  - angular.String.toDate
  - JSON serialization and deserialization (used by json filter, $xhr and $resource)
2010-11-08 22:49:30 -08:00
Igor Minar 1a43f36e23 Add isDate method + fix old code 2010-11-08 22:49:29 -08:00
Igor Minar 1c305dc67a fixing spec description for the date filter 2010-11-08 22:46:41 -08:00
Igor Minar a397645537 date filter should accept ISO 8601 formatted string as input
Closes #125
2010-11-08 22:46:41 -08:00
Igor Minar f077649f48 TzDate should support various UTC methods 2010-11-08 22:46:41 -08:00
Vojta Jina f3ac2cd434 Update AngularSpec tests to use BDD style - jasmine expect 2010-11-07 14:42:04 -08:00
Vojta Jina 7779630989 Added tests for angular.service
- should allow to override a service
- should preserve angular properties on override
- should not preserve non-angular properties on override
2010-11-07 14:42:03 -08:00
Vojta Jina 00ca67e4be Issue #51: Update extensionMap()
If user override existing extension, angular properties ($) will be preserved.

This piece of logic could be refactored into separate method:
Something like we have extend(), addMissingProperties() - I can't find a name
for this method...

Closes #51
2010-11-07 14:42:03 -08:00
Misko Hevery 91b6c5f7ff Added documentation for validators.
BACKWARD INCOMPATIBLE: removed ssn validators, since it is unlikely that most people will need it and if they do, they can added it thorough RegExp
2010-11-07 13:06:55 -08:00
Vojta Jina 5be325a0c1 Refactored toJsonArray(), added isBoolean() function 2010-11-05 21:39:00 -07:00
Vojta Jina b7027b9d87 Updated toJson() to not serialize window/document objects.
The reason to void these to objects is that they cause all sorts
of problems like exceptions being thrown and infinite loops occuring
when we iterate over object properties.
2010-11-05 21:39:00 -07:00
Vojta Jina fe8353bc5e Changed toJson() to not ignore $ properties 2010-11-05 21:39:00 -07:00
Vojta Jina c780030c6e Json - corrected test descriptions and changed to BDD style expect() 2010-11-05 21:39:00 -07:00
Misko Hevery d5e9f38f3d fix error in json parser which did not allow 1.2E10 as number 2010-11-05 16:41:36 -07:00
Misko Hevery dc66687149 added tests for documentation 2010-11-05 15:05:24 -07:00
Misko Hevery 3d6a099d6e changed to showdown from markup. added validator overview 2010-11-05 13:32:37 -07:00
Misko Hevery 8767e766d1 eclipse settings for auto run of docs 2010-11-04 14:25:11 -07:00
Misko Hevery 47066e70e1 added documentation for ng:include and ng:widget and test for doc collector. 2010-11-04 14:24:31 -07:00
Misko Hevery c0d30aedfc added LICENSE to IDEA 2010-11-04 11:07:49 -07:00
Misko Hevery b246d6e2ab rename Index.js to index.js 2010-11-04 11:02:45 -07:00
Igor Minar 3b04b48b7c preparations for the 0.9.3 cold-resistance iteration 2010-11-03 13:09:52 -07:00
Igor Minar 0462422089 cutting the 0.9.2 faunal-mimicry release 2010-11-03 13:06:45 -07:00
Igor Minar bb460d6355 updating release notes 2010-11-03 13:05:12 -07:00
Igor Minar bbb19a4d16 fixing docs scenario runner template 2010-11-03 12:55:17 -07:00
Elliott Sprehn ee5e881b9e Fix JSON serialization breakage in WebKit browsers 2010-11-03 11:47:06 -07:00
Elliott Sprehn 690dfe000b Serialize RegExp to string in JSON. Closes #119. 2010-11-03 11:10:51 -07:00
Igor Minar 91c835dc0e fix dslSpec for IE 2010-11-03 10:41:37 -07:00
Igor Minar dfa8baf59a hide example for angular.filter 2010-11-03 10:02:20 -07:00
Igor Minar a8efd43d25 doc parser should recognize the 'defaults' syntax for params 2010-11-03 09:47:23 -07:00
Igor Minar 96abeb1074 adding watchr-docs.rb 2010-11-03 09:47:22 -07:00
Misko Hevery 5159eb7635 fix the linky filter 2010-11-03 09:47:22 -07:00
Igor Minar 1ba8c2a33a more documentation for filters 2010-11-03 09:47:22 -07:00
Misko Hevery 659af29adb jsdoc parser + generator + viewer + scenario runner
- parse jsdocs from source code
- generate prerendered (markdown + mustache) partials
- generate json
- generate scenario runner for examples in docs
- basic angular doc viewer
2010-11-03 09:47:22 -07:00
Igor Minar 1fe7e3a130 add jsdocs for angular and filter namespaces + all filters 2010-11-03 09:47:21 -07:00
Igor Minar aec3c8478c binding() should return value for input/text area, innerHTML for the rest 2010-11-03 09:47:21 -07:00
Igor Minar 5c887ddb66 adding textarea() DSL for scenario runner 2010-11-03 09:47:21 -07:00
Igor Minar 0bd4a473a7 adding regular expressions support for binding() DSL 2010-11-03 09:44:54 -07:00
Elliott Sprehn dcf76e6816 Provide better sandbox error messages, and disallow running from file:// URLs 2010-11-02 11:27:54 -07:00
Elliott Sprehn 56a3d52f45 Make future names consistent and handle falsy values in jQuery generated methods properly 2010-11-02 11:20:41 -07:00
Elliott Sprehn faa7d81b67 Add browser().reload() to simulate a refresh from a user 2010-11-01 17:24:24 -07:00
Elliott Sprehn 6bb2cd6ee2 Provide browser DSL with location() to expect the iframe URL parts. Also move navigateTo() under the browser DSL. 2010-11-01 15:21:37 -07:00
Vojta Jina 2d61040fb0 Small refactor in $location service
Added new inner method updateLastLocation()
2010-10-31 21:37:54 -07:00
Vojta Jina 99f25050a3 Fixing issue #98 (infinite loop when location hash set empty)
Added tests and fixed the issue.

Closes #98
2010-10-31 21:37:33 -07:00
Misko Hevery ba5f8ee27f fix typo, and change a list to string for more efficient compression. 2010-10-31 15:04:30 -07:00
Elliott Sprehn 9a532002cf Auto generate all the jQuery get/set methods 2010-10-29 12:19:22 -07:00
Elliott Sprehn 5524d2b0fb Check if file exists (not a 404) and that document is accessible and not using file:// URLs in Application 2010-10-29 11:40:56 -07:00
Igor Minar d4839bac32 adding watchr config file watchr.rb 2010-10-29 10:47:51 -07:00
Igor Minar 602369c6a2 creating logs/ and tmp/ dirs 2010-10-29 10:47:06 -07:00
Andres Ornelas 34909520ae add optional label to dsl with selectors to improve test and output readability
e.g.
Before:
   code:   element('.actions ul li a').click();
   output: element .actions ul li a click
After
   code:   element('.actions ul li a', "'Configuration' link").click();
   output: element 'Configuration' link ( .actions ul li a ) click
2010-10-28 15:21:02 -07:00
Elliott Sprehn 92e31b556f Correctly fail tests if no binding matches and add better test cases for failure behavior. 2010-10-27 17:56:44 -07:00
Misko Hevery 62c0e5c460 Fix failing tests for ie, and mark elements as ng-widget, ng-directive, and ng-binding 2010-10-27 15:42:46 -07:00
Igor Minar c67af8a038 rename src/Parser.js to src/parser.js 2010-10-27 15:32:30 -07:00
Elliott Sprehn 2da1de5a6d Revert performance optimization of using setTimeout in SpecRunner every 10 steps. Breaks loading partials 2010-10-27 13:41:31 -07:00
Igor Minar ee8465bf10 updating version.yaml for the 0.9.2 iteration 2010-10-27 07:38:18 -07:00
Misko Hevery 9c6794a044 start new release 0.9.2 faunal-mimicry 2010-10-26 22:48:34 -07:00
97 changed files with 8885 additions and 994 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?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"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;launchConfigurationWorkingSet editPageId=&quot;org.eclipse.ui.resourceWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; id=&quot;1262905463390_2&quot; label=&quot;workingSet&quot; name=&quot;workingSet&quot;&gt;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/angular.js/test&quot; type=&quot;2&quot;/&gt;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/angular.js/src&quot; type=&quot;2&quot;/&gt;&#10;&lt;/launchConfigurationWorkingSet&gt;}"/>
<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,"/>
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;resources&gt;&#10;&lt;item path=&quot;/angular.js/build&quot; type=&quot;2&quot;/&gt;&#10;&lt;/resources&gt;}"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;resources&gt;&#10;&lt;item path=&quot;/angular.js/docs&quot; type=&quot;2&quot;/&gt;&#10;&lt;item path=&quot;/angular.js/src&quot; type=&quot;2&quot;/&gt;&#10;&lt;/resources&gt;}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/angular.js/gen_docs.sh}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/angular.js}"/>
</launchConfiguration>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;resources&gt;&#10;&lt;item path=&quot;/angular.js/docs&quot; type=&quot;2&quot;/&gt;&#10;&lt;/resources&gt;}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/angular.js/gen_docs.sh}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/angular.js}"/>
</launchConfiguration>
+3 -1
View File
@@ -1,4 +1,6 @@
build/
angularjs.netrc
jstd.log
.DS_Store
.DS_Store
regression/temp.html
.idea/workspace.xml
-1
View File
@@ -1 +0,0 @@
workspace.xml
-7
View File
@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Settings><!--This file was automatically generated by Ruby plugin.
You are allowed to:
1. Remove rake task
2. Add existing rake tasks
To add existing rake tasks automatically delete this file and reload the project.
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Compile JavaScript" fullCmd="compile" taksId="compile" /><RakeTask description="Generate Externs" fullCmd="compileexterns" taksId="compileexterns" /><RakeTask description="Lint" fullCmd="lint" taksId="lint" /><RakeGroup description="" fullCmd="" taksId="server"><RakeTask description="Run JsTestDriver Server" fullCmd="server:start" taksId="start" /><RakeTask description="Run JavaScript tests against the server" fullCmd="server:test" taksId="test" /></RakeGroup><RakeTask description="Run JavaScript tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /></RakeGroup></Settings>
Generated
+67
View File
@@ -0,0 +1,67 @@
IMPORTANT: THIS IS TO CERTIFY THE RIGHT TO USE THE JETBRAINS SOFTWARE PRODUCT, GRANTED BY JETBRAINS S.R.O. UNDER THE TERMS AND CONDITIONS OF THE LICENSE AGREEMENT INCLUDED WITH THE SOFTWARE. PLEASE SAVE A COPY OF THIS EMAIL FOR FUTURE REFERENCES.
========LICENSE DETAILS========
Type: Open Source License
Reference No*: LC-93161-D352729080
Date of Issue: 3 November 2010
Expiration Date: 3 November 2011
Number of Authorized Users: not limited
* Please quote this reference when contacting JetBrains
===========LICENSEE============
Name: angularjs
Customer ID: 93161
Address:
=======SOFTWARE PRODUCT========
Product Name: WebStorm
Licensed Version: 1.0 and any new product release which is made generally available before 3 November 2011
The software is shipped electronically and is available for download from:
http://www.jetbrains.com/webstorm/download/
Your WebStorm license includes a 1-year upgrade subscription qualifying you for free upgrades to any new versions of WebStorm released by JetBrains during your upgrade subscription period starting on your license issue date and ending on 3 November 2011. To check availability of the new versions of WebStorm, please visit http://www.jetbrains.com.
For running any new version of WebStorm released by JetBrains during your upgrade subscription period, please use the included below licensing details.
You can renew your upgrade subscription before or after its expiration. Your new subscription period will start on the date following the expiration date of your current upgrade subscription.
=========INSTALLATION==========
Run WebStorm and follow the Installation Wizard's instructions. To register for use of the software or change your existing registration details, go to Help/Register menu of the software and enter the included below the User Name and License Key(s) into the registration dialog:
User Name: angularjs
===== LICENSE BEGIN =====
93161-03112010
00000jBsEx59XVlc79fV"aAqWXQ09e
jQsg5TNp5X4HGhc10LNBdu!!ejRcFG
7h3S6T09YcRWs23TH0RgaM87!HqmQo
===== LICENSE END =====
===DOCUMENTATION AND SUPPORT===
WebStorm documentation:
http://www.jetbrains.com/webstorm/documentation/
Available support resources:
http://www.jetbrains.com/support/
Technical support contact:
support@jetbrains.com
Contact for the license renewal requests:
opensource@jetbrains.com
For questions, please contact:
sales@jetbrains.com
JetBrains Sales Team
http://www.jetbrains.com
"Develop with pleasure!"
+1 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="RUBY_MODULE" version="4">
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
+1 -4
View File
@@ -3,10 +3,7 @@
<component name="DependencyValidationManager">
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</component>
<component name="ProjectDetails">
<option name="projectName" value="master" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Ruby SDK 1.8.7 (/usr/bin/ruby)" project-jdk-type="RUBY_SDK" />
<component name="ProjectRootManager" version="2" />
<component name="SvnBranchConfigurationManager">
<option name="mySupportsUserInfoFilter" value="true" />
</component>
+1 -1
View File
@@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/master.iml" filepath="$PROJECT_DIR$/.idea/master.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/angular.js.iml" filepath="$PROJECT_DIR$/.idea/angular.js.iml" />
</modules>
</component>
</project>
+68
View File
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="USE_SAME_INDENTS" value="true" />
<option name="OTHER_INDENT_OPTIONS">
<value>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="2" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
</value>
</option>
<ADDITIONAL_INDENT_OPTIONS fileType="js">
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="jsp">
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="sass">
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="xml">
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="yml">
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
</value>
</option>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</component>
</project>
+15
View File
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="gen_docs" type="BashConfigurationType" factoryName="Bash">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="INTERPRETER_PATH" value="/bin/bash" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="PARENT_ENVS" value="true" />
<envs />
<module name="angular.js" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/gen_docs.sh" />
<option name="PARAMETERS" value="" />
<RunnerSettings RunnerId="BashRunner" />
<ConfigurationWrapper RunnerId="BashRunner" />
<method />
</configuration>
</component>
+15
View File
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="rake compile" type="BashConfigurationType" factoryName="Bash">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="INTERPRETER_PATH" value="/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="PARENT_ENVS" value="true" />
<envs />
<module name="angular.js" />
<option name="SCRIPT_NAME" value="/usr/bin/rake" />
<option name="PARAMETERS" value="compile" />
<RunnerSettings RunnerId="BashRunner" />
<ConfigurationWrapper RunnerId="BashRunner" />
<method />
</configuration>
</component>
Generated
+1 -2
View File
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>
+10
View File
@@ -20,6 +20,16 @@
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>auto,full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/docs.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+2 -1
View File
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="test/" kind="src" path="src"/>
<classpathentry kind="src" path="src/test"/>
<classpathentry excluding="docs-data.js|docs-scenario.js" kind="src" path="docs"/>
<classpathentry excluding="test/" kind="src" path="test"/>
<classpathentry kind="src" path="test/test"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
+80
View File
@@ -1,3 +1,83 @@
# <angular/> 0.9.4 total-recall (2010-11-18) #
### Docs
- searchable docs
- UI improvements
- we now have ~85% of the wiki docs migrated to ng docs
- some but not all docs were updated along the way
### Api
- ng:include now supports `onload` attribute (commit cc749760)
### Misc
- Better error handling - compilation exception now contain stack trace (commit b2d63ac4)
# <angular/> 0.9.3 cold-resistance (2010-11-10) #
### Docs
- prettier docs app with syntax highlighting for examples, etc
- added documentation, examples and scenario tests for many more apis including:
- all directives
- all formatters
- all validators
- some widgets
### Api
- date filter now accepts strings that angular.String.toDate can convert to Date objects
- angular.String.toDate supports ISO8061 formated strings with all time fractions being optional
- ng:repeat now exposes $position with values set to 'first', 'middle' or 'last'
- ng:switch now supports ng:switch-default as fallback switch option
### Breaking changes
- we now support ISO 8601 extended format datetime strings (YYYY-MM-DDTHH:mm:ss.SSSZ) as defined
in EcmaScript 5 throughout angular. This means that the following apis switched from
YYYY-MM-DDTHH:mm:ssZ to YYYY-MM-DDTHH:mm:ss.SSSZ (note the added millis) when representing dates:
- angular.Date.toString
- angular.String.fromDate
- JSON serialization and deserialization (used by json filter, $xhr and $resource)
- removed SSN validator. It's unlikely that most people will need it and if they do, it can be added
simple RegExp validator.
# <angular/> 0.9.2 faunal-mimicry (2010-11-03) #
### Docs
- created documentation framework based on jsdoc syntax (commit 659af29a)
- jsdoc parser
- template generator
- json generator
- angular doc viewer app
- scenario runner for all example code
- documentation for all angular filters (commits 1fe7e3a1 & 1ba8c2a33)
- docs
- example code
- scenario tests for example code
### Testability
#### Scenario Runner
- binding DSL in Scenario can now match bindings without specifying filters
- dsl statements now accept a label argument to make test output more readable (issue #94)
- dsl element() statement now implements most of the jQuery API (issue #106)
- new browser() dsl statement for getting info about the emulated browser running the app
(issue #109)
- scenario runner is now compatible with IE8 (issue #93)
- scenarior runner checks if URL would return a non-success status code (issue #100)
- binding() DSL now accepts regular expressions
- new textarea() scenario runner DSL for entering text into textareas
### Misc
- lots of small bugfixes
### Breaking changes
#### Scenario Runner
- navigating to about:blank is no longer supported. It results in a sandbox error
- navigateTo() is now browser().navigateTo(). Old code must be updated
- file:// URLs are no longer supported for running a scenario. You must use a web server that
implements HEAD
# <angular/> 0.9.1 repulsion-field (2010-10-26) #
### Security
+23 -3
View File
@@ -6,7 +6,7 @@ ANGULAR = [
'src/Compiler.js',
'src/Scope.js',
'src/Injector.js',
'src/Parser.js',
'src/parser.js',
'src/Resource.js',
'src/Browser.js',
'src/sanitizer.js',
@@ -156,8 +156,14 @@ task :compile => [:init, :compile_scenario, :generate_ie_compat] do
end
desc 'Generate docs'
task :docs do
`node docs/collect.js`
end
desc 'Create angular distribution'
task :package => [:clean, :compile] do
task :package => [:clean, :compile, :docs] do
v = YAML::load( File.open( 'version.yaml' ) )['version']
match = v.match(/^([^-]*)(-snapshot)?$/)
version = match[1] + (match[2] ? ('-' + %x(git rev-parse HEAD)[0..7]) : '')
@@ -178,6 +184,20 @@ task :package => [:clean, :compile] do
FileUtils.cp(src, pkg_dir + '/' + dest)
end
FileUtils.cp_r path_to('docs'), "#{pkg_dir}/docs-#{version}"
File.open("#{pkg_dir}/docs-#{version}/index.html", File::RDWR) do |f|
text = f.read
f.rewind
f.write text.sub('angular.min.js', "angular-#{version}.min.js")
end
File.open("#{pkg_dir}/docs-#{version}/docs-scenario.html", File::RDWR) do |f|
text = f.read
f.rewind
f.write text.sub('angular-scenario.js', "angular-scenario-#{version}.js")
end
%x(tar -czf #{path_to(tarball)} -C #{path_to('pkg')} .)
puts "Package created: #{path_to(tarball)}"
@@ -256,5 +276,5 @@ end
# returns path to the file in the build directory
#
def path_to(filename)
return File.join(BUILD_DIR, filename)
return File.join(BUILD_DIR, *filename)
end
+5
View File
@@ -8,6 +8,11 @@ body {
font-size: 14px;
}
#system-error {
font-size: 1.5em;
text-align: center;
}
#json, #xml {
display: none;
}
+1
View File
@@ -8,6 +8,7 @@
border: 2px solid #FF0000;
font-family: "Courier New", Courier, monospace;
font-size: smaller;
white-space: pre;
}
.ng-validation-error {
+66
View File
@@ -0,0 +1,66 @@
function noop(){}
function chain(delegateFn, explicitDone){
var onDoneFn = noop;
var onErrorFn = noop;
var waitForCount = 1;
delegateFn = delegateFn || noop;
var stackError = new Error('capture stack');
function decrementWaitFor() {
waitForCount--;
if (waitForCount == 0)
onDoneFn();
}
function self(){
try {
return delegateFn.apply(self, arguments);
} catch (error) {
self.error(error);
} finally {
if (!explicitDone)
decrementWaitFor();
}
};
self.onDone = function(callback){
onDoneFn = callback;
return self;
};
self.onError = function(callback){
onErrorFn = callback;
return self;
};
self.waitFor = function(callback){
if (waitForCount == 0)
throw new Error("Can not wait on already called callback.");
waitForCount++;
return chain(callback).onDone(decrementWaitFor).onError(self.error);
};
self.waitMany = function(callback){
if (waitForCount == 0)
throw new Error("Can not wait on already called callback.");
waitForCount++;
return chain(callback, true).onDone(decrementWaitFor).onError(self.error);
};
self.done = function(callback){
decrementWaitFor();
};
self.error = function(error) {
var stack = stackError.stack.split(/\n\r?/).splice(2);
var nakedStack = [];
stack.forEach(function(frame){
if (!frame.match(/callback\.js:\d+:\d+\)$/))
nakedStack.push(frame);
});
error.stack = error.stack + '\nCalled from:\n' + nakedStack.join('\n');
onErrorFn(error);
};
return self;
}
exports.chain = chain;
+393
View File
@@ -0,0 +1,393 @@
require.paths.push("./lib");
require.paths.push(__dirname);
var fs = require('fs'),
spawn = require('child_process').spawn,
mustache = require('mustache'),
callback = require('callback'),
Showdown = require('showdown').Showdown;
var documentation = {
pages:[],
byName: {}
};
var keywordPages = [];
var SRC_DIR = "docs/";
var OUTPUT_DIR = "build/docs/";
var NEW_LINE = /\n\r?/;
var work = callback.chain(function () {
console.log('Parsing Angular Reference Documentation');
mkdirPath(OUTPUT_DIR, work.waitFor(function(){
findJsFiles('src', work.waitMany(function(file) {
//console.log('reading', file, '...');
findNgDoc(file, work.waitMany(function(doc) {
parseNgDoc(doc);
processNgDoc(documentation, doc);
}));
}));
}));
}).onError(function(err){
console.log('ERROR:', err.stack || err);
}).onDone(function(){
keywordPages.sort(function(a,b){
// supper ugly comparator that orders all utility methods and objects before all the other stuff
// like widgets, directives, services, etc.
// Mother of all beatiful code please forgive me for the sin that this code certainly is.
if (a.name === b.name) return 0;
if (a.name === 'angular') return -1;
if (b.name === 'angular') return 1;
function namespacedName(page) {
return (page.name.match(/\./g).length === 1 && page.type !== 'overview' ? '0' : '1') + page.name;
}
var namespacedA = namespacedName(a),
namespacedB = namespacedName(b);
return namespacedA < namespacedB ? -1 : 1;
});
writeDoc(documentation.pages);
mergeTemplate('docs-data.js', 'docs-data.js', {JSON:JSON.stringify(keywordPages)}, callback.chain());
mergeTemplate('docs-scenario.js', 'docs-scenario.js', documentation, callback.chain());
copy('docs-scenario.html', callback.chain());
copy('index.html', callback.chain());
copy('docs.css', callback.chain());
mergeTemplate('docs.js', 'docs.js', documentation, callback.chain());
mergeTemplate('doc_widgets.css', 'doc_widgets.css', documentation, callback.chain());
mergeTemplate('doc_widgets.js', 'doc_widgets.js', documentation, callback.chain());
console.log('DONE');
});
if (!this.testmode) work();
////////////////////
function keywords(text){
var keywords = {};
var words = [];
var tokens = text.toLowerCase().split(/[,\.\`\'\"\s]+/mg);
tokens.forEach(function(key){
var match = key.match(/^(([a-z]|ng\:)[\w\_\-]{2,})/);
if (match){
key = match[1];
if (!keywords[key]) {
keywords[key] = true;
words.push(key);
}
}
});
words.sort();
return words.join(' ');
}
function noop(){}
function mkdirPath(path, callback) {
var parts = path.split(/\//);
path = '.';
(function next(){
if (parts.length) {
path += '/' + parts.shift();
fs.mkdir(path, 0777, next);
} else {
callback();
}
})();
}
function copy(name, callback){
fs.readFile(SRC_DIR + name, callback.waitFor(function(err, content){
if (err) return this.error(err);
fs.writeFile(OUTPUT_DIR + name, content, callback);
}));
}
function mergeTemplate(template, output, doc, callback){
fs.readFile(SRC_DIR + template,
callback.waitFor(function(err, template){
if (err) return this.error(err);
var content = mustache.to_html(template.toString(), doc);
fs.writeFile(OUTPUT_DIR + output, content, callback);
}));
}
function trim(text) {
var MAX = 9999;
var empty = RegExp.prototype.test.bind(/^\s*$/);
var lines = text.split('\n');
var minIndent = MAX;
lines.forEach(function(line){
minIndent = Math.min(minIndent, indent(line));
});
for ( var i = 0; i < lines.length; i++) {
lines[i] = lines[i].substring(minIndent);
}
// remove leading lines
while (empty(lines[0])) {
lines.shift();
}
// remove trailing
while (empty(lines[lines.length - 1])) {
lines.pop();
}
return lines.join('\n');
function indent(line) {
for(var i = 0; i < line.length; i++) {
if (line.charAt(i) != ' ') {
return i;
}
}
return MAX;
}
}
function unknownTag(doc, name) {
var error = "[" + doc.raw.file + ":" + doc.raw.line + "]: unknown tag: " + name;
console.log(error);
throw new Error(error);
}
function valueTag(doc, name, value) {
doc[name] = value;
}
function escapedHtmlTag(doc, name, value) {
doc[name] = value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
function markdownTag(doc, name, value) {
doc[name] = markdown(value.replace(/^#/gm, '##')).
replace(/\<pre\>/gmi, '<div ng:non-bindable><pre class="brush: js; html-script: true;">').
replace(/\<\/pre\>/gmi, '</pre></div>');
}
R_LINK = /{@link ([^\s}]+)((\s|\n)+(.+?))?\s*}/m
// 1 123 3 4 42
function markdown(text) {
var parts = text.split(/(<pre>[\s\S]*?<\/pre>)/),
match;
parts.forEach(function(text, i){
if (!text.match(/^<pre>/)) {
text = text.replace(/<angular\/>/gm, '<tt>&lt;angular/&gt;</tt>');
text = new Showdown.converter().makeHtml(text);
while (match = text.match(R_LINK)) {
text = text.replace(match[0], '<a href="#!' + match[1] + '"><code>' +
(match[4] || match[1]) +
'</code></a>');
}
parts[i] = text;
}
});
return parts.join('');
}
function markdownNoP(text) {
var lines = markdown(text).split(NEW_LINE);
var last = lines.length - 1;
lines[0] = lines[0].replace(/^<p>/, '');
lines[last] = lines[last].replace(/<\/p>$/, '');
return lines.join('\n');
}
function requiresTag(doc, name, value) {
doc.requires = doc.requires || [];
doc.requires.push({name: value});
}
function propertyTag(doc, name, value) {
doc[name] = doc[name] || [];
var match = value.match(/^({(\S+)}\s*)?(\S+)(\s+(.*))?/);
if (match) {
var tag = {
type: match[2],
name: match[3],
description: match[5] || false
};
} else {
throw "[" + doc.raw.file + ":" + doc.raw.line +
"]: @" + name + " must be in format '{type} name description' got: " + value;
}
return doc[name].push(tag);
}
function returnsTag(doc, name, value) {
var match = value.match(/^{(\S+)}\s+(.*)?/);
if (match) {
var tag = {
type: match[1],
description: markdownNoP(match[2]) || false
};
} else {
throw "[" + doc.raw.file + ":" + doc.raw.line +
"]: @" + name + " must be in format '{type} description' got: " + value;
}
return doc[name] = tag;
}
var TAG = {
ngdoc: valueTag,
example: escapedHtmlTag,
scenario: valueTag,
namespace: valueTag,
css: valueTag,
see: valueTag,
deprecated: valueTag,
workInProgress: function(doc, name, value) {
doc[name] = {description: markdown(value)};
},
usageContent: valueTag,
'function': valueTag,
description: markdownTag,
TODO: markdownTag,
paramDescription: markdownTag,
exampleDescription: markdownTag,
element: valueTag,
methodOf: valueTag,
name: function(doc, name, value) {
doc.name = value;
doc.shortName = value.split(/\./).pop();
doc.depth = value.split(/\./).length - 1;
},
param: function(doc, name, value){
doc.param = doc.param || [];
doc.paramRest = doc.paramRest || [];
var match = value.match(/^{([^}=]+)(=)?}\s+(([^\s=]+)|\[(\S+)=([^\]]+)\])\s+(.*)/);
// 1 12 2 34 4 5 5 6 6 3 7 7
if (match) {
var param = {
type: match[1],
name: match[5] || match[4],
optional: !!match[2],
'default':match[6],
description:markdownNoP(value.replace(match[0], match[7]))
};
doc.param.push(param);
if (!doc.paramFirst) {
doc.paramFirst = param;
} else {
doc.paramRest.push(param);
}
} else {
throw "[" + doc.raw.file + ":" + doc.raw.line +
"]: @param must be in format '{type} name=value description' got: " + value;
}
},
property: propertyTag,
requires: requiresTag,
returns: returnsTag
};
function parseNgDoc(doc){
var atName;
var atText;
var match;
doc.raw.text.split(NEW_LINE).forEach(function(line, lineNumber){
if (match = line.match(/^\s*@(\w+)(\s+(.*))?/)) {
// we found @name ...
// if we have existing name
if (atName) {
(TAG[atName] || unknownTag)(doc, atName, trim(atText.join('\n')));
}
atName = match[1];
atText = [];
if(match[3]) atText.push(match[3]);
} else {
if (atName) {
atText.push(line);
} else {
// ignore
}
}
});
if (atName) {
(TAG[atName] || unknownTag)(doc, atName, atText.join('\n'));
}
}
function findNgDoc(file, callback) {
fs.readFile(file, callback.waitFor(function(err, content){
var lines = content.toString().split(NEW_LINE);
var doc;
var match;
var inDoc = false;
lines.forEach(function(line, lineNumber){
lineNumber++;
// is the comment starting?
if (!inDoc && (match = line.match(/^\s*\/\*\*\s*(.*)$/))) {
line = match[1];
inDoc = true;
doc = {raw:{file:file, line:lineNumber, text:[]}};
}
// are we done?
if (inDoc && line.match(/\*\//)) {
doc.raw.text = doc.raw.text.join('\n');
doc.raw.text = doc.raw.text.replace(/^\n/, '');
if (doc.raw.text.match(/@ngdoc/)){
callback(doc);
}
doc = null;
inDoc = false;
}
// is the comment add text
if (inDoc){
doc.raw.text.push(line.replace(/^\s*\*\s?/, ''));
}
});
callback.done();
}));
}
function findJsFiles(dir, callback){
fs.readdir(dir, callback.waitFor(function(err, files){
if (err) return this.error(err);
files.forEach(function(file){
var path = dir + '/' + file;
fs.lstat(path, callback.waitFor(function(err, stat){
if (err) return this.error(err);
if (stat.isDirectory())
findJsFiles(path, callback.waitMany(callback));
else if (/\.js$/.test(path))
callback(path);
}));
});
callback.done();
}));
}
function processNgDoc(documentation, doc) {
if (!doc.ngdoc) return;
console.log('Found:', doc.ngdoc + ':' + doc.name);
documentation.byName[doc.name] = doc;
if (doc.methodOf) {
if (parent = documentation.byName[doc.methodOf]) {
(parent.method = parent.method || []).push(doc);
} else {
throw 'Owner "' + doc.methodOf + '" is not defined.';
}
} else {
documentation.pages.push(doc);
keywordPages.push({
name:doc.name,
type: doc.ngdoc,
keywords:keywords(doc.raw.text)
});
}
}
function writeDoc(pages) {
pages.forEach(function(doc) {
mergeTemplate(
doc.ngdoc + '.template',
doc.name + '.html', doc, callback.chain());
});
}
+58
View File
@@ -0,0 +1,58 @@
<h1>{{name}}</h1>
{{#workInProgress}}
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
{{{workInProgress.description}}}
</fieldset>
{{/workInProgress}}
{{#deprecated}}
<fieldset class="deprecated">
<legend>Deprecated API</legend>
{{deprecated}}
</fieldset>
{{/deprecated}}
<h2>Description</h2>
{{{description}}}
<h2>Usage</h2>
<h3>In HTML Template Binding</h3>
<tt>
<pre>
&lt;{{element}} {{shortName}}="{{paramFirst.name}}"&gt;
...
&lt;/{{element}}&gt;
</pre>
</tt>
<h3>Parameters</h3>
<ul>
{{#param}}
<li><tt>{{name}}</tt>
<tt>&#123;{{#type}}{{type}}{{/type}}{{^type}}*{{/type}}{{#optional}}={{/optional}}&#125;</tt>
<tt>{{#default}}[{{default}}]{{/default}}</tt>
{{{description}}}</li>
{{/param}}
</ul>
{{{paramDescription}}}
{{#css}}
<h3>CSS</h3>
{{{css}}}
{{/css}}
{{#example}}
<h2>Example</h2>
{{{exampleDescription}}}
<doc:example>
<doc:source>
{{/example}}
{{{example}}}
{{#example}}
</doc:source>
<doc:scenario>{{{scenario}}}</doc:scenario>
</doc:example>
{{/example}}
+35
View File
@@ -0,0 +1,35 @@
@namespace doc url("http://docs.angularjs.org/");
doc\:example {
display: none;
}
ul.doc-example {
list-style-type: none;
position: relative;
font-size: 14px;
}
ul.doc-example > li {
border: 2px solid gray;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
background-color: white;
margin-bottom: 20px;
}
ul.doc-example > li.doc-example-heading {
border: none;
border-radius: none;
margin-bottom: -10px;
}
li.doc-example-live {
padding: 10px;
font-size: 1.2em;
}
div.syntaxhighlighter {
padding-bottom: 1px !important; /* fix to remove unnecessary scrollbars http://is.gd/gSMgC */
}
+71
View File
@@ -0,0 +1,71 @@
(function(){
var angularJsUrl;
var scripts = document.getElementsByTagName("script");
var filename = /(.*\/)angular([^\/]*)/;
for(var j = 0; j < scripts.length; j++) {
var src = scripts[j].src;
if (src && src.match(filename)) {
angularJsUrl = src;
}
}
var HTML_TEMPLATE =
'<!doctype html>\n' +
'<html xmlns:ng="http://angularjs.org">\n' +
' <script type="text/javascript" ng:autobind\n' +
' src="' + angularJsUrl + '"></script>\n' +
' <body>\n' +
'_HTML_SOURCE_\n' +
' </body>\n' +
'</html>';
angular.widget('doc:example', function(element){
this.descend(true); //compile the example code
element.hide();
var example = element.find('doc\\:source').eq(0),
exampleSrc = example.text(),
scenario = element.find('doc\\:scenario').eq(0);
var code = indent(exampleSrc);
var tabs = angular.element(
'<ul class="doc-example">' +
'<li class="doc-example-heading"><h3>Source</h3></li>' +
'<li class="doc-example-source" ng:non-bindable>' +
'<pre class="brush: js; html-script: true; highlight: [' +
code.hilite + ']; toolbar: false;"></pre></li>' +
'<li class="doc-example-heading"><h3>Live Preview</h3></li>' +
'<li class="doc-example-live">' + exampleSrc +'</li>' +
'<li class="doc-example-heading"><h3>Scenario Test</h3></li>' +
'<li class="doc-example-scenario"><pre class="brush: js">' + scenario.text() + '</pre></li>' +
'</ul>');
tabs.find('li.doc-example-source > pre').text(HTML_TEMPLATE.replace('_HTML_SOURCE_', code.html));
element.html('');
element.append(tabs);
element.show();
var script = (exampleSrc.match(/<script[^\>]*>([\s\S]*)<\/script>/) || [])[1] || '';
try {
eval(script);
} catch (e) {
alert(e);
}
});
function indent(text) {
var lines = text.split(/\n/);
var lineNo = [];
while (lines[0].match(/^\s*$/)) lines.shift();
while (lines[lines.length - 1].match(/^\s*$/)) lines.pop();
for ( var i = 0; i < lines.length; i++) {
lines[i] = ' ' + lines[i];
lineNo.push(6 + i);
}
return {html: lines.join('\n'), hilite: lineNo.join(',') };
};
})();
+1
View File
@@ -0,0 +1 @@
NG_PAGES={{{JSON}}};
+10
View File
@@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<html xmlns:ng="http://angularjs.org" wiki:ng="http://angularjs.org">
<head>
<title>&lt;angular/&gt; Docs Scenario Runner</title>
<script type="text/javascript" src="../angular-scenario.js" ng:autobind></script>
<script type="text/javascript" src="docs-scenario.js"></script>
</head>
<body>
</body>
</html>
+9
View File
@@ -0,0 +1,9 @@
{{#pages}}
describe('{{name}}', function(){
beforeEach(function(){
browser().navigateTo('index.html#!{{name}}');
});
// {{raw.file}}:{{raw.line}}
{{{scenario}}}
});
{{/pages}}
+177
View File
@@ -0,0 +1,177 @@
body {
font-family: Arial, sans-serif;
font-size: 14px;
margin: 0;
padding: 0;
}
#page {
display: table-row;
}
#sidebar,
#section {
display: table-cell;
}
a {
color: blue;
}
.nav-section {
margin-left: 1em;
margin-top: 0.5em;
}
.section-title {
float: right;
}
#header {
background-color: #F2C200;
border-bottom: 1px solid #957800;
}
#header h1 {
font-weight: normal;
font-size: 30px;
line-height: 30px;
margin: 0;
padding: 10px 10px;
height: 30px;
}
#header .angular {
font-family: Courier New, monospace;
font-weight: bold;
}
#header h1 a {
color: black;
text-decoration: none;
}
#header h1 a:hover {
text-decoration: underline;
}
#section {
padding: 1em;
width: 100%;
}
#section h1 {
font-family: monospace;
margin-top: 0;
padding-bottom: 5px;
border-bottom: 1px solid #CCC;
}
#section h2 {
margin-top: 1.8em;
}
#section h1 + h2 {
margin-top: 1.3em;
}
#section h3 {
margin-top: 1.5em;
}
#sidebar {
padding: 10px 10px 20px 10px;
background-color: #EEE;
border-right: 1px solid #DDD;
}
#sidebar a {
text-decoration: none;
}
#sidebar a:hover {
text-decoration: underline;
}
#sidebar input {
width: 175px;
margin-bottom: 1em;
}
#sidebar ul {
list-style-type: none;
/*TODO(esprehn): Can we just reset globally and not break examples?*/
margin: 0;
padding: 0;
}
#sidebar ul li {
}
#sidebar ul li a {
display: block;
padding: 2px 2px 2px 4px;
}
#sidebar ul li.selected a {
background-color: #DDD;
border-radius: 5px;
-moz-border-radius: 5px;
border: 1px solid #CCC;
padding: 1px 1px 1px 3px;
}
#sidebar ul li.level-0 {
margin-left: 0em;
font-weight: bold;
font-size: 1.2em;
}
#sidebar ul li.level-1.level-angular {
font-family: monospace;
font-weight: normal;
font-size: 1em;
margin-top: 0;
margin-bottom: 0;
}
#sidebar ul li.level-1 {
margin-left: 1em;
margin-top: 5px;
font-size: 1.1em;
font-weight: bold;
}
#sidebar ul li.level-2 {
margin-left: 2em;
font-family: monospace;
}
#sidebar ul li.level-3 {
margin-left: 3em;
font-family: monospace;
}
.deprecated {
border: 2px solid red;
}
.deprecated legend {
font-weight: bold;
color: red;
}
.workInProgress {
border: 2px solid orange;
}
.workInProgress legend {
font-weight: bold;
color: orange;
}
#feedback {
float: right;
width: 10em;
text-align: right;
}
+48
View File
@@ -0,0 +1,48 @@
SyntaxHighlighter['defaults'].toolbar = false;
DocsController.$inject = ['$location', '$browser', '$window'];
function DocsController($location, $browser, $window) {
this.pages = NG_PAGES;
window.$root = this.$root;
this.getUrl = function(page){
return '#!' + page.name;
};
this.getCurrentPartial = function(){
return './' + this.getTitle() + '.html';
};
this.getTitle = function(){
var hashPath = $location.hashPath || '!angular';
if (hashPath.match(/^!angular/)) {
this.partialTitle = hashPath.substring(1);
}
return this.partialTitle;
};
this.getClass = function(page) {
var depth = page.name.split(/\./).length - 1,
cssClass = 'level-' + depth + (page.name == this.getTitle() ? ' selected' : '');
if (depth == 1 && page.type !== 'overview') cssClass += ' level-angular';
return cssClass;
};
this.afterPartialLoaded = function() {
$window.scroll(0,0);
SyntaxHighlighter.highlight();
};
this.getFeedbackUrl = function() {
return "mailto:angular@googlegroups.com?" +
"subject=" + escape("Feedback on " + $location.href) + "&" +
"body=" + escape("Hi there,\n\nI read " + $location.href + " and wanted to ask ....");
}
}
angular.filter('short', function(name){
return (name||'').split(/\./).pop();
});
+65
View File
@@ -0,0 +1,65 @@
<h1>{{name}}</h1>
{{#workInProgress}}
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
{{{workInProgress.description}}}
</fieldset>
{{/workInProgress}}
{{#deprecated}}
<fieldset class="deprecated">
<legend>Deprecated API</legend>
{{deprecated}}
</fieldset>
{{/deprecated}}
<h2>Description</h2>
{{{description}}}
<h2>Usage</h2>
<h3>In HTML Template Binding</h3>
<tt>
<span>{{</span>
{{paramFirst.name}}_expression
| {{shortName}}{{#paramRest}}{{^default}}:{{name}}{{/default}}{{#default}}<i>[:{{name}}={{default}}]</i>{{/default}}{{/paramRest}}
<span> }}</span>
</tt>
<h3>In JavaScript</h3>
<tt ng:non-bindable>
angular.filter.{{shortName}}({{paramFirst.name}}{{#paramRest}}, {{name}}{{/paramRest}} );
</tt>
<h3>Parameters</h3>
<ul>
{{#param}}
<li><tt>{{name}}</tt>
<tt>&#123;{{#type}}{{type}}{{/type}}{{^type}}*{{/type}}{{#optional}}={{/optional}}&#125;</tt>
<tt>{{#default}}[{{default}}]{{/default}}</tt>
{{{description}}}</li>
{{/param}}
</ul>
{{#returns}}
<h3>Returns</h3>
<tt>&#123;{{{type}}}&#125;</tt> {{{description}}}
{{/returns}}
{{#css}}
<h3>CSS</h3>
{{{css}}}
{{/css}}
{{#example}}
<h2>Example</h2>
{{{exampleDescription}}}
<doc:example>
<doc:source>
{{/example}}
{{{example}}}
{{#example}}
</doc:source>
<doc:scenario>{{{scenario}}}</doc:scenario>
</doc:example>
{{/example}}
+53
View File
@@ -0,0 +1,53 @@
<h1>{{name}}</h1>
{{#workInProgress}}
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
{{{workInProgress.description}}}
</fieldset>
{{/workInProgress}}
{{#deprecated}}
<fieldset class="deprecated">
<legend>Deprecated API</legend>
{{deprecated}}
</fieldset>
{{/deprecated}}
<h2>Description</h2>
{{{description}}}
<h2>Usage</h2>
<h3>In HTML Template Binding</h3>
<tt>
&lt;input type="text" ng:format="{{shortName}}"&gt;
</tt>
<h3>In JavaScript</h3>
<tt ng:non-bindable>
var userInputString = angular.formatter.{{shortName}}.format(modelValue);<br/>
var modelValue = angular.formatter.{{shortName}}.parse(userInputString);
</tt>
{{#returns}}
<h3>Returns</h3>
<tt>&#123;{{{type}}}&#125;</tt> {{{description}}}
{{/returns}}
{{#css}}
<h3>CSS</h3>
{{{css}}}
{{/css}}
{{#example}}
<h2>Example</h2>
{{{exampleDescription}}}
<doc:example>
<doc:source>
{{/example}}
{{{example}}}
{{#example}}
</doc:source>
<doc:scenario>{{{scenario}}}</doc:scenario>
</doc:example>
{{/example}}
+52
View File
@@ -0,0 +1,52 @@
<h1>{{name}}</h1>
{{#workInProgress}}
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
{{{workInProgress.description}}}
</fieldset>
{{/workInProgress}}
{{#deprecated}}
<fieldset class="deprecated">
<legend>Deprecated API</legend>
{{deprecated}}
</fieldset>
{{/deprecated}}
<h2>Description</h2>
{{{description}}}
<h2>Usage</h2>
<tt ng:non-bindable>
{{name}}({{paramFirst.name}}{{#paramRest}}, {{name}}{{/paramRest}} );
</tt>
<h3>Parameters</h3>
<ul>
{{#param}}
<li><tt>{{name}}</tt>
<tt>&#123;{{#type}}{{type}}{{/type}}{{^type}}*{{/type}}{{#optional}}={{/optional}}&#125;</tt>
<tt>{{#default}}[{{default}}]{{/default}}</tt>
{{{description}}}</li>
{{/param}}
</ul>
{{#returns}}
<h3>Returns</h3>
<tt>&#123;{{{type}}}&#125;</tt> {{{description}}}
{{/returns}}
{{#example}}
<h2>Example</h2>
{{{exampleDescription}}}
<doc:example>
<doc:source>
{{/example}}
{{{example}}}
{{#example}}
</doc:source>
<doc:scenario>{{{scenario}}}</doc:scenario>
</doc:example>
{{/example}}
+47
View File
@@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html xmlns:ng="http://angularjs.org/" xmlns:doc="http://docs.angularjs.org/" ng:controller="DocsController">
<head>
<title ng:bind-template="&lt;angular/&gt;: {{getTitle()}}">&lt;angular/&gt;</title>
<meta name="fragment" content="!">
<link rel="stylesheet" href="doc_widgets.css" type="text/css" />
<link rel="stylesheet" href="docs.css" type="text/css"/>
<link rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" type="text/css"/>
<link rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" type="text/css"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js"></script>
<script type="text/javascript" src="../angular.min.js" ng:autobind></script>
<script type="text/javascript" src="docs.js"></script>
<script type="text/javascript" src="doc_widgets.js"></script>
<script type="text/javascript" src="docs-data.js"></script>
</head>
<body>
<div id="header">
<h1>
<span class="section-title">{{getTitle()}}</span>
<a href="index.html"><span class="angular">&lt;angular/&gt;</span> Docs</a>
</h1>
</div>
<div id="page">
<div id="sidebar" class="nav">
<div class="doc-list">
<input type="text" name="filterText" placeholder="search documentaiton"/>
<ul>
<li ng:repeat="page in pages.$filter(filterText)" ng:class="getClass(page)">
<a href="{{getUrl(page)}}" ng:click="">{{page.name | short}}</a>
</li>
</ul>
</div>
</div>
<div id="section">
<a id="feedback" ng:href="{{getFeedbackUrl()}}">Report an Issue or Ask a Question</a>
<ng:include src="getCurrentPartial()" onload="afterPartialLoaded()"></ng:include>
</div>
</div>
</body>
</html>
+31
View File
@@ -0,0 +1,31 @@
<h1>{{name}}</h1>
{{#workInProgress}}
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
{{{workInProgress.description}}}
</fieldset>
{{/workInProgress}}
{{#deprecated}}
<fieldset class="deprecated">
<legend>Deprecated API</legend>
{{deprecated}}
</fieldset>
{{/deprecated}}
{{{description}}}
{{#example}}
<h2>Example</h2>
{{{exampleDescription}}}
<doc:example>
<doc:source>
{{/example}}
{{{example}}}
{{#example}}
</doc:source>
<doc:scenario>{{{scenario}}}</doc:scenario>
</doc:example>
{{/example}}
+53
View File
@@ -0,0 +1,53 @@
<h1><tt>{{name}}</tt></h1>
{{#workInProgress}}
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
{{{workInProgress.description}}}
</fieldset>
{{/workInProgress}}
{{#deprecated}}
<fieldset class="deprecated">
<legend>Deprecated API</legend>
{{deprecated}}
</fieldset>
{{/deprecated}}
<h2>Description</h2>
{{{description}}}
<h2>Dependencies</h2>
<ul>
{{#requires}}
<li><tt>{{name}}</tt></li>
{{/requires}}
</ul>
<h2>Methods</h2>
<ul>
{{#method}}
<li><tt>{{shortName}}</tt>: {{{description}}}</li>
{{/method}}
</ul>
<h2>Properties</h2>
<ul>
{{#property}}
<li><tt>{{name}}:{{#type}}{{type}}{{/type}}</tt>{{#description}}: {{{description}}}{{/description}}</li>
{{/property}}
</ul>
{{#example}}
<h2>Example</h2>
{{{exampleDescription}}}
<doc:example>
<doc:source>
{{/example}}
{{{example}}}
{{#example}}
</doc:source>
{{#scenario}}<doc:scenario>{{{scenario}}}</doc:scenario>{{/scenario}}
</doc:example>
{{/example}}
+277
View File
@@ -0,0 +1,277 @@
console.log(__dirname);
require.paths.push(__dirname + "/../");
require.paths.push(__dirname + "/../../");
var fs = require('fs');
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>&lt;angular/&gt;</tt></p>');
});
it('should not replace anything in <pre>', function(){
expect(collect.markdown('bah x\n<pre>\nangular.k\n</pre>\n asdf x')).
toEqual(
'<p>bah x</p>' +
'<pre>\nangular.k\n</pre>' +
'<p>asdf x</p>');
});
});
describe('processNgDoc', function() {
var processNgDoc = collect.processNgDoc,
documentation;
beforeEach(function() {
documentation = {
pages: [],
byName: {}
};
});
it('should store references to docs by name', function() {
var doc = {ngdoc: 'section', name: 'fake', raw: {text:''}};
processNgDoc(documentation, doc);
expect(documentation.byName.fake).toBe(doc);
});
it('should connect doc to owner (specified by @methodOf)', function() {
var parentDoc = {ngdoc: 'section', name: 'parent', raw: {text:''}};
var doc = {ngdoc: 'section', name: 'child', methodOf: 'parent', raw: {text:''}};
processNgDoc(documentation, parentDoc);
processNgDoc(documentation, doc);
expect(documentation.byName.parent.method).toBeDefined();
expect(documentation.byName.parent.method[0]).toBe(doc);
});
it('should not add doc to sections if @memberOf specified', function() {
var parentDoc = {ngdoc: 'parent', name: 'parent', raw: {text:''}};
var doc = {ngdoc: 'child', name: 'child', methodOf: 'parent', raw: {text:''}};
processNgDoc(documentation, parentDoc);
processNgDoc(documentation, doc);
expect(documentation.pages.child).not.toBeDefined();
});
it('should throw exception if owner does not exist', function() {
expect(function() {
processNgDoc(documentation, {ngdoc: 'section', methodOf: 'not.exist', raw: {text:''}});
}).toThrow('Owner "not.exist" is not defined.');
});
it('should ignore non-ng docs', function() {
var doc = {name: 'anything'};
expect(function() {
processNgDoc(documentation, doc);
}).not.toThrow();
expect(documentation.pages).not.toContain(doc);
});
});
describe('TAG', function(){
var TAG = collect.TAG;
var doc;
beforeEach(function(){
doc = {};
});
describe('@param', function(){
it('should parse with no default', function(){
TAG.param(doc, 'param',
'{(number|string)} number Number \n to format.');
expect(doc.param).toEqual([{
type : '(number|string)',
name : 'number',
optional: false,
'default' : undefined,
description : 'Number \n to format.' }]);
});
it('should parse with default and optional', function(){
TAG.param(doc, 'param',
'{(number|string)=} [fractionSize=2] desc');
expect(doc.param).toEqual([{
type : '(number|string)',
name : 'fractionSize',
optional: true,
'default' : '2',
description : 'desc' }]);
});
});
describe('@requires', function() {
it('should parse more @requires tag into array', function() {
TAG.requires(doc, 'requires', '$service');
TAG.requires(doc, 'requires', '$another');
expect(doc.requires).toEqual([
{name: '$service'},
{name: '$another'}
]);
});
});
describe('@property', function() {
it('should parse @property tags into array', function() {
TAG.property(doc, 'property', '{type} name1 desc');
TAG.property(doc, 'property', '{type} name2 desc');
expect(doc.property.length).toEqual(2);
});
it('should parse @property with only name', function() {
TAG.property(doc, 'property', 'fake');
expect(doc.property[0].name).toEqual('fake');
});
it('should parse @property with optional type', function() {
TAG.property(doc, 'property', '{string} name');
expect(doc.property[0].name).toEqual('name');
expect(doc.property[0].type).toEqual('string');
});
it('should parse @property with optional description', function() {
TAG.property(doc, 'property', 'name desc rip tion');
expect(doc.property[0].name).toEqual('name');
expect(doc.property[0].description).toEqual('desc rip tion');
});
it('should parse @property with type and description both', function() {
TAG.property(doc, 'property', '{bool} name desc rip tion');
expect(doc.property[0].name).toEqual('name');
expect(doc.property[0].type).toEqual('bool');
expect(doc.property[0].description).toEqual('desc rip tion');
});
/**
* If property description is undefined, this variable is not set in the template,
* so the whole @description tag is used instead
*/
it('should set undefined description to "false"', function() {
TAG.property(doc, 'property', 'name');
expect(doc.property[0].description).toBe(false);
});
});
describe('@methodOf', function() {
it('should parse @methodOf tag', function() {
expect(function() {
TAG.methodOf(doc, 'methodOf', 'parentName');
}).not.toThrow();
expect(doc.methodOf).toEqual('parentName');
});
});
describe('@returns', function() {
it('should not parse @returns without type', function() {
expect(function() {TAG.returns(doc, 'returns', 'lala');})
.toThrow();
});
it('should parse @returns with type and description', function() {
TAG.returns(doc, 'returns', '{string} descrip tion');
expect(doc.returns).toEqual({type: 'string', description: 'descrip tion'});
});
it('should transform description of @returns with markdown', function() {
TAG.returns(doc, 'returns', '{string} descrip *tion*');
expect(doc.returns).toEqual({type: 'string', description: 'descrip <em>tion</em>'});
});
});
describe('@description', function(){
it('should support pre blocks', function(){
TAG.description(doc, 'description', '<pre>abc</pre>');
expect(doc.description).
toBe('<div ng:non-bindable><pre class="brush: js; html-script: true;">abc</pre></div>');
});
it('should support multiple pre blocks', function() {
TAG.description(doc, 'description', 'foo \n<pre>abc</pre>\n#bah\nfoo \n<pre>cba</pre>');
expect(doc.description).
toBe('<p>foo </p>' +
'<div ng:non-bindable><pre class="brush: js; html-script: true;">abc</pre></div>' +
'<h2>bah</h2>\n\n' +
'<p>foo </p>' +
'<div ng:non-bindable><pre class="brush: js; html-script: true;">cba</pre></div>');
});
it('should support nested @link annotations with or without description', function() {
TAG.description(doc, 'description',
'foo {@link angular.foo}\n\n da {@link angular.foo bar foo bar } \n\n' +
'dad{@link angular.foo}\n\n' +
'{@link angular.directive.ng:foo ng:foo}');
expect(doc.description).
toBe('<p>foo <a href="#!angular.foo"><code>angular.foo</code></a></p>\n\n' +
'<p>da <a href="#!angular.foo"><code>bar foo bar</code></a> </p>\n\n' +
'<p>dad<a href="#!angular.foo"><code>angular.foo</code></a></p>\n\n' +
'<p><a href="#!angular.directive.ng:foo"><code>ng:foo</code></a></p>');
});
it('should increment all headings by one', function() {
TAG.description(doc, 'description', '# foo\nabc');
expect(doc.description).
toBe('<h2>foo</h2>\n\n<p>abc</p>');
});
});
describe('@example', function(){
it('should not remove {{}}', function(){
TAG.example(doc, 'example', 'text {{ abc }}');
expect(doc.example).toEqual('text {{ abc }}');
});
});
describe('@deprecated', function() {
it('should parse @deprecated', function() {
TAG.deprecated(doc, 'deprecated', 'Replaced with foo.');
expect(doc.deprecated).toBe('Replaced with foo.');
})
});
describe('@workInProgress', function() {
it('should parse @workInProgress without a description and default to true', function() {
TAG.workInProgress(doc, 'workInProgress', '');
expect(doc.workInProgress).toEqual({description: ''});
});
it('should parse @workInProgress with a description', function() {
TAG.workInProgress(doc, 'workInProgress', 'my description');
expect(doc.workInProgress).toEqual({description: '<p>my description</p>'});
});
});
});
describe('trim', function(){
var trim = collect.trim;
it('should remove leading/trailing space', function(){
expect(trim(' \nabc\n ')).toEqual('abc');
});
it('should remove leading space on every line', function(){
expect(trim('\n 1\n 2\n 3\n')).toEqual('1\n 2\n 3');
});
});
describe('keywords', function(){
var keywords = collect.keywords;
it('should collect keywords', function(){
expect(keywords('\nHello: World! @ignore.')).toEqual('hello world');
expect(keywords('The `ng:class-odd` and ')).toEqual('and ng:class-odd the');
});
});
});
function load(path){
var sandbox = {
require: require,
console: console,
__dirname: __dirname,
testmode: true
};
Script.runInNewContext(fs.readFileSync(path), sandbox, path);
return sandbox;
}
+21
View File
@@ -0,0 +1,21 @@
require.paths.push("./lib");
var jasmine = require('jasmine-1.0.1');
var sys = require('util');
for(var key in jasmine) {
global[key] = jasmine[key];
}
var isVerbose = false;
var showColors = true;
process.argv.forEach(function(arg){
switch(arg) {
case '--color': showColors = true; break;
case '--noColor': showColors = false; break;
case '--verbose': isVerbose = true; break;
}
});
jasmine.executeSpecsInFolder(__dirname + '/spec', function(runner, log){
process.exit(runner.results().failedCount);
}, isVerbose, showColors);
+59
View File
@@ -0,0 +1,59 @@
<h1>{{name}}</h1>
{{#workInProgress}}
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
{{{workInProgress.description}}}
</fieldset>
{{/workInProgress}}
{{#deprecated}}
<fieldset class="deprecated">
<legend>Deprecated API</legend>
{{deprecated}}
</fieldset>
{{/deprecated}}
<h2>Description</h2>
{{{description}}}
<h2>Usage</h2>
<h3>In HTML Template Binding</h3>
<tt>
&lt;input type="text" ng:validate="{{shortName}}{{#paramRest}}{{^default}}:{{name}}{{/default}}{{#default}}<i>[:{{name}}]</i>{{/default}}{{/paramRest}}"/>
</tt>
<h3>In JavaScript</h3>
<tt ng:non-bindable>
angular.validator.{{shortName}}({{paramFirst.name}}{{#paramRest}}{{^default}}, {{name}}{{/default}}{{#default}}<i>[, {{name}}]</i>{{/default}}{{/paramRest}} );
</tt>
<h3>Parameters</h3>
<ul>
{{#param}}
<li><tt>{{name}}</tt>
<tt>&#123;{{#type}}{{type}}{{/type}}{{^type}}*{{/type}}{{#optional}}={{/optional}}&#125;</tt>
<tt>{{#default}}[{{default}}]{{/default}}</tt>
{{{description}}}</li>
{{/param}}
</ul>
{{{paramDescription}}}
{{#css}}
<h3>CSS</h3>
{{{css}}}
{{/css}}
{{#example}}
<h2>Example</h2>
{{{exampleDescription}}}
<doc:example>
<doc:source>
{{/example}}
{{{example}}}
{{#example}}
</doc:source>
<doc:scenario>{{{scenario}}}</doc:scenario>
</doc:example>
{{/example}}
+68
View File
@@ -0,0 +1,68 @@
<h1>{{name}}</h1>
{{#workInProgress}}
<fieldset class="workInProgress">
<legend>Work In Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.
{{{workInProgress.description}}}
</fieldset>
{{/workInProgress}}
{{#deprecated}}
<fieldset class="deprecated">
<legend>Deprecated API</legend>
{{deprecated}}
</fieldset>
{{/deprecated}}
<h2>Description</h2>
{{{description}}}
<h2>Usage</h2>
<h3>In HTML Template Binding</h3>
<tt>
{{^element}}
<pre>
&lt;{{shortName}}{{#param}} {{#default}}<i>[</i>{{/default}}{{name}}="..."{{#default}}<i>]</i>{{/default}}{{/param}}&gt;{{#usageContent}}
{{usageContent}}
{{/usageContent}}&lt;/{{shortName}}&gt;
</pre>
{{/element}}
{{#element}}
<pre>
&lt;{{element}} {{shortName}}{{#paramFirst}}="{{paramFirst.name}}{{/paramFirst}}"&gt;
...
&lt;/{{element}}&gt;
</pre>
{{/element}}
</tt>
<h3>Parameters</h3>
<ul>
{{#param}}
<li><tt>{{name}}</tt>
<tt>&#123;{{#type}}{{type}}{{/type}}{{^type}}*{{/type}}{{#optional}}={{/optional}}&#125;</tt>
<tt>{{#default}}[{{default}}]{{/default}}</tt>
{{{description}}}</li>
{{/param}}
</ul>
{{{paramDescription}}}
{{#css}}
<h3>CSS</h3>
{{{css}}}
{{/css}}
{{#example}}
<h2>Example</h2>
{{{exampleDescription}}}
<doc:example>
<doc:source>
{{/example}}
{{{example}}}
{{#example}}
</doc:source>
<doc:scenario>{{{scenario}}}</doc:scenario>
</doc:example>
{{/example}}
@@ -1,7 +1,7 @@
describe('personal log', function() {
beforeEach(function() {
navigateTo('../personalLog.html');
browser().navigateTo('../personalLog.html');
});
@@ -64,8 +64,7 @@ describe('personal log', function() {
element('form input[type="submit"]').click();
expect(repeater('ul li').count()).toEqual(1);
navigateTo('about:blank');
navigateTo('../personalLog.html');
browser().reload();
expect(repeater('ul li').column('log.msg')).toEqual('my persistent message');
expect(repeater('ul li').count()).toEqual(1);
Executable
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
node docs/specs.js --noColor && node docs/collect.js
+34
View File
@@ -0,0 +1,34 @@
server: http://localhost:9876
load:
- lib/jasmine-1.0.1/jasmine.js
- lib/jasmine-jstd-adapter/JasmineAdapter.js
- lib/jquery/jquery-1.4.2.js
- test/jquery_remove.js
- src/Angular.js
- src/JSON.js
- src/*.js
- example/personalLog/*.js
- test/testabilityPatch.js
- src/scenario/Scenario.js
- src/scenario/output/*.js
- src/scenario/*.js
- test/angular-mocks.js
- test/scenario/*.js
- test/scenario/output/*.js
- test/*.js
- example/personalLog/test/*.js
exclude:
- test/jquery_alias.js
- src/angular.prefix
- src/angular.suffix
- src/angular-bootstrap.js
- src/scenario/angular-bootstrap.js
- src/AngularPublic.js
plugin:
- name: "coverage"
jar: "lib/jstestdriver/coverage.jar"
module: "com.google.jstestdriver.coverage.CoverageModule"
+180
View File
@@ -0,0 +1,180 @@
var fs = require('fs');
var sys = require('sys');
var path = require('path');
var filename = __dirname + '/jasmine.js';
global.window = {
setTimeout: setTimeout,
clearTimeout: clearTimeout,
setInterval: setInterval,
clearInterval: clearInterval
};
var src = fs.readFileSync(filename);
var jasmine = process.compile(src + '\njasmine;', filename);
delete global.window;
function noop(){}
jasmine.executeSpecsInFolder = function(folder, done, isVerbose, showColors, matcher){
var log = [];
var columnCounter = 0;
var start = 0;
var elapsed = 0;
var verbose = isVerbose || false;
var fileMatcher = new RegExp(matcher || "\.js$");
var colors = showColors || false;
var specs = jasmine.getAllSpecFiles(folder, fileMatcher);
var ansi = {
green: '\033[32m',
red: '\033[31m',
yellow: '\033[33m',
none: '\033[0m'
};
for (var i = 0, len = specs.length; i < len; ++i){
var filename = specs[i];
require(filename.replace(/\.*$/, ""));
}
var jasmineEnv = jasmine.getEnv();
jasmineEnv.reporter = {
log: function(str){
},
reportSpecStarting: function(runner) {
},
reportRunnerStarting: function(runner) {
sys.puts('Started');
start = Number(new Date);
},
reportSuiteResults: function(suite) {
var specResults = suite.results();
var path = [];
while(suite) {
path.unshift(suite.description);
suite = suite.parentSuite;
}
var description = path.join(' ');
if (verbose)
log.push('Spec ' + description);
specResults.items_.forEach(function(spec){
if (spec.failedCount > 0 && spec.description) {
if (!verbose)
log.push(description);
log.push(' it ' + spec.description);
spec.items_.forEach(function(result){
log.push(' ' + result.trace.stack + '\n');
});
}
});
},
reportSpecResults: function(spec) {
var result = spec.results();
var msg = '';
if (result.passed())
{
msg = (colors) ? (ansi.green + '.' + ansi.none) : '.';
// } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec?
// msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*';
} else {
msg = (colors) ? (ansi.red + 'F' + ansi.none) : 'F';
}
sys.print(msg);
if (columnCounter++ < 50) return;
columnCounter = 0;
sys.print('\n');
},
reportRunnerResults: function(runner) {
elapsed = (Number(new Date) - start) / 1000;
sys.puts('\n');
log.forEach(function(log){
sys.puts(log);
});
sys.puts('Finished in ' + elapsed + ' seconds');
var summary = jasmine.printRunnerResults(runner);
if(colors)
{
if(runner.results().failedCount === 0 )
sys.puts(ansi.green + summary + ansi.none);
else
sys.puts(ansi.red + summary + ansi.none);
} else {
sys.puts(summary);
}
(done||noop)(runner, log);
}
};
jasmineEnv.execute();
};
jasmine.getAllSpecFiles = function(dir, matcher){
var specs = [];
if (fs.statSync(dir).isFile() && dir.match(matcher)) {
specs.push(dir);
} else {
var files = fs.readdirSync(dir);
for (var i = 0, len = files.length; i < len; ++i){
var filename = dir + '/' + files[i];
if (fs.statSync(filename).isFile() && filename.match(matcher)){
specs.push(filename);
}else if (fs.statSync(filename).isDirectory()){
var subfiles = this.getAllSpecFiles(filename, matcher);
subfiles.forEach(function(result){
specs.push(result);
});
}
}
}
return specs;
};
jasmine.printRunnerResults = function(runner){
var results = runner.results();
var suites = runner.suites();
var msg = '';
msg += suites.length + ' test' + ((suites.length === 1) ? '' : 's') + ', ';
msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', ';
msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n';
return msg;
};
function now(){
return new Date().getTime();
}
jasmine.asyncSpecWait = function(){
var wait = jasmine.asyncSpecWait;
wait.start = now();
wait.done = false;
(function innerWait(){
waits(10);
runs(function() {
if (wait.start + wait.timeout < now()) {
expect('timeout waiting for spec').toBeNull();
} else if (wait.done) {
wait.done = false;
} else {
innerWait();
}
});
})();
};
jasmine.asyncSpecWait.timeout = 4 * 1000;
jasmine.asyncSpecDone = function(){
jasmine.asyncSpecWait.done = true;
};
for ( var key in jasmine) {
exports[key] = jasmine[key];
}
Binary file not shown.
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
Copyright (c) 2009 Chris Wanstrath (Ruby)
Copyright (c) 2010 Jan Lehnardt (JavaScript)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+344
View File
@@ -0,0 +1,344 @@
/*
* CommonJS-compatible mustache.js module
*
* See http://github.com/janl/mustache.js for more info.
*/
/*
mustache.js Ñ Logic-less templates in JavaScript
See http://mustache.github.com/ for more info.
*/
var Mustache = function() {
var Renderer = function() {};
Renderer.prototype = {
otag: "{{",
ctag: "}}",
pragmas: {},
buffer: [],
pragmas_implemented: {
"IMPLICIT-ITERATOR": true
},
context: {},
render: function(template, context, partials, in_recursion) {
// reset buffer & set context
if(!in_recursion) {
this.context = context;
this.buffer = []; // TODO: make this non-lazy
}
// fail fast
if(!this.includes("", template)) {
if(in_recursion) {
return template;
} else {
this.send(template);
return;
}
}
template = this.render_pragmas(template);
var html = this.render_section(template, context, partials);
if(in_recursion) {
return this.render_tags(html, context, partials, in_recursion);
}
this.render_tags(html, context, partials, in_recursion);
},
/*
Sends parsed lines
*/
send: function(line) {
if(line != "") {
this.buffer.push(line);
}
},
/*
Looks for %PRAGMAS
*/
render_pragmas: function(template) {
// no pragmas
if(!this.includes("%", template)) {
return template;
}
var that = this;
var regex = new RegExp(this.otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" +
this.ctag);
return template.replace(regex, function(match, pragma, options) {
if(!that.pragmas_implemented[pragma]) {
throw({message:
"This implementation of mustache doesn't understand the '" +
pragma + "' pragma"});
}
that.pragmas[pragma] = {};
if(options) {
var opts = options.split("=");
that.pragmas[pragma][opts[0]] = opts[1];
}
return "";
// ignore unknown pragmas silently
});
},
/*
Tries to find a partial in the curent scope and render it
*/
render_partial: function(name, context, partials) {
name = this.trim(name);
if(!partials || partials[name] === undefined) {
throw({message: "unknown_partial '" + name + "'"});
}
if(typeof(context[name]) != "object") {
return this.render(partials[name], context, partials, true);
}
return this.render(partials[name], context[name], partials, true);
},
/*
Renders inverted (^) and normal (#) sections
*/
render_section: function(template, context, partials) {
if(!this.includes("#", template) && !this.includes("^", template)) {
return template;
}
var that = this;
// CSW - Added "+?" so it finds the tighest bound, not the widest
var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
"\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag +
"\\s*", "mg");
// for each {{#foo}}{{/foo}} section do...
return template.replace(regex, function(match, type, name, content) {
var value = that.find(name, context);
if(type == "^") { // inverted section
if(!value || that.is_array(value) && value.length === 0) {
// false or empty list, render it
return that.render(content, context, partials, true);
} else {
return "";
}
} else if(type == "#") { // normal section
if(that.is_array(value)) { // Enumerable, Let's loop!
return that.map(value, function(row) {
return that.render(content, that.create_context(row),
partials, true);
}).join("");
} else if(that.is_object(value)) { // Object, Use it as subcontext!
return that.render(content, that.create_context(value),
partials, true);
} else if(typeof value === "function") {
// higher order section
return value.call(context, content, function(text) {
return that.render(text, context, partials, true);
});
} else if(value) { // boolean section
return that.render(content, context, partials, true);
} else {
return "";
}
}
});
},
/*
Replace {{foo}} and friends with values from our view
*/
render_tags: function(template, context, partials, in_recursion) {
// tit for tat
var that = this;
var new_regex = function() {
return new RegExp(that.otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" +
that.ctag + "+", "g");
};
var regex = new_regex();
var tag_replace_callback = function(match, operator, name) {
switch(operator) {
case "!": // ignore comments
return "";
case "=": // set new delimiters, rebuild the replace regexp
that.set_delimiters(name);
regex = new_regex();
return "";
case ">": // render partial
return that.render_partial(name, context, partials);
case "{": // the triple mustache is unescaped
return that.find(name, context);
default: // escape the value
return that.escape(that.find(name, context));
}
};
var lines = template.split("\n");
for(var i = 0; i < lines.length; i++) {
lines[i] = lines[i].replace(regex, tag_replace_callback, this);
if(!in_recursion) {
this.send(lines[i]);
}
}
if(in_recursion) {
return lines.join("\n");
}
},
set_delimiters: function(delimiters) {
var dels = delimiters.split(" ");
this.otag = this.escape_regex(dels[0]);
this.ctag = this.escape_regex(dels[1]);
},
escape_regex: function(text) {
// thank you Simon Willison
if(!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
},
/*
find `name` in current `context`. That is find me a value
from the view object
*/
find: function(name, context) {
name = this.trim(name);
// Checks whether a value is thruthy or false or 0
function is_kinda_truthy(bool) {
return bool === false || bool === 0 || bool;
}
var value = context;
var path = name.split(/\./);
for(var i = 0; i < path.length; i++) {
name = path[i];
if(value && is_kinda_truthy(value[name])) {
value = value[name];
} else if(i == 0 && is_kinda_truthy(this.context[name])) {
value = this.context[name];
} else {
value = undefined;
}
}
if(typeof value === "function") {
return value.apply(context);
}
if(value !== undefined) {
return value;
}
// silently ignore unkown variables
return "";
},
// Utility methods
/* includes tag */
includes: function(needle, haystack) {
return haystack.indexOf(this.otag + needle) != -1;
},
/*
Does away with nasty characters
*/
escape: function(s) {
s = String(s === null ? "" : s);
return s.replace(/&(?!\w+;)|["'<>\\]/g, function(s) {
switch(s) {
case "&": return "&amp;";
case "\\": return "\\\\";
case '"': return '&quot;';
case "'": return '&#39;';
case "<": return "&lt;";
case ">": return "&gt;";
default: return s;
}
});
},
// by @langalex, support for arrays of strings
create_context: function(_context) {
if(this.is_object(_context)) {
return _context;
} else {
var iterator = ".";
if(this.pragmas["IMPLICIT-ITERATOR"]) {
iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
}
var ctx = {};
ctx[iterator] = _context;
return ctx;
}
},
is_object: function(a) {
return a && typeof a == "object";
},
is_array: function(a) {
return Object.prototype.toString.call(a) === '[object Array]';
},
/*
Gets rid of leading and trailing whitespace
*/
trim: function(s) {
return s.replace(/^\s*|\s*$/g, "");
},
/*
Why, why, why? Because IE. Cry, cry cry.
*/
map: function(array, fn) {
if (typeof array.map == "function") {
return array.map(fn);
} else {
var r = [];
var l = array.length;
for(var i = 0; i < l; i++) {
r.push(fn(array[i]));
}
return r;
}
}
};
return({
name: "mustache.js",
version: "0.3.1-dev",
/*
Turns a template and view into HTML
*/
to_html: function(template, view, partials, send_fun) {
var renderer = new Renderer();
if(send_fun) {
renderer.send = send_fun;
}
renderer.render(template, view, partials);
if(!send_fun) {
return renderer.buffer.join("\n");
}
}
});
}();
exports.name = Mustache.name;
exports.version = Mustache.version;
exports.to_html = function() {
return Mustache.to_html.apply(this, arguments);
};
+33 -21
View File
@@ -8,10 +8,8 @@ var DEFAULT_PORT = 8000;
function main(argv) {
new HttpServer({
'GET': (function() {
var servlet = new StaticServlet();
return servlet.handleRequest.bind(servlet)
})()
'GET': createServlet(StaticServlet),
'HEAD': createServlet(StaticServlet)
}).start(Number(argv[2]) || DEFAULT_PORT);
}
@@ -22,6 +20,11 @@ function escapeHtml(value) {
replace('"', '&quot;');
}
function createServlet(Class) {
var servlet = new Class();
return servlet.handleRequest.bind(servlet);
}
/**
* An Http server implementation that uses a map of methods to decide
* action routing.
@@ -61,11 +64,10 @@ HttpServer.prototype.handleRequest_ = function(req, res) {
}
};
/**
* Handles static content.
*/
function StaticServlet() {}
function StaticServlet() {}
StaticServlet.MimeMap = {
'txt': 'text/plain',
@@ -82,12 +84,14 @@ StaticServlet.MimeMap = {
StaticServlet.prototype.handleRequest = function(req, res) {
var self = this;
var path = ('./' + req.url.pathname).replace('//','/');
var path = ('./' + req.url.pathname).replace('//','/').replace(/%(..)/, function(match, hex){
return String.fromCharCode(parseInt(hex, 16));
});
var parts = path.split('/');
if (parts[parts.length-1].charAt(0) === '.')
return self.sendForbidden_(req, res, path);
fs.stat(path, function(err, stat) {
if (err)
if (err)
return self.sendMissing_(req, res, path);
if (stat.isDirectory())
return self.sendDirectory_(req, res, path);
@@ -116,8 +120,8 @@ StaticServlet.prototype.sendMissing_ = function(req, res, path) {
res.write('<title>404 Not Found</title>\n');
res.write('<h1>Not Found</h1>');
res.write(
'<p>The requested URL ' +
escapeHtml(path) +
'<p>The requested URL ' +
escapeHtml(path) +
' was not found on this server.</p>'
);
res.end();
@@ -133,7 +137,7 @@ StaticServlet.prototype.sendForbidden_ = function(req, res, path) {
res.write('<title>403 Forbidden</title>\n');
res.write('<h1>Forbidden</h1>');
res.write(
'<p>You do not have permission to access ' +
'<p>You do not have permission to access ' +
escapeHtml(path) + ' on this server.</p>'
);
res.end();
@@ -149,8 +153,8 @@ StaticServlet.prototype.sendRedirect_ = function(req, res, redirectUrl) {
res.write('<title>301 Moved Permanently</title>\n');
res.write('<h1>Moved Permanently</h1>');
res.write(
'<p>The document has moved <a href="' +
redirectUrl +
'<p>The document has moved <a href="' +
redirectUrl +
'">here</a>.</p>'
);
res.end();
@@ -164,13 +168,17 @@ StaticServlet.prototype.sendFile_ = function(req, res, path) {
'Content-Type': StaticServlet.
MimeMap[path.split('.').pop()] || 'text/plain'
});
file.on('data', res.write.bind(res));
file.on('close', function() {
if (req.method === 'HEAD') {
res.end();
});
file.on('error', function(error) {
self.sendError_(req, res, error);
});
} else {
file.on('data', res.write.bind(res));
file.on('close', function() {
res.end();
});
file.on('error', function(error) {
self.sendError_(req, res, error);
});
}
};
StaticServlet.prototype.sendDirectory_ = function(req, res, path) {
@@ -181,7 +189,7 @@ StaticServlet.prototype.sendDirectory_ = function(req, res, path) {
return self.sendRedirect_(req, res, redirectUrl);
}
fs.readdir(path, function(err, files) {
if (err)
if (err)
return self.sendError_(req, res, error);
if (!files.length)
@@ -207,6 +215,10 @@ StaticServlet.prototype.writeDirectoryIndex_ = function(req, res, path, files) {
res.writeHead(200, {
'Content-Type': 'text/html'
});
if (req.method === 'HEAD') {
res.end();
return;
}
res.write('<!doctype html>\n');
res.write('<title>' + escapeHtml(path) + '</title>\n');
res.write('<style>\n');
@@ -225,5 +237,5 @@ StaticServlet.prototype.writeDirectoryIndex_ = function(req, res, path, files) {
res.end();
};
// Must be last,
// Must be last,
main(process.argv);
+6
View 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;
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+8 -7
View File
@@ -1,6 +1,6 @@
describe('widgets', function() {
it('should verify that basic widgets work', function(){
navigateTo('widgets.html');
browser().navigateTo('widgets.html');
using('#text-basic-box').input('text.basic').enter('Carlos');
expect(binding('text.basic')).toEqual('Carlos');
@@ -29,25 +29,26 @@ describe('widgets', function() {
expect(binding('button').fromJson()).toEqual({'count': 0});
expect(binding('form').fromJson()).toEqual({'count': 0});
element('form a').click();
element('form a', "'action' link").click();
expect(binding('button').fromJson()).toEqual({'count': 1});
element('input[value="submit input"]').click();
element('input[value="submit input"]', "'submit input' button").click();
expect(binding('button').fromJson()).toEqual({'count': 2});
expect(binding('form').fromJson()).toEqual({'count': 1});
element('button:contains("submit button")').click();
element('button:contains("submit button")', "'submit button' button").click();
expect(binding('button').fromJson()).toEqual({'count': 2});
expect(binding('form').fromJson()).toEqual({'count': 2});
element('input[value="button"]').click();
element('input[value="button"]', "'button' button").click();
expect(binding('button').fromJson()).toEqual({'count': 3});
element('input[type="image"]').click();
element('input[type="image"]', 'form image').click();
expect(binding('button').fromJson()).toEqual({'count': 4});
element('#navigate a').click();
element('#navigate a', "'Go to #route' link").click();
expect(binding('$location.hash')).toEqual('route');
expect(browser().location().hash()).toEqual('route');
/**
* Custom value parser for futures.
+1
View File
@@ -0,0 +1 @@
java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 --browserTimeout 20000 --config jsTestDriver-coverage.conf
+629 -7
View File
@@ -3,9 +3,32 @@
if (typeof document.getAttribute == $undefined)
document.getAttribute = function() {};
//The below may not be true on browsers in the Turkish locale.
var lowercase = function (value){ return isString(value) ? value.toLowerCase() : value; };
var uppercase = function (value){ return isString(value) ? value.toUpperCase() : value; };
/**
* @workInProgress
* @ngdoc function
* @name angular.lowercase
* @function
*
* @description Converts string to lowercase
* @param {string} string String to be lowercased.
* @returns {string} Lowercased string.
*/
var lowercase = function (string){ return isString(string) ? string.toLowerCase() : string; };
/**
* @workInProgress
* @ngdoc function
* @name angular.uppercase
* @function
*
* @description Converts string to uppercase.
* @param {string} string String to be uppercased.
* @returns {string} Uppercased string.
*/
var uppercase = function (string){ return isString(string) ? string.toUpperCase() : string; };
var manualLowercase = function (s) {
return isString(s) ? s.replace(/[A-Z]/g,
function (ch) {return fromCharCode(ch.charCodeAt(0) | 32); }) : s;
@@ -14,9 +37,14 @@ var manualUppercase = function (s) {
return isString(s) ? s.replace(/[a-z]/g,
function (ch) {return fromCharCode(ch.charCodeAt(0) & ~32); }) : s;
};
// String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
// locale, for this reason we need to detect this case and redefine lowercase/uppercase methods with
// correct but slower alternatives.
if ('i' !== 'I'.toLowerCase()) {
lowercase = manualLowercase;
uppercase = manulaUppercase;
uppercase = manualUppercase;
}
function fromCharCode(code) { return String.fromCharCode(code); }
@@ -49,6 +77,7 @@ var _undefined = undefined,
PRIORITY_WATCH = -1000,
PRIORITY_LAST = 99999,
PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH},
Error = window.Error,
jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
_ = window['_'],
/** holds major version number for IE or NaN for real browsers */
@@ -57,14 +86,435 @@ var _undefined = undefined,
slice = Array.prototype.slice,
push = Array.prototype.push,
error = window[$console] ? bind(window[$console], window[$console]['error'] || noop) : noop,
/**
* @workInProgress
* @ngdoc overview
* @name angular
* @namespace The exported angular namespace.
*/
angular = window[$angular] || (window[$angular] = {}),
angularTextMarkup = extensionMap(angular, 'markup'),
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
/**
* @workInProgress
* @ngdoc overview
* @name angular.directive
* @namespace Namespace for all directives.
*
* @description
* A directive is an HTML attribute that you can use in an existing HTML element type or in a
* DOM element type that you create as {@link angular.widget}, to modify that element's
* properties. You can use any number of directives per element.
*
* For example, you can add the ng:bind directive as an attribute of an HTML span element, as in
* `<span ng:bind="1+2"></span>`. How does this work? The compiler passes the attribute value
* `1+2` to the ng:bind extension, which in turn tells the {@link angular.scope} to watch that
* expression and report changes. On any change it sets the span text to the expression value.
*
* Here's how to define {@link angular.directive.ng:bind ng:bind}:
* <pre>
angular.directive('ng:bind', function(expression, compiledElement) {
var compiler = this;
return function(linkElement) {
var currentScope = this;
currentScope.$watch(expression, function(value) {
linkElement.text(value);
});
};
});
* </pre>
*
* # Directive vs. Attribute Widget
* Both [attribute widgets](#!angular.widget) and directives can compile a DOM element
* attribute. So why have two different ways to do the same thing? The answer is that order
* matters, but we have no control over the order in which attributes are read. To solve this
* we apply attribute widget before the directive.
*
* For example, consider this piece of HTML, which uses the directives `ng:repeat`, `ng:init`,
* and `ng:bind`:
* <pre>
<ul ng:init="people=['mike', 'mary']">
<li ng:repeat="person in people" ng:init="a=a+1" ng:bind="person"></li>
</ul>
* </pre>
*
* Notice that the order of execution matters here. We need to execute
* {@link angular.directive.ng:repeat ng:repeat} before we run the
* {@link angular.directive.ng:init ng:init} and `ng:bind` on the `<li/>;`. This is because we
* want to run the `ng:init="a=a+1` and `ng:bind="person"` once for each person in people. We
* could not have used directive to create this template because attributes are read in an
* unspecified order and there is no way of guaranteeing that the repeater attribute would
* execute first. Using the `ng:repeat` attribute directive ensures that we can transform the
* DOM element into a template.
*
* Widgets run before directives. Widgets may manipulate the DOM whereas directives are not
* expected to do so, and so they run last.
*/
angularDirective = extensionMap(angular, 'directive'),
/**
* @workInProgress
* @ngdoc overview
* @name angular.widget
* @namespace Namespace for all widgets.
* @description
* # Overview
* Widgets allow you to create DOM elements that the browser doesn't
* already understand. You create the widget in your namespace and
* assign it behavior. You can only bind one widget per DOM element
* (unlike directives, in which you can use any number per DOM
* element). Widgets are expected to manipulate the DOM tree by
* adding new elements whereas directives are expected to only modify
* element properties.
*
* Widgets come in two flavors: element and attribute.
*
* # Element Widget
* Let's say we would like to create a new element type in the
* namespace `my` that can watch an expression and alert() the user
* with each new value.
*
* <pre>
* &lt;my:watch exp="name"/&gt;
* </pre>
*
* You can implement `my:watch` like this:
* <pre>
* angular.widget('my:watch', function(compileElement) {
* var compiler = this;
* var exp = compileElement.attr('exp');
* return function(linkElement) {
* var currentScope = this;
* currentScope.$watch(exp, function(value){
* alert(value);
* }};
* };
* });
* </pre>
*
* # Attribute Widget
* Let's implement the same widget, but this time as an attribute
* that can be added to any existing DOM element.
* <pre>
* &lt;div my-watch="name"&gt;text&lt;/div&gt;
* </pre>
* You can implement `my:watch` attribute like this:
* <pre>
* angular.widget('@my:watch', function(expression, compileElement) {
* var compiler = this;
* return function(linkElement) {
* var currentScope = this;
* currentScope.$watch(expression, function(value){
* alert(value);
* });
* };
* });
* </pre>
*
* @example
* <script>
* angular.widget('my:time', function(compileElement){
* compileElement.css('display', 'block');
* return function(linkElement){
* function update(){
* linkElement.text('Current time is: ' + new Date());
* setTimeout(update, 1000);
* }
* update();
* };
* });
* </script>
* <my:time></my:time>
*/
angularWidget = extensionMap(angular, 'widget', lowercase),
/**
* @workInProgress
* @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.
*
* <doc:example>
* <doc:source>
* Change me: &lt;input type="text" name="number" ng:validate="integer" value="123"&gt;
* </doc:source>
* <doc:scenario>
* it('should validate the default number string', function() {
* expect(element('input[name=number]').attr('class')).
* not().toMatch(/ng-validation-error/);
* });
* it('should not validate "foo"', function() {
* input('number').enter('foo');
* expect(element('input[name=number]').attr('class')).
* toMatch(/ng-validation-error/);
* });
* </doc:scenario>
* </doc:example>
*
*
* # 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.
*
* @css ng-validation-error
* When validation fails, this css class is applied to the binding, making its borders red by
* default.
*
* @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"/>
*
* @scenario
* it('should validate correct UPS tracking number', function() {
* expect(element('input[name=trackNo]').attr('class')).
* not().toMatch(/ng-validation-error/);
* });
*
* it('should not validate in correct UPS tracking number', function() {
* input('trackNo').enter('foo');
* expect(element('input[name=trackNo]').attr('class')).
* toMatch(/ng-validation-error/);
* });
*
*/
angularValidator = extensionMap(angular, 'validator'),
/**
* @workInProgress
* @ngdoc overview
* @name angular.filter
* @namespace Namespace for all filters.
* @description
* # Overview
* Filters are a standard way to format your data for display to the user. For example, you
* might have the number 1234.5678 and would like to display it as US currency: $1,234.57.
* Filters allow you to do just that. In addition to transforming the data, filters also modify
* the DOM. This allows the filters to for example apply css styles to the filtered output if
* certain conditions were met.
*
*
* # Standard Filters
*
* The Angular framework provides a standard set of filters for common operations, including:
* {@link angular.filter.currency currency}, {@link angular.filter.json json},
* {@link angular.filter.number number}, and {@link angular.filter.html html}. You can also add
* your own filters.
*
*
* # Syntax
*
* Filters can be part of any {@link angular.scope} evaluation but are typically used with
* {{bindings}}. Filters typically transform the data to a new data type, formating the data in
* the process. Filters can be chained and take optional arguments. Here are few examples:
*
* * No filter: {{1234.5678}} => 1234.5678
* * Number filter: {{1234.5678|number}} => 1,234.57. Notice the “,” and rounding to two
* significant digits.
* * Filter with arguments: {{1234.5678|number:5}} => 1,234.56780. Filters can take optional
* arguments, separated by colons in a binding. To number, the argument “5” requests 5 digits
* to the right of the decimal point.
*
*
* # Writing your own Filters
*
* Writing your own filter is very easy: just define a JavaScript function on `angular.filter`.
* The framework passes in the input value as the first argument to your function. Any filter
* arguments are passed in as additional function arguments.
*
* 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.
*
*
* @exampleDescription
* 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
* modification).
*
* @example
<script type="text/javascript">
angular.filter('reverse', function(input, uppercase, color) {
var out = "";
for (var i = 0; i < input.length; i++) {
out = input.charAt(i) + out;
}
if (uppercase) {
out = out.toUpperCase();
}
if (color) {
this.$element.css('color', color);
}
return out;
});
</script>
<input name="text" type="text" value="hello" /><br>
No filter: {{text}}<br>
Reverse: {{text|reverse}}<br>
Reverse + uppercase: {{text|reverse:true}}<br>
Reverse + uppercase + blue: {{text|reverse:true:"blue"}}
*/
angularFilter = extensionMap(angular, 'filter'),
/**
* @workInProgress
* @ngdoc overview
* @name angular.formatter
* @namespace Namespace for all formats.
* @description
* # Overview
* The formatters are responsible for translating user readable text in an input widget to a
* data model stored in an application.
*
* # Writting your own Formatter
* Writing your own formatter is easy. Just register a pair of JavaScript functions with
* `angular.formatter`. One function for parsing user input text to the stored form,
* and one for formatting the stored data to user-visible text.
*
* Here is an example of a "reverse" formatter: The data is stored in uppercase and in
* reverse, while it is displayed in lower case and non-reversed. User edits are
* automatically parsed into the internal form and data changes are automatically
* formatted to the viewed form.
*
* <pre>
* function reverse(text) {
* var reversed = [];
* for (var i = 0; i < text.length; i++) {
* reversed.unshift(text.charAt(i));
* }
* return reversed.join('');
* }
*
* angular.formatter('reverse', {
* parse: function(value){
* return reverse(value||'').toUpperCase();
* },
* format: function(value){
* return reverse(value||'').toLowerCase();
* }
* });
* </pre>
*
* @example
* <script type="text/javascript">
* function reverse(text) {
* var reversed = [];
* for (var i = 0; i < text.length; i++) {
* reversed.unshift(text.charAt(i));
* }
* return reversed.join('');
* }
*
* angular.formatter('reverse', {
* parse: function(value){
* return reverse(value||'').toUpperCase();
* },
* format: function(value){
* return reverse(value||'').toLowerCase();
* }
* });
* </script>
*
* Formatted:
* <input type="text" name="data" value="angular" ng:format="reverse"/>
* <br/>
*
* Stored:
* <input type="text" name="data"/><br/>
* <pre>{{data}}</pre>
*
*
* @scenario
* it('should store reverse', function(){
* expect(element('.doc-example input:first').val()).toEqual('angular');
* expect(element('.doc-example input:last').val()).toEqual('RALUGNA');
*
* this.addFutureAction('change to XYZ', function($window, $document, done){
* $document.elements('.doc-example input:last').val('XYZ').trigger('change');
* done();
* });
* expect(element('.doc-example input:first').val()).toEqual('zyx');
* });
*/
angularFormatter = extensionMap(angular, 'formatter'),
/**
* @workInProgress
* @ngdoc overview
* @name angular.service
*
* @description
* # Overview
* Services are substituable objects, which are wired together using dependency injection.
* Each service could have dependencies (other services), which are passed in constructor.
* Because JS is dynamicaly typed language, dependency injection can not use static types
* to satisfy these dependencies, so each service must explicitely define its dependencies.
* This is done by $inject property.
*
* For now, life time of all services is the same as the life time of page.
*
*
* # Standard services
* The Angular framework provides a standard set of services for common operations.
* You can write your own services and rewrite these standard services as well.
* Like other core angular variables, standard services always start with $.
*
* * `angular.service.$window`
* * `angular.service.$document`
* * `angular.service.$location`
* * `angular.service.$log`
* * `angular.service.$exceptionHandler`
* * `angular.service.$hover`
* * `angular.service.$invalidWidgets`
* * `angular.service.$route`
* * `angular.service.$xhr`
* * `angular.service.$xhr.error`
* * `angular.service.$xhr.bulk`
* * `angular.service.$xhr.cache`
* * `angular.service.$resource`
* * `angular.service.$cookies`
* * `angular.service.$cookieStore`
*
* # Writing your own services
* <pre>
* angular.service('notify', function(location) {
* this.one = function() {
* }
* }, {$inject: ['$location']});
* </pre>
*
* # Using services in controller
*/
angularService = extensionMap(angular, 'service'),
angularCallbacks = extensionMap(angular, 'callbacks'),
nodeName,
@@ -103,6 +553,18 @@ function foreachSorted(obj, iterator, context) {
}
function formatError(arg) {
if (arg instanceof Error) {
if (arg.stack) {
arg = arg.stack;
} else if (arg.sourceURL) {
arg = arg.message + '\n' + arg.sourceURL + ':' + arg.line;
}
}
return arg;
}
function extend(dst) {
foreach(arguments, function(obj){
if (obj !== dst) {
@@ -121,11 +583,18 @@ function inherit(parent, extra) {
function noop() {}
function identity($) {return $;}
function valueFn(value) {return function(){ return value; };}
function extensionMap(angular, name, transform) {
var extPoint;
return angular[name] || (extPoint = angular[name] = function (name, fn, prop){
name = (transform || identity)(name);
if (isDefined(fn)) {
if (isDefined(extPoint[name])) {
foreach(extPoint[name], function(property, key) {
if (key.charAt(0) == '$' && isUndefined(fn[key]))
fn[key] = property;
});
}
extPoint[name] = extend(fn, prop || {});
}
return extPoint[name];
@@ -150,8 +619,10 @@ function isDefined(value){ return typeof value != $undefined; }
function isObject(value){ return value!=_null && typeof value == $object;}
function isString(value){ return typeof value == $string;}
function isNumber(value){ return typeof value == $number;}
function isDate(value){ return value instanceof Date; }
function isArray(value) { return value instanceof Array; }
function isFunction(value){ return typeof value == $function;}
function isBoolean(value) { return typeof value == $boolean;}
function isTextNode(node) { return nodeName(node) == '#text'; }
function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; }
function isElement(node) {
@@ -255,7 +726,7 @@ function isLeafNode (node) {
* @param {*} source The source to be used during copy.
* Can be any type including primitives, null and undefined.
* @param {(Object|Array)=} destination Optional destination into which the source is copied
* @return {*}
* @returns {*}
*/
function copy(source, destination){
if (!destination) {
@@ -263,7 +734,7 @@ function copy(source, destination){
if (source) {
if (isArray(source)) {
destination = copy(source, []);
} else if (source instanceof Date) {
} else if (isDate(source)) {
destination = new Date(source.getTime());
} else if (isObject(source)) {
destination = copy(source, {});
@@ -398,7 +869,7 @@ function compile(element, existingScope) {
/**
* Parses an escaped url query string into key-value pairs.
* @return Object.<(string|boolean)>
* @returns Object.<(string|boolean)>
*/
function parseKeyValue(/**string*/keyValue) {
var obj = {}, key_value, key;
@@ -420,6 +891,157 @@ function toKeyValue(obj) {
return parts.length ? parts.join('&') : '';
}
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:autobind
* @element script
*
* @TODO ng:autobind is not a directive!! it should be documented as bootstrap parameter in a
* separate bootstrap section.
* @TODO rename to ng:autobind to ng:autoboot
*
* @description
* This section explains how to bootstrap your application with angular using either the angular
* javascript file.
*
*
* ## The angular distribution
* Note that there are two versions of the angular javascript file that you can use:
*
* * `angular.js` - the development version - this file is unobfuscated, uncompressed, and thus
* human-readable and useful when developing your angular applications.
* * `angular.min.js` - the production version - this is a minified and obfuscated version of
* `angular.js`. You want to use this version when you want to load a smaller but functionally
* equivalent version of the code in your application. We use the Closure compiler to create this
* file.
*
*
* ## Auto-bootstrap with `ng:autobind`
* The simplest way to get an <angular/> application up and running is by inserting a script tag in
* your HTML file that bootstraps the `http://code.angularjs.org/angular-x.x.x.min.js` code and uses
* the special `ng:autobind` attribute, like in this snippet of HTML:
*
* <pre>
&lt;!doctype html&gt;
&lt;html xmlns:ng="http://angularjs.org"&gt;
&lt;head&gt;
&lt;script type="text/javascript" src="http://code.angularjs.org/angular-0.9.3.min.js"
ng:autobind&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
Hello {{'world'}}!
&lt;/body&gt;
&lt;/html&gt;
* </pre>
*
* The `ng:autobind` attribute tells <angular/> to compile and manage the whole HTML document. The
* compilation occurs in the page's `onLoad` handler. Note that you don't need to explicitly add an
* `onLoad` event; auto bind mode takes care of all the magic for you.
*
*
* ## Auto-bootstrap with `#autobind`
* In rare cases when you can't define the `ng` namespace before the script tag (e.g. in some CMS
* systems, etc), it is possible to auto-bootstrap angular by appending `#autobind` to the script
* src URL, like in this snippet:
*
* <pre>
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"
src="http://code.angularjs.org/angular-0.9.3.min.js#autobind"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div xmlns:ng="http://angularjs.org"&gt;
Hello {{'world'}}!
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
* </pre>
*
* In this case it's the `#autobind` URL fragment that tells angular to auto-bootstrap.
*
*
* ## Filename Restrictions for Auto-bootstrap
* In order for us to find the auto-bootstrap script attribute or URL fragment, the value of the
* `script` `src` attribute that loads angular script must match one of these naming
* conventions:
*
* - `angular.js`
* - `angular-min.js`
* - `angular-x.x.x.js`
* - `angular-x.x.x.min.js`
* - `angular-x.x.x-xxxxxxxx.js` (dev snapshot)
* - `angular-x.x.x-xxxxxxxx.min.js` (dev snapshot)
* - `angular-bootstrap.js` (used for development of angular)
*
* Optionally, any of the filename format above can be prepended with relative or absolute URL that
* ends with `/`.
*
*
* ## Manual Bootstrap
* Using auto-bootstrap is a handy way to start using <angular/>, but advanced users who want more
* control over the initialization process might prefer to use manual bootstrap instead.
*
* The best way to get started with manual bootstraping is to look at the magic behind `ng:autobind`
* by writing out each step of the autobind process explicitly. Note that the following code is
* equivalent to the code in the previous section.
*
* <pre>
&lt;!doctype html&gt;
&lt;html xmlns:ng="http://angularjs.org"&gt;
&lt;head&gt;
&lt;script type="text/javascript" src="http://code.angularjs.org/angular-0.9.3.min.js"
ng:autobind&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
(function(window, previousOnLoad){
window.onload = function(){
try { (previousOnLoad||angular.noop)(); } catch(e) {}
angular.compile(window.document).$init();
};
})(window, window.onload);
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
Hello {{'World'}}!
&lt;/body&gt;
&lt;/html&gt;
* </pre>
*
* This is the sequence that your code should follow if you're bootstrapping angular on your own:
*
* * After the page is loaded, find the root of the HTML template, which is typically the root of
* the document.
* * Run the HTML compiler, which converts the templates into an executable, bi-directionally bound
* application.
*
*
* ##XML Namespace
* *IMPORTANT:* When using <angular/> you must declare the ng namespace using the xmlns tag. If you
* don't declare the namespace, Internet Explorer does not render widgets properly.
*
* <pre>
* &lt;html xmlns:ng="http://angularjs.org"&gt;
* </pre>
*
*
* ## Create your own namespace
* If you want to define your own widgets, you must create your own namespace and use that namespace
* to form the fully qualified widget name. For example, you could map the alias `my` to your domain
* and create a widget called my:widget. To create your own namespace, simply add another xmlsn tag
* to your page, create an alias, and set it to your unique domain:
*
* <pre>
* &lt;html xmlns:ng="http://angularjs.org" xmlns:my="http://mydomain.com"&gt;
* </pre>
*
*
* ## Global Object
* The <angular/> script creates a single global variable `angular` in the global namespace. All
* APIs are bound to fields of this global object.
*
*/
function angularInit(config){
if (config.autobind) {
// TODO default to the source of angular.js
+9
View File
@@ -1,4 +1,13 @@
var browserSingleton;
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$browser
* @requires $log
*
* @description
* Represents the browser.
*/
angularService('$browser', function($log){
if (!browserSingleton) {
browserSingleton = new Browser(
+145 -27
View File
@@ -19,7 +19,21 @@ function Browser(location, document, head, XHR, $log) {
var outstandingRequestCount = 0;
var outstandingRequestCallbacks = [];
self.xhr = function(method, url, post, callback){
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#xhr
* @methodOf angular.service.$browser
*
* @param {string} method Requested method (get|post|put|delete|head|json)
* @param {string} url Requested url
* @param {string=} post Post data to send
* @param {function(number, string)} callback Function that will be called on response
*
* @description
* Send ajax request
*/
self.xhr = function(method, url, post, callback) {
if (isFunction(post)) {
callback = post;
post = _null;
@@ -63,7 +77,15 @@ function Browser(location, document, head, XHR, $log) {
}
};
self.notifyWhenNoOutstandingRequests = function(callback){
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#notifyWhenNoOutstandingRequests
* @methodOf angular.service.$browser
*
* @param {function()} callback Function that will be called when no outstanding request
*/
self.notifyWhenNoOutstandingRequests = function(callback) {
if (outstandingRequestCount === 0) {
callback();
} else {
@@ -75,27 +97,51 @@ function Browser(location, document, head, XHR, $log) {
// Poll Watcher API
//////////////////////////////////////////////////////////////
var pollFns = [];
function poll(){
foreach(pollFns, function(pollFn){ pollFn(); });
}
self.poll = poll;
/**
* Adds a function to the list of functions that poller periodically executes
* @return {Function} the added function
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#poll
* @methodOf angular.service.$browser
*/
self.addPollFn = function(/**Function*/fn){
self.poll = function() {
foreach(pollFns, function(pollFn){ pollFn(); });
};
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#addPollFn
* @methodOf angular.service.$browser
*
* @param {function()} fn Poll function to add
*
* @description
* Adds a function to the list of functions that poller periodically executes
*
* @returns {function()} the added function
*/
self.addPollFn = function(fn) {
pollFns.push(fn);
return fn;
};
/**
* Configures the poller to run in the specified intervals, using the specified setTimeout fn and
* kicks it off.
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#startPoller
* @methodOf angular.service.$browser
*
* @param {number} interval How often should browser call poll functions (ms)
* @param {function()} setTimeout Reference to a real or fake `setTimeout` function.
*
* @description
* Configures the poller to run in the specified intervals, using the specified
* setTimeout fn and kicks it off.
*/
self.startPoller = function(/**number*/interval, /**Function*/setTimeout){
self.startPoller = function(interval, setTimeout) {
(function check(){
poll();
self.poll();
setTimeout(check, interval);
})();
};
@@ -103,15 +149,39 @@ function Browser(location, document, head, XHR, $log) {
//////////////////////////////////////////////////////////////
// URL API
//////////////////////////////////////////////////////////////
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#setUrl
* @methodOf angular.service.$browser
*
* @param {string} url New url
*
* @description
* Sets browser's url
*/
self.setUrl = function(url) {
var existingURL = location.href;
if (!existingURL.match(/#/)) existingURL += '#';
if (!url.match(/#/)) url += '#';
location.href = url;
};
self.getUrl = function() {
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#getUrl
* @methodOf angular.service.$browser
*
* @description
* Get current browser's url
*
* @returns {string} Browser's url
*/
self.getUrl = function() {
return location.href;
};
};
//////////////////////////////////////////////////////////////
// Cookies API
@@ -121,19 +191,28 @@ function Browser(location, document, head, XHR, $log) {
var lastCookieString = '';
/**
* The cookies method provides a 'private' low level access to browser cookies. It is not meant to
* be used directly, use the $cookie service instead.
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#cookies
* @methodOf angular.service.$browser
*
* @param {string=} name Cookie name
* @param {string=} value Cokkie value
*
* @description
* The cookies method provides a 'private' low level access to browser cookies.
* It is not meant to be used directly, use the $cookie service instead.
*
* The return values vary depending on the arguments that the method was called with as follows:
* <ul><li>
* cookies() -> hash of all cookies, this is NOT a copy of the internal state, so do not modify it
* </li><li>
* cookies(name, value) -> set name to value, if value is undefined delete the cookie
* </li><li>
* cookies(name) -> the same as (name, undefined) == DELETES (no one calls it right now that way)
* </li></ul>
* <ul>
* <li>cookies() -> hash of all cookies, this is NOT a copy of the internal state, so do not modify it</li>
* <li>cookies(name, value) -> set name to value, if value is undefined delete the cookie</li>
* <li>cookies(name) -> the same as (name, undefined) == DELETES (no one calls it right now that way)</li>
* </ul>
*
* @returns {Object} Hash of all cookies (if called without any parameter)
*/
self.cookies = function (/**string*/name, /**string*/value){
self.cookies = function (name, value) {
var cookieLength, cookieArray, i, keyValue;
if (name) {
@@ -175,7 +254,30 @@ function Browser(location, document, head, XHR, $log) {
// Misc API
//////////////////////////////////////////////////////////////
var hoverListener = noop;
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#hover
* @methodOf angular.service.$browser
*
* @description
* Set hover listener.
*
* @param {function(Object, boolean)} listener Function that will be called when hover event
* occurs.
*/
self.hover = function(listener) { hoverListener = listener; };
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#bind
* @methodOf angular.service.$browser
*
* @description
* Register hover function to real browser
*/
self.bind = function() {
document.bind("mouseover", function(event){
hoverListener(jqLite(msie ? event.srcElement : event.target), true);
@@ -189,9 +291,16 @@ function Browser(location, document, head, XHR, $log) {
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#addCss
* @methodOf angular.service.$browser
*
* @param {string} url Url to css file
* @description
* Adds a stylesheet tag to the head.
*/
self.addCss = function(/**string*/url) {
self.addCss = function(url) {
var link = jqLite(rawDocument.createElement('link'));
link.attr('rel', 'stylesheet');
link.attr('type', 'text/css');
@@ -201,9 +310,18 @@ function Browser(location, document, head, XHR, $log) {
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$browser#addJs
* @methodOf angular.service.$browser
*
* @param {string} url Url to js file
* @param {string=} dom_id Optional id for the script tag
*
* @description
* Adds a script tag to the head.
*/
self.addJs = function(/**string*/url, /**string*/dom_id) {
self.addJs = function(url, dom_id) {
var script = jqLite(rawDocument.createElement('script'));
script.attr('type', 'text/javascript');
script.attr('src', url);
+63 -2
View File
@@ -109,12 +109,66 @@ Compiler.prototype = {
};
},
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:eval-order
*
* @description
* Normally the view is updated from top to bottom. This usually is
* not a problem, but under some circumstances the values for data
* is not available until after the full view is computed. If such
* values are needed before they are computed the order of
* evaluation can be change using ng:eval-order
*
* @element ANY
* @param {integer|string=} [priority=0] priority integer, or FIRST, LAST constant
*
* @exampleDescription
* try changing the invoice and see that the Total will lag in evaluation
* @example
<div>TOTAL: without ng:eval-order {{ items.$sum('total') | currency }}</div>
<div ng:eval-order='LAST'>TOTAL: with ng:eval-order {{ items.$sum('total') | currency }}</div>
<table ng:init="items=[{qty:1, cost:9.99, desc:'gadget'}]">
<tr>
<td>QTY</td>
<td>Description</td>
<td>Cost</td>
<td>Total</td>
<td></td>
</tr>
<tr ng:repeat="item in items">
<td><input name="item.qty"/></td>
<td><input name="item.desc"/></td>
<td><input name="item.cost"/></td>
<td>{{item.total = item.qty * item.cost | currency}}</td>
<td><a href="" ng:click="items.$remove(item)">X</a></td>
</tr>
<tr>
<td colspan="3"><a href="" ng:click="items.$add()">add</a></td>
<td>{{ items.$sum('total') | currency }}</td>
</tr>
</table>
*
* @scenario
it('should check ng:format', function(){
expect(using('.doc-example-live div:first').binding("items.$sum('total')")).toBe('$9.99');
expect(using('.doc-example-live div:last').binding("items.$sum('total')")).toBe('$9.99');
input('item.qty').enter('2');
expect(using('.doc-example-live div:first').binding("items.$sum('total')")).toBe('$9.99');
expect(using('.doc-example-live div:last').binding("items.$sum('total')")).toBe('$19.98');
});
*/
templatize: function(element, elementIndex, priority){
var self = this,
widget,
fn,
directiveFns = self.directives,
descend = true,
directives = true,
elementName = nodeName(element),
template,
selfApi = {
compile: bind(self, self.compile),
@@ -138,12 +192,15 @@ Compiler.prototype = {
eachAttribute(element, function(value, name){
if (!widget) {
if (widget = self.widgets('@' + name)) {
element.addClass('ng-attr-widget');
widget = bind(selfApi, widget, value, element);
}
}
});
if (!widget) {
if (widget = self.widgets(nodeName(element))) {
if (widget = self.widgets(elementName)) {
if (elementName.indexOf(':') > 0)
element.addClass('ng-widget');
widget = bind(selfApi, widget, element);
}
}
@@ -179,7 +236,11 @@ Compiler.prototype = {
});
});
eachAttribute(element, function(value, name){
template.addInit((directiveFns[name]||noop).call(selfApi, value, element));
fn = directiveFns[name];
if (fn) {
element.addClass('ng-directive');
template.addInit((directiveFns[name]).call(selfApi, value, element));
}
});
}
// Process non text child nodes
+3 -2
View File
@@ -19,8 +19,9 @@ function createInjector(providerScope, providers, cache) {
* string: return an instance for the injection key.
* array of keys: returns an array of instances.
* function: look at $inject property of function to determine instances
* and then call the function with instances and scope. Any
* additional arguments are passed on to function.
* and then call the function with instances and `scope`. Any
* additional arguments (`args`) are appended to the function
* arguments.
* object: initialize eager providers and publish them the ones with publish here.
* none: same as object but use providerScope as place to publish.
*/
+51 -15
View File
@@ -1,11 +1,36 @@
var array = [].constructor;
function toJson(obj, pretty){
/**
* @workInProgress
* @ngdoc function
* @name angular.toJson
* @function
*
* @description
* Serializes the input into a JSON formated string.
*
* @param {Object|Array|Date|string|number} obj Input to jsonify.
* @param {boolean=} pretty If set to true, the JSON output will contain newlines and whitespace.
* @returns {string} Jsonified string representing `obj`.
*/
function toJson(obj, pretty) {
var buf = [];
toJsonArray(buf, obj, pretty ? "\n " : _null, []);
return buf.join('');
}
/**
* @workInProgress
* @ngdoc function
* @name angular.fromJson
* @function
*
* @description
* Deserializes a string in the JSON format.
*
* @param {string} json JSON string to deserialize.
* @returns {Object|Array|Date|string|number} Deserialized thingy.
*/
function fromJson(json) {
if (!json) return json;
try {
@@ -22,38 +47,49 @@ function fromJson(json) {
angular['toJson'] = toJson;
angular['fromJson'] = fromJson;
function toJsonArray(buf, obj, pretty, stack){
if (typeof obj == "object") {
function toJsonArray(buf, obj, pretty, stack) {
if (isObject(obj)) {
if (obj === window) {
buf.push('WINDOW');
return;
}
if (obj === document) {
buf.push('DOCUMENT');
return;
}
if (includes(stack, obj)) {
buf.push("RECURSION");
buf.push('RECURSION');
return;
}
stack.push(obj);
}
var type = typeof obj;
if (obj === _null) {
buf.push($null);
} else if (type === $function) {
} else if (obj instanceof RegExp) {
buf.push(angular['String']['quoteUnicode'](obj.toString()));
} else if (isFunction(obj)) {
return;
} else if (type === $boolean) {
} else if (isBoolean(obj)) {
buf.push('' + obj);
} else if (type === $number) {
} else if (isNumber(obj)) {
if (isNaN(obj)) {
buf.push($null);
} else {
buf.push('' + obj);
}
} else if (type === $string) {
} else if (isString(obj)) {
return buf.push(angular['String']['quoteUnicode'](obj));
} else if (type === $object) {
if (obj instanceof Array) {
} else if (isObject(obj)) {
if (isArray(obj)) {
buf.push("[");
var len = obj.length;
var sep = false;
for(var i=0; i<len; i++) {
var item = obj[i];
if (sep) buf.push(",");
if (typeof item == $function || typeof item == $undefined) {
if (!(item instanceof RegExp) && (isFunction(item) || isUndefined(item))) {
buf.push($null);
} else {
toJsonArray(buf, item, pretty, stack);
@@ -61,7 +97,7 @@ function toJsonArray(buf, obj, pretty, stack){
sep = true;
}
buf.push("]");
} else if (obj instanceof Date) {
} else if (isDate(obj)) {
buf.push(angular['String']['quoteUnicode'](angular['Date']['toString'](obj)));
} else {
buf.push("{");
@@ -70,7 +106,7 @@ function toJsonArray(buf, obj, pretty, stack){
var childPretty = pretty ? pretty + " " : false;
var keys = [];
for(var k in obj) {
if (k.indexOf('$') === 0 || obj[k] === _undefined)
if (obj[k] === _undefined)
continue;
keys.push(k);
}
@@ -92,7 +128,7 @@ function toJsonArray(buf, obj, pretty, stack){
buf.push("}");
}
}
if (typeof obj == $object) {
if (isObject(obj)) {
stack.pop();
}
}
+353 -14
View File
@@ -49,11 +49,11 @@ var scopeId = 0,
compileCache = {},
JS_KEYWORDS = {};
foreach(
["abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default",
"delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", $function, "goto",
"if", "implements", "import", "ininstanceof", "intinterface", "long", "native", "new", $null, "package", "private",
"protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws",
"transient", "true", "try", "typeof", "var", "volatile", "void", $undefined, "while", "with"],
("abstract,boolean,break,byte,case,catch,char,class,const,continue,debugger,default," +
"delete,do,double,else,enum,export,extends,false,final,finally,float,for,function,goto," +
"if,implements,import,ininstanceof,intinterface,long,native,new,null,package,private," +
"protected,public,return,short,static,super,switch,synchronized,this,throw,throws," +
"transient,true,try,typeof,var,volatile,void,undefined,while,with").split(/,/),
function(key){ JS_KEYWORDS[key] = true;}
);
function getterFn(path){
@@ -101,9 +101,134 @@ function expressionCompile(exp){
}
function errorHandlerFor(element, error) {
elementError(element, NG_EXCEPTION, isDefined(error) ? toJson(error) : error);
elementError(element, NG_EXCEPTION, isDefined(error) ? formatError(error) : error);
}
/**
* @workInProgress
* @ngdoc overview
* @name angular.scope
*
* @description
* Scope is a JavaScript object and the execution context for expressions. You can think about
* scopes as JavaScript objects that have extra APIs for registering watchers. A scope is the model
* in the model-view-controller design pattern.
*
* A few other characteristics of scopes:
*
* - Scopes can be nested. A scope (prototypically) inherits properties from its parent scope.
* - Scopes can be attached (bound) to the HTML DOM tree (the view).
* - A scope {@link angular.scope.$become becomes} `this` for a controller.
* - Scope's {@link angular.scope.$eval $eval} is used to update its view.
* - Scopes can {@link angular.scope.$watch watch} properties and fire events.
*
* # Basic Operations
* Scopes can be created by calling {@link angular.scope() angular.scope()} or by compiling HTML.
*
* {@link angular.widget Widgets} and data bindings register listeners on the current scope to get
* notified of changes to the scope state. When notified, these listeners push the updated state
* through to the DOM.
*
* Here is a simple scope snippet to show how you can interact with the scope.
* <pre>
var scope = angular.scope();
scope.salutation = 'Hello';
scope.name = 'World';
expect(scope.greeting).toEqual(undefined);
scope.$watch('name', function(){
this.greeting = this.salutation + ' ' + this.name + '!';
});
expect(scope.greeting).toEqual('Hello World!');
scope.name = 'Misko';
// scope.$eval() will propagate the change to listeners
expect(scope.greeting).toEqual('Hello World!');
scope.$eval();
expect(scope.greeting).toEqual('Hello Misko!');
* </pre>
*
* # Inheritance
* A scope can inherit from a parent scope, as in this example:
* <pre>
var parent = angular.scope();
var child = angular.scope(parent);
parent.salutation = "Hello";
child.name = "World";
expect(child.salutation).toEqual('Hello');
child.salutation = "Welcome";
expect(child.salutation).toEqual('Welcome');
expect(parent.salutation).toEqual('Hello');
* </pre>
*
* # Dependency Injection
* Scope also acts as a simple dependency injection framework.
*
* **TODO**: more info needed
*
* # When scopes are evaluated
* Anyone can update a scope by calling its {@link angular.scope.$eval $eval()} method. By default
* angular widgets listen to user change events (e.g. the user enters text into text field), copy
* the data from the widget to the scope (the MVC model), and then call the `$eval()` method on the
* root scope to update dependents. This creates a spreadsheet-like behavior: the bound views update
* immediately as the user types into the text field.
*
* Similarly, when a request to fetch data from a server is made and the response comes back, the
* data is written into the model and then $eval() is called to push updates through to the view and
* any other dependents.
*
* Because a change in the model that's triggered either by user input or by server response calls
* `$eval()`, it is unnecessary to call `$eval()` from within your controller. The only time when
* calling `$eval()` is needed, is when implementing a custom widget or service.
*
* Because scopes are inherited, the child scope `$eval()` overrides the parent `$eval()` method.
* So to update the whole page you need to call `$eval()` on the root scope as `$root.$eval()`.
*
* Note: A widget that creates scopes (i.e. {@link angular.widget.@ng:repeat ng:repeat}) is
* responsible for forwarding `$eval()` calls from the parent to those child scopes. That way,
* calling $eval() on the root scope will update the whole page.
*
* @exampleDescription
* This example demonstrates scope inheritance and property overriding.
*
* In this example, the root scope encompasses the whole HTML DOM tree. This scope has `salutation`,
* `name`, and `names` properties. The {@link angular.widget@ng:repeat ng:repeat} creates a child
* scope, one for each element in the names array. The repeater also assigns $index and name into
* the child scope.
*
* Notice that:
*
* - While the name is set in the child scope it does not change the name defined in the root scope.
* - The child scope inherits the salutation property from the root scope.
* - The $index property does not leak from the child scope to the root scope.
*
* @example
<ul ng:init="salutation='Hello'; name='Misko'; names=['World', 'Earth']">
<li ng:repeat="name in names">
{{$index}}: {{salutation}} {{name}}!
</li>
</ul>
<pre>
$index={{$index}}
salutation={{salutation}}
name={{name}}</pre>
@scenario
it('should inherit the salutation property and override the name property', function() {
expect(using('.doc-example-live').repeater('li').row(0)).
toEqual(['0', 'Hello', 'World']);
expect(using('.doc-example-live').repeater('li').row(1)).
toEqual(['1', 'Hello', 'Earth']);
expect(using('.doc-example-live').element('pre').text()).
toBe('$index=\nsalutation=Hello\nname=Misko');
});
*/
function createScope(parent, providers, instanceCache) {
function Parent(){}
parent = Parent.prototype = (parent || {});
@@ -115,11 +240,64 @@ function createScope(parent, providers, instanceCache) {
'this': instance,
$id: (scopeId++),
$parent: parent,
/**
* @workInProgress
* @ngdoc function
* @name angular.scope.$bind
* @function
*
* @description
* Binds a function `fn` to the current scope. See: {@link angular.bind}.
<pre>
var scope = angular.scope();
var fn = scope.$bind(function(){
return this;
});
expect(fn()).toEqual(scope);
</pre>
*
* @param {function()} fn Function to be bound.
*/
$bind: bind(instance, bind, instance),
$get: bind(instance, getter, instance),
$set: bind(instance, setter, instance),
$eval: function $eval(exp) {
/**
* @workInProgress
* @ngdoc function
* @name angular.scope.$eval
* @function
*
* @description
* Without the `exp` parameter triggers an eval cycle, for this scope and it's child scopes.
*
* With the `exp` parameter, compiles the expression to a function and calls it with `this` set
* to the current scope and returns the result.
*
* # Example
<pre>
var scope = angular.scope();
scope.a = 1;
scope.b = 2;
expect(scope.$eval('a+b')).toEqual(3);
expect(scope.$eval(function(){ return this.a + this.b; })).toEqual(3);
scope.$onEval('sum = a+b');
expect(scope.sum).toEqual(undefined);
scope.$eval();
expect(scope.sum).toEqual(3);
</pre>
*
* @param {(string|function())=} exp An angular expression to be compiled to a function or a js
* function.
*
* @returns {*} The result of calling compiled `exp` with `this` set to the current scope.
*/
$eval: function(exp) {
var type = typeof exp;
var i, iSize;
var j, jSize;
@@ -145,6 +323,44 @@ function createScope(parent, providers, instanceCache) {
}
},
/**
* @workInProgress
* @ngdoc function
* @name angular.scope.$tryEval
* @function
*
* @description
* Evaluates the expression in the context of the current scope just like
* {@link angular.scope.$eval()} with expression parameter, but also wraps it in a try/catch
* block.
*
* If exception is thrown then `exceptionHandler` is used to handle the exception.
*
* # Example
<pre>
var scope = angular.scope();
scope.error = function(){ throw 'myerror'; };
scope.$exceptionHandler = function(e) {this.lastException = e; };
expect(scope.$eval('error()'));
expect(scope.lastException).toEqual('myerror');
this.lastException = null;
expect(scope.$eval('error()'), function(e) {this.lastException = e; });
expect(scope.lastException).toEqual('myerror');
var body = angular.element(window.document.body);
expect(scope.$eval('error()'), body);
expect(body.attr('ng-exception')).toEqual('"myerror"');
expect(body.hasClass('ng-exception')).toEqual(true);
</pre>
*
* @param {string|function()} expression Angular expression to evaluate.
* @param {function()|DOMElement} exceptionHandler Function to be called or DOMElement to be
* decorated.
* @returns {*} The result of `expression` evaluation.
*/
$tryEval: function (expression, exceptionHandler) {
var type = typeof expression;
try {
@@ -165,14 +381,58 @@ function createScope(parent, providers, instanceCache) {
}
},
$watch: function(watchExp, listener, exceptionHandler) {
/**
* @workInProgress
* @ngdoc function
* @name angular.scope.$watch
* @function
*
* @description
* Registers `listener` as a callback to be executed every time the `watchExp` changes. Be aware
* that callback gets, by default, called upon registration, this can be prevented via the
* `initRun` parameter.
*
* # Example
<pre>
var scope = angular.scope();
scope.name = 'misko';
scope.counter = 0;
expect(scope.counter).toEqual(0);
scope.$watch('name', 'counter = counter + 1');
expect(scope.counter).toEqual(1);
scope.$eval();
expect(scope.counter).toEqual(1);
scope.name = 'adam';
scope.$eval();
expect(scope.counter).toEqual(2);
</pre>
*
* @param {function()|string} watchExp Expression that should be evaluated and checked for
* change during each eval cycle. Can be an angular string expression or a function.
* @param {function()|string} listener Function (or angular string expression) that gets called
* every time the value of the `watchExp` changes. The function will be called with two
* parameters, `newValue` and `oldValue`.
* @param {(function()|DOMElement)=} [exceptionHanlder=angular.service.$exceptionHandler] Handler
* that gets called when `watchExp` or `listener` throws an exception. If a DOMElement is
* specified as handler, the element gets decorated by angular with the information about the
* exception.
* @param {boolean=} [initRun=true] Flag that prevents the first execution of the listener upon
* registration.
*
*/
$watch: function(watchExp, listener, exceptionHandler, initRun) {
var watch = expressionCompile(watchExp),
last;
last = watch.call(instance);
listener = expressionCompile(listener);
function watcher(){
function watcher(firstRun){
var value = watch.call(instance),
// we have to save the value because listener can call ourselves => inf loop
lastValue = last;
if (last !== value) {
if (firstRun || lastValue !== value) {
last = value;
instance.$tryEval(function(){
return listener.call(instance, value, lastValue);
@@ -180,9 +440,36 @@ function createScope(parent, providers, instanceCache) {
}
}
instance.$onEval(PRIORITY_WATCH, watcher);
watcher();
if (isUndefined(initRun)) initRun = true;
if (initRun) watcher(true);
},
/**
* @workInProgress
* @ngdoc function
* @name angular.scope.$onEval
* @function
*
* @description
* Evaluates the `expr` expression in the context of the current scope during each
* {@link angular.scope.$eval eval cycle}.
*
* # Example
<pre>
var scope = angular.scope();
scope.counter = 0;
scope.$onEval('counter = counter + 1');
expect(scope.counter).toEqual(0);
scope.$eval();
expect(scope.counter).toEqual(1);
</pre>
*
* @param {number} [priority=0] Execution priority. Lower priority numbers get executed first.
* @param {string|function()} expr Angular expression or function to be executed.
* @param {(function()|DOMElement)=} [exceptionHandler=angular.service.$exceptionHandler] Handler
* function to call or DOM element to decorate when an exception occurs.
*
*/
$onEval: function(priority, expr, exceptionHandler){
if (!isNumber(priority)) {
exceptionHandler = expr;
@@ -202,6 +489,12 @@ function createScope(parent, providers, instanceCache) {
});
},
/**
* @workInProgress
* @ngdoc function
* @name angular.scope.$postEval
* @function
*/
$postEval: function(expr) {
if (expr) {
var fn = expressionCompile(expr);
@@ -216,6 +509,36 @@ function createScope(parent, providers, instanceCache) {
}
},
/**
* @workInProgress
* @ngdoc function
* @name angular.scope.$become
* @function
* @deprecated This method will be removed before 1.0
*
* @description
* Modifies the scope to act like an instance of the given class by:
*
* - copying the class's prototype methods
* - applying the class's initialization function to the scope instance (without using the new
* operator)
*
* That makes the scope be a `this` for the given class's methods — effectively an instance of
* the given class with additional (scope) stuff. A scope can later `$become` another class.
*
* `$become` gets used to make the current scope act like an instance of a controller class.
* This allows for use of a controller class in two ways.
*
* - as an ordinary JavaScript class for standalone testing, instantiated using the new
* operator, with no attached view.
* - as a controller for an angular model stored in a scope, "instantiated" by
* `scope.$become(ControllerClass)`.
*
* Either way, the controller's methods refer to the model variables like `this.name`. When
* stored in a scope, the model supports data binding. When bound to a view, {{name}} in the
* HTML template refers to the same variable.
*/
$become: function(Class) {
if (isFunction(Class)) {
instance.constructor = Class;
@@ -231,9 +554,25 @@ function createScope(parent, providers, instanceCache) {
}
},
$new: function(Class) {
/**
* @workInProgress
* @ngdoc function
* @name angular.scope.$new
* @function
*
* @description
* Creates a new {@link angular.scope scope}, that:
*
* - is a child of the current scope
* - will {@link angular.scope.$become $become} of type specified via `constructor`
*
* @param {function()} constructor Constructor function of the type the new scope should assume.
* @returns {Object} The newly created child scope.
*
*/
$new: function(constructor) {
var child = createScope(instance);
child.$become.apply(instance, concat([Class], arguments, 1));
child.$become.apply(instance, concat([constructor], arguments, 1));
instance.$onEval(child.$eval);
return child;
}
+16 -12
View File
@@ -4,7 +4,7 @@ var angularGlobal = {
var type = typeof obj;
if (type == $object) {
if (obj instanceof Array) return $array;
if (obj instanceof Date) return $date;
if (isDate(obj)) return $date;
if (obj.nodeType == 1) return $element;
}
return type;
@@ -177,6 +177,8 @@ var angularArray = {
}
};
var R_ISO8061_STR = /^(\d{4})-(\d\d)-(\d\d)(?:T(\d\d)(?:\:(\d\d)(?:\:(\d\d)(?:\.(\d{3}))?)?)?Z)?$/
var angularString = {
'quote':function(string) {
return '"' + string.replace(/\\/g, '\\\\').
@@ -210,11 +212,10 @@ var angularString = {
*/
'toDate':function(string){
var match;
if (typeof string == 'string' &&
(match = string.match(/^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/))){
if (isString(string) && (match = string.match(R_ISO8061_STR))){
var date = new Date(0);
date.setUTCFullYear(match[1], match[2] - 1, match[3]);
date.setUTCHours(match[4], match[5], match[6], 0);
date.setUTCHours(match[4]||0, match[5]||0, match[6]||0, match[7]||0);
return date;
}
return string;
@@ -223,14 +224,17 @@ var angularString = {
var angularDate = {
'toString':function(date){
function pad(n) { return n < 10 ? "0" + n : n; }
return !date ? date :
date.getUTCFullYear() + '-' +
pad(date.getUTCMonth() + 1) + '-' +
pad(date.getUTCDate()) + 'T' +
pad(date.getUTCHours()) + ':' +
pad(date.getUTCMinutes()) + ':' +
pad(date.getUTCSeconds()) + 'Z' ;
return !date ?
date :
date.toISOString ?
date.toISOString() :
padNumber(date.getUTCFullYear(), 4) + '-' +
padNumber(date.getUTCMonth() + 1, 2) + '-' +
padNumber(date.getUTCDate(), 2) + 'T' +
padNumber(date.getUTCHours(), 2) + ':' +
padNumber(date.getUTCMinutes(), 2) + ':' +
padNumber(date.getUTCSeconds(), 2) + '.' +
padNumber(date.getUTCMilliseconds(), 3) + 'Z';
}
};
+520 -61
View File
@@ -1,9 +1,99 @@
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:init
*
* @description
* `ng:init` attribute allows the for initialization tasks to be executed
* before the template enters execution mode during bootstrap.
*
* @element ANY
* @param {expression} expression to eval.
*
* @example
<div ng:init="greeting='Hello'; person='World'">
{{greeting}} {{person}}!
</div>
*
* @scenario
it('should check greeting', function(){
expect(binding('greeting')).toBe('Hello');
expect(binding('person')).toBe('World');
});
*/
angularDirective("ng:init", function(expression){
return function(element){
this.$tryEval(expression, element);
};
});
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:controller
*
* @description
* To support the Model-View-Controller design pattern, it is possible
* to assign behavior to a scope through `ng:controller`. The scope is
* the MVC model. The HTML (with data bindings) is the MVC view.
* The `ng:controller` directive specifies the MVC controller class
*
* @element ANY
* @param {expression} expression to eval.
*
* @example
<script type="text/javascript">
function SettingsController() {
this.name = "John Smith";
this.contacts = [
{type:'phone', value:'408 555 1212'},
{type:'email', value:'john.smith@example.org'} ];
}
SettingsController.prototype = {
greet: function(){
alert(this.name);
},
addContact: function(){
this.contacts.push({type:'email', value:'yourname@example.org'});
},
removeContact: function(contactToRemove) {
angular.Array.remove(this.contacts, contactToRemove);
},
clearContact: function(contact) {
contact.type = 'phone';
contact.value = '';
}
};
</script>
<div ng:controller="SettingsController">
Name: <input type="text" name="name"/>
[ <a href="" ng:click="greet()">greet</a> ]<br/>
Contact:
<ul>
<li ng:repeat="contact in contacts">
<select name="contact.type">
<option>phone</option>
<option>email</option>
</select>
<input type="text" name="contact.value"/>
[ <a href="" ng:click="clearContact(contact)">clear</a>
| <a href="" ng:click="removeContact(contact)">X</a> ]
</li>
<li>[ <a href="" ng:click="addContact()">add</a> ]</li>
</ul>
</div>
*
* @scenario
it('should check controller', function(){
expect(element('.doc-example-live div>:input').val()).toBe('John Smith');
expect(element('.doc-example-live li[ng\\:repeat-index="0"] input').val()).toBe('408 555 1212');
expect(element('.doc-example-live li[ng\\:repeat-index="1"] input').val()).toBe('john.smith@example.org');
element('.doc-example-live li:first a:contains("clear")').click();
expect(element('.doc-example-live li:first input').val()).toBe('');
element('.doc-example-live li:last a:contains("add")').click();
expect(element('.doc-example-live li[ng\\:repeat-index="2"] input').val()).toBe('yourname@example.org');
});
*/
angularDirective("ng:controller", function(expression){
this.scope(true);
return function(element){
@@ -16,13 +106,79 @@ angularDirective("ng:controller", function(expression){
};
});
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:eval
*
* @description
* The `ng:eval` allows you to execute a binding which has side effects
* without displaying the result to the user.
*
* @element ANY
* @param {expression} expression to eval.
*
* @exampleDescription
* Notice that `{{` `obj.multiplied = obj.a * obj.b` `}}` has a side effect of assigning
* a value to `obj.multiplied` and displaying the result to the user. Sometimes,
* however, it is desirable to execute a side effect without showing the value to
* the user. In such a case `ng:eval` allows you to execute code without updating
* the display.
*
* @example
* <input name="obj.a" value="6" >
* * <input name="obj.b" value="2">
* = {{obj.multiplied = obj.a * obj.b}} <br>
* <span ng:eval="obj.divide = obj.a / obj.b"></span>
* <span ng:eval="obj.updateCount = 1 + (obj.updateCount||0)"></span>
* <tt>obj.divide = {{obj.divide}}</tt><br/>
* <tt>obj.updateCount = {{obj.updateCount}}</tt>
*
* @scenario
it('should check eval', function(){
expect(binding('obj.divide')).toBe('3');
expect(binding('obj.updateCount')).toBe('2');
input('obj.a').enter('12');
expect(binding('obj.divide')).toBe('6');
expect(binding('obj.updateCount')).toBe('3');
});
*/
angularDirective("ng:eval", function(expression){
return function(element){
this.$onEval(expression, element);
};
});
angularDirective("ng:bind", function(expression){
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:bind
*
* @description
* The `ng:bind` attribute asks <angular/> to replace the text content of this
* HTML element with the value of the given expression and kept it up to
* date when the expression's value changes. Usually you just write
* {{expression}} and let <angular/> compile it into
* `<span ng:bind="expression"></span>` at bootstrap time.
*
* @element ANY
* @param {expression} expression to eval.
*
* @exampleDescription
* Try it here: enter text in text box and watch the greeting change.
* @example
* Enter name: <input type="text" name="name" value="Whirled">. <br>
* Hello <span ng:bind="name" />!
*
* @scenario
it('should check ng:bind', function(){
expect(using('.doc-example-live').binding('name')).toBe('Whirled');
using('.doc-example-live').input('name').enter('world');
expect(using('.doc-example-live').binding('name')).toBe('world');
});
*/
angularDirective("ng:bind", function(expression, element){
element.addClass('ng-binding');
return function(element) {
var lastValue = noop, lastError = noop;
this.$onEval(function() {
@@ -30,7 +186,7 @@ angularDirective("ng:bind", function(expression){
oldElement = this.hasOwnProperty($$element) ? this.$element : _undefined;
this.$element = element;
value = this.$tryEval(expression, function(e){
error = toJson(e);
error = formatError(e);
});
this.$element = oldElement;
// If we are HTML than save the raw HTML data so that we don't
@@ -97,7 +253,41 @@ function compileBindTemplate(template){
return fn;
}
angularDirective("ng:bind-template", function(expression){
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:bind-template
*
* @description
* The `ng:bind-template` attribute specifies that the element
* text should be replaced with the template in ng:bind-template.
* Unlike ng:bind the ng:bind-template can contain multiple `{{` `}}`
* expressions. (This is required since some HTML elements
* can not have SPAN elements such as TITLE, or OPTION to name a few.
*
* @element ANY
* @param {string} template of form
* <tt>{{</tt> <tt>expression</tt> <tt>}}</tt> to eval.
*
* @exampleDescription
* Try it here: enter text in text box and watch the greeting change.
* @example
Salutation: <input type="text" name="salutation" value="Hello"><br/>
Name: <input type="text" name="name" value="World"><br/>
<pre ng:bind-template="{{salutation}} {{name}}!"></pre>
*
* @scenario
it('should check ng:bind', function(){
expect(using('.doc-example-live').binding('{{salutation}} {{name}}')).
toBe('Hello World!');
using('.doc-example-live').input('salutation').enter('Greetings');
using('.doc-example-live').input('name').enter('user');
expect(using('.doc-example-live').binding('{{salutation}} {{name}}')).
toBe('Greetings user!');
});
*/
angularDirective("ng:bind-template", function(expression, element){
element.addClass('ng-binding');
var templateFn = compileBindTemplate(expression);
return function(element) {
var lastValue;
@@ -116,6 +306,56 @@ var REMOVE_ATTRIBUTES = {
'readonly':'readOnly',
'checked':'checked'
};
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:bind-attr
*
* @description
* The `ng:bind-attr` attribute specifies that the element attributes
* which should be replaced by the expression in it. Unlike `ng:bind`
* the `ng:bind-attr` contains a JSON key value pairs representing
* which attributes need to be changed. You dont usually write the
* `ng:bind-attr` in the HTML since embedding
* <tt ng:non-bindable>{{expression}}</tt> into the
* attribute directly is the preferred way. The attributes get
* translated into `<span ng:bind-attr="{attr:expression}"/>` at
* bootstrap time.
*
* This HTML snippet is preferred way of working with `ng:bind-attr`
* <pre>
* <a href="http://www.google.com/search?q={{query}}">Google</a>
* </pre>
*
* The above gets translated to bellow during bootstrap time.
* <pre>
* <a ng:bind-attr='{"href":"http://www.google.com/search?q={{query}}"}'>Google</a>
* </pre>
*
* @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
* <tt ng:non-bindable>{{expression}}</tt>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:
<input type="text" name="query" value="AngularJS"/>
<a href="http://www.google.com/search?q={{query}}">Google</a>
*
* @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 = {};
@@ -144,65 +384,31 @@ angularDirective("ng:bind-attr", function(expression){
};
});
angularWidget("@ng:non-bindable", noop);
angularWidget("@ng:repeat", function(expression, element){
element.removeAttr('ng:repeat');
element.replaceWith(this.comment("ng:repeat: " + expression));
var template = this.compile(element);
return function(reference){
var match = expression.match(/^\s*(.+)\s+in\s+(.*)\s*$/),
lhs, rhs, valueIdent, keyIdent;
if (! match) {
throw "Expected ng:repeat in form of 'item in collection' but got '" +
expression + "'.";
}
lhs = match[1];
rhs = match[2];
match = lhs.match(/^([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\)$/);
if (!match) {
throw "'item' in 'item in collection' should be identifier or (key, value) but got '" +
keyValue + "'.";
}
valueIdent = match[3] || match[1];
keyIdent = match[2];
var children = [], currentScope = this;
this.$onEval(function(){
var index = 0, childCount = children.length, childScope, lastElement = reference,
collection = this.$tryEval(rhs, reference), is_array = isArray(collection);
for ( var key in collection) {
if (!is_array || collection.hasOwnProperty(key)) {
if (index < childCount) {
// reuse existing child
childScope = children[index];
childScope[valueIdent] = collection[key];
if (keyIdent) childScope[keyIdent] = key;
} else {
// grow children
childScope = template(quickClone(element), createScope(currentScope));
childScope[valueIdent] = collection[key];
if (keyIdent) childScope[keyIdent] = key;
lastElement.after(childScope.$element);
childScope.$index = index;
childScope.$element.attr('ng:repeat-index', index);
childScope.$init();
children.push(childScope);
}
childScope.$eval();
lastElement = childScope.$element;
index ++;
}
}
// shrink children
while(children.length > index) {
children.pop().$element.remove();
}
}, reference);
};
});
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:click
*
* @description
* The ng:click allows you to specify custom behavior when
* element is clicked.
*
* @element ANY
* @param {expression} expression to eval upon click.
*
* @example
<button ng:click="count = count + 1" ng:init="count=0">
Increment
</button>
count: {{count}}
* @scenario
it('should check ng:click', function(){
expect(binding('count')).toBe('0');
element('.doc-example-live :button').click();
expect(binding('count')).toBe('1');
});
*/
/*
* A directive that allows creation of custom onclick handlers that are defined as angular
* expressions and are compiled and executed within the current scope.
@@ -223,6 +429,36 @@ angularDirective("ng:click", function(expression, element){
});
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:submit
*
* @description
*
* @element form
* @param {expression} expression to eval.
*
* @exampleDescription
* @example
* <form ng:submit="list.push(text);text='';" ng:init="list=[]">
* Enter text and hit enter:
* <input type="text" name="text" value="hello"/>
* </form>
* <pre>list={{list}}</pre>
* @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.
*
@@ -241,6 +477,34 @@ angularDirective("ng:submit", function(expression, element) {
});
/**
* @workInProgress
* @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
<div ng:init="counter=0" ng:watch="name: counter = counter+1">
<input type="text" name="name" value="hello"><br/>
Change counter: {{counter}} Name: {{name}}
</div>
* @scenario
it('should check ng:watch', function(){
expect(using('.doc-example-live').binding('counter')).toBe('2');
using('.doc-example-live').input('name').enter('abc');
expect(using('.doc-example-live').binding('counter')).toBe('3');
});
*/
//TODO: delete me, since having watch in UI is logic in UI. (leftover form getangular)
angularDirective("ng:watch", function(expression, element){
return function(element){
var self = this;
@@ -269,10 +533,145 @@ function ngClass(selector) {
};
}
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:class
*
* @description
* The `ng:class` allows you to set CSS class on HTML element
* conditionally.
*
* @element ANY
* @param {expression} expression to eval.
*
* @exampleDescription
* @example
<input type="button" value="set" ng:click="myVar='ng-input-indicator-wait'">
<input type="button" value="clear" ng:click="myVar=''">
<br>
<span ng:class="myVar">Sample Text &nbsp;&nbsp;&nbsp;&nbsp;</span>
*
* @scenario
it('should check ng:class', function(){
expect(element('.doc-example-live span').attr('className')).not().
toMatch(/ng-input-indicator-wait/);
using('.doc-example-live').element(':button:first').click();
expect(element('.doc-example-live span').attr('className')).
toMatch(/ng-input-indicator-wait/);
using('.doc-example-live').element(':button:last').click();
expect(element('.doc-example-live span').attr('className')).not().
toMatch(/ng-input-indicator-wait/);
});
*/
angularDirective("ng:class", ngClass(function(){return true;}));
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:class-odd
*
* @description
* The `ng:class-odd` and `ng:class-even` works exactly as
* `ng:class`, except it works in conjunction with `ng:repeat`
* and takes affect only on odd (even) rows.
*
* @element ANY
* @param {expression} expression to eval. Must be inside
* `ng:repeat`.
*
* @exampleDescription
* @example
<ol ng:init="names=['John', 'Mary', 'Cate', 'Suz']">
<li ng:repeat="name in names">
<span ng:class-odd="'ng-format-negative'"
ng:class-even="'ng-input-indicator-wait'">
{{name}} &nbsp; &nbsp; &nbsp;
</span>
</li>
</ol>
*
* @scenario
it('should check ng:class-odd and ng:class-even', function(){
expect(element('.doc-example-live li:first span').attr('className')).
toMatch(/ng-format-negative/);
expect(element('.doc-example-live li:last span').attr('className')).
toMatch(/ng-input-indicator-wait/);
});
*/
angularDirective("ng:class-odd", ngClass(function(i){return i % 2 === 0;}));
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:class-even
*
* @description
* The `ng:class-odd` and `ng:class-even` works exactly as
* `ng:class`, except it works in conjunction with `ng:repeat`
* and takes affect only on odd (even) rows.
*
* @element ANY
* @param {expression} expression to eval. Must be inside
* `ng:repeat`.
*
* @exampleDescription
* @example
<ol ng:init="names=['John', 'Mary', 'Cate', 'Suz']">
<li ng:repeat="name in names">
<span ng:class-odd="'ng-format-negative'"
ng:class-even="'ng-input-indicator-wait'">
{{name}} &nbsp; &nbsp; &nbsp;
</span>
</li>
</ol>
*
* @scenario
it('should check ng:class-odd and ng:class-even', function(){
expect(element('.doc-example-live li:first span').attr('className')).
toMatch(/ng-format-negative/);
expect(element('.doc-example-live li:last span').attr('className')).
toMatch(/ng-input-indicator-wait/);
});
*/
angularDirective("ng:class-even", ngClass(function(i){return i % 2 === 1;}));
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:show
*
* @description
* The `ng:show` and `ng:hide` allows you to show or hide a portion
* of the HTML conditionally.
*
* @element ANY
* @param {expression} expression if truthy then the element is
* shown or hidden respectively.
*
* @exampleDescription
* @example
Click me: <input type="checkbox" name="checked"><br/>
Show: <span ng:show="checked">I show up when you checkbox is checked?</span> <br/>
Hide: <span ng:hide="checked">I hide when you checkbox is checked?</span>
*
* @scenario
it('should check ng:show / ng:hide', function(){
expect(element('.doc-example-live span:first:hidden').count()).toEqual(1);
expect(element('.doc-example-live span:last:visible').count()).toEqual(1);
input('checked').check();
expect(element('.doc-example-live span:first:visible').count()).toEqual(1);
expect(element('.doc-example-live span:last:hidden').count()).toEqual(1);
});
*/
angularDirective("ng:show", function(expression, element){
return function(element){
this.$onEval(function(){
@@ -281,6 +680,36 @@ angularDirective("ng:show", function(expression, element){
};
});
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:hide
*
* @description
* The `ng:show` and `ng:hide` allows you to show or hide a portion
* of the HTML conditionally.
*
* @element ANY
* @param {expression} expression if truthy then the element is
* shown or hidden respectively.
*
* @exampleDescription
* @example
Click me: <input type="checkbox" name="checked"><br/>
Show: <span ng:show="checked">I show up when you checkbox is checked?</span> <br/>
Hide: <span ng:hide="checked">I hide when you checkbox is checked?</span>
*
* @scenario
it('should check ng:show / ng:hide', function(){
expect(element('.doc-example-live span:first:hidden').count()).toEqual(1);
expect(element('.doc-example-live span:last:visible').count()).toEqual(1);
input('checked').check();
expect(element('.doc-example-live span:first:visible').count()).toEqual(1);
expect(element('.doc-example-live span:last:hidden').count()).toEqual(1);
});
*/
angularDirective("ng:hide", function(expression, element){
return function(element){
this.$onEval(function(){
@@ -289,6 +718,36 @@ angularDirective("ng:hide", function(expression, element){
};
});
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:style
*
* @description
* The ng:style allows you to set CSS style on an HTML element conditionally.
*
* @element ANY
* @param {expression} expression which evals to an object whes key's are
* CSS style names and values are coresponding values for those
* CSS keys.
*
* @exampleDescription
* @example
<input type="button" value="set" ng:click="myStyle={color:'red'}">
<input type="button" value="clear" ng:click="myStyle={}">
<br/>
<span ng:style="myStyle">Sample Text</span>
<pre>myStyle={{myStyle}}</pre>
*
* @scenario
it('should check ng:style', function(){
expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)');
element('.doc-example-live :button[value=set]').click();
expect(element('.doc-example-live span').css('color')).toBe('red');
element('.doc-example-live :button[value=clear]').click();
expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)');
});
*/
angularDirective("ng:style", function(expression, element){
return function(element){
var resetStyle = getStyle(element);
+351 -20
View File
@@ -1,17 +1,82 @@
/**
* @workInProgress
* @ngdoc filter
* @name angular.filter.currency
* @function
*
* @description
* Formats a number as a currency (ie $1,234.56).
*
* @param {number} amount Input to filter.
* @returns {string} Formated number.
*
* @css ng-format-negative
* When the value is negative, this css class is applied to the binding making it by default red.
*
* @example
<input type="text" name="amount" value="1234.56"/> <br/>
{{amount | currency}}
*
* @scenario
it('should init with 1234.56', function(){
expect(binding('amount | currency')).toBe('$1,234.56');
});
it('should update', function(){
input('amount').enter('-1234');
expect(binding('amount | currency')).toBe('$-1,234.00');
expect(element('.doc-example-live .ng-binding').attr('className')).
toMatch(/ng-format-negative/);
});
*/
angularFilter.currency = function(amount){
this.$element.toggleClass('ng-format-negative', amount < 0);
return '$' + angularFilter['number'].apply(this, [amount, 2]);
};
angularFilter.number = function(amount, fractionSize){
if (isNaN(amount) || !isFinite(amount)) {
/**
* @workInProgress
* @ngdoc filter
* @name angular.filter.number
* @function
*
* @description
* Formats a number as text.
*
* If the input is not a number empty string is returned.
*
* @param {number|string} number Number to format.
* @param {(number|string)=} [fractionSize=2] Number of decimal places to round the number to.
* @returns {string} Number rounded to decimalPlaces and places a “,” after each third digit.
*
* @example
Enter number: <input name='val' value='1234.56789' /><br/>
Default formatting: {{val | number}}<br/>
No fractions: {{val | number:0}}<br/>
Negative number: {{-val | number:4}}
* @scenario
it('should format numbers', function(){
expect(binding('val | number')).toBe('1,234.57');
expect(binding('val | number:0')).toBe('1,235');
expect(binding('-val | number:4')).toBe('-1,234.5679');
});
it('should update', function(){
input('val').enter('3374.333');
expect(binding('val | number')).toBe('3,374.33');
expect(binding('val | number:0')).toBe('3,374');
expect(binding('-val | number:4')).toBe('-3,374.3330');
});
*/
angularFilter.number = function(number, fractionSize){
if (isNaN(number) || !isFinite(number)) {
return '';
}
fractionSize = typeof fractionSize == $undefined ? 2 : fractionSize;
var isNegative = amount < 0;
amount = Math.abs(amount);
var isNegative = number < 0;
number = Math.abs(number);
var pow = Math.pow(10, fractionSize);
var text = "" + Math.round(amount * pow);
var text = "" + Math.round(number * pow);
var whole = text.substring(0, text.length - fractionSize);
whole = whole || '0';
var frc = text.substring(text.length - fractionSize);
@@ -30,6 +95,8 @@ angularFilter.number = function(amount, fractionSize){
}
return text;
};
function padNumber(num, digits, trim) {
var neg = '';
if (num < 0) {
@@ -42,6 +109,8 @@ function padNumber(num, digits, trim) {
num = num.substr(num.length - digits);
return neg + num;
}
function dateGetter(name, size, offset, trim) {
return function(date) {
var value = date['get' + name]();
@@ -51,6 +120,8 @@ function dateGetter(name, size, offset, trim) {
return padNumber(value, size, trim);
};
}
var DATE_FORMATS = {
yyyy: dateGetter('FullYear', 4),
yy: dateGetter('FullYear', 2, 0, true),
@@ -66,23 +137,80 @@ var DATE_FORMATS = {
m: dateGetter('Minutes', 1),
ss: dateGetter('Seconds', 2),
s: dateGetter('Seconds', 1),
a: function(date){return date.getHours() < 12 ? 'am' : 'pm'; },
a: function(date){return date.getHours() < 12 ? 'am' : 'pm';},
Z: function(date){
var offset = date.getTimezoneOffset();
return padNumber(offset / 60, 2) + padNumber(Math.abs(offset % 60), 2);
}
};
var DATE_FORMATS_SPLIT = /([^yMdHhmsaZ]*)(y+|M+|d+|H+|h+|m+|s+|a|Z)(.*)/;
var NUMBER_STRING = /^\d+$/;
/**
* @workInProgress
* @ngdoc filter
* @name angular.filter.date
* @function
*
* @description
* Formats `date` to a string based on the requested `format`.
*
* `format` string can be composed of the following elements:
*
* * `'yyyy'`: 4 digit representation of year e.g. 2010
* * `'yy'`: 2 digit representation of year, padded (00-99)
* * `'MM'`: Month in year, padded (0112)
* * `'M'`: Month in year (112)
* * `'dd'`: Day in month, padded (0131)
* * `'d'`: Day in month (1-31)
* * `'HH'`: Hour in day, padded (0023)
* * `'H'`: Hour in day (0-23)
* * `'hh'`: Hour in am/pm, padded (0112)
* * `'h'`: Hour in am/pm, (1-12)
* * `'mm'`: Minute in hour, padded (0059)
* * `'m'`: Minute in hour (0-59)
* * `'ss'`: Second in minute, padded (0059)
* * `'s'`: Second in minute (059)
* * `'a'`: am/pm marker
* * `'Z'`: 4 digit (+sign) representation of the timezone offset (-12001200)
*
* @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or
* number) or ISO 8601 extended datetime string (yyyy-MM-ddTHH:mm:ss.SSSZ).
* @param {string=} format Formatting rules. If not specified, Date#toLocaleDateString is used.
* @returns {string} Formatted string or the input if input is not recognized as date/millis.
*
* @example
<span ng:non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>:
{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}<br/>
<span ng:non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}<br/>
*
* @scenario
it('should format date', function(){
expect(binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).
toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} \-?\d{4}/);
expect(binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).
toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(am|pm)/);
});
*
*/
angularFilter.date = function(date, format) {
if (isString(date) && NUMBER_STRING.test(date)) {
date = parseInt(date, 10);
if (isString(date)) {
if (NUMBER_STRING.test(date)) {
date = parseInt(date, 10);
} else {
date = angularString.toDate(date);
}
}
if (isNumber(date)) {
date = new Date(date);
} else if (!(date instanceof Date)) {
}
if (!isDate(date)) {
return date;
}
@@ -102,29 +230,229 @@ angularFilter.date = function(date, format) {
return text;
};
/**
* @workInProgress
* @ngdoc filter
* @name angular.filter.json
* @function
*
* @description
* Allows you to convert a JavaScript object into JSON string.
*
* This filter is mostly useful for debugging. When using the double curly {{value}} notation
* the binding is automatically converted to JSON.
*
* @param {*} object Any JavaScript object (including arrays and primitive types) to filter.
* @returns {string} JSON string.
*
* @css ng-monospace Always applied to the encapsulating element.
*
* @example:
<input type="text" name="objTxt" value="{a:1, b:[]}"
ng:eval="obj = $eval(objTxt)"/>
<pre>{{ obj | json }}</pre>
*
* @scenario
it('should jsonify filtered objects', function() {
expect(binding('obj | json')).toBe('{\n "a":1,\n "b":[]}');
});
it('should update', function() {
input('objTxt').enter('[1, 2, 3]');
expect(binding('obj | json')).toBe('[1,2,3]');
});
*
*/
angularFilter.json = function(object) {
this.$element.addClass("ng-monospace");
return toJson(object, true);
};
/**
* @workInProgress
* @ngdoc filter
* @name angular.filter.lowercase
* @function
*
* @see angular.lowercase
*/
angularFilter.lowercase = lowercase;
/**
* @workInProgress
* @ngdoc filter
* @name angular.filter.uppercase
* @function
*
* @see angular.uppercase
*/
angularFilter.uppercase = uppercase;
/**</>
* @exportedAs filter:html
* @param {string=} option if 'unsafe' then do not sanitize the HTML input
/**
* @workInProgress
* @ngdoc filter
* @name angular.filter.html
* @function
*
* @description
* Prevents the input from getting escaped by angular. By default the input is sanitized and
* inserted into the DOM as is.
*
* The input is sanitized by parsing the html into tokens. All safe tokens (from a whitelist) are
* then serialized back to properly escaped html string. This means that no unsafe input can make
* it into the returned string, however since our parser is more strict than a typical browser
* parser, it's possible that some obscure input, which would be recognized as valid HTML by a
* browser, won't make it through the sanitizer.
*
* If you hate your users, you may call the filter with optional 'unsafe' argument, which bypasses
* the html sanitizer, but makes your application vulnerable to XSS and other attacks. Using this
* option is strongly discouraged and should be used only if you absolutely trust the input being
* filtered and you can't get the content through the sanitizer.
*
* @param {string} html Html input.
* @param {string=} option If 'unsafe' then do not sanitize the HTML input.
* @returns {string} Sanitized or raw html.
*
* @example
Snippet: <textarea name="snippet" cols="60" rows="3">
&lt;p style="color:blue"&gt;an html
&lt;em onmouseover="this.textContent='PWN3D!'"&gt;click here&lt;/em&gt;
snippet&lt;/p&gt;</textarea>
<table>
<tr>
<td>Filter</td>
<td>Source</td>
<td>Rendered</td>
</tr>
<tr id="html-filter">
<td>html filter</td>
<td>
<pre>&lt;div ng:bind="snippet | html"&gt;<br/>&lt;/div&gt;</pre>
</td>
<td>
<div ng:bind="snippet | html"></div>
</td>
</tr>
<tr id="escaped-html">
<td>no filter</td>
<td><pre>&lt;div ng:bind="snippet"&gt;<br/>&lt;/div&gt;</pre></td>
<td><div ng:bind="snippet"></div></td>
</tr>
<tr id="html-unsafe-filter">
<td>unsafe html filter</td>
<td><pre>&lt;div ng:bind="snippet | html:'unsafe'"&gt;<br/>&lt;/div&gt;</pre></td>
<td><div ng:bind="snippet | html:'unsafe'"></div></td>
</tr>
</table>
*
* @scenario
it('should sanitize the html snippet ', function(){
expect(using('#html-filter').binding('snippet | html')).
toBe('<p>an html\n<em>click here</em>\nsnippet</p>');
});
it ('should escape snippet without any filter', function() {
expect(using('#escaped-html').binding('snippet')).
toBe("&lt;p style=\"color:blue\"&gt;an html\n" +
"&lt;em onmouseover=\"this.textContent='PWN3D!'\"&gt;click here&lt;/em&gt;\n" +
"snippet&lt;/p&gt;");
});
it ('should inline raw snippet if filtered as unsafe', function() {
expect(using('#html-unsafe-filter').binding("snippet | html:'unsafe'")).
toBe("<p style=\"color:blue\">an html\n" +
"<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" +
"snippet</p>");
});
it('should update', function(){
input('snippet').enter('new <b>text</b>');
expect(using('#html-filter').binding('snippet | html')).toBe('new <b>text</b>');
expect(using('#escaped-html').binding('snippet')).toBe("new &lt;b&gt;text&lt;/b&gt;");
expect(using('#html-unsafe-filter').binding("snippet | html:'unsafe'")).toBe('new <b>text</b>');
});
*/
angularFilter.html = function(html, option){
return new HTML(html, option);
};
/**
* @workInProgress
* @ngdoc filter
* @name angular.filter.linky
* @function
*
* @description
* Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
* plane email address links.
*
* @param {string} text Input text.
* @returns {string} Html-linkified text.
*
* @example
Snippet: <textarea name="snippet" cols="60" rows="3">
Pretty text with some links:
http://angularjs.org/,
mailto:us@somewhere.org,
another@somewhere.org,
and one more: ftp://127.0.0.1/.</textarea>
<table>
<tr>
<td>Filter</td>
<td>Source</td>
<td>Rendered</td>
</tr>
<tr id="linky-filter">
<td>linky filter</td>
<td>
<pre>&lt;div ng:bind="snippet | linky"&gt;<br/>&lt;/div&gt;</pre>
</td>
<td>
<div ng:bind="snippet | linky"></div>
</td>
</tr>
<tr id="escaped-html">
<td>no filter</td>
<td><pre>&lt;div ng:bind="snippet"&gt;<br/>&lt;/div&gt;</pre></td>
<td><div ng:bind="snippet"></div></td>
</tr>
</table>
@scenario
it('should linkify the snippet with urls', function(){
expect(using('#linky-filter').binding('snippet | linky')).
toBe('Pretty text with some links:\n' +
'<a href="http://angularjs.org/">http://angularjs.org/</a>,\n' +
'<a href="mailto:us@somewhere.org">us@somewhere.org</a>,\n' +
'<a href="mailto:another@somewhere.org">another@somewhere.org</a>,\n' +
'and one more: <a href="ftp://127.0.0.1/">ftp://127.0.0.1/</a>.');
});
it ('should not linkify snippet without the linky filter', function() {
expect(using('#escaped-html').binding('snippet')).
toBe("Pretty text with some links:\n" +
"http://angularjs.org/,\n" +
"mailto:us@somewhere.org,\n" +
"another@somewhere.org,\n" +
"and one more: ftp://127.0.0.1/.");
});
it('should update', function(){
input('snippet').enter('new http://link.');
expect(using('#linky-filter').binding('snippet | linky')).
toBe('new <a href="http://link">http://link</a>.');
expect(using('#escaped-html').binding('snippet')).toBe('new http://link.');
});
*/
//TODO: externalize all regexps
angularFilter.linky = function(text){
if (!text) return text;
function regExpEscape(text) {
return text.replace(/([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1');
}
var URL = /(ftp|http|https|mailto):\/\/([^\(\)|\s]+)/;
var URL = /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s\.\;\,\(\)\{\}\<\>]/;
var match;
var raw = text;
var html = [];
@@ -132,13 +460,16 @@ angularFilter.linky = function(text){
var url;
var i;
while (match=raw.match(URL)) {
url = match[0].replace(/[\.\;\,\(\)\{\}\<\>]$/,'');
i = raw.indexOf(url);
// We can not end in these as they are sometimes found at the end of the sentence
url = match[0];
// if we did not match ftp/http/mailto then assume mailto
if (match[2]==match[3]) url = 'mailto:' + url;
i = match.index;
writer.chars(raw.substr(0, i));
writer.start('a', {href:url});
writer.chars(url);
writer.chars(match[0].replace(/^mailto:/, ''));
writer.end('a');
raw = raw.substring(i + url.length);
raw = raw.substring(i + match[0].length);
}
writer.chars(raw);
return new HTML(html.join(''));
+123
View File
@@ -6,8 +6,79 @@ function toString(obj) {
var NUMBER = /^\s*[-+]?\d*(\.\d*)?\s*$/;
angularFormatter.noop = formatter(identity, identity);
/**
* @workInProgress
* @ngdoc formatter
* @name angular.formatter.json
*
* @description
* Formats the user input as JSON text.
*
* @returns {string} A JSON string representation of the model.
*
* @example
* <div ng:init="data={name:'misko', project:'angular'}">
* <input type="text" size='50' name="data" ng:format="json"/>
* <pre>data={{data}}</pre>
* </div>
*
* @scenario
* it('should format json', function(){
* expect(binding('data')).toEqual('data={\n \"name\":\"misko\",\n \"project\":\"angular\"}');
* input('data').enter('{}');
* expect(binding('data')).toEqual('data={\n }');
* });
*/
angularFormatter.json = formatter(toJson, fromJson);
/**
* @workInProgress
* @ngdoc formatter
* @name angular.formatter.boolean
*
* @description
* Use boolean formatter if you wish to store the data as boolean.
*
* @returns {boolean} Converts to `true` unless user enters (blank), `f`, `false`, `0`, `no`, `[]`.
*
* @example
* Enter truthy text:
* <input type="text" name="value" ng:format="boolean" value="no"/>
* <input type="checkbox" name="value"/>
* <pre>value={{value}}</pre>
*
* @scenario
* it('should format boolean', function(){
* expect(binding('value')).toEqual('value=false');
* input('value').enter('truthy');
* expect(binding('value')).toEqual('value=true');
* });
*/
angularFormatter['boolean'] = formatter(toString, toBoolean);
/**
* @workInProgress
* @ngdoc formatter
* @name angular.formatter.number
*
* @description
* Use number formatter if you wish to convert the user entered string to a number.
*
* @returns {number} Number from the parsed string.
*
* @example
* Enter valid number:
* <input type="text" name="value" ng:format="number" value="1234"/>
* <pre>value={{value}}</pre>
*
* @scenario
* it('should format numbers', function(){
* expect(binding('value')).toEqual('value=1234');
* input('value').enter('5678');
* expect(binding('value')).toEqual('value=5678');
* });
*/
angularFormatter.number = formatter(toString, function(obj){
if (obj == _null || NUMBER.exec(obj)) {
return obj===_null || obj === '' ? _null : 1*obj;
@@ -16,6 +87,32 @@ angularFormatter.number = formatter(toString, function(obj){
}
});
/**
* @workInProgress
* @ngdoc formatter
* @name angular.formatter.list
*
* @description
* Use list formatter if you wish to convert the user entered string to an array.
*
* @returns {Array} Array parsed from the entered string.
*
* @example
* Enter a list of items:
* <input type="text" name="value" ng:format="list" value=" chair ,, table"/>
* <input type="text" name="value" ng:format="list"/>
* <pre>value={{value}}</pre>
*
* @scenario
* it('should format lists', function(){
* expect(binding('value')).toEqual('value=["chair","table"]');
* this.addFutureAction('change to XYZ', function($window, $document, done){
* $document.elements('.doc-example :input:last').val(',,a,b,').trigger('change');
* done();
* });
* expect(binding('value')).toEqual('value=["a","b"]');
* });
*/
angularFormatter.list = formatter(
function(obj) { return obj ? obj.join(", ") : obj; },
function(value) {
@@ -28,6 +125,32 @@ angularFormatter.list = formatter(
}
);
/**
* @workInProgress
* @ngdoc formatter
* @name angular.formatter.trim
*
* @description
* Use trim formatter if you wish to trim extra spaces in user text.
*
* @returns {String} Trim excess leading and trailing space.
*
* @example
* Enter text with leading/trailing spaces:
* <input type="text" name="value" ng:format="trim" value=" book "/>
* <input type="text" name="value" ng:format="trim"/>
* <pre>value={{value|json}}</pre>
*
* @scenario
* it('should format trim', function(){
* expect(binding('value')).toEqual('value="book"');
* this.addFutureAction('change to XYZ', function($window, $document, done){
* $document.elements('.doc-example :input:last').val(' text ').trigger('change');
* done();
* });
* expect(binding('value')).toEqual('value="text"');
* });
*/
angularFormatter.trim = formatter(
function(obj) { return obj ? trim("" + obj) : ""; }
);
+53
View File
@@ -68,6 +68,59 @@ angularTextMarkup('OPTION', function(text, textNode, parentElement){
}
});
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:href
*
* @description
* Using <angular/> markup like {{hash}} in an href attribute makes
* the page open to a wrong URL, ff the user clicks that link before
* angular has a chance to replace the {{hash}} with actual URL, the
* link will be broken and will most likely return a 404 error.
* The `ng:href` solves this problem by placing the `href` in the
* `ng:` namespace.
*
* The buggy way to write it:
* <pre>
* <a href="http://www.gravatar.com/avatar/{{hash}}"/>
* </pre>
*
* The correct way to write it:
* <pre>
* <a ng:href="http://www.gravatar.com/avatar/{{hash}}"/>
* </pre>
*
* @element ANY
* @param {template} template any string which can contain `{{}}` markup.
*/
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:src
*
* @description
* Using <angular/> markup like `{{hash}}` in a `src` attribute doesn't
* work right: The browser will fetch from the URL with the literal
* text `{{hash}}` until <angular/> replaces the expression inside
* `{{hash}}`. The `ng:src` attribute solves this problem by placing
* the `src` attribute in the `ng:` namespace.
*
* The buggy way to write it:
* <pre>
* <img src="http://www.gravatar.com/avatar/{{hash}}"/>
* </pre>
*
* The correct way to write it:
* <pre>
* <img ng:src="http://www.gravatar.com/avatar/{{hash}}"/>
* </pre>
*
* @element ANY
* @param {template} template any string which can contain `{{}}` markup.
*/
var NG_BIND_ATTR = 'ng:bind-attr';
var SPECIAL_ATTRS = {'ng:src': 'src', 'ng:href': 'href'};
angularAttrMarkup('{{}}', function(value, name, element){
+39 -58
View File
@@ -26,7 +26,7 @@ var OPERATORS = {
var ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'};
function lex(text, parseStringsForObjects){
var dateParseLength = parseStringsForObjects ? 20 : -1,
var dateParseLength = parseStringsForObjects ? 24 : -1,
tokens = [],
token,
index = 0,
@@ -67,10 +67,7 @@ function lex(text, parseStringsForObjects){
tokens.push({index:index, text:ch, fn:fn, json: was('[,:') && is('+-')});
index += 1;
} else {
throw "Lexer Error: Unexpected next character [" +
text.substring(index) +
"] in expression '" + text +
"' at column '" + (index+1) + "'.";
throwError("Unexpected next character ", index, index+1);
}
}
lastCh = ch;
@@ -101,27 +98,37 @@ function lex(text, parseStringsForObjects){
'_' == ch || ch == '$';
}
function isExpOperator(ch) {
return ch == '-' || ch == '+';
return ch == '-' || ch == '+' || isNumber(ch);
}
function throwError(error, start, end) {
end = end || index;
throw Error("Lexer Error: " + error + " at column" +
(isDefined(start) ?
"s " + start + "-" + index + " [" + text.substring(start, end) + "]" :
" " + end) +
" in expression [" + text + "].");
}
function readNumber() {
var number = "";
var start = index;
while (index < text.length) {
var ch = text.charAt(index);
var ch = lowercase(text.charAt(index));
if (ch == '.' || isNumber(ch)) {
number += ch;
} else {
var peekCh = peek();
if (ch == 'E' && isExpOperator(peekCh)) {
if (ch == 'e' && isExpOperator(peekCh)) {
number += ch;
} else if (isExpOperator(ch) &&
peekCh && isNumber(peekCh) &&
number.charAt(number.length - 1) == 'E') {
number.charAt(number.length - 1) == 'e') {
number += ch;
} else if (isExpOperator(ch) &&
(!peekCh || !isNumber(peekCh)) &&
number.charAt(number.length - 1) == 'E') {
throw 'Lexer found invalid exponential value "' + text + '"';
number.charAt(number.length - 1) == 'e') {
throwError('Invalid exponent');
} else {
break;
}
@@ -151,7 +158,7 @@ function lex(text, parseStringsForObjects){
}
tokens.push({index:start, text:ident, fn:fn, json: OPERATORS[ident]});
}
function readString(quote) {
var start = index;
index++;
@@ -165,9 +172,7 @@ function lex(text, parseStringsForObjects){
if (ch == 'u') {
var hex = text.substring(index + 1, index + 5);
if (!hex.match(/[\da-f]{4}/i))
throw "Lexer Error: Invalid unicode escape [\\u" +
hex + "] starting at column '" +
start + "' in expression '" + text + "'.";
throwError( "Invalid unicode escape [\\u" + hex + "]");
index += 4;
string += String.fromCharCode(parseInt(hex, 16));
} else {
@@ -194,9 +199,7 @@ function lex(text, parseStringsForObjects){
}
index++;
}
throw "Lexer Error: Unterminated quote [" +
text.substring(start) + "] starting at column '" +
(start+1) + "' in expression '" + text + "'.";
throwError("Unterminated quote", start);
}
function readRegexp(quote) {
var start = index;
@@ -227,9 +230,7 @@ function lex(text, parseStringsForObjects){
}
index++;
}
throw "Lexer Error: Unterminated RegExp [" +
text.substring(start) + "] starting at column '" +
(start+1) + "' in expression '" + text + "'.";
throwError("Unterminated RegExp", start);
}
}
@@ -244,21 +245,21 @@ function parser(text, json){
statements: statements,
validator: validator,
filter: filter,
//TODO: delete me, since having watch in UI is logic in UI. (leftover form getangular)
watch: watch
};
///////////////////////////////////
function error(msg, token) {
throw "Token '" + token.text +
"' is " + msg + " at column='" +
(token.index + 1) + "' of expression '" +
text + "' starting at '" + text.substring(token.index) + "'.";
function throwError(msg, token) {
throw Error("Parse Error: Token '" + token.text +
"' " + msg + " at column " +
(token.index + 1) + " of expression [" +
text + "] starting at [" + text.substring(token.index) + "].");
}
function peekToken() {
if (tokens.length === 0)
throw "Unexpected end of expression: " + text;
throw Error("Unexpected end of expression: " + text);
return tokens[0];
}
@@ -279,10 +280,7 @@ function parser(text, json){
if (token) {
if (json && !token.json) {
index = token.index;
throw "Expression at column='" +
token.index + "' of expression '" +
text + "' starting at '" + text.substring(token.index) +
"' is not valid json.";
throwError("is not valid json", token);
}
tokens.shift();
this.currentToken = token;
@@ -293,11 +291,7 @@ function parser(text, json){
function consume(e1){
if (!expect(e1)) {
var token = peek();
throw "Expecting '" + e1 + "' at column '" +
(token.index+1) + "' in '" +
text + "' got '" +
text.substring(token.index) + "'.";
throwError("is unexpected, expecting [" + e1 + "]", peek());
}
}
@@ -319,8 +313,7 @@ function parser(text, json){
function assertAllConsumed(){
if (tokens.length !== 0) {
throw "Did not understand '" + text.substring(tokens[0].index) +
"' while evaluating '" + text + "'.";
throwError("is extra token not part of expression", tokens[0]);
}
}
@@ -386,18 +379,7 @@ function parser(text, json){
}
function expression(){
return throwStmt();
}
function throwStmt(){
if (expect('throw')) {
var throwExp = assignment();
return function (self) {
throw throwExp(self);
};
} else {
return assignment();
}
return assignment();
}
function assignment(){
@@ -405,9 +387,8 @@ function parser(text, json){
var token;
if (token = expect('=')) {
if (!left.isAssignable) {
throw "Left hand side '" +
text.substring(0, token.index) + "' of assignment '" +
text.substring(token.index) + "' is not assignable.";
throwError("implies assignment but [" +
text.substring(0, token.index) + "] can not be assigned to", token);
}
var ident = function(){return left.isAssignable;};
return binaryFn(ident, token.fn, logicalOR());
@@ -497,8 +478,7 @@ function parser(text, json){
instance = instance[key];
}
if (typeof instance != $function) {
throw "Function '" + token.text + "' at column '" +
(token.index+1) + "' in '" + text + "' is not defined.";
throwError("should be a function", token);
}
return instance;
}
@@ -517,7 +497,7 @@ function parser(text, json){
var token = expect();
primary = token.fn;
if (!primary) {
error("not a primary expression", token);
throwError("not a primary expression", token);
}
}
var next;
@@ -529,7 +509,7 @@ function parser(text, json){
} else if (next.text === '.') {
primary = fieldAccess(primary);
} else {
throw "IMPOSSIBLE";
throwError("IMPOSSIBLE");
}
}
return primary;
@@ -624,6 +604,7 @@ function parser(text, json){
};
}
//TODO: delete me, since having watch in UI is logic in UI. (leftover form getangular)
function watch () {
var decl = [];
while(hasTokens()) {
+57 -11
View File
@@ -37,28 +37,71 @@ angular.scenario.Application.prototype.getWindow_ = function() {
return contentWindow;
};
/**
* Checks that a URL would return a 2xx success status code. Callback is called
* with no arguments on success, or with an error on failure.
*
* Warning: This requires the server to be able to respond to HEAD requests
* and not modify the state of your application.
*
* @param {string} url Url to check
* @param {Function} callback function(error) that is called with result.
*/
angular.scenario.Application.prototype.checkUrlStatus_ = function(url, callback) {
var self = this;
_jQuery.ajax({
url: url,
type: 'HEAD',
complete: function(request) {
if (request.status < 200 || request.status >= 300) {
if (!request.status) {
callback.call(self, 'Sandbox Error: Cannot access ' + url);
} else {
callback.call(self, request.status + ' ' + request.statusText);
}
} else {
callback.call(self);
}
}
});
};
/**
* Changes the location of the frame.
*
* @param {string} url The URL. If it begins with a # then only the
* @param {string} url The URL. If it begins with a # then only the
* hash of the page is changed.
* @param {Function} onloadFn function($window, $document)
* @param {Function} loadFn function($window, $document) Called when frame loads.
* @param {Function} errorFn function(error) Called if any error when loading.
*/
angular.scenario.Application.prototype.navigateTo = function(url, onloadFn) {
angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorFn) {
var self = this;
var frame = this.getFrame_();
if (url.charAt(0) === '#') {
//TODO(esprehn): Refactor to use rethrow()
errorFn = errorFn || function(e) { throw e; };
if (url === 'about:blank') {
errorFn('Sandbox Error: Navigating to about:blank is not allowed.');
} else if (url.charAt(0) === '#') {
url = frame.attr('src').split('#')[0] + url;
frame.attr('src', url);
this.executeAction(onloadFn);
this.executeAction(loadFn);
} else {
frame.css('display', 'none').attr('src', 'about:blank');
this.context.find('#test-frames').append('<iframe>');
frame = this.getFrame_();
frame.load(function() {
self.executeAction(onloadFn);
frame.unbind();
}).attr('src', url);
this.checkUrlStatus_(url, function(error) {
if (error) {
return errorFn(error);
}
self.context.find('#test-frames').append('<iframe>');
frame = this.getFrame_();
frame.load(function() {
frame.unbind();
try {
self.executeAction(loadFn);
} catch (e) {
errorFn(e);
}
}).attr('src', url);
});
}
this.context.find('> h2 a').attr('href', url).text(url);
};
@@ -73,6 +116,9 @@ angular.scenario.Application.prototype.navigateTo = function(url, onloadFn) {
angular.scenario.Application.prototype.executeAction = function(action) {
var self = this;
var $window = this.getWindow_();
if (!$window.document) {
throw 'Sandbox Error: Application document not accessible.';
}
if (!$window.angular) {
return action.call(this, $window, _jQuery($window.document));
}
+40 -1
View File
@@ -1,3 +1,4 @@
/**
* Setup file for the Scenario.
* Must be first in the compilation/bootstrap list.
@@ -92,6 +93,7 @@ angular.scenario.matcher = angular.scenario.matcher || function(name, fn) {
* @param {Object} config Config options
*/
function angularScenarioInit($scenario, config) {
var href = window.location.href;
var body = _jQuery(document.body);
var output = [];
@@ -107,6 +109,15 @@ function angularScenarioInit($scenario, config) {
}
});
if (!/^http/.test(href) && !/^https/.test(href)) {
body.append('<p id="system-error"></p>');
body.find('#system-error').text(
'Scenario runner must be run using http or https. The protocol ' +
href.split(':')[0] + ':// is not supported.'
);
return;
}
var appFrame = body.append('<div id="application"></div>').find('#application');
var application = new angular.scenario.Application(appFrame);
@@ -133,7 +144,7 @@ function angularScenarioInit($scenario, config) {
*
* @param {Array} list list to iterate over
* @param {Function} iterator Callback function(value, continueFunction)
* @param {Function} done Callback function(error, result) called when
* @param {Function} done Callback function(error, result) called when
* iteration finishes or an error occurs.
*/
function asyncForEach(list, iterator, done) {
@@ -283,3 +294,31 @@ function browserTrigger(element, type) {
};
})(_jQuery.fn);
/**
* Finds all bindings with the substring match of name and returns an
* array of their values.
*
* @param {string} name The name to match
* @return {Array.<string>} String of binding values
*/
_jQuery.fn.bindings = function(name) {
function contains(text, value) {
return value instanceof RegExp ?
value.test(text) :
text && text.indexOf(value) >= 0;
}
var result = [];
this.find('.ng-binding:visible').each(function() {
var element = new _jQuery(this);
if (!angular.isDefined(name) ||
contains(element.attr('ng:bind'), name) ||
contains(element.attr('ng:bind-template'), name)) {
if (element.is('input, textarea')) {
result.push(element.val());
} else {
result.push(element.html());
}
}
});
return result;
};
+3 -9
View File
@@ -21,7 +21,6 @@ angular.scenario.SpecRunner = function() {
*/
angular.scenario.SpecRunner.prototype.run = function(spec, specDone) {
var self = this;
var count = 0;
this.spec = spec;
this.emit('SpecBegin', spec);
@@ -59,11 +58,7 @@ angular.scenario.SpecRunner.prototype.run = function(spec, specDone) {
return handleError(error, futureDone);
}
self.emit('StepEnd', spec, future);
if ((count++) % 10 === 0) {
self.$window.setTimeout(function() { futureDone(); }, 0);
} else {
futureDone();
}
self.$window.setTimeout(function() { futureDone(); }, 0);
});
} catch (e) {
self.emit('StepError', spec, future, e);
@@ -115,9 +110,8 @@ angular.scenario.SpecRunner.prototype.addFutureAction = function(name, behavior,
//TODO(esprehn): Refactor this so it doesn't need to be in here.
$document.elements = function(selector) {
var args = Array.prototype.slice.call(arguments, 1);
if (self.selector) {
selector = self.selector + ' ' + (selector || '');
}
selector = (self.selector || '') + ' ' + (selector || '');
selector = _jQuery.trim(selector) || '*';
angular.foreach(args, function(value, index) {
selector = selector.replace('$' + (index + 1), value);
});
+167 -105
View File
@@ -16,15 +16,98 @@ angular.scenario.dsl('wait', function() {
});
/**
* Usage:
* pause(seconds) pauses the test for specified number of seconds
*/
* Usage:
* pause(seconds) pauses the test for specified number of seconds
*/
angular.scenario.dsl('pause', function() {
return function(time) {
return this.addFuture('pause for ' + time + ' seconds', function(done) {
this.$window.setTimeout(function() { done(null, time * 1000); }, time * 1000);
});
};
return function(time) {
return this.addFuture('pause for ' + time + ' seconds', function(done) {
this.$window.setTimeout(function() { done(null, time * 1000); }, time * 1000);
});
};
});
/**
* Usage:
* browser().navigateTo(url) Loads the url into the frame
* browser().navigateTo(url, fn) where fn(url) is called and returns the URL to navigate to
* browser().reload() refresh the page (reload the same URL)
* browser().location().href() the full URL of the page
* browser().location().hash() the full hash in the url
* browser().location().path() the full path in the url
* browser().location().hashSearch() the hashSearch Object from angular
* browser().location().hashPath() the hashPath string from angular
*/
angular.scenario.dsl('browser', function() {
var chain = {};
chain.navigateTo = function(url, delegate) {
var application = this.application;
return this.addFuture("browser navigate to '" + url + "'", function(done) {
if (delegate) {
url = delegate.call(this, url);
}
application.navigateTo(url, function() {
done(null, url);
}, done);
});
};
chain.reload = function() {
var application = this.application;
return this.addFutureAction('browser reload', function($window, $document, done) {
var href = $window.location.href;
application.navigateTo(href, function() {
done(null, href);
}, done);
});
};
chain.location = function() {
var api = {};
api.href = function() {
return this.addFutureAction('browser url', function($window, $document, done) {
done(null, $window.location.href);
});
};
api.hash = function() {
return this.addFutureAction('browser url hash', function($window, $document, done) {
done(null, $window.location.hash.replace('#', ''));
});
};
api.path = function() {
return this.addFutureAction('browser url path', function($window, $document, done) {
done(null, $window.location.pathname);
});
};
api.search = function() {
return this.addFutureAction('browser url search', function($window, $document, done) {
done(null, $window.angular.scope().$location.search);
});
};
api.hashSearch = function() {
return this.addFutureAction('browser url hash search', function($window, $document, done) {
done(null, $window.angular.scope().$location.hashSearch);
});
};
api.hashPath = function() {
return this.addFutureAction('browser url hash path', function($window, $document, done) {
done(null, $window.angular.scope().$location.hashPath);
});
};
return api;
};
return function(time) {
return chain;
};
});
/**
@@ -50,53 +133,35 @@ angular.scenario.dsl('expect', function() {
/**
* Usage:
* navigateTo(url) Loads the url into the frame
* navigateTo(url, fn) where fn(url) is called and returns the URL to navigate to
*/
angular.scenario.dsl('navigateTo', function() {
return function(url, delegate) {
var application = this.application;
return this.addFuture('navigate to ' + url, function(done) {
if (delegate) {
url = delegate.call(this, url);
}
application.navigateTo(url, function() {
done(null, url);
});
});
};
});
/**
* Usage:
* using(selector) scopes the next DSL element selection
* using(selector, label) scopes the next DSL element selection
*
* ex.
* using('#foo').input('bar')
* using('#foo', "'Foo' text field").input('bar')
*/
angular.scenario.dsl('using', function() {
return function(selector) {
this.selector = (this.selector||'') + ' ' + selector;
return function(selector, label) {
this.selector = _jQuery.trim((this.selector||'') + ' ' + selector);
if (angular.isString(label) && label.length) {
this.label = label + ' ( ' + this.selector + ' )';
} else {
this.label = this.selector;
}
return this.dsl;
};
});
/**
* Usage:
* binding(name) returns the value of a binding
* binding(name) returns the value of the first matching binding
*/
angular.scenario.dsl('binding', function() {
return function(name) {
return this.addFutureAction("select binding '" + name + "'", function($window, $document, done) {
var element;
try {
element = $document.elements('[ng\\:bind-template*="{{$1}}"]', name);
} catch(e) {
if (e.type !== 'selector')
throw e;
element = $document.elements('[ng\\:bind="$1"]', name);
var values = $document.elements().bindings(name);
if (!values.length) {
return done("Binding selector '" + name + "' did not match.");
}
done(null, element.text());
done(null, values[0]);
});
};
});
@@ -112,7 +177,7 @@ angular.scenario.dsl('input', function() {
chain.enter = function(value) {
return this.addFutureAction("input '" + this.name + "' enter '" + value + "'", function($window, $document, done) {
var input = $document.elements('input[name="$1"]', this.name);
var input = $document.elements(':input[name="$1"]', this.name);
input.val(value);
input.trigger('change');
done();
@@ -121,7 +186,7 @@ angular.scenario.dsl('input', function() {
chain.check = function() {
return this.addFutureAction("checkbox '" + this.name + "' toggle", function($window, $document, done) {
var input = $document.elements('input:checkbox[name="$1"]', this.name);
var input = $document.elements(':checkbox[name="$1"]', this.name);
input.trigger('click');
done();
});
@@ -130,7 +195,7 @@ angular.scenario.dsl('input', function() {
chain.select = function(value) {
return this.addFutureAction("radio button '" + this.name + "' toggle '" + value + "'", function($window, $document, done) {
var input = $document.
elements('input:radio[name$="@$1"][value="$2"]', this.name, value);
elements(':radio[name$="@$1"][value="$2"]', this.name, value);
input.trigger('click');
done();
});
@@ -142,17 +207,18 @@ angular.scenario.dsl('input', function() {
};
});
/**
* Usage:
* repeater('#products table').count() number of rows
* repeater('#products table').row(1) all bindings in row as an array
* repeater('#products table').column('product.name') all values across all rows in an array
* repeater('#products table', 'Product List').count() number of rows
* repeater('#products table', 'Product List').row(1) all bindings in row as an array
* repeater('#products table', 'Product List').column('product.name') all values across all rows in an array
*/
angular.scenario.dsl('repeater', function() {
var chain = {};
chain.count = function() {
return this.addFutureAction('repeater ' + this.selector + ' count', function($window, $document, done) {
return this.addFutureAction("repeater '" + this.label + "' count", function($window, $document, done) {
try {
done(null, $document.elements().length);
} catch (e) {
@@ -162,52 +228,37 @@ angular.scenario.dsl('repeater', function() {
};
chain.column = function(binding) {
return this.addFutureAction('repeater ' + this.selector + ' column ' + binding, function($window, $document, done) {
var values = [];
$document.elements().each(function() {
_jQuery(this).find(':visible').each(function() {
var element = _jQuery(this);
if (element.attr('ng:bind') === binding) {
values.push(element.text());
}
});
});
done(null, values);
return this.addFutureAction("repeater '" + this.label + "' column '" + binding + "'", function($window, $document, done) {
done(null, $document.elements().bindings(binding));
});
};
chain.row = function(index) {
return this.addFutureAction('repeater ' + this.selector + ' row ' + index, function($window, $document, done) {
return this.addFutureAction("repeater '" + this.label + "' row '" + index + "'", function($window, $document, done) {
var values = [];
var matches = $document.elements().slice(index, index + 1);
if (!matches.length)
return done('row ' + index + ' out of bounds');
_jQuery(matches[0]).find(':visible').each(function() {
var element = _jQuery(this);
if (element.attr('ng:bind')) {
values.push(element.text());
}
});
done(null, values);
done(null, matches.bindings());
});
};
return function(selector) {
this.dsl.using(selector);
return function(selector, label) {
this.dsl.using(selector, label);
return chain;
};
});
/**
* Usage:
* select(selector).option('value') select one option
* select(selector).options('value1', 'value2', ...) select options from a multi select
* select(name).option('value') select one option
* select(name).options('value1', 'value2', ...) select options from a multi select
*/
angular.scenario.dsl('select', function() {
var chain = {};
chain.option = function(value) {
return this.addFutureAction('select ' + this.name + ' option ' + value, function($window, $document, done) {
return this.addFutureAction("select '" + this.name + "' option '" + value + "'", function($window, $document, done) {
var select = $document.elements('select[name="$1"]', this.name);
select.val(value);
select.trigger('change');
@@ -217,7 +268,7 @@ angular.scenario.dsl('select', function() {
chain.options = function() {
var values = arguments;
return this.addFutureAction('select ' + this.name + ' options ' + values, function($window, $document, done) {
return this.addFutureAction("select '" + this.name + "' options '" + values + "'", function($window, $document, done) {
var select = $document.elements('select[multiple][name="$1"]', this.name);
select.val(values);
select.trigger('change');
@@ -233,19 +284,24 @@ angular.scenario.dsl('select', function() {
/**
* Usage:
* element(selector).count() get the number of elements that match selector
* element(selector).click() clicks an element
* element(selector).attr(name) gets the value of an attribute
* element(selector).attr(name, value) sets the value of an attribute
* element(selector).val() gets the value (as defined by jQuery)
* element(selector).val(value) sets the value (as defined by jQuery)
* element(selector).query(fn) executes fn(selectedElements, done)
* element(selector, label).count() get the number of elements that match selector
* element(selector, label).click() clicks an element
* element(selector, label).query(fn) executes fn(selectedElements, done)
* element(selector, label).{method}() gets the value (as defined by jQuery, ex. val)
* element(selector, label).{method}(value) sets the value (as defined by jQuery, ex. val)
* element(selector, label).{method}(key) gets the value (as defined by jQuery, ex. attr)
* element(selector, label).{method}(key, value) sets the value (as defined by jQuery, ex. attr)
*/
angular.scenario.dsl('element', function() {
var KEY_VALUE_METHODS = ['attr', 'css'];
var VALUE_METHODS = [
'val', 'text', 'html', 'height', 'innerHeight', 'outerHeight', 'width',
'innerWidth', 'outerWidth', 'position', 'scrollLeft', 'scrollTop', 'offset'
];
var chain = {};
chain.count = function() {
return this.addFutureAction('element ' + this.selector + ' count', function($window, $document, done) {
return this.addFutureAction("element '" + this.label + "' count", function($window, $document, done) {
try {
done(null, $document.elements().length);
} catch (e) {
@@ -255,48 +311,54 @@ angular.scenario.dsl('element', function() {
};
chain.click = function() {
return this.addFutureAction('element ' + this.selector + ' click', function($window, $document, done) {
return this.addFutureAction("element '" + this.label + "' click", function($window, $document, done) {
var elements = $document.elements();
var href = elements.attr('href');
elements.trigger('click');
if (href && elements[0].nodeName.toUpperCase() === 'A') {
this.application.navigateTo(href, function() {
done();
});
}, done);
} else {
done();
}
});
};
chain.attr = function(name, value) {
var futureName = 'element ' + this.selector + ' get attribute ' + name;
if (value) {
futureName = 'element ' + this.selector + ' set attribute ' + name + ' to ' + value;
}
return this.addFutureAction(futureName, function($window, $document, done) {
done(null, $document.elements().attr(name, value));
});
};
chain.val = function(value) {
var futureName = 'element ' + this.selector + ' value';
if (value) {
futureName = 'element ' + this.selector + ' set value to ' + value;
}
return this.addFutureAction(futureName, function($window, $document, done) {
done(null, $document.elements().val(value));
});
};
chain.query = function(fn) {
return this.addFutureAction('element ' + this.selector + ' custom query', function($window, $document, done) {
return this.addFutureAction('element ' + this.label + ' custom query', function($window, $document, done) {
fn.call(this, $document.elements(), done);
});
};
return function(selector) {
this.dsl.using(selector);
angular.foreach(KEY_VALUE_METHODS, function(methodName) {
chain[methodName] = function(name, value) {
var futureName = "element '" + this.label + "' get " + methodName + " '" + name + "'";
if (angular.isDefined(value)) {
futureName = "element '" + this.label + "' set " + methodName + " '" + name + "' to " + "'" + value + "'";
}
return this.addFutureAction(futureName, function($window, $document, done) {
var element = $document.elements();
done(null, element[methodName].call(element, name, value));
});
};
});
angular.foreach(VALUE_METHODS, function(methodName) {
chain[methodName] = function(value) {
var futureName = "element '" + this.label + "' " + methodName;
if (angular.isDefined(value)) {
futureName = "element '" + this.label + "' set " + methodName + " to '" + value + "'";
}
return this.addFutureAction(futureName, function($window, $document, done) {
var element = $document.elements();
done(null, element[methodName].call(element, value));
});
};
});
return function(selector, label) {
this.dsl.using(selector, label);
return chain;
};
});
+456 -37
View File
@@ -8,20 +8,78 @@ function angularServiceInject(name, fn, inject, eager) {
angularService(name, fn, {$inject:inject, $creation:eager});
}
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$window
*
* @description
* Is reference to the browser's <b>window</b> object. While <b>window</b>
* is globally available in JavaScript, it causes testability problems, because
* it is a global variable. In <b><angular/></b> we always refer to it through the
* $window service, so it may be overriden, removed or mocked for testing.
*
* All expressions are evaluated with respect to current scope so they don't
* suffer from window globality.
*
* @example
<input ng:init="greeting='Hello World!'" type="text" name="greeting" />
<button ng:click="$window.alert(greeting)">ALERT</button>
*/
angularServiceInject("$window", bind(window, identity, window), [], EAGER_PUBLISHED);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$document
* @requires $window
*
* @description
* Reference to the browser window.document, but wrapped into angular.element().
*/
angularServiceInject("$document", function(window){
return jqLite(window.document);
}, ['$window'], EAGER_PUBLISHED);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$location
* @requires $browser
*
* @property {string} href
* @property {string} protocol
* @property {string} host
* @property {number} port
* @property {string} path
* @property {Object.<string|boolean>} search
* @property {string} hash
* @property {string} hashPath
* @property {Object.<string|boolean>} hashSearch
*
* @description
* Parses the browser location url and makes it available to your application.
* Any changes to the url are reflected into $location service and changes to
* $location are reflected to url.
* Notice that using browser's forward/back buttons changes the $location.
*
* @example
<a href="#">clear hash</a> |
<a href="#myPath?name=misko">test hash</a><br/>
<input type='text' name="$location.hash"/>
<pre>$location = {{$location}}</pre>
*/
angularServiceInject("$location", function(browser) {
var scope = this,
location = {toString:toString, update:update, updateHash: updateHash},
lastLocationHref = browser.getUrl(),
lastBrowserUrl = browser.getUrl(),
lastLocationHref,
lastLocationHash;
browser.addPollFn(function(){
if (lastLocationHref !== browser.getUrl()) {
update(lastLocationHref = browser.getUrl());
browser.addPollFn(function() {
if (lastBrowserUrl != browser.getUrl()) {
update(lastBrowserUrl = browser.getUrl());
updateLastLocation();
scope.$eval();
}
});
@@ -29,14 +87,20 @@ angularServiceInject("$location", function(browser) {
this.$onEval(PRIORITY_FIRST, updateBrowser);
this.$onEval(PRIORITY_LAST, updateBrowser);
update(lastLocationHref);
lastLocationHash = location.hash;
update(lastBrowserUrl);
updateLastLocation();
return location;
// PUBLIC METHODS
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$location#update
* @methodOf angular.service.$location
*
* @description
* Update location object
* Does not immediately update the browser
* Browser is updated at the end of $eval()
@@ -67,7 +131,13 @@ angularServiceInject("$location", function(browser) {
}
/**
* Update location hash
* @workInProgress
* @ngdoc method
* @name angular.service.$location#updateHash
* @methodOf angular.service.$location
*
* @description
* Update location hash part
* @see update()
*
* @example
@@ -97,9 +167,13 @@ angularServiceInject("$location", function(browser) {
}
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$location#toString
* @methodOf angular.service.$location
*
* @description
* Returns string representation - href
*
* @return {string} Location's href property
*/
function toString() {
updateLocation();
@@ -130,6 +204,14 @@ angularServiceInject("$location", function(browser) {
update(location.href);
}
/**
* Update information about last location
*/
function updateLastLocation() {
lastLocationHref = location.href;
lastLocationHash = location.hash;
}
/**
* If location has changed, update the browser
* This method is called at the end of $eval() phase
@@ -137,9 +219,9 @@ angularServiceInject("$location", function(browser) {
function updateBrowser() {
updateLocation();
if (location.href != lastLocationHref) {
browser.setUrl(lastLocationHref = location.href);
lastLocationHash = location.hash;
if (location.href != lastLocationHref) {
browser.setUrl(lastBrowserUrl = location.href);
updateLastLocation();
}
}
@@ -166,7 +248,9 @@ angularServiceInject("$location", function(browser) {
*/
function composeHash(loc) {
var hashSearch = toKeyValue(loc.hashSearch);
return escape(loc.hashPath) + (hashSearch ? '?' + hashSearch : '');
//TODO: temporary fix for issue #158
return escape(loc.hashPath).replace(/%21/gi, '!').replace(/%3A/gi, ':').replace(/%24/gi, '$') +
(hashSearch ? '?' + hashSearch : '');
}
/**
@@ -180,7 +264,7 @@ angularServiceInject("$location", function(browser) {
var match = URL_MATCH.exec(href);
if (match) {
loc.href = href.replace('#$', '');
loc.href = href.replace(/#$/, '');
loc.protocol = match[1];
loc.host = match[3] || '';
loc.port = match[5] || DEFAULT_PORTS[loc.protocol] || _null;
@@ -214,23 +298,127 @@ angularServiceInject("$location", function(browser) {
}, ['$browser'], EAGER_PUBLISHED);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$log
* @requires $window
*
* @description
* Is simple service for logging. Default implementation writes the message
* into the browser's console (if present).
*
* This is useful for debugging.
*
* @example
<p>Reload this page with open console, enter text and hit the log button...</p>
Message:
<input type="text" name="message" value="Hello World!"/>
<button ng:click="$log.log(message)">log</button>
<button ng:click="$log.warn(message)">warn</button>
<button ng:click="$log.info(message)">info</button>
<button ng:click="$log.error(message)">error</button>
*/
angularServiceInject("$log", function($window){
var console = $window.console || {log: noop, warn: noop, info: noop, error: noop},
log = console.log || noop;
return {
log: bind(console, log),
warn: bind(console, console.warn || log),
info: bind(console, console.info || log),
error: bind(console, console.error || log)
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$log#log
* @methodOf angular.service.$log
*
* @description
* Write a log message
*/
log: consoleLog('log'),
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$log#warn
* @methodOf angular.service.$log
*
* @description
* Write a warning message
*/
warn: consoleLog('warn'),
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$log#info
* @methodOf angular.service.$log
*
* @description
* Write an information message
*/
info: consoleLog('info'),
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$log#error
* @methodOf angular.service.$log
*
* @description
* Write an error message
*/
error: consoleLog('error')
};
function consoleLog(type) {
var console = $window.console || {};
var logFn = console[type] || console.log || noop;
if (logFn.apply) {
return function(){
var args = [];
foreach(arguments, function(arg){
args.push(formatError(arg));
});
return logFn.apply(console, args);
};
} else {
// we are IE, in which case there is nothing we can do
return logFn;
}
}
}, ['$window'], EAGER_PUBLISHED);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$exceptionHandler
* @requires $log
*
* @description
* Any uncaught exception in <angular/> is delegated to this service.
* The default implementation simply delegates to $log.error which logs it into
* the browser console.
*
* When unit testing it is useful to have uncaught exceptions propagate
* to the test so the test will fail rather than silently log the exception
* to the browser console. For this purpose you can override this service with
* a simple rethrow.
*
* @example
*/
angularServiceInject('$exceptionHandler', function($log){
return function(e) {
$log.error(e);
};
}, ['$log'], EAGER_PUBLISHED);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$hover
* @requires $browser
* @requires $document
*
* @description
*
* @example
*/
angularServiceInject("$hover", function(browser, document) {
var tooltip, self = this, error, width = 300, arrowWidth = 10, body = jqLite(document[0].body);
browser.hover(function(element, show){
@@ -277,9 +465,16 @@ angularServiceInject("$hover", function(browser, document) {
});
}, ['$browser', '$document'], EAGER);
/* Keeps references to all invalid widgets found during validation. Can be queried to find if there
* are invalid widgets currently displayed
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$invalidWidgets
*
* @description
* Keeps references to all invalid widgets found during validation.
* Can be queried to find whether there are any invalid widgets currently displayed.
*
* @example
*/
angularServiceInject("$invalidWidgets", function(){
var invalidWidgets = [];
@@ -363,7 +558,60 @@ function switchRouteMatcher(on, when, dstName) {
return match ? dst : _null;
}
angularServiceInject('$route', function(location){
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$route
* @requires $location
*
* @property {Object} current Name of the current route
* @property {Array.<Object>} routes List of configured routes
*
* @description
* Watches $location.hashPath and tries to map the hash to an existing route
* definition. It is used for deep-linking URLs to controllers and views (HTML partials).
*
* $route is typically used in conjunction with ng:include widget.
*
* @example
<p>
This example shows how changing the URL hash causes the <tt>$route</tt>
to match a route against the URL, and the <tt>[[ng:include]]</tt> pulls in the partial.
Try changing the URL in the input box to see changes.
</p>
<script>
angular.service('myApp', function($route) {
$route.when('/Book/:bookId', {template:'rsrc/book.html', controller:BookCntl});
$route.when('/Book/:bookId/ch/:chapterId', {template:'rsrc/chapter.html', controller:ChapterCntl});
$route.onChange(function() {
$route.current.scope.params = $route.current.params;
});
}, {$inject: ['$route']});
function BookCntl() {
this.name = "BookCntl";
}
function ChapterCntl() {
this.name = "ChapterCntl";
}
</script>
Chose:
<a href="#/Book/Moby">Moby</a> |
<a href="#/Book/Moby/ch/1">Moby: Ch1</a> |
<a href="#/Book/Gatsby">Gatsby</a> |
<a href="#/Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a><br/>
<input type="text" name="$location.hashPath" size="80" />
<pre>$location={{$location}}</pre>
<pre>$route.current.template={{$route.current.template}}</pre>
<pre>$route.current.params={{$route.current.params}}</pre>
<pre>$route.current.scope.name={{$route.current.scope.name}}</pre>
<hr/>
<ng:include src="$route.current.template" scope="$route.current.scope"/>
*/
angularServiceInject('$route', function(location) {
var routes = {},
onChange = [],
matcher = switchRouteMatcher,
@@ -371,8 +619,35 @@ angularServiceInject('$route', function(location){
dirty = 0,
$route = {
routes: routes,
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$route#onChange
* @methodOf angular.service.$route
*
* @param {function()} fn Function that will be called on route change
*
* @description
* Register a handler function that will be called when route changes
*/
onChange: bind(onChange, onChange.push),
when:function (path, params){
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$route#when
* @methodOf angular.service.$route
*
* @param {string} path Route path (matched against $location.hash)
* @param {Object} params Mapping information to be assigned to `$route.current` on route
* match.
* @returns {Object} route object
*
* @description
* Add new route
*/
when:function (path, params) {
if (angular.isUndefined(path)) return routes;
var route = routes[path];
if (!route) route = routes[path] = {};
@@ -405,6 +680,18 @@ angularServiceInject('$route', function(location){
return $route;
}, ['$location'], EAGER_PUBLISHED);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$xhr
* @requires $browser
* @requires $error
* @requires $log
*
* @description
*
* @example
*/
angularServiceInject('$xhr', function($browser, $error, $log){
var self = this;
return function(method, url, post, callback){
@@ -436,12 +723,34 @@ angularServiceInject('$xhr', function($browser, $error, $log){
};
}, ['$browser', '$xhr.error', '$log']);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$xhr.error
* @requires $log
*
* @description
*
* @example
*/
angularServiceInject('$xhr.error', function($log){
return function(request, response){
$log.error('ERROR: XHR: ' + request.url, request, response);
};
}, ['$log']);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$xhr.bulk
* @requires $xhr
* @requires $xhr.error
* @requires $log
*
* @description
*
* @example
*/
angularServiceInject('$xhr.bulk', function($xhr, $error, $log){
var requests = [],
scope = this;
@@ -492,6 +801,16 @@ angularServiceInject('$xhr.bulk', function($xhr, $error, $log){
return bulkXHR;
}, ['$xhr', '$xhr.error', '$log']);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$xhr.cache
* @requires $xhr
*
* @description
*
* @example
*/
angularServiceInject('$xhr.cache', function($xhr){
var inflight = {}, self = this;
function cache(method, url, post, callback, verifyCache){
@@ -536,18 +855,76 @@ angularServiceInject('$xhr.cache', function($xhr){
return cache;
}, ['$xhr.bulk']);
/**
* @workInProgress
* @ngdoc service
* @name angular.service.$resource
* @requires $xhr
*
* @description
* Is a factory which creates a resource object which lets you interact with
* <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer" target="_blank">RESTful</a>
* server-side data sources.
* Resource object has action methods which provide high-level behaviors without
* the need to interact with the low level $xhr or XMLHttpRequest().
*
* @example
<script>
function BuzzController($resource) {
this.Activity = $resource(
'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
{alt:'json', callback:'JSON_CALLBACK'},
{get:{method:'JSON', params:{visibility:'@self'}}, replies: {method:'JSON', params:{visibility:'@self', comments:'@comments'}}}
);
}
BuzzController.prototype = {
fetch: function() {
this.activities = this.Activity.get({userId:this.userId});
},
expandReplies: function(activity) {
activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id});
}
};
BuzzController.$inject = ['$resource'];
</script>
<div ng:controller="BuzzController">
<input name="userId" value="googlebuzz"/>
<button ng:click="fetch()">fetch</button>
<hr/>
<div ng:repeat="item in activities.data.items">
<h1 style="font-size: 15px;">
<img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
<a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
<a href="#" ng:click="expandReplies(item)" style="float: right;">Expand replies: {{item.links.replies[0].count}}</a>
</h1>
{{item.object.content | html}}
<div ng:repeat="reply in item.replies.data.items" style="margin-left: 20px;">
<img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
<a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>: {{reply.content | html}}
</div>
</div>
</div>
*/
angularServiceInject('$resource', function($xhr){
var resource = new ResourceFactory($xhr);
return bind(resource, resource.route);
}, ['$xhr.cache']);
/**
* $cookies service provides read/write access to the browser cookies. Currently only session
* cookies are supported.
*
* Only a simple Object is exposed and by adding or removing properties to/from this object, new
* cookies are created or deleted from the browser at the end of the current eval.
* @workInProgress
* @ngdoc service
* @name angular.service.$cookies
* @requires $browser
*
* @description
* Provides read/write access to browser's cookies.
*
* Only a simple Object is exposed and by adding or removing properties to/from
* this object, new cookies are created/deleted at the end of current $eval.
*
* @example
*/
angularServiceInject('$cookies', function($browser) {
var rootScope = this,
@@ -620,23 +997,65 @@ angularServiceInject('$cookies', function($browser) {
}
}, ['$browser'], EAGER_PUBLISHED);
/**
* $cookieStore provides a key-value (string-object) storage that is backed by session cookies.
* Objects put or retrieved from this storage are automatically serialized or deserialized.
* @workInProgress
* @ngdoc service
* @name angular.service.$cookieStore
* @requires $cookies
*
* @description
* Provides a key-value (string-object) storage, that is backed by session cookies.
* Objects put or retrieved from this storage are automatically serialized or
* deserialized by angular's toJson/fromJson.
* @example
*/
angularServiceInject('$cookieStore', function($store) {
return {
get: function(/**string*/key) {
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$cookieStore#get
* @methodOf angular.service.$cookieStore
*
* @description
* Returns the value of given cookie key
*
* @param {string} key Id to use for lookup.
* @returns {Object} Deserialized cookie value.
*/
get: function(key) {
return fromJson($store[key]);
},
put: function(/**string*/key, /**Object*/value) {
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$cookieStore#put
* @methodOf angular.service.$cookieStore
*
* @description
* Sets a value for given cookie key
*
* @param {string} key Id for the `value`.
* @param {Object} value Value to be stored.
*/
put: function(key, value) {
$store[key] = toJson(value);
},
remove: function(/**string*/key) {
/**
* @workInProgress
* @ngdoc method
* @name angular.service.$cookieStore#remove
* @methodOf angular.service.$cookieStore
*
* @description
* Remove given cookie
*
* @param {string} key Id of the key-value pair to delete.
*/
remove: function(key) {
delete $store[key];
}
};
+283 -9
View File
@@ -1,6 +1,32 @@
foreach({
extend(angularValidator, {
'noop': function() { return _null; },
/**
* @workInProgress
* @ngdoc validator
* @name angular.validator.regexp
* @description
* Use regexp validator to restrict the input to any Regular Expression.
*
* @param {string} value value to validate
* @param {regexp} expression regular expression.
* @css ng-validation-error
*
* @example
* Enter valid SSN:
* <input name="ssn" value="123-45-6789" ng:validate="regexp:/^\d\d\d-\d\d-\d\d\d\d$/" >
*
* @scenario
* it('should invalidate non ssn', function(){
* var textBox = element('.doc-example :input');
* expect(textBox.attr('className')).not().toMatch(/ng-validation-error/);
* expect(textBox.val()).toEqual('123-45-6789');
*
* input('ssn').enter('123-45-67890');
* expect(textBox.attr('className')).toMatch(/ng-validation-error/);
* });
*
*/
'regexp': function(value, regexp, msg) {
if (!value.match(regexp)) {
return msg ||
@@ -10,6 +36,44 @@ foreach({
}
},
/**
* @workInProgress
* @ngdoc validator
* @name angular.validator.number
* @description
* Use number validator to restrict the input to numbers with an
* optional range. (See integer for whole numbers validator).
*
* @param {string} value value to validate
* @param {int=} [min=MIN_INT] minimum value.
* @param {int=} [max=MAX_INT] maximum value.
* @css ng-validation-error
*
* @example
* Enter number: <input name="n1" ng:validate="number" > <br>
* Enter number greater than 10: <input name="n2" ng:validate="number:10" > <br>
* Enter number between 100 and 200: <input name="n3" ng:validate="number:100:200" > <br>
*
* @scenario
* it('should invalidate number', function(){
* var n1 = element('.doc-example :input[name=n1]');
* expect(n1.attr('className')).not().toMatch(/ng-validation-error/);
* input('n1').enter('1.x');
* expect(n1.attr('className')).toMatch(/ng-validation-error/);
*
* var n2 = element('.doc-example :input[name=n2]');
* expect(n2.attr('className')).not().toMatch(/ng-validation-error/);
* input('n2').enter('9');
* expect(n2.attr('className')).toMatch(/ng-validation-error/);
*
* var n3 = element('.doc-example :input[name=n3]');
* expect(n3.attr('className')).not().toMatch(/ng-validation-error/);
* input('n3').enter('201');
* expect(n3.attr('className')).toMatch(/ng-validation-error/);
*
* });
*
*/
'number': function(value, min, max) {
var num = 1 * value;
if (num == value) {
@@ -25,6 +89,43 @@ foreach({
}
},
/**
* @workInProgress
* @ngdoc validator
* @name angular.validator.integer
* @description
* Use number validator to restrict the input to integers with an
* optional range. (See integer for whole numbers validator).
*
* @param {string} value value to validate
* @param {int=} [min=MIN_INT] minimum value.
* @param {int=} [max=MAX_INT] maximum value.
* @css ng-validation-error
*
* @example
* Enter integer: <input name="n1" ng:validate="integer" > <br>
* Enter integer equal or greater than 10: <input name="n2" ng:validate="integer:10" > <br>
* Enter integer between 100 and 200 (inclusive): <input name="n3" ng:validate="integer:100:200" > <br>
*
* @scenario
* it('should invalidate integer', function(){
* var n1 = element('.doc-example :input[name=n1]');
* expect(n1.attr('className')).not().toMatch(/ng-validation-error/);
* input('n1').enter('1.1');
* expect(n1.attr('className')).toMatch(/ng-validation-error/);
*
* var n2 = element('.doc-example :input[name=n2]');
* expect(n2.attr('className')).not().toMatch(/ng-validation-error/);
* input('n2').enter('10.1');
* expect(n2.attr('className')).toMatch(/ng-validation-error/);
*
* var n3 = element('.doc-example :input[name=n3]');
* expect(n3.attr('className')).not().toMatch(/ng-validation-error/);
* input('n3').enter('100.1');
* expect(n3.attr('className')).toMatch(/ng-validation-error/);
*
* });
*/
'integer': function(value, min, max) {
var numberError = angularValidator['number'](value, min, max);
if (numberError) return numberError;
@@ -34,6 +135,30 @@ foreach({
return _null;
},
/**
* @workInProgress
* @ngdoc validator
* @name angular.validator.date
* @description
* Use date validator to restrict the user input to a valid date
* in format in format MM/DD/YYYY.
*
* @param {string} value value to validate
* @css ng-validation-error
*
* @example
* Enter valid date:
* <input name="text" value="1/1/2009" ng:validate="date" >
*
* @scenario
* it('should invalidate date', function(){
* var n1 = element('.doc-example :input');
* expect(n1.attr('className')).not().toMatch(/ng-validation-error/);
* input('text').enter('123/123/123');
* expect(n1.attr('className')).toMatch(/ng-validation-error/);
* });
*
*/
'date': function(value) {
var fields = /^(\d\d?)\/(\d\d?)\/(\d\d\d\d)$/.exec(value);
var date = fields ? new Date(fields[3], fields[1]-1, fields[2]) : 0;
@@ -44,13 +169,29 @@ foreach({
_null : "Value is not a date. (Expecting format: 12/31/2009).";
},
'ssn': function(value) {
if (value.match(/^\d\d\d-\d\d-\d\d\d\d$/)) {
return _null;
}
return "SSN needs to be in 999-99-9999 format.";
},
/**
* @workInProgress
* @ngdoc validator
* @name angular.validator.email
* @description
* Use email validator if you wist to restrict the user input to a valid email.
*
* @param {string} value value to validate
* @css ng-validation-error
*
* @example
* Enter valid email:
* <input name="text" ng:validate="email" value="me@example.com">
*
* @scenario
* it('should invalidate email', function(){
* var n1 = element('.doc-example :input');
* expect(n1.attr('className')).not().toMatch(/ng-validation-error/);
* input('text').enter('a@b.c');
* expect(n1.attr('className')).toMatch(/ng-validation-error/);
* });
*
*/
'email': function(value) {
if (value.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/)) {
return _null;
@@ -58,6 +199,29 @@ foreach({
return "Email needs to be in username@host.com format.";
},
/**
* @workInProgress
* @ngdoc validator
* @name angular.validator.phone
* @description
* Use phone validator to restrict the input phone numbers.
*
* @param {string} value value to validate
* @css ng-validation-error
*
* @example
* Enter valid phone number:
* <input name="text" value="1(234)567-8901" ng:validate="phone" >
*
* @scenario
* it('should invalidate phone', function(){
* var n1 = element('.doc-example :input');
* expect(n1.attr('className')).not().toMatch(/ng-validation-error/);
* input('text').enter('+12345678');
* expect(n1.attr('className')).toMatch(/ng-validation-error/);
* });
*
*/
'phone': function(value) {
if (value.match(/^1\(\d\d\d\)\d\d\d-\d\d\d\d$/)) {
return _null;
@@ -68,6 +232,29 @@ foreach({
return "Phone number needs to be in 1(987)654-3210 format in North America or +999 (123) 45678 906 internationaly.";
},
/**
* @workInProgress
* @ngdoc validator
* @name angular.validator.url
* @description
* Use phone validator to restrict the input URLs.
*
* @param {string} value value to validate
* @css ng-validation-error
*
* @example
* Enter valid phone number:
* <input name="text" value="http://example.com/abc.html" size="40" ng:validate="url" >
*
* @scenario
* it('should invalidate url', function(){
* var n1 = element('.doc-example :input');
* expect(n1.attr('className')).not().toMatch(/ng-validation-error/);
* input('text').enter('abc://server/path');
* expect(n1.attr('className')).toMatch(/ng-validation-error/);
* });
*
*/
'url': function(value) {
if (value.match(/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/)) {
return _null;
@@ -75,6 +262,30 @@ foreach({
return "URL needs to be in http://server[:port]/path format.";
},
/**
* @workInProgress
* @ngdoc validator
* @name angular.validator.json
* @description
* Use json validator if you wish to restrict the user input to a valid JSON.
*
* @param {string} value value to validate
* @css ng-validation-error
*
* @example
* <textarea name="json" cols="60" rows="5" ng:validate="json">
* {name:'abc'}
* </textarea>
*
* @scenario
* it('should invalidate json', function(){
* var n1 = element('.doc-example :input');
* expect(n1.attr('className')).not().toMatch(/ng-validation-error/);
* input('json').enter('{name}');
* expect(n1.attr('className')).toMatch(/ng-validation-error/);
* });
*
*/
'json': function(value) {
try {
fromJson(value);
@@ -84,6 +295,69 @@ foreach({
}
},
/**
* @workInProgress
* @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, ng-validation-error
*
* @example
* <script>
* function myValidator(inputToValidate, validationDone) {
* setTimeout(function(){
* validationDone(inputToValidate.length % 2);
* }, 500);
* }
* </script>
* This input is validated asynchronously:
* <input name="text" ng:validate="asynchronous:$window.myValidator">
*
* @scenario
* it('should change color in delayed way', function(){
* var textBox = element('.doc-example :input');
* expect(textBox.attr('className')).not().toMatch(/ng-input-indicator-wait/);
* expect(textBox.attr('className')).not().toMatch(/ng-validation-error/);
*
* input('text').enter('X');
* expect(textBox.attr('className')).toMatch(/ng-input-indicator-wait/);
*
* pause(.6);
*
* expect(textBox.attr('className')).not().toMatch(/ng-input-indicator-wait/);
* expect(textBox.attr('className')).toMatch(/ng-validation-error/);
*
* });
*
*/
/*
* cache is attached to the element
* cache: {
@@ -132,4 +406,4 @@ foreach({
return inputState.error;
}
}, function(v,k) {angularValidator[k] = v;});
});
+535 -16
View File
@@ -1,3 +1,137 @@
/**
* @workInProgress
* @ngdoc widget
* @name angular.widget.HTML
*
* @description
* The most common widgets you will use will be in the from of the
* standard HTML set. These widgets are bound using the name attribute
* to an expression. In addition they can have `ng:validate`, `ng:required`,
* `ng:format`, `ng:change` attribute to further control their behavior.
*
* @usageContent
* see example below for usage
*
* <input type="text|checkbox|..." ... />
* <textarea ... />
* <select ...>
* <option>...</option>
* </select>
*
* @example
<table style="font-size:.9em;">
<tr>
<th>Name</th>
<th>Format</th>
<th>HTML</th>
<th>UI</th>
<th ng:non-bindable>{{input#}}</th>
</tr>
<tr>
<th>text</th>
<td>String</td>
<td><tt>&lt;input type="text" name="input1"&gt;</tt></td>
<td><input type="text" name="input1" size="4"></td>
<td><tt>{{input1|json}}</tt></td>
</tr>
<tr>
<th>textarea</th>
<td>String</td>
<td><tt>&lt;textarea name="input2"&gt;&lt;/textarea&gt;</tt></td>
<td><textarea name="input2" cols='6'></textarea></td>
<td><tt>{{input2|json}}</tt></td>
</tr>
<tr>
<th>radio</th>
<td>String</td>
<td><tt>
&lt;input type="radio" name="input3" value="A"&gt;<br>
&lt;input type="radio" name="input3" value="B"&gt;
</tt></td>
<td>
<input type="radio" name="input3" value="A">
<input type="radio" name="input3" value="B">
</td>
<td><tt>{{input3|json}}</tt></td>
</tr>
<tr>
<th>checkbox</th>
<td>Boolean</td>
<td><tt>&lt;input type="checkbox" name="input4" value="checked"&gt;</tt></td>
<td><input type="checkbox" name="input4" value="checked"></td>
<td><tt>{{input4|json}}</tt></td>
</tr>
<tr>
<th>pulldown</th>
<td>String</td>
<td><tt>
&lt;select name="input5"&gt;<br>
&nbsp;&nbsp;&lt;option value="c"&gt;C&lt;/option&gt;<br>
&nbsp;&nbsp;&lt;option value="d"&gt;D&lt;/option&gt;<br>
&lt;/select&gt;<br>
</tt></td>
<td>
<select name="input5">
<option value="c">C</option>
<option value="d">D</option>
</select>
</td>
<td><tt>{{input5|json}}</tt></td>
</tr>
<tr>
<th>multiselect</th>
<td>Array</td>
<td><tt>
&lt;select name="input6" multiple size="4"&gt;<br>
&nbsp;&nbsp;&lt;option value="e"&gt;E&lt;/option&gt;<br>
&nbsp;&nbsp;&lt;option value="f"&gt;F&lt;/option&gt;<br>
&lt;/select&gt;<br>
</tt></td>
<td>
<select name="input6" multiple size="4">
<option value="e">E</option>
<option value="f">F</option>
</select>
</td>
<td><tt>{{input6|json}}</tt></td>
</tr>
</table>
* @scenario
* it('should exercise text', function(){
* input('input1').enter('Carlos');
* expect(binding('input1')).toEqual('"Carlos"');
* });
* it('should exercise textarea', function(){
* input('input2').enter('Carlos');
* expect(binding('input2')).toEqual('"Carlos"');
* });
* it('should exercise radio', function(){
* expect(binding('input3')).toEqual('null');
* input('input3').select('A');
* expect(binding('input3')).toEqual('"A"');
* input('input3').select('B');
* expect(binding('input3')).toEqual('"B"');
* });
* it('should exercise checkbox', function(){
* expect(binding('input4')).toEqual('false');
* input('input4').check();
* expect(binding('input4')).toEqual('true');
* });
* it('should exercise pulldown', function(){
* expect(binding('input5')).toEqual('"c"');
* select('input5').option('d');
* expect(binding('input5')).toEqual('"d"');
* });
* it('should exercise multiselect', function(){
* expect(binding('input6')).toEqual('[]');
* select('input6').options('e');
* expect(binding('input6')).toEqual('["e"]');
* select('input6').options('e', 'f');
* expect(binding('input6')).toEqual('["e","f"]');
* });
*/
function modelAccessor(scope, element) {
var expr = element.attr('name');
if (!expr) throw "Required field 'name' not found.";
@@ -32,6 +166,101 @@ function compileValidator(expr) {
return parser(expr).validator()();
}
/**
* @workInProgress
* @ngdoc widget
* @name angular.widget.@ng:validate
*
* @description
* The `ng:validate` attribute widget validates the user input. If the input does not pass
* validation, the `ng-validation-error` CSS class and the `ng:error` attribute are set on the input
* element. Check out {@link angular.validator validators} to find out more.
*
* @param {string} validator The name of a built-in or custom {@link angular.validator validator} to
* to be used.
*
* @element INPUT
* @css ng-validation-error
*
* @exampleDescription
* This example shows how the input element becomes red when it contains invalid input. Correct
* the input to make the error disappear.
*
* @example
I don't validate:
<input type="text" name="value" value="NotANumber"><br/>
I need an integer or nothing:
<input type="text" name="value" ng:validate="integer"><br/>
*
* @scenario
it('should check ng:validate', function(){
expect(element('.doc-example-live :input:last').attr('className')).
toMatch(/ng-validation-error/);
input('value').enter('123');
expect(element('.doc-example-live :input:last').attr('className')).
not().toMatch(/ng-validation-error/);
});
*/
/**
* @workInProgress
* @ngdoc widget
* @name angular.widget.@ng:required
*
* @description
* The `ng:required` attribute widget validates that the user input is present. It is a special case
* of the {@link angular.widget.@ng:validate ng:validate} attribute widget.
*
* @element INPUT
* @css ng-validation-error
*
* @exampleDescription
* This example shows how the input element becomes red when it contains invalid input. Correct
* the input to make the error disappear.
*
* @example
I cannot be blank: <input type="text" name="value" ng:required><br/>
*
* @scenario
it('should check ng:required', function(){
expect(element('.doc-example-live :input').attr('className')).toMatch(/ng-validation-error/);
input('value').enter('123');
expect(element('.doc-example-live :input').attr('className')).not().toMatch(/ng-validation-error/);
});
*/
/**
* @workInProgress
* @ngdoc widget
* @name angular.widget.@ng:format
*
* @description
* The `ng:format` attribute widget formats stored data to user-readable text and parses the text
* back to the stored form. You might find this useful for example if you collect user input in a
* text field but need to store the data in the model as a list. Check out
* {@link angular.formatter formatters} to learn more.
*
* @param {string} formatter The name of the built-in or custom {@link angular.formatter formatter}
* to be used.
*
* @element INPUT
*
* @exampleDescription
* This example shows how the user input is converted from a string and internally represented as an
* array.
*
* @example
Enter a comma separated list of items:
<input type="text" name="list" ng:format="list" value="table, chairs, plate">
<pre>list={{list}}</pre>
*
* @scenario
it('should check ng:format', function(){
expect(binding('list')).toBe('list=["table","chairs","plate"]');
input('list').enter(',,, a ,,,');
expect(binding('list')).toBe('list=["a"]');
});
*/
function valueAccessor(scope, element) {
var validatorName = element.attr('ng:validate') || NOOP,
validator = compileValidator(validatorName),
@@ -187,6 +416,40 @@ function radioInit(model, view, element) {
view.set(modelValue);
}
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:change
*
* @description
* The directive executes an expression whenever the input widget changes.
*
* @element INPUT
* @param {expression} expression to execute.
*
* @exampleDescription
* @example
<div ng:init="checkboxCount=0; textCount=0"></div>
<input type="text" name="text" ng:change="textCount = 1 + textCount">
changeCount {{textCount}}<br/>
<input type="checkbox" name="checkbox" ng:change="checkboxCount = 1 + checkboxCount">
changeCount {{checkboxCount}}<br/>
*
* @scenario
it('should check ng:change', function(){
expect(binding('textCount')).toBe('0');
expect(binding('checkboxCount')).toBe('0');
using('.doc-example-live').input('text').enter('abc');
expect(binding('textCount')).toBe('1');
expect(binding('checkboxCount')).toBe('0');
using('.doc-example-live').input('checkbox').check();
expect(binding('textCount')).toBe('1');
expect(binding('checkboxCount')).toBe('1');
});
*/
function inputWidget(events, modelAccessor, viewAccessor, initFn) {
return function(element) {
var scope = this,
@@ -240,10 +503,49 @@ angularWidget('option', function(){
});
/**
* @workInProgress
* @ngdoc widget
* @name angular.widget.ng:include
*
* @description
* Include external HTML fragment.
*
* Keep in mind that Same Origin Policy applies to included resources
* (e.g. ng:include won't work for file:// access).
*
* @param {string} src expression evaluating to URL.
* @param {Scope=} [scope=new_child_scope] expression evaluating to angular.scope
* @param {string=} onload Expression to evaluate when a new partial is loaded.
*
* @example
* <select name="url">
* <option value="angular.filter.date.html">date filter</option>
* <option value="angular.filter.html.html">html filter</option>
* <option value="">(blank)</option>
* </select>
* <tt>url = <a href="{{url}}">{{url}}</a></tt>
* <hr/>
* <ng:include src="url"></ng:include>
*
* @scenario
* it('should load date filter', function(){
* expect(element('.doc-example ng\\:include').text()).toMatch(/angular\.filter\.date/);
* });
* it('should change to hmtl filter', function(){
* select('url').option('angular.filter.html.html');
* expect(element('.doc-example ng\\:include').text()).toMatch(/angular\.filter\.html/);
* });
* it('should change to blank', function(){
* select('url').option('(blank)');
* expect(element('.doc-example ng\\:include').text()).toEqual('');
* });
*/
angularWidget('ng:include', function(element){
var compiler = this,
srcExp = element.attr("src"),
scopeExp = element.attr("scope") || '';
scopeExp = element.attr("scope") || '',
onloadExp = element[0].getAttribute('onload') || ''; //workaround for jquery bug #7537
if (element[0]['ng:compiled']) {
this.descend(true);
this.directives(true);
@@ -268,13 +570,15 @@ angularWidget('ng:include', function(element){
});
this.$watch(function(){return changeCounter;}, function(){
var src = this.$eval(srcExp),
useScope = this.$eval(scopeExp);
useScope = this.$eval(scopeExp);
if (src) {
xhr('GET', src, function(code, response){
element.html(response);
childScope = useScope || createScope(scope);
compiler.compile(element)(element, childScope);
childScope.$init();
scope.$eval(onloadExp);
});
} else {
childScope = null;
@@ -285,6 +589,56 @@ angularWidget('ng:include', function(element){
}
});
/**
* @workInProgress
* @ngdoc widget
* @name angular.widget.ng:switch
*
* @description
* Conditionally change the DOM structure.
*
* @usageContent
* <any ng:switch-when="matchValue1">...</any>
* <any ng:switch-when="matchValue2">...</any>
* ...
* <any ng:switch-default>...</any>
*
* @param {*} on expression to match against <tt>ng:switch-when</tt>.
* @paramDescription
* On child elments add:
*
* * `ng:switch-when`: the case statement to match against. If match then this
* case will be displayed.
* * `ng:switch-default`: the default case when no other casses match.
*
* @example
<select name="switch">
<option>settings</option>
<option>home</option>
<option>other</option>
</select>
<tt>switch={{switch}}</tt>
</hr>
<ng:switch on="switch" >
<div ng:switch-when="settings">Settings Div</div>
<span ng:switch-when="home">Home Span</span>
<span ng:switch-default>default</span>
</ng:switch>
</code>
*
* @scenario
* it('should start in settings', function(){
* expect(element('.doc-example ng\\:switch').text()).toEqual('Settings Div');
* });
* it('should change to home', function(){
* select('switch').option('home');
* expect(element('.doc-example ng\\:switch').text()).toEqual('Home Span');
* });
* it('should select deafault', function(){
* select('switch').option('other');
* expect(element('.doc-example ng\\:switch').text()).toEqual('default');
* });
*/
var ngSwitch = angularWidget('ng:switch', function (element){
var compiler = this,
watchExpr = element.attr("on"),
@@ -294,21 +648,26 @@ var ngSwitch = angularWidget('ng:switch', function (element){
changeExpr = element.attr('change') || '',
cases = [];
if (!usingFn) throw "Using expression '" + usingExpr + "' unknown.";
if (!watchExpr) throw "Missing 'on' attribute.";
eachNode(element, function(caseElement){
var when = caseElement.attr('ng:switch-when');
if (when) {
cases.push({
when: function(scope, value){
var args = [value, when];
foreach(usingExprParams, function(arg){
args.push(arg);
});
return usingFn.apply(scope, args);
},
var switchCase = {
change: changeExpr,
element: caseElement,
template: compiler.compile(caseElement)
});
};
if (isString(when)) {
switchCase.when = function(scope, value){
var args = [value, when];
foreach(usingExprParams, function(arg){
args.push(arg);
});
return usingFn.apply(scope, args);
};
cases.unshift(switchCase);
} else if (isString(caseElement.attr('ng:switch-default'))) {
switchCase.when = valueFn(true);
cases.push(switchCase);
}
});
@@ -321,10 +680,12 @@ var ngSwitch = angularWidget('ng:switch', function (element){
return function(element){
var scope = this, childScope;
this.$watch(watchExpr, function(value){
var found = false;
element.html('');
childScope = createScope(scope);
foreach(cases, function(switchCase){
if (switchCase.when(childScope, value)) {
if (!found && switchCase.when(childScope, value)) {
found = true;
var caseElement = quickClone(switchCase.element);
element.append(caseElement);
childScope.$tryEval(switchCase.change, element);
@@ -339,7 +700,7 @@ var ngSwitch = angularWidget('ng:switch', function (element){
};
}, {
equals: function(on, when) {
return on == when;
return ''+on == when;
},
route: switchRouteMatcher
});
@@ -353,7 +714,7 @@ var ngSwitch = angularWidget('ng:switch', function (element){
* changing the location or causing page reloads, e.g.:
* <a href="" ng:click="model.$save()">Save</a>
*/
angular.widget('a', function() {
angularWidget('a', function() {
this.descend(true);
this.directives(true);
@@ -364,4 +725,162 @@ angular.widget('a', function() {
});
}
};
});
});
/**
* @workInProgress
* @ngdoc widget
* @name angular.widget.@ng:repeat
*
* @description
* `ng:repeat` instantiates a template once per item from a collection. The collection is enumerated
* with `ng:repeat-index` attribute starting from 0. Each template instance gets its own scope where
* the given loop variable is set to the current collection item and `$index` is set to the item
* index or key.
*
* There are special properties exposed on the local scope of each template instance:
*
* * `$index` `{number}` iterator offset of the repeated element (0..length-1)
* * `$position` {string} position of the repeated element in the iterator. One of: `'first'`,
* `'middle'` or `'last'`.
*
* NOTE: `ng:repeat` looks like a directive, but is actually an attribute widget.
*
* @element ANY
* @param {string} repeat_expression The expression indicating how to enumerate a collection. Two
* formats are currently supported:
*
* * `variable in expression` where variable is the user defined loop variable and `expression`
* is a scope expression giving the collection to enumerate.
*
* For example: `track in cd.tracks`.
* * `(key, value) in expression` where `key` and `value` can be any user defined identifiers,
* and `expression` is the scope expression giving the collection to enumerate.
*
* For example: `(name, age) in {'adam':10, 'amalie':12}`.
*
* @exampleDescription
* This example initializes the scope to a list of names and
* than uses `ng:repeat` to display every person.
* @example
<div ng:init="friends = [{name:'John', age:25}, {name:'Mary', age:28}]">
I have {{friends.length}} friends. They are:
<ul>
<li ng:repeat="friend in friends">
[{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old.
</li>
</ul>
</div>
* @scenario
it('should check ng:repeat', function(){
var r = using('.doc-example-live').repeater('ul li');
expect(r.count()).toBe(2);
expect(r.row(0)).toEqual(["1","John","25"]);
expect(r.row(1)).toEqual(["2","Mary","28"]);
});
*/
angularWidget("@ng:repeat", function(expression, element){
element.removeAttr('ng:repeat');
element.replaceWith(this.comment("ng:repeat: " + expression));
var template = this.compile(element);
return function(reference){
var match = expression.match(/^\s*(.+)\s+in\s+(.*)\s*$/),
lhs, rhs, valueIdent, keyIdent;
if (! match) {
throw Error("Expected ng:repeat in form of 'item in collection' but got '" +
expression + "'.");
}
lhs = match[1];
rhs = match[2];
match = lhs.match(/^([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\)$/);
if (!match) {
throw Error("'item' in 'item in collection' should be identifier or (key, value) but got '" +
keyValue + "'.");
}
valueIdent = match[3] || match[1];
keyIdent = match[2];
var children = [], currentScope = this;
this.$onEval(function(){
var index = 0,
childCount = children.length,
lastElement = reference,
collection = this.$tryEval(rhs, reference),
is_array = isArray(collection),
collectionLength = 0,
childScope,
key;
if (is_array) {
collectionLength = collection.length;
} else {
for (key in collection)
if (collection.hasOwnProperty(key))
collectionLength++;
}
for (key in collection) {
if (!is_array || collection.hasOwnProperty(key)) {
if (index < childCount) {
// reuse existing child
childScope = children[index];
childScope[valueIdent] = collection[key];
if (keyIdent) childScope[keyIdent] = key;
} else {
// grow children
childScope = template(quickClone(element), createScope(currentScope));
childScope[valueIdent] = collection[key];
if (keyIdent) childScope[keyIdent] = key;
lastElement.after(childScope.$element);
childScope.$index = index;
childScope.$position = index == 0 ?
'first' :
(index == collectionLength - 1 ? 'last' : 'middle');
childScope.$element.attr('ng:repeat-index', index);
childScope.$init();
children.push(childScope);
}
childScope.$eval();
lastElement = childScope.$element;
index ++;
}
}
// shrink children
while(children.length > index) {
children.pop().$element.remove();
}
}, reference);
};
});
/**
* @workInProgress
* @ngdoc widget
* @name angular.widget.@ng:non-bindable
*
* @description
* Sometimes it is necessary to write code which looks like bindings but which should be left alone
* by angular. Use `ng:non-bindable` to make angular ignore a chunk of HTML.
*
* NOTE: `ng:non-bindable` looks like a directive, but is actually an attribute widget.
*
* @element ANY
*
* @exampleDescription
* In this example there are two location where a siple binding (`{{}}`) is present, but the one
* wrapped in `ng:non-bindable` is left alone.
*
* @example
<div>Normal: {{1 + 2}}</div>
<div ng:non-bindable>Ignored: {{1 + 2}}</div>
*
* @scenario
it('should check ng:non-bindable', function(){
expect(using('.doc-example-live').binding('1 + 2')).toBe('3');
expect(using('.doc-example-live').element('div:last').text()).
toMatch(/1 \+ 2/);
});
*/
angularWidget("@ng:non-bindable", noop);
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
tests=$1
if [[ $tests = "" ]]; then
tests="all"
fi
java -Xmx1g -jar lib/jstestdriver/JsTestDriver.jar --config jsTestDriver-coverage.conf --testOutput=tmp/lcov --tests "$tests"
+1
View File
@@ -1,3 +1,4 @@
#!/bin/sh
tests=$1
if [[ $tests = "" ]]; then
tests="all"
+87 -12
View File
@@ -26,8 +26,8 @@ describe("copy", function(){
it("should return same object", function (){
var obj = {};
var arr = [];
assertSame(obj, copy({}, obj));
assertSame(arr, copy([], arr));
expect(copy({}, obj)).toBe(obj);
expect(copy([], arr)).toBe(arr);
});
it("should copy Date", function(){
@@ -40,26 +40,26 @@ describe("copy", function(){
it("should copy array", function(){
var src = [1, {name:"value"}];
var dst = [{key:"v"}];
assertSame(dst, copy(src, dst));
assertEquals([1, {name:"value"}], dst);
assertEquals({name:"value"}, dst[1]);
assertNotSame(src[1], dst[1]);
expect(copy(src, dst)).toBe(dst);
expect(dst).toEqual([1, {name:"value"}]);
expect(dst[1]).toEqual({name:"value"});
expect(dst[1]).not.toBe(src[1]);
});
it('should copy empty array', function() {
var src = [];
var dst = [{key: "v"}];
assertEquals([], copy(src, dst));
assertEquals([], dst);
expect(copy(src, dst)).toEqual([]);
expect(dst).toEqual([]);
});
it("should copy object", function(){
var src = {a:{name:"value"}};
var dst = {b:{key:"v"}};
assertSame(dst, copy(src, dst));
assertEquals({a:{name:"value"}}, dst);
assertEquals(src.a, dst.a);
assertNotSame(src.a, dst.a);
expect(copy(src, dst)).toBe(dst);
expect(dst).toEqual({a:{name:"value"}});
expect(dst.a).toEqual(src.a);
expect(dst.a).not.toBe(src.a);
});
it("should copy primitives", function(){
@@ -255,6 +255,20 @@ describe('angularJsConfig', function() {
});
it('should extract angular autobind config from the script hashpath attributes', function() {
var doc = { getElementsByTagName: function(tagName) {
expect(lowercase(tagName)).toEqual('script');
return [{nodeName: 'SCRIPT',
src: 'angularjs/angular.js#autobind'}];
}};
expect(angularJsConfig(doc)).toEqual({base_url: 'angularjs/',
autobind: true,
ie_compat: 'angularjs/angular-ie-compat.js',
ie_compat_id: 'ng-ie-compat'});
});
it("should default to versioned ie-compat file if angular file is versioned", function() {
var doc = { getElementsByTagName: function(tagName) {
expect(lowercase(tagName)).toEqual('script');
@@ -280,3 +294,64 @@ describe('angularJsConfig', function() {
ie_compat_id: 'ng-ie-compat'});
});
});
describe('extensionMap', function() {
it('should preserve $ properties on override', function() {
var extension = extensionMap({}, 'fake');
extension('first', {$one: true, $two: true});
var result = extension('first', {$one: false, $three: true});
expect(result.$one).toBeFalsy();
expect(result.$two).toBeTruthy();
expect(result.$three).toBeTruthy();
});
it('should not preserve non-angular properties', function() {
var extension = extensionMap({}, 'fake');
extension('first', {two: true});
var result = extension('first', {$one: false, $three: true});
expect(result.two).not.toBeDefined();
});
});
describe('angular service', function() {
it('should override services', function() {
var scope = createScope();
angular.service('fake', function() { return 'old'; });
angular.service('fake', function() { return 'new'; });
expect(scope.$inject('fake')).toEqual('new');
});
it('should preserve $ properties on override', function() {
angular.service('fake', {$one: true}, {$two: true});
var result = angular.service('fake', {$third: true});
expect(result.$one).toBeTruthy();
expect(result.$two).toBeTruthy();
expect(result.$third).toBeTruthy();
});
it('should not preserve non-angular properties on override', function() {
angular.service('fake', {one: true}, {two: true});
var result = angular.service('fake', {third: true});
expect(result.one).not.toBeDefined();
expect(result.two).not.toBeDefined();
expect(result.third).toBeTruthy();
});
});
describe('isDate', function() {
it('should return true for Date object', function() {
expect(isDate(new Date())).toBe(true);
});
it('should return false for non Date objects', function() {
expect(isDate([])).toBe(false);
expect(isDate('')).toBe(false);
expect(isDate(23)).toBe(false);
expect(isDate({})).toBe(false);
});
});
+22 -4
View File
@@ -185,18 +185,36 @@ describe('api', function(){
it('DateToUTC', function(){
var date = new Date("Sep 10 2003 13:02:03 GMT");
assertEquals("date", angular.Object.typeOf(date));
assertEquals("2003-09-10T13:02:03Z", angular.Date.toString(date));
assertEquals("2003-09-10T13:02:03.000Z", angular.Date.toString(date));
assertEquals(date.getTime(), angular.String.toDate(angular.Date.toString(date)).getTime());
});
it('UTCtoDate', function(){
expect(angular.String.toDate("2003-09-10T13:02:03Z")).toEqual(new Date("Sep 10 2003 13:02:03 GMT"));
//full ISO8061
expect(angular.String.toDate("2003-09-10T13:02:03.000Z")).
toEqual(new Date("Sep 10 2003 13:02:03 GMT"));
//no millis
expect(angular.String.toDate("2003-09-10T13:02:03Z")).
toEqual(new Date("Sep 10 2003 13:02:03 GMT"));
//no seconds
expect(angular.String.toDate("2003-09-10T13:02Z")).
toEqual(new Date("Sep 10 2003 13:02:00 GMT"));
//no minutes
expect(angular.String.toDate("2003-09-10T13Z")).
toEqual(new Date("Sep 10 2003 13:00:00 GMT"));
//no time
expect(angular.String.toDate("2003-09-10")).
toEqual(new Date("Sep 10 2003 00:00:00 GMT"));
});
it('StringFromUTC', function(){
var date = angular.String.toDate("2003-09-10T13:02:03Z");
var date = angular.String.toDate("2003-09-10T13:02:03.000Z");
assertEquals("date", angular.Object.typeOf(date));
assertEquals("2003-09-10T13:02:03Z", angular.Date.toString(date));
assertEquals("2003-09-10T13:02:03.000Z", angular.Date.toString(date));
assertEquals("str", angular.String.toDate("str"));
});
+10 -11
View File
@@ -276,15 +276,15 @@ BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){
a.scope.$eval();
var span = childNode(doc, 0);
assertTrue(span.hasClass('ng-exception'));
assertEquals('ErrorMsg1', fromJson(span.text()));
assertEquals('"ErrorMsg1"', span.attr('ng-exception'));
assertTrue(!!span.text().match(/ErrorMsg1/));
assertTrue(!!span.attr('ng-exception').match(/ErrorMsg1/));
a.scope.$set('error.throw', function(){throw "MyError";});
a.scope.$eval();
span = childNode(doc, 0);
assertTrue(span.hasClass('ng-exception'));
assertTrue(span.text(), span.text().match('MyError') !== null);
assertEquals('"MyError"', span.attr('ng-exception'));
assertEquals('MyError', span.attr('ng-exception'));
a.scope.$set('error.throw', function(){return "ok";});
a.scope.$eval();
@@ -438,13 +438,12 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){
var model = {books:[]};
var c = this.compile('<a ng:click="action()">Add Phone</a>', model);
c.scope.action = function(){
throw {a:'abc', b:2};
throw new Error('MyError');
};
var input = c.node;
browserTrigger(input, 'click');
var error = fromJson(input.attr('ng-exception'));
assertEquals("abc", error.a);
assertEquals(2, error.b);
var error = input.attr('ng-exception');
assertTrue(!!error.match(/MyError/));
assertTrue("should have an error class", input.hasClass('ng-exception'));
// TODO: I think that exception should never get cleared so this portion of test makes no sense
@@ -607,13 +606,13 @@ BinderTest.prototype.testItShouldListenOnRightScope = function() {
'<ul ng:init="counter=0; gCounter=0" ng:watch="w:counter=counter+1">' +
'<li ng:repeat="n in [1,2,4]" ng:watch="w:counter=counter+1;w:$root.gCounter=$root.gCounter+n"/></ul>');
c.scope.$eval();
assertEquals(0, c.scope.$get("counter"));
assertEquals(0, c.scope.$get("gCounter"));
assertEquals(1, c.scope.$get("counter"));
assertEquals(7, c.scope.$get("gCounter"));
c.scope.$set("w", "something");
c.scope.$eval();
assertEquals(1, c.scope.$get("counter"));
assertEquals(7, c.scope.$get("gCounter"));
assertEquals(2, c.scope.$get("counter"));
assertEquals(14, c.scope.$get("gCounter"));
};
BinderTest.prototype.testItShouldRepeatOnHashes = function() {
+7 -2
View File
@@ -14,7 +14,8 @@ describe('compiler', function(){
watch: function(expression, element){
return function() {
this.$watch(expression, function(val){
log += ":" + val;
if (val)
log += ":" + val;
});
};
}
@@ -46,6 +47,7 @@ describe('compiler', function(){
var init = template(e).$init;
expect(log).toEqual("found");
init();
expect(e.hasClass('ng-directive')).toEqual(true);
expect(log).toEqual("found:init");
});
@@ -102,12 +104,13 @@ describe('compiler', function(){
}
});
var scope = compile('before<span>middle</span>after');
expect(lowercase(scope.$element[0].innerHTML)).toEqual('before<span hello="middle">replaced</span>after');
expect(sortedHtml(scope.$element[0], true)).toEqual('<div>before<span class="ng-directive" hello="middle">replaced</span>after</div>');
expect(log).toEqual("hello middle");
});
it('should replace widgets', function(){
widgets['NG:BUTTON'] = function(element) {
expect(element.hasClass('ng-widget')).toEqual(true);
element.replaceWith('<div>button</div>');
return function(element) {
log += 'init';
@@ -120,6 +123,8 @@ describe('compiler', function(){
it('should use the replaced element after calling widget', function(){
widgets['H1'] = function(element) {
// HTML elements which are augmented by acting as widgets, should not be marked as so
expect(element.hasClass('ng-widget')).toEqual(false);
var span = angular.element('<span>{{1+2}}</span>');
element.replaceWith(span);
this.descend(true);
+82 -61
View File
@@ -1,100 +1,115 @@
describe('filter', function(){
describe('filter', function() {
var filter = angular.filter;
it('should called the filter when evaluating expression', function() {
var scope = createScope();
filter.fakeFilter = function(){};
spyOn(filter, 'fakeFilter');
scope.$eval('10|fakeFilter');
expect(filter.fakeFilter).toHaveBeenCalledWith(10);
delete filter['fakeFilter'];
});
it('should call filter on scope context', function() {
var scope = createScope();
scope.name = 'misko';
filter.fakeFilter = function() {
expect(this.name).toEqual('misko');
};
spyOn(filter, 'fakeFilter').andCallThrough();
scope.$eval('10|fakeFilter');
expect(filter.fakeFilter).toHaveBeenCalled();
delete filter['fakeFilter'];
});
describe('Currency', function(){
it('should do basic filter', function(){
describe('currency', function() {
it('should do basic filter', function() {
var html = jqLite('<span/>');
var context = {$element:html};
var currency = bind(context, filter.currency);
assertEquals(currency(0), '$0.00');
assertEquals(html.hasClass('ng-format-negative'), false);
assertEquals(currency(-999), '$-999.00');
assertEquals(html.hasClass('ng-format-negative'), true);
assertEquals(currency(1234.5678), '$1,234.57');
assertEquals(html.hasClass('ng-format-negative'), false);
expect(currency(0)).toEqual('$0.00');
expect(html.hasClass('ng-format-negative')).toBeFalsy();
expect(currency(-999)).toEqual('$-999.00');
expect(html.hasClass('ng-format-negative')).toBeTruthy();
expect(currency(1234.5678)).toEqual('$1,234.57');
expect(html.hasClass('ng-format-negative')).toBeFalsy();
});
});
describe('FilterThisIsContext', function(){
it('should do basic filter', function(){
expectAsserts(1);
var scope = createScope();
scope.name = 'misko';
filter.testFn = function () {
assertEquals('scope not equal', 'misko', this.name);
};
scope.$eval("0|testFn");
delete angular.filter['testFn'];
});
});
describe('NumberFormat', function(){
it('should do basic filter', function(){
describe('number', function() {
it('should do basic filter', function() {
var context = {jqElement:jqLite('<span/>')};
var number = bind(context, filter.number);
assertEquals('0', number(0, 0));
assertEquals('0.00', number(0));
assertEquals('-999.00', number(-999));
assertEquals('1,234.57', number(1234.5678));
assertEquals('', number(Number.NaN));
assertEquals('1,234.57', number("1234.5678"));
assertEquals("", number(1/0));
expect(number(0, 0)).toEqual('0');
expect(number(0)).toEqual('0.00');
expect(number(-999)).toEqual('-999.00');
expect(number(1234.5678)).toEqual('1,234.57');
expect(number(Number.NaN)).toEqual('');
expect(number("1234.5678")).toEqual('1,234.57');
expect(number(1/0)).toEqual("");
});
});
describe('Json', function () {
it('should do basic filter', function(){
assertEquals(toJson({a:"b"}, true), filter.json.call({$element:jqLite('<div></div>')}, {a:"b"}));
describe('json', function () {
it('should do basic filter', function() {
expect(filter.json.call({$element:jqLite('<div></div>')}, {a:"b"})).toEqual(toJson({a:"b"}, true));
});
});
describe('Lowercase', function() {
it('should do basic filter', function(){
assertEquals('abc', filter.lowercase('AbC'));
assertEquals(null, filter.lowercase(null));
describe('lowercase', function() {
it('should do basic filter', function() {
expect(filter.lowercase('AbC')).toEqual('abc');
expect(filter.lowercase(null)).toBeNull();
});
});
describe('Uppercase', function() {
it('should do basic filter', function(){
assertEquals('ABC', filter.uppercase('AbC'));
assertEquals(null, filter.uppercase(null));
describe('uppercase', function() {
it('should do basic filter', function() {
expect(filter.uppercase('AbC')).toEqual('ABC');
expect(filter.uppercase(null)).toBeNull();
});
});
describe('Html', function() {
it('should do basic filter', function(){
describe('html', function() {
it('should do basic filter', function() {
var html = filter.html("a<b>c</b>d");
expect(html instanceof HTML).toBeTruthy();
expect(html.html).toEqual("a<b>c</b>d");
});
});
describe('Linky', function() {
it('should do basic filter', function(){
var linky = filter.linky;
assertEquals(
'<a href="http://ab/">http://ab/</a> ' +
'(<a href="http://a/">http://a/</a>) ' +
'&lt;<a href="http://a/">http://a/</a>&gt; ' +
'<a href="http://1.2/v:~-123">http://1.2/v:~-123</a>. c',
linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c").html);
assertEquals(undefined, linky(undefined));
describe('linky', function() {
var linky = filter.linky;
it('should do basic filter', function() {
expect(linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c").html).
toEqual('<a href="http://ab/">http://ab/</a> ' +
'(<a href="http://a/">http://a/</a>) ' +
'&lt;<a href="http://a/">http://a/</a>&gt; ' +
'<a href="http://1.2/v:~-123">http://1.2/v:~-123</a>. c');
expect(linky(undefined)).not.toBeDefined();
});
it('should handle mailto:', function() {
expect(linky("mailto:me@example.com").html).toEqual('<a href="mailto:me@example.com">me@example.com</a>');
expect(linky("me@example.com").html).toEqual('<a href="mailto:me@example.com">me@example.com</a>');
expect(linky("send email to me@example.com, but").html).
toEqual('send email to <a href="mailto:me@example.com">me@example.com</a>, but');
});
});
describe('date', function(){
var morning = new TzDate(+5, '2010-09-03T12:05:08Z'); //7am
var noon = new TzDate(+5, '2010-09-03T17:05:08Z'); //12pm
var midnight = new TzDate(+5, '2010-09-03T05:05:08Z'); //12am
var morning = new TzDate(+5, '2010-09-03T12:05:08.000Z'); //7am
var noon = new TzDate(+5, '2010-09-03T17:05:08.000Z'); //12pm
var midnight = new TzDate(+5, '2010-09-03T05:05:08.000Z'); //12am
it('should ignore falsy inputs', function() {
expect(filter.date(null)).toEqual(null);
expect(filter.date(null)).toBeNull();
expect(filter.date('')).toEqual('');
});
@@ -108,7 +123,7 @@ describe('filter', function(){
expect(filter.date(noon.getTime() + "")).toEqual(noon.toLocaleDateString());
});
it('should accept format', function() {
it('should accept various format strings', function() {
expect(filter.date(morning, "yy-MM-dd HH:mm:ss")).
toEqual('10-09-03 07:05:08');
@@ -121,5 +136,11 @@ describe('filter', function(){
expect(filter.date(noon, "yyyy-MM-dd hh=HH:mm:ssaZ")).
toEqual('2010-09-03 12=12:05:08pm0500');
});
it('should be able to parse ISO 8601 dates/times using', function() {
var isoString = '2010-09-03T05:05:08.872Z';
expect(filter.date(isoString)).
toEqual(angular.String.toDate(isoString).toLocaleDateString());
});
});
});
+85 -67
View File
@@ -1,102 +1,107 @@
describe('json', function(){
it('should parse Primitives', function() {
assertEquals("null", toJson(0/0));
assertEquals("null", toJson(null));
assertEquals("true", toJson(true));
assertEquals("false", toJson(false));
assertEquals("123.45", toJson(123.45));
assertEquals('"abc"', toJson("abc"));
assertEquals('"a \\t \\n \\r b \\\\"', toJson("a \t \n \r b \\"));
it('should serialize primitives', function() {
expect(toJson(0/0)).toEqual('null');
expect(toJson(null)).toEqual('null');
expect(toJson(true)).toEqual('true');
expect(toJson(false)).toEqual('false');
expect(toJson(123.45)).toEqual("123.45");
expect(toJson("abc")).toEqual('"abc"');
expect(toJson("a \t \n \r b \\")).toEqual('"a \\t \\n \\r b \\\\"');
});
it('should parse Escaping', function() {
assertEquals("\"7\\\\\\\"7\"", toJson("7\\\"7"));
it('should serialize strings with escaped characters', function() {
expect(toJson("7\\\"7")).toEqual("\"7\\\\\\\"7\"");
});
it('should parse Objects', function() {
assertEquals('{"a":1,"b":2}', toJson({a:1,b:2}));
assertEquals('{"a":{"b":2}}', toJson({a:{b:2}}));
assertEquals('{"a":{"b":{"c":0}}}', toJson({a:{b:{c:0}}}));
assertEquals('{"a":{"b":null}}', toJson({a:{b:0/0}}));
it('should serialize objects', function() {
expect(toJson({a:1,b:2})).toEqual('{"a":1,"b":2}');
expect(toJson({a:{b:2}})).toEqual('{"a":{"b":2}}');
expect(toJson({a:{b:{c:0}}})).toEqual('{"a":{"b":{"c":0}}}');
expect(toJson({a:{b:0/0}})).toEqual('{"a":{"b":null}}');
});
it('should parse ObjectPretty', function() {
assertEquals('{\n "a":1,\n "b":2}', toJson({a:1,b:2}, true));
assertEquals('{\n "a":{\n "b":2}}', toJson({a:{b:2}}, true));
it('should format objects pretty', function() {
expect(toJson({a:1,b:2}, true)).toEqual('{\n "a":1,\n "b":2}');
expect(toJson({a:{b:2}}, true)).toEqual('{\n "a":{\n "b":2}}');
});
it('should parse Array', function() {
assertEquals('[]', toJson([]));
assertEquals('[1,"b"]', toJson([1,"b"]));
it('should serialize array', function() {
expect(toJson([])).toEqual('[]');
expect(toJson([1,"b"])).toEqual('[1,"b"]');
});
it('should parse IgnoreFunctions', function() {
assertEquals('[null,1]', toJson([function(){},1]));
assertEquals('{}', toJson({a:function(){}}));
it('should serialize RegExp', function() {
expect(toJson(/foo/)).toEqual('"/foo/"');
expect(toJson([1,new RegExp("foo")])).toEqual('[1,"/foo/"]');
});
it('should parse ParseNull', function() {
assertNull(fromJson("null"));
it('should ignore functions', function() {
expect(toJson([function(){},1])).toEqual('[null,1]');
expect(toJson({a:function(){}})).toEqual('{}');
});
it('should parse ParseBoolean', function() {
assertTrue(fromJson("true"));
assertFalse(fromJson("false"));
it('should parse null', function() {
expect(fromJson("null")).toBeNull();
});
it('should parse $$isIgnored', function() {
assertEquals("{}", toJson({$$:0}));
it('should parse boolean', function() {
expect(fromJson("true")).toBeTruthy();
expect(fromJson("false")).toBeFalsy();
});
it('should parse ArrayWithEmptyItems', function() {
it('should serialize array with empty items', function() {
var a = [];
a[1] = "X";
assertEquals('[null,"X"]', toJson(a));
expect(toJson(a)).toEqual('[null,"X"]');
});
it('should parse ItShouldEscapeUnicode', function() {
assertEquals(1, "\u00a0".length);
assertEquals(8, toJson("\u00a0").length);
assertEquals(1, fromJson(toJson("\u00a0")).length);
it('should escape unicode', function() {
expect("\u00a0".length).toEqual(1);
expect(toJson("\u00a0").length).toEqual(8);
expect(fromJson(toJson("\u00a0")).length).toEqual(1);
});
it('should parse ItShouldUTCDates', function() {
var date = angular.String.toDate("2009-10-09T01:02:03Z");
assertEquals('"2009-10-09T01:02:03Z"', toJson(date));
assertEquals(date.getTime(),
fromJson('"2009-10-09T01:02:03Z"').getTime());
it('should serialize UTC dates', function() {
var date = angular.String.toDate("2009-10-09T01:02:03.027Z");
expect(toJson(date)).toEqual('"2009-10-09T01:02:03.027Z"');
expect(fromJson('"2009-10-09T01:02:03.027Z"').getTime()).toEqual(date.getTime());
});
it('should parse ItShouldPreventRecursion', function() {
it('should prevent recursion', function() {
var obj = {a:'b'};
obj.recursion = obj;
assertEquals('{"a":"b","recursion":RECURSION}', angular.toJson(obj));
expect(angular.toJson(obj)).toEqual('{"a":"b","recursion":RECURSION}');
});
it('should parse ItShouldIgnore$Properties', function() {
var scope = createScope();
scope.a = 'a';
scope['$b'] = '$b';
scope.c = 'c';
expect(angular.toJson(scope)).toEqual('{"a":"a","c":"c","this":RECURSION}');
it('should serialize $ properties', function() {
var obj = {$a: 'a'};
expect(angular.toJson(obj)).toEqual('{"$a":"a"}');
});
it('should parse ItShouldSerializeInheritedProperties', function() {
var scope = createScope({p:'p'});
scope.a = 'a';
expect(angular.toJson(scope)).toEqual('{"a":"a","p":"p","this":RECURSION}');
it('should serialize inherited properties', function() {
var obj = inherit({p:'p'});
obj.a = 'a';
expect(angular.toJson(obj)).toEqual('{"a":"a","p":"p"}');
});
it('should parse ItShouldSerializeSameObjectsMultipleTimes', function() {
it('should serialize same objects multiple times', function() {
var obj = {a:'b'};
assertEquals('{"A":{"a":"b"},"B":{"a":"b"}}', angular.toJson({A:obj, B:obj}));
expect(angular.toJson({A:obj, B:obj})).toEqual('{"A":{"a":"b"},"B":{"a":"b"}}');
});
it('should parse ItShouldNotSerializeUndefinedValues', function() {
assertEquals('{}', angular.toJson({A:undefined}));
it('should not serialize undefined values', function() {
expect(angular.toJson({A:undefined})).toEqual('{}');
});
it('should not serialize $window object', function() {
expect(toJson(window)).toEqual('WINDOW');
});
it('should not serialize $document object', function() {
expect(toJson(document)).toEqual('DOCUMENT');
});
it('should parse ItShouldParseFloats', function() {
it('should parse floats', function() {
expect(fromJson("{value:2.55, name:'misko'}")).toEqual({value:2.55, name:'misko'});
});
@@ -104,35 +109,48 @@ describe('json', function(){
expect(fromJson("{neg:-2.55, pos:+.3, a:[-2, +.1, -.2, +.3]}")).toEqual({neg:-2.55, pos:+.3, a:[-2, +.1, -.2, +.3]});
});
it('should parse exponents', function() {
expect(fromJson("{exp:1.2E10}")).toEqual({exp:1.2E10});
expect(fromJson("{exp:1.2E-10}")).toEqual({exp:1.2E-10});
expect(fromJson("{exp:1.2e+10}")).toEqual({exp:1.2E10});
expect(fromJson("{exp:1.2e-10}")).toEqual({exp:1.2E-10});
});
describe('security', function(){
it('should not allow naked expressions', function(){
expect(function(){fromJson('1+2');}).toThrow("Did not understand '+2' while evaluating '1+2'.");
expect(function(){fromJson('1+2');}).
toThrow(new Error("Parse Error: Token '+' is extra token not part of expression at column 2 of expression [1+2] starting at [+2]."));
});
it('should not allow naked expressions group', function(){
expect(function(){fromJson('(1+2)');}).toThrow("Expression at column='0' of expression '(1+2)' starting at '(1+2)' is not valid json.");
expect(function(){fromJson('(1+2)');}).
toThrow(new Error("Parse Error: Token '(' is not valid json at column 1 of expression [(1+2)] starting at [(1+2)]."));
});
it('should not allow expressions in objects', function(){
expect(function(){fromJson('{a:abc()}');}).toThrow("Expression at column='3' of expression '{a:abc()}' starting at 'abc()}' is not valid json.");
expect(function(){fromJson('{a:abc()}');}).
toThrow(new Error("Parse Error: Token 'abc' is not valid json at column 4 of expression [{a:abc()}] starting at [abc()}]."));
});
it('should not allow expressions in arrays', function(){
expect(function(){fromJson('[1+2]');}).toThrow("Expression at column='2' of expression '[1+2]' starting at '+2]' is not valid json.");
expect(function(){fromJson('[1+2]');}).
toThrow(new Error("Parse Error: Token '+' is not valid json at column 3 of expression [[1+2]] starting at [+2]]."));
});
it('should not allow vars', function(){
expect(function(){fromJson('[1, x]');}).toThrow("Expression at column='4' of expression '[1, x]' starting at 'x]' is not valid json.");
expect(function(){fromJson('[1, x]');}).
toThrow(new Error("Parse Error: Token 'x' is not valid json at column 5 of expression [[1, x]] starting at [x]]."));
});
it('should not allow dereference', function(){
expect(function(){fromJson('["".constructor]');}).toThrow("Expression at column='3' of expression '[\"\".constructor]' starting at '.constructor]' is not valid json.");
expect(function(){fromJson('["".constructor]');}).
toThrow(new Error("Parse Error: Token '.' is not valid json at column 4 of expression [[\"\".constructor]] starting at [.constructor]]."));
});
it('should not allow expressions ofter valid json', function(){
expect(function(){fromJson('[].constructor');}).toThrow("Expression at column='2' of expression '[].constructor' starting at '.constructor' is not valid json.");
expect(function(){fromJson('[].constructor');}).
toThrow(new Error("Parse Error: Token '.' is not valid json at column 3 of expression [[].constructor] starting at [.constructor]."));
});
});
});
+222 -270
View File
@@ -1,146 +1,144 @@
describe('parser', function(){
describe('lexer', function(){
it('should TokenizeAString', function(){
describe('parser', function() {
describe('lexer', function() {
it('should tokenize a string', function() {
var tokens = lex("a.bc[22]+1.3|f:'a\\\'c':\"d\\\"e\"");
var i = 0;
assertEquals(tokens[i].index, 0);
assertEquals(tokens[i].text, 'a.bc');
expect(tokens[i].index).toEqual(0);
expect(tokens[i].text).toEqual('a.bc');
i++;
assertEquals(tokens[i].index, 4);
assertEquals(tokens[i].text, '[');
expect(tokens[i].index).toEqual(4);
expect(tokens[i].text).toEqual('[');
i++;
assertEquals(tokens[i].index, 5);
assertEquals(tokens[i].text, 22);
expect(tokens[i].index).toEqual(5);
expect(tokens[i].text).toEqual(22);
i++;
assertEquals(tokens[i].index, 7);
assertEquals(tokens[i].text, ']');
expect(tokens[i].index).toEqual(7);
expect(tokens[i].text).toEqual(']');
i++;
assertEquals(tokens[i].index, 8);
assertEquals(tokens[i].text, '+');
expect(tokens[i].index).toEqual(8);
expect(tokens[i].text).toEqual('+');
i++;
assertEquals(tokens[i].index, 9);
assertEquals(tokens[i].text, 1.3);
expect(tokens[i].index).toEqual(9);
expect(tokens[i].text).toEqual(1.3);
i++;
assertEquals(tokens[i].index, 12);
assertEquals(tokens[i].text, '|');
expect(tokens[i].index).toEqual(12);
expect(tokens[i].text).toEqual('|');
i++;
assertEquals(tokens[i].index, 13);
assertEquals(tokens[i].text, 'f');
expect(tokens[i].index).toEqual(13);
expect(tokens[i].text).toEqual('f');
i++;
assertEquals(tokens[i].index, 14);
assertEquals(tokens[i].text, ':');
expect(tokens[i].index).toEqual(14);
expect(tokens[i].text).toEqual(':');
i++;
assertEquals(tokens[i].index, 15);
assertEquals(tokens[i].string, "a'c");
expect(tokens[i].index).toEqual(15);
expect(tokens[i].string).toEqual("a'c");
i++;
assertEquals(tokens[i].index, 21);
assertEquals(tokens[i].text, ':');
expect(tokens[i].index).toEqual(21);
expect(tokens[i].text).toEqual(':');
i++;
assertEquals(tokens[i].index, 22);
assertEquals(tokens[i].string, 'd"e');
expect(tokens[i].index).toEqual(22);
expect(tokens[i].string).toEqual('d"e');
});
it('should TokenizeUndefined', function(){
it('should tokenize undefined', function() {
var tokens = lex("undefined");
var i = 0;
assertEquals(tokens[i].index, 0);
assertEquals(tokens[i].text, 'undefined');
assertEquals(undefined, tokens[i].fn());
expect(tokens[i].index).toEqual(0);
expect(tokens[i].text).toEqual('undefined');
expect(undefined).toEqual(tokens[i].fn());
});
it('should TokenizeRegExp', function(){
it('should tokenize RegExp', function() {
var tokens = lex("/r 1/");
var i = 0;
assertEquals(tokens[i].index, 0);
assertEquals(tokens[i].text, 'r 1');
assertEquals("r 1".match(tokens[i].fn())[0], 'r 1');
expect(tokens[i].index).toEqual(0);
expect(tokens[i].text).toEqual('r 1');
expect("r 1".match(tokens[i].fn())[0]).toEqual('r 1');
});
it('should QuotedString', function(){
it('should tokenize quoted string', function() {
var str = "['\\'', \"\\\"\"]";
var tokens = lex(str);
assertEquals(1, tokens[1].index);
assertEquals("'", tokens[1].string);
expect(tokens[1].index).toEqual(1);
expect(tokens[1].string).toEqual("'");
assertEquals(7, tokens[3].index);
assertEquals('"', tokens[3].string);
expect(tokens[3].index).toEqual(7);
expect(tokens[3].string).toEqual('"');
});
it('should QuotedStringEscape', function(){
it('should tokenize escaped quoted string', function() {
var str = '"\\"\\n\\f\\r\\t\\v\\u00A0"';
var tokens = lex(str);
assertEquals('"\n\f\r\t\v\u00A0', tokens[0].string);
expect(tokens[0].string).toEqual('"\n\f\r\t\v\u00A0');
});
it('should TokenizeUnicode', function(){
it('should tokenize unicode', function() {
var tokens = lex('"\\u00A0"');
assertEquals(1, tokens.length);
assertEquals('\u00a0', tokens[0].string);
expect(tokens.length).toEqual(1);
expect(tokens[0].string).toEqual('\u00a0');
});
it('should TokenizeRegExpWithOptions', function(){
it('should tokenize RegExp with options', function() {
var tokens = lex("/r/g");
var i = 0;
assertEquals(tokens[i].index, 0);
assertEquals(tokens[i].text, 'r');
assertEquals(tokens[i].flags, 'g');
assertEquals("rr".match(tokens[i].fn()).length, 2);
expect(tokens[i].index).toEqual(0);
expect(tokens[i].text).toEqual('r');
expect(tokens[i].flags).toEqual('g');
expect("rr".match(tokens[i].fn()).length).toEqual(2);
});
it('should TokenizeRegExpWithEscape', function(){
it('should tokenize RegExp with escaping', function() {
var tokens = lex("/\\/\\d/");
var i = 0;
assertEquals(tokens[i].index, 0);
assertEquals(tokens[i].text, '\\/\\d');
assertEquals("/1".match(tokens[i].fn())[0], '/1');
expect(tokens[i].index).toEqual(0);
expect(tokens[i].text).toEqual('\\/\\d');
expect("/1".match(tokens[i].fn())[0]).toEqual('/1');
});
it('should IgnoreWhitespace', function(){
it('should ignore whitespace', function() {
var tokens = lex("a \t \n \r b");
assertEquals(tokens[0].text, 'a');
assertEquals(tokens[1].text, 'b');
expect(tokens[0].text).toEqual('a');
expect(tokens[1].text).toEqual('b');
});
it('should Relation', function(){
it('should tokenize relation', function() {
var tokens = lex("! == != < > <= >=");
assertEquals(tokens[0].text, '!');
assertEquals(tokens[1].text, '==');
assertEquals(tokens[2].text, '!=');
assertEquals(tokens[3].text, '<');
assertEquals(tokens[4].text, '>');
assertEquals(tokens[5].text, '<=');
assertEquals(tokens[6].text, '>=');
expect(tokens[0].text).toEqual('!');
expect(tokens[1].text).toEqual('==');
expect(tokens[2].text).toEqual('!=');
expect(tokens[3].text).toEqual('<');
expect(tokens[4].text).toEqual('>');
expect(tokens[5].text).toEqual('<=');
expect(tokens[6].text).toEqual('>=');
});
it('should Statements', function(){
it('should tokenize statements', function() {
var tokens = lex("a;b;");
assertEquals(tokens[0].text, 'a');
assertEquals(tokens[1].text, ';');
assertEquals(tokens[2].text, 'b');
assertEquals(tokens[3].text, ';');
expect(tokens[0].text).toEqual('a');
expect(tokens[1].text).toEqual(';');
expect(tokens[2].text).toEqual('b');
expect(tokens[3].text).toEqual(';');
});
it('should Number', function(){
it('should tokenize number', function() {
var tokens = lex("0.5");
expect(tokens[0].text).toEqual(0.5);
});
it('should NegativeNumber', function(){
it('should tokenize negative number', function() {
var value = createScope().$eval("-0.5");
expect(value).toEqual(-0.5);
@@ -148,7 +146,7 @@ describe('parser', function(){
expect(value).toEqual({a:-0.5});
});
it('should NumberExponent', function(){
it('should tokenize number with exponent', function() {
var tokens = lex("0.5E-10");
expect(tokens[0].text).toEqual(0.5E-10);
expect(createScope().$eval("0.5E-10")).toEqual(0.5E-10);
@@ -157,308 +155,262 @@ describe('parser', function(){
expect(tokens[0].text).toEqual(0.5E+10);
});
it('should NumberExponentInvalid', function(){
assertThrows('Lexer found invalid exponential value "0.5E-"', function(){
it('should throws exception for invalid exponent', function() {
expect(function() {
lex("0.5E-");
});
assertThrows('Lexer found invalid exponential value "0.5E-A"', function(){
}).toThrow(new Error('Lexer Error: Invalid exponent at column 4 in expression [0.5E-].'));
expect(function() {
lex("0.5E-A");
});
}).toThrow(new Error('Lexer Error: Invalid exponent at column 4 in expression [0.5E-A].'));
});
it('should NumberStartingWithDot', function(){
it('should tokenize number starting with a dot', function() {
var tokens = lex(".5");
expect(tokens[0].text).toEqual(0.5);
});
it('should throw error on invalid unicode', function(){
assertThrows("Lexer Error: Invalid unicode escape [\\u1''b] starting at column '0' in expression ''\\u1''bla''.", function(){
it('should throw error on invalid unicode', function() {
expect(function() {
lex("'\\u1''bla'");
});
}).toThrow(new Error("Lexer Error: Invalid unicode escape [\\u1''b] at column 2 in expression ['\\u1''bla']."));
});
});
var scope;
beforeEach(function () {
scope = createScope();
});
it('should parse Expressions', function(){
var scope = createScope();
assertEquals(scope.$eval("-1"), -1);
assertEquals(scope.$eval("1 + 2.5"), 3.5);
assertEquals(scope.$eval("1 + -2.5"), -1.5);
assertEquals(scope.$eval("1+2*3/4"), 1+2*3/4);
assertEquals(scope.$eval("0--1+1.5"), 0- -1 + 1.5);
assertEquals(scope.$eval("-0--1++2*-3/-4"), -0- -1+ +2*-3/-4);
assertEquals(scope.$eval("1/2*3"), 1/2*3);
it('should parse expressions', function() {
expect(scope.$eval("-1")).toEqual(-1);
expect(scope.$eval("1 + 2.5")).toEqual(3.5);
expect(scope.$eval("1 + -2.5")).toEqual(-1.5);
expect(scope.$eval("1+2*3/4")).toEqual(1+2*3/4);
expect(scope.$eval("0--1+1.5")).toEqual(0- -1 + 1.5);
expect(scope.$eval("-0--1++2*-3/-4")).toEqual(-0- -1+ +2*-3/-4);
expect(scope.$eval("1/2*3")).toEqual(1/2*3);
});
it('should parse Comparison', function(){
var scope = createScope();
assertEquals(scope.$eval("false"), false);
assertEquals(scope.$eval("!true"), false);
assertEquals(scope.$eval("1==1"), true);
assertEquals(scope.$eval("1!=2"), true);
assertEquals(scope.$eval("1<2"), true);
assertEquals(scope.$eval("1<=1"), true);
assertEquals(scope.$eval("1>2"), 1>2);
assertEquals(scope.$eval("2>=1"), 2>=1);
assertEquals(true === 2<3, scope.$eval("true==2<3"));
it('should parse comparison', function() {
expect(scope.$eval("false")).toBeFalsy();
expect(scope.$eval("!true")).toBeFalsy();
expect(scope.$eval("1==1")).toBeTruthy();
expect(scope.$eval("1!=2")).toBeTruthy();
expect(scope.$eval("1<2")).toBeTruthy();
expect(scope.$eval("1<=1")).toBeTruthy();
expect(scope.$eval("1>2")).toEqual(1>2);
expect(scope.$eval("2>=1")).toEqual(2>=1);
expect(scope.$eval("true==2<3")).toEqual(true === 2<3);
});
it('should parse Logical', function(){
var scope = createScope();
assertEquals(scope.$eval("0&&2"), 0&&2);
assertEquals(scope.$eval("0||2"), 0||2);
assertEquals(scope.$eval("0||1&&2"), 0||1&&2);
it('should parse logical', function() {
expect(scope.$eval("0&&2")).toEqual(0&&2);
expect(scope.$eval("0||2")).toEqual(0||2);
expect(scope.$eval("0||1&&2")).toEqual(0||1&&2);
});
it('should parse String', function(){
var scope = createScope();
assertEquals(scope.$eval("'a' + 'b c'"), "ab c");
it('should parse string', function() {
expect(scope.$eval("'a' + 'b c'")).toEqual("ab c");
});
it('should parse Filters', function(){
it('should parse filters', function(){
angular.filter.substring = function(input, start, end) {
return input.substring(start, end);
};
angular.filter.upper = {_case:function(input) {
angular.filter.upper = {_case: function(input) {
return input.toUpperCase();
}};
var scope = createScope();
try {
expect(function() {
scope.$eval("1|nonExistant");
fail();
} catch (e) {
assertEquals(e, "Function 'nonExistant' at column '3' in '1|nonExistant' is not defined.");
}
}).toThrow(new Error("Parse Error: Token 'nonExistant' should be a function at column 3 of expression [1|nonExistant] starting at [nonExistant]."));
scope.$set('offset', 3);
assertEquals(scope.$eval("'abcd'|upper._case"), "ABCD");
assertEquals(scope.$eval("'abcd'|substring:1:offset"), "bc");
assertEquals(scope.$eval("'abcd'|substring:1:3|upper._case"), "BC");
expect(scope.$eval("'abcd'|upper._case")).toEqual("ABCD");
expect(scope.$eval("'abcd'|substring:1:offset")).toEqual("bc");
expect(scope.$eval("'abcd'|substring:1:3|upper._case")).toEqual("BC");
});
it('should parse ScopeAccess', function(){
var scope = createScope();
it('should access scope', function() {
scope.$set('a', 123);
scope.$set('b.c', 456);
assertEquals(scope.$eval("a", scope), 123);
assertEquals(scope.$eval("b.c", scope), 456);
assertEquals(scope.$eval("x.y.z", scope), undefined);
expect(scope.$eval("a", scope)).toEqual(123);
expect(scope.$eval("b.c", scope)).toEqual(456);
expect(scope.$eval("x.y.z", scope)).not.toBeDefined();
});
it('should parse Grouping', function(){
var scope = createScope();
assertEquals(scope.$eval("(1+2)*3"), (1+2)*3);
it('should evaluate grouped expressions', function() {
expect(scope.$eval("(1+2)*3")).toEqual((1+2)*3);
});
it('should parse Assignments', function(){
var scope = createScope();
assertEquals(scope.$eval("a=12"), 12);
assertEquals(scope.$get("a"), 12);
it('should evaluate assignments', function() {
expect(scope.$eval("a=12")).toEqual(12);
expect(scope.$get("a")).toEqual(12);
scope = createScope();
assertEquals(scope.$eval("x.y.z=123;"), 123);
assertEquals(scope.$get("x.y.z"), 123);
expect(scope.$eval("x.y.z=123;")).toEqual(123);
expect(scope.$get("x.y.z")).toEqual(123);
assertEquals(234, scope.$eval("a=123; b=234"));
assertEquals(123, scope.$get("a"));
assertEquals(234, scope.$get("b"));
expect(scope.$eval("a=123; b=234")).toEqual(234);
expect(scope.$get("a")).toEqual(123);
expect(scope.$get("b")).toEqual(234);
});
it('should parse FunctionCallsNoArgs', function(){
var scope = createScope();
it('should evaluate function call without arguments', function() {
scope.$set('const', function(a,b){return 123;});
assertEquals(scope.$eval("const()"), 123);
expect(scope.$eval("const()")).toEqual(123);
});
it('should parse FunctionCalls', function(){
var scope = createScope();
scope.$set('add', function(a,b){
it('should evaluate function call with arguments', function() {
scope.$set('add', function(a,b) {
return a+b;
});
assertEquals(3, scope.$eval("add(1,2)"));
expect(scope.$eval("add(1,2)")).toEqual(3);
});
it('should parse CalculationBug', function(){
var scope = createScope();
it('should evaluate multiplication and division', function() {
scope.$set('taxRate', 8);
scope.$set('subTotal', 100);
assertEquals(scope.$eval("taxRate / 100 * subTotal"), 8);
assertEquals(scope.$eval("subTotal * taxRate / 100"), 8);
expect(scope.$eval("taxRate / 100 * subTotal")).toEqual(8);
expect(scope.$eval("subTotal * taxRate / 100")).toEqual(8);
});
it('should parse Array', function(){
var scope = createScope();
assertEquals(scope.$eval("[]").length, 0);
assertEquals(scope.$eval("[1, 2]").length, 2);
assertEquals(scope.$eval("[1, 2]")[0], 1);
assertEquals(scope.$eval("[1, 2]")[1], 2);
it('should evaluate array', function() {
expect(scope.$eval("[]").length).toEqual(0);
expect(scope.$eval("[1, 2]").length).toEqual(2);
expect(scope.$eval("[1, 2]")[0]).toEqual(1);
expect(scope.$eval("[1, 2]")[1]).toEqual(2);
});
it('should parse ArrayAccess', function(){
var scope = createScope();
assertEquals(scope.$eval("[1][0]"), 1);
assertEquals(scope.$eval("[[1]][0][0]"), 1);
assertEquals(scope.$eval("[].length"), 0);
assertEquals(scope.$eval("[1, 2].length"), 2);
it('should evaluate array access', function() {
expect(scope.$eval("[1][0]")).toEqual(1);
expect(scope.$eval("[[1]][0][0]")).toEqual(1);
expect(scope.$eval("[].length")).toEqual(0);
expect(scope.$eval("[1, 2].length")).toEqual(2);
});
it('should parse Object', function(){
var scope = createScope();
assertEquals(toJson(scope.$eval("{}")), "{}");
assertEquals(toJson(scope.$eval("{a:'b'}")), '{"a":"b"}');
assertEquals(toJson(scope.$eval("{'a':'b'}")), '{"a":"b"}');
assertEquals(toJson(scope.$eval("{\"a\":'b'}")), '{"a":"b"}');
it('should evaluate object', function() {
expect(toJson(scope.$eval("{}"))).toEqual("{}");
expect(toJson(scope.$eval("{a:'b'}"))).toEqual('{"a":"b"}');
expect(toJson(scope.$eval("{'a':'b'}"))).toEqual('{"a":"b"}');
expect(toJson(scope.$eval("{\"a\":'b'}"))).toEqual('{"a":"b"}');
});
it('should parse ObjectAccess', function(){
var scope = createScope();
assertEquals("WC", scope.$eval("{false:'WC', true:'CC'}[false]"));
it('should evaluate object access', function() {
expect(scope.$eval("{false:'WC', true:'CC'}[false]")).toEqual("WC");
});
it('should parse JSON', function(){
var scope = createScope();
assertEquals(toJson(scope.$eval("[{}]")), "[{}]");
assertEquals(toJson(scope.$eval("[{a:[]}, {b:1}]")), '[{"a":[]},{"b":1}]');
it('should evaluate JSON', function() {
expect(toJson(scope.$eval("[{}]"))).toEqual("[{}]");
expect(toJson(scope.$eval("[{a:[]}, {b:1}]"))).toEqual('[{"a":[]},{"b":1}]');
});
it('should parse MultippleStatements', function(){
var scope = createScope();
assertEquals(scope.$eval("a=1;b=3;a+b"), 4);
assertEquals(scope.$eval(";;1;;"), 1);
it('should evaluate multipple statements', function() {
expect(scope.$eval("a=1;b=3;a+b")).toEqual(4);
expect(scope.$eval(";;1;;")).toEqual(1);
});
it('should parse ParseThrow', function(){
expectAsserts(1);
var scope = createScope();
scope.$set('e', 'abc');
try {
scope.$eval("throw e");
} catch(e) {
assertEquals(e, 'abc');
}
});
it('should parse MethodsGetDispatchedWithCorrectThis', function(){
var scope = createScope();
var C = function (){
this.a=123;
it('should evaluate object methods in correct context (this)', function() {
var C = function () {
this.a = 123;
};
C.prototype.getA = function(){
C.prototype.getA = function() {
return this.a;
};
scope.$set("obj", new C());
assertEquals(123, scope.$eval("obj.getA()"));
expect(scope.$eval("obj.getA()")).toEqual(123);
});
it('should parse MethodsArgumentsGetCorrectThis', function(){
var scope = createScope();
var C = function (){
this.a=123;
it('should evaluate methods in correct context (this) in argument', function() {
var C = function () {
this.a = 123;
};
C.prototype.sum = function(value){
C.prototype.sum = function(value) {
return this.a + value;
};
C.prototype.getA = function(){
C.prototype.getA = function() {
return this.a;
};
scope.$set("obj", new C());
assertEquals(246, scope.$eval("obj.sum(obj.getA())"));
expect(scope.$eval("obj.sum(obj.getA())")).toEqual(246);
});
it('should parse ObjectPointsToScopeValue', function(){
var scope = createScope();
it('should evaluate objects on scope context', function() {
scope.$set('a', "abc");
assertEquals("abc", scope.$eval("{a:a}").a);
expect(scope.$eval("{a:a}").a).toEqual("abc");
});
it('should parse FieldAccess', function(){
var scope = createScope();
var fn = function(){
return {name:'misko'};
};
scope.$set('a', fn);
assertEquals("misko", scope.$eval("a().name"));
it('should evaluate field access on function call result', function() {
scope.$set('a', function() {
return {name:'misko'};
});
expect(scope.$eval("a().name")).toEqual("misko");
});
it('should parse ArrayIndexBug', function () {
var scope = createScope();
it('should evaluate field access after array access', function () {
scope.$set('items', [{}, {name:'misko'}]);
assertEquals("misko", scope.$eval('items[1].name'));
expect(scope.$eval('items[1].name')).toEqual("misko");
});
it('should parse ArrayAssignment', function () {
var scope = createScope();
it('should evaluate array assignment', function() {
scope.$set('items', []);
assertEquals("abc", scope.$eval('items[1] = "abc"'));
assertEquals("abc", scope.$eval('items[1]'));
expect(scope.$eval('items[1] = "abc"')).toEqual("abc");
expect(scope.$eval('items[1]')).toEqual("abc");
// Dont know how to make this work....
// assertEquals("moby", scope.$eval('books[1] = "moby"'));
// assertEquals("moby", scope.$eval('books[1]'));
// expect(scope.$eval('books[1] = "moby"')).toEqual("moby");
// expect(scope.$eval('books[1]')).toEqual("moby");
});
it('should parse FiltersCanBeGrouped', function () {
var scope = createScope({name:'MISKO'});
assertEquals('misko', scope.$eval('n = (name|lowercase)'));
assertEquals('misko', scope.$eval('n'));
it('should evaluate grouped filters', function() {
scope.name = 'MISKO';
expect(scope.$eval('n = (name|lowercase)')).toEqual('misko');
expect(scope.$eval('n')).toEqual('misko');
});
it('should parse Remainder', function () {
var scope = createScope();
assertEquals(1, scope.$eval('1%2'));
it('should evaluate remainder', function() {
expect(scope.$eval('1%2')).toEqual(1);
});
it('should parse SumOfUndefinedIsNotUndefined', function () {
var scope = createScope();
assertEquals(1, scope.$eval('1+undefined'));
assertEquals(1, scope.$eval('undefined+1'));
it('should evaluate sum with undefined', function() {
expect(scope.$eval('1+undefined')).toEqual(1);
expect(scope.$eval('undefined+1')).toEqual(1);
});
it('should parse MissingThrowsError', function(){
var scope = createScope();
try {
it('should throw exception on non-closed bracket', function() {
expect(function() {
scope.$eval('[].count(');
fail();
} catch (e) {
assertEquals('Unexpected end of expression: [].count(', e);
}
}).toThrow('Unexpected end of expression: [].count(');
});
it('should parse DoubleNegationBug', function (){
var scope = createScope();
assertEquals(true, scope.$eval('true'));
assertEquals(false, scope.$eval('!true'));
assertEquals(true, scope.$eval('!!true'));
assertEquals('a', scope.$eval('{true:"a", false:"b"}[!!true]'));
it('should evaluate double negation', function() {
expect(scope.$eval('true')).toBeTruthy();
expect(scope.$eval('!true')).toBeFalsy();
expect(scope.$eval('!!true')).toBeTruthy();
expect(scope.$eval('{true:"a", false:"b"}[!!true]')).toEqual('a');
});
it('should parse NegationBug', function () {
var scope = createScope();
assertEquals(!false || true, scope.$eval("!false || true"));
assertEquals(!11 == 10, scope.$eval("!11 == 10"));
assertEquals(12/6/2, scope.$eval("12/6/2"));
it('should evaluate negation', function() {
expect(scope.$eval("!false || true")).toEqual(!false || true);
expect(scope.$eval("!11 == 10")).toEqual(!11 == 10);
expect(scope.$eval("12/6/2")).toEqual(12/6/2);
});
it('should parse BugStringConfusesparser', function(){
var scope = createScope();
assertEquals('!', scope.$eval('suffix = "!"'));
it('should evaluate exclamation mark', function() {
expect(scope.$eval('suffix = "!"')).toEqual('!');
});
it('should parse ParsingBug', function () {
var scope = createScope();
assertEquals({a: "-"}, scope.$eval("{a:'-'}"));
it('should evaluate minus', function() {
expect(scope.$eval("{a:'-'}")).toEqual({a: "-"});
});
it('should parse Undefined', function () {
var scope = createScope();
assertEquals(undefined, scope.$eval("undefined"));
assertEquals(undefined, scope.$eval("a=undefined"));
assertEquals(undefined, scope.$get("a"));
it('should evaluate undefined', function() {
expect(scope.$eval("undefined")).not.toBeDefined();
expect(scope.$eval("a=undefined")).not.toBeDefined();
expect(scope.$get("a")).not.toBeDefined();
});
});
+39 -5
View File
@@ -96,6 +96,40 @@ describe('scope/model', function(){
model.$eval();
expect(count).toEqual(1);
});
it('should run listener upon registration by default', function() {
var model = createScope();
var count = 0,
nameNewVal = 'crazy val 1',
nameOldVal = 'crazy val 2';
model.$watch('name', function(newVal, oldVal){
count ++;
nameNewVal = newVal;
nameOldVal = oldVal;
});
expect(count).toBe(1);
expect(nameNewVal).not.toBeDefined();
expect(nameOldVal).not.toBeDefined();
});
it('should not run listener upon registration if flag is passed in', function() {
var model = createScope();
var count = 0,
nameNewVal = 'crazy val 1',
nameOldVal = 'crazy val 2';
model.$watch('name', function(newVal, oldVal){
count ++;
nameNewVal = newVal;
nameOldVal = oldVal;
}, undefined, false);
expect(count).toBe(0);
expect(nameNewVal).toBe('crazy val 1');
expect(nameOldVal).toBe('crazy val 2');
});
});
describe('$bind', function(){
@@ -109,17 +143,17 @@ describe('scope/model', function(){
describe('$tryEval', function(){
it('should report error on element', function(){
var scope = createScope();
scope.$tryEval('throw "myerror";', function(error){
scope.$tryEval(function(){throw "myError";}, function(error){
scope.error = error;
});
expect(scope.error).toEqual('myerror');
expect(scope.error).toEqual('myError');
});
it('should report error on visible element', function(){
var element = jqLite('<div></div>');
var scope = createScope();
scope.$tryEval('throw "myError"', element);
expect(element.attr('ng-exception')).toEqual('"myError"'); // errors are jsonified
scope.$tryEval(function(){throw "myError";}, element);
expect(element.attr('ng-exception')).toEqual('myError');
expect(element.hasClass('ng-exception')).toBeTruthy();
});
@@ -129,7 +163,7 @@ describe('scope/model', function(){
scope.$exceptionHandler = function(e){
this.error = e;
};
scope.$tryEval('throw "myError"');
scope.$tryEval(function(){throw "myError";});
expect(scope.error).toEqual("myError");
});
});
-6
View File
@@ -69,12 +69,6 @@ ValidatorTest.prototype.testPhone = function() {
assertEquals(null, angular.validator.phone("+421 0905 933 297"));
};
ValidatorTest.prototype.testSSN = function() {
var error = "SSN needs to be in 999-99-9999 format.";
assertEquals(angular.validator.ssn("ab"), error);
assertEquals(angular.validator.ssn("123-45-6789"), null);
};
ValidatorTest.prototype.testURL = function() {
var error = "URL needs to be in http://server[:port]/path format.";
assertEquals(angular.validator.url("ab"), error);
+33 -4
View File
@@ -195,12 +195,17 @@ angular.service('$browser', function(){
function TzDate(offset, timestamp) {
if (angular.isString(timestamp)) {
var tsStr = timestamp;
timestamp = angular.String.toDate(timestamp).getTime();
this.origDate = angular.String.toDate(timestamp);
timestamp = this.origDate.getTime();
if (isNaN(timestamp))
throw {
name: "Illegal Argument",
message: "Arg '" + tsStr + "' passed into TzDate constructor is not a valid date string"
};
} else {
this.origDate = new Date(timestamp);
}
var localOffset = new Date(timestamp).getTimezoneOffset();
@@ -243,10 +248,34 @@ function TzDate(offset, timestamp) {
return offset * 60;
};
this.getUTCFullYear = function() {
return this.origDate.getUTCFullYear();
};
this.getUTCMonth = function() {
return this.origDate.getUTCMonth();
};
this.getUTCDate = function() {
return this.origDate.getUTCDate();
};
this.getUTCHours = function() {
return this.origDate.getUTCHours();
};
this.getUTCMinutes = function() {
return this.origDate.getUTCMinutes();
};
this.getUTCSeconds = function() {
return this.origDate.getUTCSeconds();
};
//hide all methods not implemented in this mock that the Date prototype exposes
var unimplementedMethods = ['getDay', 'getMilliseconds', 'getTime', 'getUTCDate', 'getUTCDay',
'getUTCFullYear', 'getUTCHours', 'getUTCMilliseconds', 'getUTCMinutes', 'getUTCMonth',
'getUTCSeconds', 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds',
var unimplementedMethods = ['getDay', 'getMilliseconds', 'getTime', 'getUTCDay',
'getUTCMilliseconds', 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds',
'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear',
'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds',
'setYear', 'toDateString', 'toJSON', 'toGMTString', 'toLocaleFormat', 'toLocaleString',
+25 -3
View File
@@ -10,8 +10,8 @@ describe('TzDate', function() {
});
it('should take dateString as constructor argument', function() {
expect(new TzDate(0, '1970-01-01T00:00:00Z').getTime()).toBe(0);
expect(new TzDate(0, '2010-09-03T23:05:08Z').getTime()).toBe(1283555108000);
expect(new TzDate(0, '1970-01-01T00:00:00.000Z').getTime()).toBe(0);
expect(new TzDate(0, '2010-09-03T23:05:08.023Z').getTime()).toBe(1283555108023);
});
@@ -88,7 +88,7 @@ describe('TzDate', function() {
it('should create a date representing new year in Bratislava', function() {
var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00Z');
var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00.000Z');
expect(newYearInBratislava.getTimezoneOffset()).toBe(-60);
expect(newYearInBratislava.getFullYear()).toBe(2010);
expect(newYearInBratislava.getMonth()).toBe(0);
@@ -96,4 +96,26 @@ describe('TzDate', function() {
expect(newYearInBratislava.getHours()).toBe(0);
expect(newYearInBratislava.getMinutes()).toBe(0);
});
it('should delegate all the UTC methods to the original UTC Date object', function() {
//from when created from string
var date1 = new TzDate(-1, '2009-12-31T23:00:00.000Z');
expect(date1.getUTCFullYear()).toBe(2009);
expect(date1.getUTCMonth()).toBe(11);
expect(date1.getUTCDate()).toBe(31);
expect(date1.getUTCHours()).toBe(23);
expect(date1.getUTCMinutes()).toBe(0);
expect(date1.getUTCSeconds()).toBe(0);
//from when created from millis
var date2 = new TzDate(-1, angular.String.toDate('2009-12-31T23:00:00.000Z').getTime());
expect(date2.getUTCFullYear()).toBe(2009);
expect(date2.getUTCMonth()).toBe(11);
expect(date2.getUTCDate()).toBe(31);
expect(date2.getUTCHours()).toBe(23);
expect(date2.getUTCMinutes()).toBe(0);
expect(date2.getUTCSeconds()).toBe(0);
});
});
+5 -43
View File
@@ -1,4 +1,4 @@
describe("directives", function(){
describe("directive", function(){
var compile, model, element;
@@ -35,6 +35,7 @@ describe("directives", function(){
expect(element.text()).toEqual('');
scope.a = 'misko';
scope.$eval();
expect(element.hasClass('ng-binding')).toEqual(true);
expect(element.text()).toEqual('misko');
});
@@ -87,6 +88,7 @@ describe("directives", function(){
var scope = compile('<div ng:bind-template="Hello {{name}}!"></div>');
scope.$set('name', 'Misko');
scope.$eval();
expect(element.hasClass('ng-binding')).toEqual(true);
expect(element.text()).toEqual('Hello Misko!');
});
@@ -126,56 +128,16 @@ describe("directives", function(){
expect(input.checked).toEqual(true);
});
it('should ng:non-bindable', function(){
var scope = compile('<div ng:non-bindable><span ng:bind="name"></span></div>');
scope.$set('name', 'misko');
scope.$eval();
expect(element.text()).toEqual('');
});
it('should ng:repeat over array', function(){
var scope = compile('<ul><li ng:repeat="item in items" ng:init="suffix = \';\'" ng:bind="item + suffix"></li></ul>');
Array.prototype.extraProperty = "should be ignored";
scope.items = ['misko', 'shyam'];
scope.$eval();
expect(element.text()).toEqual('misko;shyam;');
delete Array.prototype.extraProperty;
scope.items = ['adam', 'kai', 'brad'];
scope.$eval();
expect(element.text()).toEqual('adam;kai;brad;');
scope.items = ['brad'];
scope.$eval();
expect(element.text()).toEqual('brad;');
});
it('should ng:repeat over object', function(){
var scope = compile('<ul><li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li></ul>');
scope.$set('items', {misko:'swe', shyam:'set'});
scope.$eval();
expect(element.text()).toEqual('misko:swe;shyam:set;');
});
it('should error on wrong parsing of ng:repeat', function(){
var scope = compile('<ul><li ng:repeat="i dont parse"></li></ul>');
var log = "";
log += element.attr('ng-exception') + ';';
log += element.hasClass('ng-exception') + ';';
expect(log).toEqual("\"Expected ng:repeat in form of 'item in collection' but got 'i dont parse'.\";true;");
});
it('should ng:watch', function(){
var scope = compile('<div ng:watch="i: count = count + 1" ng:init="count = 0">');
scope.$eval();
scope.$eval();
expect(scope.$get('count')).toEqual(0);
expect(scope.$get('count')).toEqual(1);
scope.$set('i', 0);
scope.$eval();
scope.$eval();
expect(scope.$get('count')).toEqual(1);
expect(scope.$get('count')).toEqual(2);
});
describe('ng:click', function(){
+117 -16
View File
@@ -1,15 +1,25 @@
describe('angular.scenario.Application', function() {
var $window;
var app, frames;
function callLoadHandlers(app) {
var handlers = app.getFrame_().data('events').load;
expect(handlers).toBeDefined();
expect(handlers.length).toEqual(1);
handlers[0].handler();
}
beforeEach(function() {
frames = _jQuery("<div></div>");
app = new angular.scenario.Application(frames);
app.checkUrlStatus_ = function(url, callback) {
callback.call(this);
};
});
it('should return new $window and $document after navigate', function() {
var called;
var testWindow, testDocument, counter = 0;
app.navigateTo = noop;
app.getWindow_ = function() {
return {x:counter++, document:{x:counter++}};
};
@@ -43,42 +53,70 @@ describe('angular.scenario.Application', function() {
});
it('should use a new iframe each time', function() {
app.navigateTo('about:blank');
app.navigateTo('http://localhost/');
var frame = app.getFrame_();
frame.attr('test', true);
app.navigateTo('about:blank');
app.navigateTo('http://localhost/');
expect(app.getFrame_().attr('test')).toBeFalsy();
});
it('should call error handler if document not accessible', function() {
var called;
app.getWindow_ = function() {
return {};
};
app.navigateTo('http://localhost/', angular.noop, function(error) {
expect(error).toMatch(/Sandbox Error/);
called = true;
});
callLoadHandlers(app);
expect(called).toBeTruthy();
});
it('should call error handler if navigating to about:blank', function() {
var called;
app.navigateTo('about:blank', angular.noop, function(error) {
expect(error).toMatch(/Sandbox Error/);
called = true;
});
expect(called).toBeTruthy();
});
it('should call error handler if status check fails', function() {
app.checkUrlStatus_ = function(url, callback) {
callback.call(this, 'Example Error');
};
app.navigateTo('http://localhost/', angular.noop, function(error) {
expect(error).toEqual('Example Error');
});
});
it('should hide old iframes and navigate to about:blank', function() {
app.navigateTo('about:blank#foo');
app.navigateTo('about:blank#bar');
app.navigateTo('http://localhost/#foo');
app.navigateTo('http://localhost/#bar');
var iframes = frames.find('iframe');
expect(iframes.length).toEqual(2);
expect(iframes[0].src).toEqual('about:blank');
expect(iframes[1].src).toEqual('about:blank#bar');
expect(iframes[1].src).toEqual('http://localhost/#bar');
expect(_jQuery(iframes[0]).css('display')).toEqual('none');
});
it('should URL update description bar', function() {
app.navigateTo('about:blank');
app.navigateTo('http://localhost/');
var anchor = frames.find('> h2 a');
expect(anchor.attr('href')).toEqual('about:blank');
expect(anchor.text()).toEqual('about:blank');
expect(anchor.attr('href')).toEqual('http://localhost/');
expect(anchor.text()).toEqual('http://localhost/');
});
it('should call onload handler when frame loads', function() {
var called;
app.getWindow_ = function() {
return {};
return {document: {}};
};
app.navigateTo('about:blank', function($window, $document) {
app.navigateTo('http://localhost/', function($window, $document) {
called = true;
});
var handlers = app.getFrame_().data('events').load;
expect(handlers).toBeDefined();
expect(handlers.length).toEqual(1);
handlers[0].handler();
callLoadHandlers(app);
expect(called).toBeTruthy();
});
@@ -99,7 +137,7 @@ describe('angular.scenario.Application', function() {
notifyWhenNoOutstandingRequests: function(fn) {
handlers.push(fn);
}
}
};
};
app.getWindow_ = function() {
return testWindow;
@@ -113,4 +151,67 @@ describe('angular.scenario.Application', function() {
expect(handlers.length).toEqual(1);
handlers[0]();
});
describe('jQuery ajax', function() {
var options;
var response;
var jQueryAjax;
beforeEach(function() {
response = {
status: 200,
statusText: 'OK'
};
jQueryAjax = _jQuery.ajax;
_jQuery.ajax = function(opts) {
options = opts;
opts.complete.call(this, response);
};
app.checkUrlStatus_ = angular.scenario.Application.
prototype.checkUrlStatus_;
});
afterEach(function() {
_jQuery.ajax = jQueryAjax;
});
it('should perform a HEAD request to verify file existence', function() {
app.navigateTo('http://www.google.com/', angular.noop, angular.noop);
expect(options.type).toEqual('HEAD');
expect(options.url).toEqual('http://www.google.com/');
});
it('should call error handler if status code is less than 200', function() {
var finished;
response.status = 199;
response.statusText = 'Error Message';
app.navigateTo('http://localhost/', angular.noop, function(error) {
expect(error).toEqual('199 Error Message');
finished = true;
});
expect(finished).toBeTruthy();
});
it('should call error handler if status code is greater than 299', function() {
var finished;
response.status = 300;
response.statusText = 'Error';
app.navigateTo('http://localhost/', angular.noop, function(error) {
expect(error).toEqual('300 Error');
finished = true;
});
expect(finished).toBeTruthy();
});
it('should call error handler if status code is 0 for sandbox error', function() {
var finished;
response.status = 0;
response.statusText = '';
app.navigateTo('http://localhost/', angular.noop, function(error) {
expect(error).toEqual('Sandbox Error: Cannot access http://localhost/');
finished = true;
});
expect(finished).toBeTruthy();
});
});
});
+212 -24
View File
@@ -87,26 +87,89 @@ describe("angular.scenario.dsl", function() {
});
});
describe('NavigateTo', function() {
it('should allow a string url', function() {
$root.dsl.navigateTo('http://myurl');
expect($window.location).toEqual('http://myurl');
expect($root.futureResult).toEqual('http://myurl');
});
it('should allow a future url', function() {
$root.dsl.navigateTo('http://myurl', function() {
return 'http://futureUrl/';
describe('Browser', function() {
describe('Reload', function() {
it('should navigateTo', function() {
$window.location = {
href: '#foo'
};
$root.dsl.browser().reload();
expect($root.futureResult).toEqual('#foo');
expect($window.location).toEqual('#foo');
});
expect($window.location).toEqual('http://futureUrl/');
expect($root.futureResult).toEqual('http://futureUrl/');
});
it('should complete if angular is missing from app frame', function() {
delete $window.angular;
$root.dsl.navigateTo('http://myurl');
expect($window.location).toEqual('http://myurl');
expect($root.futureResult).toEqual('http://myurl');
describe('NavigateTo', function() {
it('should allow a string url', function() {
$root.dsl.browser().navigateTo('http://myurl');
expect($window.location).toEqual('http://myurl');
expect($root.futureResult).toEqual('http://myurl');
});
it('should allow a future url', function() {
$root.dsl.browser().navigateTo('http://myurl', function() {
return 'http://futureUrl/';
});
expect($window.location).toEqual('http://futureUrl/');
expect($root.futureResult).toEqual('http://futureUrl/');
});
it('should complete if angular is missing from app frame', function() {
delete $window.angular;
$root.dsl.browser().navigateTo('http://myurl');
expect($window.location).toEqual('http://myurl');
expect($root.futureResult).toEqual('http://myurl');
});
});
describe('Location', function() {
beforeEach(function() {
$window.location = {
href: 'http://myurl/some/path?foo=10#/bar?x=2',
pathname: '/some/path',
search: '?foo=10',
hash: '#bar?x=2'
};
$window.angular.scope = function() {
return {
$location: {
hashSearch: {x: 2},
hashPath: '/bar',
search: {foo: 10}
}
};
};
});
it('should return full URL for href', function() {
$root.dsl.browser().location().href();
expect($root.futureResult).toEqual($window.location.href);
});
it('should return the pathname', function() {
$root.dsl.browser().location().path();
expect($root.futureResult).toEqual($window.location.pathname);
});
it('should return the hash without the #', function() {
$root.dsl.browser().location().hash();
expect($root.futureResult).toEqual('bar?x=2');
});
it('should return the query string as an object', function() {
$root.dsl.browser().location().search();
expect($root.futureResult).toEqual({foo: 10});
});
it('should return the hashSearch as an object', function() {
$root.dsl.browser().location().hashSearch();
expect($root.futureResult).toEqual({x: 2});
});
it('should return the hashPath', function() {
$root.dsl.browser().location().hashPath();
expect($root.futureResult).toEqual('/bar');
});
});
});
@@ -203,6 +266,26 @@ describe("angular.scenario.dsl", function() {
expect(doc.find('div').attr('class')).toEqual('bam');
});
it('should get css', function() {
doc.append('<div id="test" style="border: 1px solid red"></div>');
$root.dsl.element('#test').css('border');
expect($root.futureResult).toMatch(/red/);
});
it('should set css', function() {
doc.append('<div id="test" style="border: 1px solid red"></div>');
$root.dsl.element('#test').css('border', '1px solid green');
expect(doc.find('#test').css('border')).toMatch(/green/);
});
it('should add all jQuery key/value methods', function() {
var METHODS = ['css', 'attr'];
var chain = $root.dsl.element('input');
angular.foreach(METHODS, function(name) {
expect(angular.isFunction(chain[name])).toBeTruthy();
});
});
it('should get val', function() {
doc.append('<input value="bar">');
$root.dsl.element('input').val();
@@ -215,6 +298,29 @@ describe("angular.scenario.dsl", function() {
expect(doc.find('input').val()).toEqual('baz');
});
it('should use correct future name for generated set methods', function() {
doc.append('<input value="bar">');
$root.dsl.element('input').val(false);
expect($root.futures.pop()).toMatch(/element 'input' set val/);
});
it('should use correct future name for generated get methods', function() {
doc.append('<input value="bar">');
$root.dsl.element('input').val();
expect($root.futures.pop()).toMatch(/element 'input' val/);
});
it('should add all jQuery property methods', function() {
var METHODS = [
'val', 'text', 'html', 'height', 'innerHeight', 'outerHeight', 'width',
'innerWidth', 'outerWidth', 'position', 'scrollLeft', 'scrollTop', 'offset'
];
var chain = $root.dsl.element('input');
angular.foreach(METHODS, function(name) {
expect(angular.isFunction(chain[name])).toBeTruthy();
});
});
it('should execute custom query', function() {
doc.append('<a id="test" href="http://example.com/myUrl"></a>');
$root.dsl.element('#test').query(function(elements, done) {
@@ -222,6 +328,16 @@ describe("angular.scenario.dsl", function() {
});
expect($root.futureResult).toEqual('http://example.com/myUrl');
});
it('should use the selector as label if none is given', function() {
$root.dsl.element('mySelector');
expect($root.label).toEqual('mySelector');
});
it('should include the selector in paren when a label is given', function() {
$root.dsl.element('mySelector', 'myLabel');
expect($root.label).toEqual('myLabel ( mySelector )');
});
});
describe('Repeater', function() {
@@ -229,8 +345,10 @@ describe("angular.scenario.dsl", function() {
beforeEach(function() {
doc.append(
'<ul>' +
' <li ng:repeat-index="0"><span ng:bind="name">misko</span><span ng:bind="gender">male</span></li>' +
' <li ng:repeat-index="1"><span ng:bind="name">felisa</span><span ng:bind="gender">female</span></li>' +
' <li ng:repeat-index="0"><span ng:bind="name" class="ng-binding">misko</span>' +
' <span ng:bind="test && gender" class="ng-binding">male</span></li>' +
' <li ng:repeat-index="1"><span ng:bind="name" class="ng-binding">felisa</span>' +
' <span ng:bind="gender | uppercase" class="ng-binding">female</span></li>' +
'</ul>'
);
chain = $root.dsl.repeater('ul li');
@@ -256,24 +374,67 @@ describe("angular.scenario.dsl", function() {
chain.column('gender');
expect($root.futureResult).toEqual(['male', 'female']);
});
it('should use the selector as label if none is given', function() {
expect($root.label).toEqual('ul li');
});
it('should include the selector in paren when a label is given', function() {
$root.dsl.repeater('mySelector', 'myLabel');
expect($root.label).toEqual('myLabel ( ul li mySelector )');
});
});
describe('Binding', function() {
it('should select binding by name', function() {
if (msie) return; // TODO reenable!
doc.append('<span ng:bind="foo.bar">some value</span>');
doc.append('<span class="ng-binding" ng:bind="foo.bar">some value</span>');
$root.dsl.binding('foo.bar');
expect($root.futureResult).toEqual('some value');
});
it('should select binding by regexp', function() {
doc.append('<span class="ng-binding" ng:bind="foo.bar">some value</span>');
$root.dsl.binding(/^foo\..+/);
expect($root.futureResult).toEqual('some value');
});
it('should return value for input elements', function() {
doc.append('<input type="text" class="ng-binding" ng:bind="foo.bar" value="some value"/>');
$root.dsl.binding('foo.bar');
expect($root.futureResult).toEqual('some value');
});
it('should return value for textarea elements', function() {
doc.append('<textarea class="ng-binding" ng:bind="foo.bar">some value</textarea>');
$root.dsl.binding('foo.bar');
expect($root.futureResult).toEqual('some value');
});
it('should return innerHTML for all the other elements', function() {
doc.append('<div class="ng-binding" ng:bind="foo.bar">some <b>value</b></div>');
$root.dsl.binding('foo.bar');
expect($root.futureResult.toLowerCase()).toEqual('some <b>value</b>');
});
it('should select binding in template by name', function() {
if (msie) return; // TODO reenable!
doc.append('<pre ng:bind-template="foo {{bar}} baz">foo some baz</pre>');
doc.append('<pre class="ng-binding" ng:bind-template="foo {{bar}} baz">foo some baz</pre>');
$root.dsl.binding('bar');
expect($root.futureResult).toEqual('foo some baz');
});
it('should return error if no binding exists', function() {
it('should match bindings by substring match', function() {
doc.append('<pre class="ng-binding" ng:bind="foo.bar() && test.baz() | filter">binding value</pre>');
$root.dsl.binding('test.baz');
expect($root.futureResult).toEqual('binding value');
});
it('should return error if no bindings in document', function() {
$root.dsl.binding('foo.bar');
expect($root.futureError).toMatch(/did not match/);
});
it('should return error if no binding matches', function() {
doc.append('<span class="ng-binding" ng:bind="foo">some value</span>');
$root.dsl.binding('foo.bar');
expect($root.futureError).toMatch(/did not match/);
});
@@ -292,6 +453,17 @@ describe("angular.scenario.dsl", function() {
expect(inputs.first().val()).toEqual('something');
expect(inputs.last().val()).toEqual('foo');
});
it('should use the selector as label if none is given', function() {
$root.dsl.using('mySelector');
expect($root.label).toEqual('mySelector');
});
it('should include the selector in paren when a label is given', function() {
$root.dsl.using('mySelector', 'myLabel');
expect($root.label).toEqual('myLabel ( mySelector )');
});
});
describe('Input', function() {
@@ -354,5 +526,21 @@ describe("angular.scenario.dsl", function() {
});
});
describe('Textarea', function() {
it('should change value in textarea', function() {
doc.append('<textarea name="test.textarea">something</textarea>');
var chain = $root.dsl.input('test.textarea');
chain.enter('foo');
expect(_jQuery('textarea[name="test.textarea"]').val()).toEqual('foo');
});
it('should return error if no textarea exists', function() {
var chain = $root.dsl.input('test.textarea');
chain.enter('foo');
expect($root.futureError).toMatch(/did not match/);
});
});
});
});
+48
View File
@@ -70,6 +70,42 @@ describe("service", function(){
scope.$log.info();
scope.$log.error();
});
describe('Error', function(){
var e, $log, $console, errorArgs;
beforeEach(function(){
e = new Error('');
e.message = undefined;
e.sourceURL = undefined;
e.line = undefined;
e.stack = undefined;
$console = angular.service('$log')({console:{error:function(){
errorArgs = arguments;
}}});
});
it('should pass error if does not have trace', function(){
$console.error('abc', e);
expect(errorArgs).toEqual(['abc', e]);
});
it('should print stack', function(){
e.stack = 'stack';
$console.error('abc', e);
expect(errorArgs).toEqual(['abc', 'stack']);
});
it('should print line', function(){
e.message = 'message';
e.sourceURL = 'sourceURL';
e.line = '123';
$console.error('abc', e);
expect(errorArgs).toEqual(['abc', 'message\nsourceURL:123']);
});
});
});
describe("$exceptionHandler", function(){
@@ -207,6 +243,18 @@ describe("service", function(){
expect(scope.$location.hashSearch).toEqual({a: 'b'});
expect(scope.$location.hashPath).toEqual('path');
});
it('should remove # if hash is empty', function() {
scope.$location.update('http://www.angularjs.org/index.php#');
expect(scope.$location.href).toEqual('http://www.angularjs.org/index.php');
});
it('should not change browser\'s url with empty hash', function() {
$browser.setUrl('http://www.angularjs.org/index.php#');
spyOn($browser, 'setUrl');
$browser.poll();
expect($browser.setUrl).not.toHaveBeenCalled();
});
});
describe("$invalidWidgets", function(){
+9 -3
View File
@@ -81,7 +81,7 @@ extend(angular, {
});
function sortedHtml(element) {
function sortedHtml(element, showNgClass) {
var html = "";
foreach(jqLite(element), function toString(node) {
if (node.nodeName == "#text") {
@@ -93,8 +93,14 @@ function sortedHtml(element) {
html += '<' + node.nodeName.toLowerCase();
var attributes = node.attributes || [];
var attrs = [];
if (node.className)
attrs.push(' class="' + node.className + '"');
var className = node.className || '';
if (!showNgClass) {
className = className.replace(/ng-[\w-]+\s*/g, '');
}
className = trim(className);
if (className) {
attrs.push(' class="' + className + '"');
}
for(var i=0; i<attributes.length; i++) {
var attr = attributes[i];
if(attr.name.match(/^ng:/) ||
+120 -2
View File
@@ -11,6 +11,7 @@ describe("widget", function(){
(before||noop).apply(scope);
if (parent) parent.append(element);
scope.$init();
return scope;
};
});
@@ -430,7 +431,11 @@ describe("widget", function(){
describe('ng:switch', function(){
it('should switch on value change', function(){
compile('<ng:switch on="select"><div ng:switch-when="1">first:{{name}}</div><div ng:switch-when="2">second:{{name}}</div></ng:switch>');
compile('<ng:switch on="select">' +
'<div ng:switch-when="1">first:{{name}}</div>' +
'<div ng:switch-when="2">second:{{name}}</div>' +
'<div ng:switch-when="true">true:{{name}}</div>' +
'</ng:switch>');
expect(element.html()).toEqual('');
scope.select = 1;
scope.$eval();
@@ -444,8 +449,28 @@ describe("widget", function(){
scope.name = 'misko';
scope.$eval();
expect(element.text()).toEqual('second:misko');
scope.select = true;
scope.$eval();
expect(element.text()).toEqual('true:misko');
});
it("should compare stringified versions", function(){
var switchWidget = angular.widget('ng:switch');
expect(switchWidget.equals(true, 'true')).toEqual(true);
});
it('should switch on switch-when-default', function(){
compile('<ng:switch on="select">' +
'<div ng:switch-when="1">one</div>' +
'<div ng:switch-default>other</div>' +
'</ng:switch>');
scope.$eval();
expect(element.text()).toEqual('other');
scope.select = 1;
scope.$eval();
expect(element.text()).toEqual('one');
});
it("should match urls", function(){
var scope = angular.compile('<ng:switch on="url" using="route:params"><div ng:switch-when="/Book/:name">{{params.name}}</div></ng:switch>');
scope.url = '/Book/Moby';
@@ -459,7 +484,7 @@ describe("widget", function(){
expect(match).toBeFalsy();
});
it('should call init on switch', function(){
it('should call change on switch', function(){
var scope = angular.compile('<ng:switch on="url" change="name=\'works\'"><div ng:switch-when="a">{{name}}</div></ng:switch>');
var cleared = false;
scope.url = 'a';
@@ -508,6 +533,19 @@ describe("widget", function(){
// we need to have real events on the scopes.
expect(element.text()).toEqual('4');
});
it('should evaluate onload expression when a partial is loaded', function() {
var element = jqLite('<ng:include src="url" onload="loaded = true"></ng:include>');
var scope = angular.compile(element);
expect(scope.loaded).not.toBeDefined();
scope.url = 'myUrl';
scope.$inject('$xhr.cache').data.myUrl = {value:'my partial'};
scope.$init();
expect(element.text()).toEqual('my partial');
expect(scope.loaded).toBe(true);
});
});
describe('a', function() {
@@ -544,5 +582,85 @@ describe("widget", function(){
expect(document.location.href).toEqual(orgLocation);
});
});
describe('@ng:repeat', function() {
it('should ng:repeat over array', function(){
var scope = compile('<ul><li ng:repeat="item in items" ng:init="suffix = \';\'" ng:bind="item + suffix"></li></ul>');
Array.prototype.extraProperty = "should be ignored";
scope.items = ['misko', 'shyam'];
scope.$eval();
expect(element.text()).toEqual('misko;shyam;');
delete Array.prototype.extraProperty;
scope.items = ['adam', 'kai', 'brad'];
scope.$eval();
expect(element.text()).toEqual('adam;kai;brad;');
scope.items = ['brad'];
scope.$eval();
expect(element.text()).toEqual('brad;');
});
it('should ng:repeat over object', function(){
var scope = compile('<ul><li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li></ul>');
scope.$set('items', {misko:'swe', shyam:'set'});
scope.$eval();
expect(element.text()).toEqual('misko:swe;shyam:set;');
});
it('should error on wrong parsing of ng:repeat', function(){
var scope = compile('<ul><li ng:repeat="i dont parse"></li></ul>');
var log = "";
log += element.attr('ng-exception') + ';';
log += element.hasClass('ng-exception') + ';';
expect(log.match(/Expected ng:repeat in form of 'item in collection' but got 'i dont parse'./)).toBeTruthy();
});
it('should expose iterator offset as $index when iterating over arrays', function() {
var scope = compile('<ul><li ng:repeat="item in items" ' +
'ng:bind="item + $index + \'|\'"></li></ul>');
scope.items = ['misko', 'shyam', 'frodo'];
scope.$eval();
expect(element.text()).toEqual('misko0|shyam1|frodo2|');
});
it('should expose iterator offset as $index when iterating over objects', function() {
var scope = compile('<ul><li ng:repeat="(key, val) in items" ' +
'ng:bind="key + \':\' + val + $index + \'|\'"></li></ul>');
scope.items = {'misko':'m', 'shyam':'s', 'frodo':'f'};
scope.$eval();
expect(element.text()).toEqual('misko:m0|shyam:s1|frodo:f2|');
});
it('should expose iterator position as $position when iterating over arrays', function() {
var scope = compile('<ul><li ng:repeat="item in items" ' +
'ng:bind="item + \':\' + $position + \'|\'"></li></ul>');
scope.items = ['misko', 'shyam', 'doug', 'frodo'];
scope.$eval();
expect(element.text()).toEqual('misko:first|shyam:middle|doug:middle|frodo:last|');
});
it('should expose iterator position as $position when iterating over objects', function() {
var scope = compile('<ul><li ng:repeat="(key, val) in items" ' +
'ng:bind="key + \':\' + val + \':\' + $position + \'|\'"></li></ul>');
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'};
scope.$eval();
expect(element.text()).toEqual('misko:m:first|shyam:s:middle|doug:d:middle|frodo:f:last|');
});
});
describe('@ng:non-bindable', function() {
it('should prevent compilation of the owning element and its children', function(){
var scope = compile('<div ng:non-bindable><span ng:bind="name"></span></div>');
scope.$set('name', 'misko');
scope.$eval();
expect(element.text()).toEqual('');
});
});
});
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+2 -2
View File
@@ -1,4 +1,4 @@
# <angular/> build config file
---
version: 0.9.1
codename: repulsion-field
version: 0.9.4
codename: total-recall
+8
View File
@@ -0,0 +1,8 @@
# config file for watchr http://github.com/mynyml/watchr
# install: gem install watchr
# run: watch watchr.rb
# note: make sure that you have jstd server running (server.sh) and a browser captured
watch( '^src/|^docs/' ) do
%x{ echo "\n\ndoc run started @ `date`" > logs/docs.log; node docs/collect.js &> logs/docs.log & }
end
+9
View File
@@ -0,0 +1,9 @@
# config file for watchr http://github.com/mynyml/watchr
# install: gem install watchr
# run: watch watchr.rb
# note: make sure that you have jstd server running (server.sh) and a browser captured
watch( '(src|test|example)/' ) do
%x{ echo "\n\ntest run started @ `date`" > logs/jstd.log; ./test.sh &> logs/jstd.log & }
%x{ echo "\n\nlint started @ `date`" > logs/lint.log; rake lint &> logs/lint.log & }
end