Customize T4 Scaffolding With PowerShell - powershell

I want to create a Custom Scaffolder that uses arbitrary PowerShell logic. It can render T4 templates (multiple ones if I want), with the result being output:
As a new file in your project
as a new code block inserted into an existing class
my PowerShell logic can use Visual Studio’s “code model” API to manipulate files and code elements in other arbitrary ways.
How to Customize T4 Scaffolding With PowerShell?

From http://blog.stevensanderson.com/2011/04/07/mvcscaffolding-creating-custom-scaffolders/:
In Package Manager Console of Visual Studio execute the following
command :
Scaffold CustomScaffolder ClassName
This adds a CodeTemplates folder to your project, containing files for
the new scaffolder.
As you can see, we’ve got two files:
A PowerShell script (.ps1), where we can put arbitrary logic to decide what templates get rendered and where the output goes. By
default, it renders a T4 template and uses the output to create a new
file called ExampleOutput in the root of your project.
A T4 template (.t4), i.e., the thing that the default .ps1 file renders. By default this generates a simple C#/VB class (depending on
your project type). If you want to see this working, you can run the
custom scaffolder right away:
Scaffold ClassName
This will generate a new class file, ExampleOutput.cs, in the root
folder of your project. That’s really just to show you how it works.
We don’t really want that, so don’t run the new scaffolder yet, or if
you already have done, delete ExampleOutput.cs

Related

TYPO3: Where can I find the template created in the backend?

I'm trying to create separate templates for webpages with either a single or a double column structure. Currently my webpage only has one template, placed on the root page which is used by all its subpages.
However, I cannot find the template in myextension/Resources/Private/Templates as this folder is empty. Where is the template located in my extension and where should I add the alternative template?
I assume you use "fluid_styled_template"? Then the templates are in that respective core directory, in "Resources/Private".
If you want to manipulate them, copy them to your sitePackage into "Resources/Private/Extension/fluid_styled_content" (that at least is one of the recommended ways where to place it) and override the TypoScript that "fluid_stlyed_content" provides.
templateis not unique in TYPO3 context. we have:
typoscript records, maybe also as files which are included in a record or by PHP
HTML files, which are define a markup for parts of the website
they can be differed in
Marker-Templated. The old and less and less used kind with markers and subparts as placeholders for data defined in typoscript
Fluid templates. The modern kind with control structures and data objects
with the statemant
my webpage only has one template, placed on the root page
it is not clear what you mean:
records are defined in pages -> typoscript templates
maybe you mean in the root page a template is selected. that could mean HTML templates, probably fluid templates as the path myextension/Resources/Private/Templates matches the usual structure for fluid templates.
assuming fluid templates:
Templates are search in a list of folders. This list is managed in typoscript.
Any usage has it's own list and the list of your main/page template probably is at page.10.templatePaths. You can look for it in the TSOB (Typoscript Object browser)
If the list consists of one entry only you have only the basic config.
As the list of folders is consulted each time a template (,partial, layout) is accessed and only that file with matching name in the folder with highest priority is taken you can add your folders with higher numbers in the list so you do not need to change the original files (use copies in your folder to modify) or add files to the original folder (inside of other extensions).
So you need two things:
create your template file in an appropriate folder
(ext:myextension/Resources/Private/Templates sounds good)
and add this folder to the list of folders for these templates
(e.g. page.10.templatePaths.20 = EXT:myextension/Resources/Private/Templates)

Generating the separate ecore files for the sub-Epackes present in the existing model

Problem: I have an ecore file which has the sub-E Packages. Using this model I am trying to create the GUI part using Sirius. But the problem with Sirius is that it does not support ecore files containing sub-E Packages. So we have to extract those sub-E Packages to separate ecore files. But each sub-E Packages has relation with the other sub-E Packages. So how can we extract those sub-E Packages to separate ecore files such that the relations still exists between separate ecore files after extracting them.
Thanks
By extracting them the ecore Editor will lose the information unfortunately, which means some extra work...
I had the same issue with sirius and sub e-packages leading to sirius crashing the diagram constantly.
Here is how i solved extracting a sub-epackage:
First Create a new .ecore file for your desired sub-package.
Open both .ecore files (your main and the new one) with the Sample
ecore model editor (treeview).
Copy the Package properties to your new epackage node(ns, praefix,
uri) you need to do this manually.
Then drag and drop your whole contents(excluding the purple package
node) from your subpackage into the new Epackage
Save and make sure no errors in your new file occur.
load your new .ecore file into your main file by clicking "Load
resource" Now your main file knows 2 kinds of the EClasses you have in your sub-package, their names are identical but their uri is
different.
you could now simply replace all occurrences of sub-epackage-eclasses with the newer ones or smarter and safer
Replace an etype one time (where actually use the etype in your root package)
open your main .ecore file as text, you will see that the etype values all
have a path like eType="ecore:EClass
../../org.eclipse.emf.ecore/model/Ecore.ecore#//EObject" Then You need to know how your etype paths (from your sub-epackage and your new one) differ so you can simply replace them all and your good.
finally delete the sub-epackage
Hope this helps
In eclipse ecore editor you can use "Load Resource" in pop-up menu to load any ecore file and use objects from it.

Unable to loacte properites file in wicket

In my wicket application i have 3-4 different packages say pack1,pack2 and so on .
In pack1 i have different html and java classes. I am validating the null check by setRequired(true) and getting the message from properties file.I am naming my properties file as Send.properties ... as i have Send.html and Send.java in pack1.In properties file i am mentioning like this
formname.field.Required=The ${label} is missing
I want to validate all the html fields which are present in different html pages of the same package (pack1)in one properties file say pack1.properties .So my question here is will one singe properties will be sufficient for one package where in all the validation will be taken care.
Yes, wicket first looks for the property in the properties file associated to the page, and then in the properties asociated to the package (and after that in parents packages...).
But, as long as I know the package properties file is called package.properties (independently of the package name).

poEdit not creating source files

I am using poedit with zend_translate.
I have done everything required in zend. I have created some sample code in zend view files
$this->translate("Hello");
I have then created a new catalog in poedit.
I specified the initial settings (like base directory, translation function)
I edited php parser tab:
a) *.php to *.php;*.phtml
b) adding '-L php'
Then also its not getting any strings.
Anyone has any idea what i am doing wrong.
Under catalog settings, go to "Keywords" and add "translate" — that should fix it.

Invalid child element MvcBuildViews

I have an ASP.NET MVC 2 Beta app and have set <MvcBuildViews>true</MvcBuildViews>
in the property group at the top of my csproj file. But my views are not being compiled. A closer look at the .csproj file shows a squiggly under the MvcBuildViews tag and when I hover over it, it says
The element 'PropertyGroup'
in namespace
'http://schemas.microsoft.com/developer/msbuild/2003'
has invalid child element
'MvcBuildViews' in namespace
'http://schemas.microsoft.com/developer/msbuild/2003'.
List of possible elements expected:
'Property' in namespace
'http://schemas.microsoft.com/developer/msbuild/2003'.
What am I doing wrong?
Many elements you define in the .config are not part of that schema, but still operate. It's the same way for MSBuild scripts.
That's a custom property we include in the project files to compile views. It shouldn't cause any problems, since you can define your own properties (see http://msdn.microsoft.com/en-us/library/t4w159bs.aspx) in your project file.
For further detail, please refer to:
http://forums.asp.net/t/1506782.aspx?Error+invalid+child+element+MvcBuildViews+in+namespace
btw, this issue existed in 2009, but now is 2015, it still exists.