Commit Graph

91 Commits

Author SHA1 Message Date
N. Taylor Mullen 0c95315500 Update tests to not require quotes for TH directives.
- Updated .cshtml files to not provide quotes for the various `TagHelper` directives.
- Updated `TagHelper` directive parsing tests. This also involved removing several tests that expected errors which no longer occur since we don't have to ensure quotes are balanced.
- Updated line mappings which significantly changed due to us no longer generating line pragmas at design time for `TagHelper` directives.

#561
2015-11-06 12:19:40 -08:00
N. Taylor Mullen 02d6b00d8f Generate `async` lambda for template attributes.
- Template attributes should be of type `Func<TextWriter, Task>`. We weren't generating an `async` lambda for attributes prior to this change resulting in a compilation failure when used at runtime and the inability to `@await` code (unless a user returns some sort of `Task`).
- Updated code generation files to reflect the new code generation behavior.

#594
2015-11-04 16:04:29 -08:00
N. Taylor Mullen a76f16cda8 Removed `TagHelper` infrastructure `using` statements.
- The using statements had a chance to conflict with user code. Removed them and changed the default configured type names to be `global::` full name based.
- Updated test file `TagHelperDescriptor.TypeName`s to have namespaces to make them easier to read.

#580
2015-10-29 16:23:38 -07:00
N. Taylor Mullen 22ecf85f88 Added `TagHelper` support for `enum`s.
- If a `TagHelper` attribute is an `enum` then you no longer need to provide the `enum` name. To override this functionality you can add the `@` symbol.
- Added code generation tests.
- Added `TagHelperDescriptorFactoryTest`s that double for Precompilation tests.

#196
2015-10-29 10:04:07 -07:00
N. Taylor Mullen b1ad14fd46 Rename `Microsoft.AspNet.Razor.Runtime.TagHelpers`.
- Changed non-user facing type names to `Microsoft.AspNet.Razor.TagHelpers`.
- Updated folder structure to reflect new namespaces.
- Updated generated code files to reflect new runtime type namespaces.

#578
2015-10-22 10:45:43 -07:00
N. Taylor Mullen deaf2dc828 Enable `TagHelper`s to properly flatten to enable partial parsing.
- `TagHelper`s used to not flatten correctly resulting in inconsistent start locations for `SyntaxTreeNode`s following/within `TagHelper`s.
- This change indirectly corrected bad indentation that existed in generated C#.
- Added a test to validate `TreesAreDifferent` returns expected behavior when modifying content inside of `TagHelper`.
- Added `TagHelperBlock` `Flatten` test.

#553
2015-10-16 15:57:37 -07:00
N. Taylor Mullen 2d4092ca32 Add line pragmas to dynamic attributes.
- This enables debugging and proper error reporting for dynamic attributes. Without the pragmas errors would showcase generated Razor C# instead of their corresponding .cshtml files.
- Did not have to do any `TagHelper` specific changes since they utilize the same core attribute rendering logic.
- Updated generated C# files for tests.

#569
2015-10-16 09:41:12 -07:00
N. Taylor Mullen ed617d17e9 Remove linemappings file. 2015-10-15 15:20:57 -07:00
Pranav K 3e8b7b607d Refactor WriteAttribute \ AddHtmlAttribute
Fixes #177
2015-09-30 16:12:10 -07:00
Ajay Bhargav Baaskaran bc103fcaa4 Fix: Index out of bounds for incomplete attribute value
- #555
- Added a unit and a code generation test
2015-09-30 14:51:43 -07:00
Ryan Nowak c9341ee3d7 React to removal of ToString on TagHelperContent
The code generator generates calls to ToString() on a TagHelperContent
when used with dynamic content inside an attribute that needs to be passed
to a TagHelper as a string.

This change updates the codegen to use GetContent(IHtmlEncoder)
2015-09-23 11:07:44 -07:00
N. Taylor Mullen 7239eb015c Add support for data bound symbols as attribute names.
- Took the HTML5 spec approach of disallowing specific characters and accepting all others.
- Added several parser and code generation tests to cover both `TagHelper` and non-`TagHelper` variations of symbol bound attribute names.

