Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ItemTemplates for Razor Pages #566

Merged
merged 4 commits into from
Apr 15, 2017

Conversation

rynowak
Copy link
Member

@rynowak rynowak commented Apr 11, 2017

{
"author": "Microsoft",
"classifications": ["Web", "ASP.NET"],
"name": "Razor Page with Page Model",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DamianEdwards @Eilon - do the branding thing plz

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not it.

"groupIdentity": "Microsoft.AspNetCore.Mvc.RazorPageWithPageModel",
"precedence": "100",
"identity": "Microsoft.AspNetCore.Mvc.RazorPageWithPageModel",
"shortName": "page",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideas about a short name to distinguish this from pages (without pagemodel)??

We also have the option to make this a single item and have another parameter to distinguish.

Copy link
Contributor

@seancpeters seancpeters Apr 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd advocate for making these into a single template with a distinguishing param, maybe something like:

"model": {
  "type": "parameter",
  "datatype": "bool",
  "defaultValue": "false",
  "description": "<insert appropriate desc. here>"
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give this a try thanks

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace MyApp.Namespace
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does the right thing. Relax.

"primaryOutputs": [ { "path": "Index.cshtml"}, { "path": "Index.cs" } ],
"defaultName": "Index",
"symbols": {
"namespace": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably good to add a description to the namespace symbol, it'll get displayed in the detailed help for the template in the CLI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@Eilon Eilon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tentative-approval. Others will need to approve other stuff.

{
"author": "Microsoft",
"classifications": ["Web", "ASP.NET"],
"name": "Razor Page with Page Model",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not it.

using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a good default set of namespaces? Anything else common that should go here? (Not at all saying it isn't, I'm just not familiar with what's generally used.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For templates, we generally only include the usings that are required by the generated template code. But I could see including additional usings that most users would end up adding as they modify the content.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same set of namespaces that the template uses for HomeController with the Microsoft.AspNetCore.Mvc.RazorPages namespace added (required).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me then.

{
public void OnGet()
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace? Is this a joke?

@rynowak rynowak force-pushed the rynowak/razorpages branch from 87ea568 to 951743f Compare April 12, 2017 21:28
"sources": {
"modifiers": [
{
"condition": "(no-pagemodel)",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seancpeters - this isn't working. I've tried some stuff and it still wants to output the Index.cs file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I screwed up the syntax when we were chatting. Sources should be like this:

  "sources": [
    {
      "modifiers": [
        {
          "condition": "(no-pagemodel)",
          "exclude": [
            "Index.cs"
          ]
        }
      ]
    }
  ],

Copy link
Member

@DamianEdwards DamianEdwards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add item templates for _ViewStart.cshmtl and _ViewImports.cshtml too?


namespace MyApp.Namespace
{
public class Index : PageModel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls name this IndexModel and the file Index.cshtml.cs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@model Index
@*#endif*@
@{
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't​we usually include blank lines at the end of template files? I think it makes it easier to start adding HTML, etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't usually know. Added a blank line

]
},
"symbols": {
"namespace": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rynowak - you had asked me about making a parameter required. You can add
"isRequired": "true"
... to the symbol definition to make it required.

Note: I'm tracking down a bug related to isRequired, so you may want to hold off on making that change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I wasn't planning to do it for this change, I just wanted to know.

@rynowak
Copy link
Member Author

rynowak commented Apr 12, 2017

Should we add item templates for _ViewStart.cshmtl and _ViewImports.cshtml too?

Sure, I'll do this in a follow up PR

@rynowak
Copy link
Member Author

rynowak commented Apr 12, 2017

dotnet new page

Generates Page and PageModel, uses a placeholder namespace


dotnet new page --namespace MyCoolApp.MyCoolNamespace

Generates Page and PageModel, uses provided namespace


dotnet new page --no-pagemodel

Generates Page

"identity": "Microsoft.AspNetCore.Mvc.RazorPage",
"shortName": "page",
"sourceName": "Index",
"primaryOutputs": [ { "path": "Index.cshtml"}, { "path": "Index.cs" } ],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rynowak - for adding conditions to primary outputs, the format is like this:

"primaryOutputs": [ 
  {  "path": "Index.cshtml" }, 
  { 
    "path": "Index.cs",
    "condition": "(!no-pagemodel)"
  } 
]

If I understood correctly, that example should do what we talked about earlier.

@rynowak rynowak force-pushed the rynowak/razorpages branch from 22ccce8 to c8e600b Compare April 12, 2017 22:31
@rynowak
Copy link
Member Author

rynowak commented Apr 12, 2017

Updated

@rynowak
Copy link
Member Author

rynowak commented Apr 14, 2017

@mlorbetske @seancpeters - Ping. this is ready to go

@mlorbetske mlorbetske merged commit 597fcb0 into dotnet:rel/vs2017/post-rtw Apr 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants