I am using T4 for generation of some DTO classes + mappers.
I am splitting the files in a number of re-usable bits (some of which containing common methods, some others common procedures) and including them into the T4 templates that will produce my output - which is all good.
My problem is that the re-usable .tt files will try and produce their own output and fail (because they are coupled to some other .tt files) every time I make a change to them, which plain sucks.
I am pretty sure I saw somewhere some directive to specify a given file shouldn't try and produce any output, but I can't seem to track it back.
Any help appreciated!
You can specify invalid extension to suppress the output of your template, for example:
<## output extension="\n" #>
In the properties (select file and press F4) of the T4 files for which you'd like to suppress output, clear the 'Custom Tool' entry.
I don't have enough 'StackOverflow street cred' to reply to Stanislav Kniazev's answer, so will have to post my own here. Thanks for the lead Stanislav Kniazev.
The following worked; but if you are using a T4 syntax highlighter (like Tangible T4) you will find that it stuffs up the highlighting.
<## output extension="\n" #>
So I found setting the extension to something that is not an escape char like this:
<## output extension="" #>
and then in the code section programmatically setting the file extension, like this:
Host.SetFileExtension("\n");
T4 highlighting is then restored.
rename them to .ttinclude and see how that goes for ya....
Related
Context
I am making a script that dynamically inserts include directives in code blocks on an AsciiDoc file and then generates a PDF out of that. A generated AsciiDoc file could look like this:
= Title
[source,java]
---
include::foo.java[]
---
I want the user to be free to include whatever char-based file he or she wants, even other AsciiDoc files.
Problems
My goal is to show the contents as are of these included files. I run into problems when the included file:
is recognized as AsciiDoc beacuse of its extension, an thus any include directives it has are interpreted. I don't want nested includes, just to show the include directive in the code block. Example of undesired behaviour:
contains the code block delimiter ----, as seen on the image above when I end up with two code blocks instead of the intended single one. In this case, it does not matter if the file is recognized as an AsciiDoc file, the problem persists.
My workaround
The script I am writing uses AsciidoctorJ and I am leveraging that I can control how the content of each file is included by using an include processor. Using the include processor I wrap each line of each file with the pass:[] macro. Additionally, I activate macro substitution on the desired code block. A demonstration of this idea is shown in the image above.
Is there a better way to show the exact contents of a file? This works, but it seems like a hack. I would much rather prefer not having to change the read lines as I am currently doing.
EDIT for futher information
I would like to:
not have to escape the block delimiter. I am not exclusively referring to ----, but whatever the delimiter happens to be. For example, the answer by cirrus still has the problem when a line of the included file has .....
not have to escape the include directives in files recognized as AsciiDoc.
In a general note, I don't want to escape (or modify in any way) any lines.
Problem I found with my workaround:
If the last char of a line is a backslash (\), it escapes the closing bracket of the pass:[] macro.
You can try using a literal block. Based on your above example:
a.adoc:
= Title
....
include::c.adoc[]
....
If you use include:: in c.adoc, asciidoctor will still try to find and include the file. As such you will need to replace include:: with \include::
c.adoc:
\include::foo.txt[]
----
----
Which should output the following pdf:
Is there a way to include plain text in a doxygen file
Hello Wold
----------
#include helloworld.txt
without it ending up in a fragment like:
I dont want this
I wanted it to end up like the other text I write in a .markdown file:
I want this
I'm sorry to say I don't think there's an easy way to do this as of May 2016 - what you really need is a mdinclude command to match htmlinclude.
The problem is that Markdown is processed as a pre-processing step and the output from that then run through the normal Doxygen processing detecting generated HTML and special commands.
So, unless you want to make a submission to Doxygen, the only way I can think of is to do your own pre-processing for this particular include.
You could do that in a build step where you use some Unix commands or a script to merge in a file at the include stage.
If you wanted this driven by Doxygen you could use a custom file extension and write your own filter, as described in this SO answer
I am trying to create custom syntax highlighting for Kivy '.kv' files in the Geany editor. Although the specific filetype seems irrelavant to the issue I'm having, as any efforts I make at getting syntax highlighting to work for a custom filetype results in a completely non-highlighted file. I believe I have done my homework on this, and nothing seems to work.
I have added the following to ~/.config/geany/filetype_extensions.conf
Kivy=*.kv;
I also have a custom type definition file named 'filetypes.Kivy.conf' in ~/.config/geany/filedefs/. I have tried basing this file off several of the stock type definition files in /usr/share/geany/ and the file never gets any syntax highlighting applied in Geany. Right now, just for experimentation's sake, my 'filetypes.Kivy.conf' file looks like this:
# For complete documentation of this file, please see Geany's main documentation
[settings]
# default extension used when saving files
extension=kv
# single comments, like # in this file
comment_single=#
[keywords]
# all items must be in one line
primary=size canvas
secondary=pos size
[indentation]
width=4
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=0
This is very loosly based on the stock XML definition file, but like I said I've tried many other stock files. In many cases I only changed the 'extension=' value to kv and still no highlighting was applied, even though going to Document>Set Filetype in Geany and choosing virtually any random filetype (besides my custom entry) would yeild some sort of highlighting within my .kv file. This is even the case when using the unmodified contents of a stock definition which otherwise works fine on my .kv file when specifically selected in Geany!
Also, the Kivy filetype is listed and selected by default in Document>Set Filetype within Geany, so I must be doing something right here!
I realize this similar question has been asked, but the solutions seem irrelavent to my case, as I've tried every related topic on this and many other sites. My Geany version is 1.22 and I'm running Arch Linux. This is driving me nuts - any suggestions?
Thank you!
Set lexer_filetype= property in the [settings] section of your filetype file. Working highlighting requires that there is a lexer that could be used for highlighting the .kv-files.
For more info see http://www.geany.org/manual/#lexer-filetype
There are three important things to obey:
the configuration file should be placed in "~/.config/geany/filedefs"
the configuration file must have the extension ".conf" - otherwise it won't show up at all (the files in "/usr/share/geany/filesdefs", where I copied my base file from, do not have a ".conf" extension!)
you must set the "lexer_filetype" to an existing (presumably builtin) configuration; e.g. "lexer_filetype=Python"
I have a t4 template that is outputting to a specified file name. t4 however when run is creating a xx.cs file for each tt file that I have. Within this file is the text "ErrorGeneratingOutput"
Is there a way to prevent this file from being created?
I'm afraid not, no.
When using one of the mechanisms to create specific files, there will always be a dummy stub file.
Typically I set it to be a text file with
<## output extension=".stub.txt" #>
and put some explanatory text in it to the effect that it's a placeholder by putting that text as the body of the template. I then set its build action to 'None' permanently.
I'm not sure what's causing the error, but that's where any error in the rest of your template would get reported typically.
If you just want to prevent the erroneous generated .cs file from compiling until you are finished writing you t4 file, you can set the Build Action property for the .cs file to None and then set it back when you're done
everyone. I have an advanced T4 question and I'm hoping someone can help.
I've created a SQL-like DSL, and the scripts are saved in '.satsql' files in my C# projects, like so;
// contents of myqueries.satsql
SELECT <column t1.Id> FROM <table mytable t1>
I have a .tt file which loads the file and attempts to parse it. If it fails, I want to add an error to the Visual Studio error list, like so;
myqueries.satsql (1,8) error: unknown column 'xid' on table 't3'.
myqueries.satsql (2,9) error: bad reference: pid.
When the user clicks on the error, VS should open the 'myqueries.satsql' file and point the cursor at the appropriate line and character, just as it does for C# errors.
T4 already provides the void TextTransform.Error(string) method, but that doesn't seem to give me the opportunity to set the file, line, and character the way C# errors do.
Does anyone know a way for a T4 file to report an error in another file -- not the T4 file itself?
Many thanks,
Steve Cooper.
You can use TextTransformation.Errors collection to report errors with file and line number information.