#137
2015-09-22 16:12:37 -07:00
N. Taylor Mullen fb6a08d5de Allow `TagHelper`s inside of text/html typed script tags.
- To limit the impact of the change ensured that we only do extra work in the case that we detect a script tag with a `type` attribute.
- The parsing changes include normal HTML parsing behaviors when we detect that a script tag has a `type` attribute with value `text/html`.
- Added unit and code generation tests to validate `text/html` script tag behavior.

#502
2015-09-17 21:14:40 -07:00
Ajay Bhargav Baaskaran e2881b0eca Extra newline no longer rendered at the end of a code block
- #485
- Using a flag to consume whitespace and newline at the end of a verbatim block
- Added tests to validate nested blocks
2015-09-10 10:39:37 -07:00
Ajay Bhargav Baaskaran 08c8f9f7ba Parse the whitespace surrounding equals in attribute correctly
- #123
 - Handled the corresponding cases in tag helper scenarios
 - Added unit and code generation tests
2015-09-08 11:43:37 -07:00
N. Taylor Mullen d458e8ecb2 Change HTML in nested C# blocks to properly handle dots.
- Prior to this change adding a `.` after an implicit expression would result in compile errors due to Razor thinking the `.` was part of the C# (normally not the case).
- Added a code generation and unit tests to validate behavior.

#491
2015-09-07 19:18:09 -07:00
Ajay Bhargav Baaskaran 39dda01f47 [Fixes #484] Attributes parsed correctly when newlines precedes attributes 2015-08-28 14:59:24 -07:00
N. Taylor Mullen d0688a7e00 Add the ability for `TagHelper`s to exist inside templates.
- Previously doing `@<mytaghelper />` was invalid due to how we constructed templates lambdas.

#489
2015-08-21 16:51:47 -07:00
Pranav K 3361507c29 Remove ability to specify ignored '@' in the middle of non-string
TagHelper bound attributes.

Fixes #436
2015-08-14 18:12:31 -07:00
N. Taylor Mullen e9292a0e30 Add ability to write start tag only `TagHelper` elements.
- To write a start tag only `TagHelper` you can now utilize the `TagStructure` property on the `TargetElement` attribute. If none is specified it'll be treated as unspecified and default to old behavior of being start/end tag or self-closing.
- Added `TagMode` to showcase what the user initially wrote in their Razor document. This way `TagHelper`s can flow end-to-end in thesame format as they were written with.
- Updated code generation to specify `TagMode` instead of the boolean self-closing.
- Updated existing tests to move from `SelfClosing` => `TagMode`.
- Added `TagStructure` related tests to the set of tests that we currently have for `TagHelperBlockRewriter` and `TagHelperParseTreeRewriter`.

#450
2015-08-13 16:18:06 -07:00
Ajay Bhargav Baaskaran 71c4c8dac6 [Fixes #428] Removed newlines at the end of razor comments 2015-08-13 15:06:09 -07:00
N. Taylor Mullen 4604c807c4 Add ability for unbound complex `TagHelper` attributes to flow through MVC attribute resolution system.
- Today MVC has specific rules about resolving Razor attribute values. Ex: `true` => attribute name being used as attribute value. This change ensures that unbound complex `TagHelper` attribute use that same logic.
- Added configuration to `GeneratedTagHelperContext` for `AddHtmlAttributeValues`.
- Had to be careful with code generating `AddHtmlAttributeValues`. In the case of `data-`; they can appear as complex attributes but may not contain any pieces that are `DynamicAttributeBlockChunk`s. Had to protect against this scenario.
- Updated existing test files.
- Added a new code gen test case to showcase the various use-cases of unbound dynamic `TagHelper` attributes.

#247
2015-08-10 11:29:22 -07:00
N. Taylor Mullen 48a6b567d6 Remove ~/ handling from core Razor.
- Removed parsing, chunk generation and code generation.
- Removed related tests.
- Did not modify existing unrelated tests with ~/ since it's just plain text and may be valid for end-users.

#427
2015-07-31 15:55:29 -07:00
N. Taylor Mullen 0bb9457fd9 Change duplicate TagHelper bound attributes to flow to output.
- Duplicate TagHelper bound attributes used to be ignored entirely; they now flow to the output as if they were unbound.
- Added code generation test to verify duplicate attributes. Added runtime and design time versions.
- Updated existing tests that happened to have duplicate bound attributes.

#418
2015-06-25 11:11:04 -07:00
N. Taylor Mullen ddbd603653 Enable instrumentation for TagHelpers.
- Removed old code that disabled instrumentation for TagHelper bodies. Instrumentation will throw out sections for begin/end context that don't make it to the final output.
- Added instrumentation around WriteTagHelperAsync. Any content inside of the TagHelper will get sub-mapped via begin/end context.
- Hand verified BasicTagHelpers.cs begin/end context tests to ensure correctness.

#172
2015-06-10 12:52:25 -07:00
N. Taylor Mullen b0b4ac4f3f Enable TagHelper attributes to render in the order they were originally.
- This was accomplished by changing when/how TagHelper attributes are rendered. Previously they were rendered: Bound => Unbound. Now they're rendered in the order that they exist on the TagHelperChunk.
- Regenerated test files to account for new re-ordering of TagHelper attributes.
- Added duplicate, unbound HTML attribute, unminimized same name test to ComplexTagHelpers.
- Did not add additional tests (other than the one noted above) since the current tests seem to be heavily impacted by the re-organization of code rendering; effectively showcasing the fix.

#225
2015-06-04 15:32:45 -07:00
Doug Bunting 113d80c6f5 Ensure `CodeVisitor`s consistenctly find tag helpers
- #412
- fix `CSharpTagHelperRunnerInitializationVisitor` and `CSharpUsingVisitor`
- fix existing test of the tag helper in a section scenario
2015-06-01 09:03:09 -07:00
Doug Bunting d545f47fe4 Avoid errors when generating baselines
- ignore missing expected output resources in this mode
- update `BaselineWriter` to avoid `IOException`s (file access issues)
 - serialize file operations
 - one file handle per file
- repeatedly `rm TestFiles/CodeGenerator/Output/*; `dnx . test`; no errors

also
- add generation of design-time line mappings
- fix ChunkGenerator -> CodeGenerator typo in path names
- update files only if they have changed
 - new `TestFiles.Exists()` method to support this check
- do not check results in `CSharpCodeBuilderTests` if `GENERATE_BASELINES` set

nits:
- update BOM in CodeBlockWithTextElement.cs to avoid future `git diff`s
- use more `var` and improve variable names in `TestFile`
- wrap long lines
2015-06-01 08:42:23 -07:00
N. Taylor Mullen 6df8bc23f1 Renamed CodeBuilder related classes to CodeGenerator
- Now that what used to be CodeGenerators are now ChunkGenerators we can rename the CodeBuilder into its correct structure: a CodeGenerator.
- Moved the TagHelperAttributeValueCodeRenderer from the TagHelpers namespace into the CodeGeneration namespace.
- Went through several classes and remove and sorted usings.
- Updated test files to abide by the new naming convention of Builders => CodeGenerators.

#140
2015-05-27 17:00:41 -07:00
N. Taylor Mullen 5df9b52afe Renamed and moved several Razor classes for clarity.
- Renamed CodeGenerators to ChunkGenerators.
- Updated location of TestFiles from TestFiles/CodeGenerator/CS/{Output|Source} => TestFiles/CodeGenerator/{Output|Source}.
- Removed ChunkTree test; it was a legacy test used to experiment with Razor rendering (not a real test).
- Removed CSharpRazorCodeGenerator; it's now replaced with RazorCodeGenerator. It was an empty class that did nothing.
- Updated ChunkBlock => ParentChunk. Also updated several patterns throughout the code base that referenced these blocks as blocks and not parents.
- Moved Chunks and ChunkGenerators into the Chunks/Chunks.Generators namespace/folder structure. Updated test project to reflect the same.
- Moved CodeBuilders and CodeVisitors to the CodeGeneration/CodeGeneration.Visitors namespace/folder structure. Updated test project to reflect the same.
- Moved several TagHelper assets outside of their own namespaces and into Razors more general structures; such as CodeGeneration and Chunks/Chunks.Generators.

#140
2015-05-27 17:00:25 -07:00
Doug Bunting 60c47c8874 Add `[HtmlAttributeName(..., DictionaryAttributePrefix="prefix")]` part III
- #89 remainder
- support adding attributes (that aren't otherwise bound) to a tag helper dictionary
- use two `TagHelperAttributeDescriptor`s for dictionary and indexer
 - most exising descriptor properties have two meanings depending on new `IsIndexer`
 - add `TagHelperAttributeDescriptor.IsNameMatch()`
- create no `TagHelperAttributeDescriptor`s if property name or `HtmlAttributeNameAttribute`
  is invalid
 - avoid corner case misfeatures where invalidity removes just one descriptor
- extend handling of invalid attribute names to include `[HtmlAttributeName]`
- handle prefix matches in `TagHelperBlockRewriter`
 - add parse error when resolved dictionary key is `string.Empty`
- generate code for indexer property assignments
 - add code generation for runtime error if using indexer when property is `null`
 - use new `GeneratedTagHelperContext.FormatInvalidIndexerAssignmentMethodName` for message
- code generation now handles attributes in source order; thus above errors occur only when
  expected if dictionary is also initialized in the Razor source
 - surprisingly generation order change did not break existing tests!

nits:
- improve `TagHelperDescriptorFactory_InvalidBoundAttributeName` wording
 - rename resource to `TagHelperDescriptorFactory_InvalidAttributeNameOrPrefixStart`
- correct order of arguments to `FormatTagHelperDescriptorFactory_InvalidBoundAttributeName`
- correct `TagHelperBlockRewriter_TagHelperAttributeListMustBeWellFormed` resource
- correct `TagHelperDescriptorFactoryTest` test names
 - remove a few unnecessary `ToArray()` calls
- update `TagHelperAttributeDescriptorComparer` comments
2015-05-20 22:01:00 -07:00
N. Taylor Mullen 1879ac6427 Add support for static usings.
- Added special cases to the using statement parser to understand `@using static Foo`.
- Added several unit tests to validate the static using structure.
- Modified existing import code generation tests to validate several static usings.

#44
2015-05-20 21:47:23 -07:00
Ajay Bhargav Baaskaran aaa14cd36b More bug fix for #379 2015-05-20 13:55:12 -07:00
Ajay Bhargav Baaskaran 47577fd936 [Fixes #379] Ignoring whitespace at the end of text tag 2015-05-19 17:21:28 -07:00
N. Taylor Mullen 58c0a36200 Add support for null conditional operators in implicit expressions.
- Added case in ImplicitExpression handling to understand question marks.
- text?. is special compared to text. because with text. we currently validate content after text. to determine if it's an expression or if it's a period. Now with ?. we always treat it as an expression because ?. is not a useful sentance of any kind.
- Added unit tests to validate new implicit expression handling
- Added runtime and design time code generation tests to validate null conditional operators.

#44
2015-05-19 16:34:08 -07:00
N. Taylor Mullen b25bf01158 Add TagHelper support for unbound data- attributes.
- Involved updating the HtmlMarkupParser to properly separate data- attributes. Prior to this change `data-foo="abc @DateTime.Now def"` would involve 1 Span for `data-foo="abc` 1 Span for `@DateTime.Now` and 1 Span for `def"`. This was very unique behavior from an attribute standpoint (as far as Razor is concerned) and made it difficult for the TagHelper rewriting system to rewrite attributes. With this change it gets broken out as follows: `|data-foo="|abc| @DateTime.Now| def|"|`.
- Added unit tests to validate the various ways you can write unbound data- attributes.
- Updated the BasicTagHelpers codegeneration test to intermix some unbound data- attributes.

#342
2015-05-18 22:43:03 -07:00
N. Taylor Mullen 0882ff4a13 Add tests to validate minimized attributes.
- Added parse level rewriting tests to validate new TagHelper rewritten structures for minimized attributes.
- Updated existing parser tests to understand minimized attributes.
- Added codegen test to validate understanding of minimized attributes.
- Added TagHelperExecutionContext tests to validate maintaining of runtime TagHelperOutput tests.
- Refactored part of the TagHelperParseTreeRewriterTest file into a base class file so we can make better rewriting tests.

#220
2015-05-15 12:23:11 -07:00
Ajay Bhargav Baaskaran 7bd338fc4a [Fixes #266] Maintain HTML provided case for TagHelper attributes 2015-05-13 15:27:38 -07:00
Ajay Bhargav Baaskaran 4d80c96f9c [Fixes #50] Removed unnecessary whitespaces before text tag 2015-05-13 10:55:52 -07:00
N. Taylor Mullen 2d20063ba5 Remove layout directive.
- Removed all instances of the layout directive from src and test projects.

#359
2015-04-27 14:48:53 -07:00
N. Taylor Mullen 7d7b2795e1 Change tests to utilize Environment.NewLine.
- Normalized newlines for code generation tests. We default all tests to use \r\n. This way we can have a consistent test experience cross plat.
- For tests that expected indexes that were affected by new lines I modified them to account for cross plat scenarios.
- Added a few test classes to ensure we could normalize newlines for codegen tests.

#106
2015-04-03 23:50:21 -07:00
Doug Bunting 33407ef1be Enforce new invariants around HTML encoding
- #335
- bound `string` attribute values are _not_ encoded
 - rework `CSharpCodeVisitor` and `CSharpTagHelperCodeRenderer` to enable this case
- values in `TagHelperOutput.Attributes` are encoded unless special-cased elsewhere
 - `Dictionary<string, object>` type allows `RazorPage` to use `HtmlString`
- wrap HTML unbound attribute values using `Html.Raw()`
2015-03-30 11:09:26 -07:00
N. Taylor Mullen 2b6220205d Updated duplicate TargetElement TagHelper tests.
#326
2015-03-20 00:20:36 -07:00
N. Taylor Mullen 842549bba9 De-dupe TagHelperDescriptors based on Type for rendering.
- This can occur if you have multiple [TargetElement] attributes that overlap. Ultimately the descriptor is the same because its the same type, just the required attributes differ.
- Added tests to validate.

#326
2015-03-19 22:46:49 -07:00
Ajay Bhargav Baaskaran fa40fe6e46 Fix build break 2015-03-19 16:16:18 -07:00
Ajay Bhargav Baaskaran 7b468344c0 [Fixes #169] Await TagHelper generated objects 2015-03-19 16:08:07 -07:00
N. Taylor Mullen 4345b06e88 Add tests to validate TagHelper attribute targeting.
- Added tests to validate TargetElementAttribute, TagHelperDescriptorFactory, CSharpTagHelperCodeRenderer and TagHelperParseTreeRewriterTests.
- Renamed HtmlElementNameAttributeTest to TargetElementAttributeTest.

#311
2015-03-17 21:48:54 -07:00
Ajay Bhargav Baaskaran b3c60976a4 Removed @helper directive 2015-03-17 13:54:37 -07:00
sornaks 7daec14e49 Issue #318: Removing Generate*() methods. 2015-03-17 13:15:03 -07:00
sornaks bd9d57d33e Introducing buffering in TagHelperOutput.PreContent, Content, PostContent. 2015-03-04 12:56:13 -08:00