plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Feature Request]: Additional Variables

Open dillingham opened this issue 4 years ago • 10 comments

Feature Description

variable output plural output
{{ model.lower }} user account {{ model.lowerPlural }} user accounts
{{ model.title }} User Account {{ model.titlePlural }} User Accounts
{{ model.upper }} User account {{ model.upperPlural }} User accounts
{{ model.studly }} UserAccount {{ model.studlyPlural }} UserAccounts
{{ model.camel }} userAccount {{ model.camelPlural }} userAccounts
{{ model.slug }} user-account {{ model.slugPlural }} user-accounts
{{ model.snake }} user_account {{ model.snakePlural }} user_accounts

The slug is good for file paths like views or route names like product-categories.index Inertia uses OrderItems/Index view format and MODEL_CLASS_VARIABLE_PLURAL is neeeded

dillingham avatar Sep 20 '21 02:09 dillingham

Str::macro('reset', function ($value) {
    return Str::of($value)->snake()->replace('_', ' ')->singular();
});

This reset was needed because multiple word models

Str::slug('AccountUser') == accountuser

Above didn't work, but this does:

Str::reset('AccountUser')->slug() == account-user
'title' => function ($value) {
    return Str::reset($value)->title();
},

'studly' => function ($value) {
    return Str::reset($value)->studly();
},

'camel' => function ($value) {
    return Str::reset($value)->camel();
},

'slug' => function ($value) {
    return Str::reset($value)->slug();
},

'snake' => function ($value) {
    return Str::reset($value)->snake();
},

'lowerPlural' => function ($value) {
    return Str::reset($value)->plural();
},

'titlePlural' => function ($value) {
    return Str::reset($value)->plural()->title();
},

'studlyPlural' => function ($value) {
    return Str::reset($value)->plural()->studly();
},

'camelPlural' => function ($value) {
    return Str::reset($value)->plural()->camel();
},

'slugPlural' => function ($value) {
    return Str::reset($value)->plural()->slug();
},

'snakePlural' => function ($value) {
    return Str::reset($value)->plural()->snake();
},

dillingham avatar Sep 20 '21 02:09 dillingham

Hi, Brian.

I already have something very similar for all variables with the "_CLASS" prefix - https://laravel-idea.com/docs/custom_generations#code_templates I'll try to add the same for the main class name. Thank you.

adelf avatar Sep 20 '21 13:09 adelf

@adelf yes Im using them.. and was suggesting adding more variations. Having slug, title, lower, studly, snake, uppercase, and camel. And then appending PLURAL for all like my table shows would be amazing. Would be great if any variable automatically had all variations

dillingham avatar Sep 20 '21 14:09 dillingham

@adelf are variables available in directory / parameter paths?

directory: views/${MODEL_SLUG_PLURAL}/index.vue directory: views/products/index.vue directory: views/product-categories/index.vue

dillingham avatar Sep 20 '21 14:09 dillingham

For custom generations?

adelf avatar Sep 20 '21 15:09 adelf

@adelf yes, for custom generations. Great feature btw.

dillingham avatar Sep 20 '21 15:09 dillingham

I'll try to add. Thanks for the great suggestions!

adelf avatar Sep 20 '21 15:09 adelf

@adelf thank you!

dillingham avatar Sep 20 '21 15:09 dillingham

I've added some template variables in the last update. https://laravel-idea.com/docs/custom_generations#code_templates But using them in the paths is still not supported.

adelf avatar Nov 22 '21 14:11 adelf

@adelf thank you! Looks great.. only one I can think of is title case UserAccount User Account. I appreciate you adding these variables though.

dillingham avatar Nov 29 '21 23:11 dillingham