I want to make a code snippet where a part of the snippet text is substituted with a value that can be configured by the user.
Following this page I tried using an environment variable like
"${env:MYVALUE}"
and a configuration variable like
"${config:my.value}"
Both the environment variable and the user defined settings exist but they are not substituted. Are these variables not supported in snippets and if not is there some other way?
The variables from documentation mentioned in the question are only used in configuration files. Snippets have their own set of supported variables. Taken from the source these are:
CURRENT_YEAR
CURRENT_YEAR_SHORT
CURRENT_MONTH
CURRENT_DATE
CURRENT_HOUR
CURRENT_MINUTE
CURRENT_SECOND
CURRENT_DAY_NAME
CURRENT_DAY_NAME_SHORT
CURRENT_MONTH_NAME
CURRENT_MONTH_NAME_SHORT
SELECTION
CLIPBOARD
TM_SELECTED_TEXT
TM_CURRENT_LINE
TM_CURRENT_WORD
TM_LINE_INDEX
TM_LINE_NUMBER
TM_FILENAME
TM_FILENAME_BASE
TM_DIRECTORY
TM_FILEPATH
BLOCK_COMMENT_START
BLOCK_COMMENT_END
LINE_COMMENT
WORKSPACE_NAME
Details can be found here.
Related
I am using environment variables for testing (username and password).
I have my .env file setup.
I also have the flutter_dotenv imported in my test file as per:
https://pub.dev/packages/flutter_dotenv
However, under "Using in tests #" it mentions using the method testLoad to load a static set of variables for testing.
The document also offers 2 examples:
Example 1: Loading from a static string.
dotenv.testLoad(fileInput: '''FOO=foo
BAR=bar
''');
Example 2: Loading from a file synchronously.
dotenv.testLoad(fileInput: File('test/.env').readAsStringSync());
Can someone explain how these examples work?
In Example 1, it seems the testLoad method would return all variables listed in .env in a single call.
So I have a USERNAME=Bobby and a PASSWORD=1234 in my .env file.
If I use testLoad it would return both Bobby and 1234.
However, I don't want to get both variables at once. When I test my app, I need to select the field "username" to input the username and afterwards, select the field "password" to input the password; I don't want to input both variables in a single field.
Am I missing something? What use is there for both variables to come in at once?
I also do not understand the use for Example 2 at all.
maybe someone can help me on this. I am trying to generate a document via the DocumentGenerator interface. All in all this works well, except that the DocumentGenerator does not replace the Report Constants with actual values (which are defined on the report package stereotype.
This is the general flow of the document creation code (which generally works):
var gen = Repository.CreateDocumentGenerator();
gen.SetProjectConstant("ReportName", "My Project");
gen.NewDocument(string.Empty);
gen.ReplaceField("ReportName", "My Project");
gen.InsertCoverPageDocument(tags[REPORT_COVERPAGE]);
gen.InsertBreak(DocumentBreak.breakPage);
gen.InsertTOCDocument(tags[REPORT_TOC]);
gen.InsertBreak(DocumentBreak.breakPage);
gen.DocumentPackage((int)nativeId, 0, template);
gen.SaveDocument(fileName, DocumentType.dtDOCX);
I tried ReplaceField and SetProjectConstant both and one at a time before and after calls to NewDocument/InsertCoverPageDocument:
Strangely there is one constant that is being replaced: ReportSummary.
When I run the document generator via "F8" all constants are being replaced correctly.
Other project constants are being replaced correctly.
I can reproduce the behaviour on EA v14.1.1429 and v12.0.1215.
Does someone have a hint for further troubleshooting? Thanks in advance!
========== UPDATE ==========
When I use ReplaceField at the end (before the actual call to SaveDocument the following Report Constants get replaced: {ReportTitle} and {ReportName}
I discovered some workaround: when I manually remove the predefined {Report~} constants from the template and re-add them as Project Constants, their values get replaced correctly.
I will examine this further and give an update as
I did some further investigation on this and came to the following conclusion and workaround (as I have received no comments or answers on this):
I deleted all references to ReportConstants in my EA templates and replaced them by ProjectConstants with the same name.
In my code where I want to generate the documentation I (re)set all ProjectConstants with the actual values via SetProjectConstant and additionally added a call to ReplaceField to replace the constants with the actual values.
The previous mentioned calls are inserted directly before the call to SaveDocument document.
tags.ForEach(t =>
{
if (string.IsNullOrWhiteSpace(t.Key)) return;
generator.SetProjectConstant(t.Key, t.Value);
generator.ReplaceField(t.Key, t.Value);
});
generator.SaveDocument(fileName, DocumentType.dtDOCX);
If someone comes up with a better resonse or explanation for the behaviour I am happy to accept this as answer.
I have also found that when you call ReplaceField on these project constants in a CoverPage template, the formatting defined in the template is overwritten. It seems that some of the SetProjectConstant calls actually set the values as you would expect, and the rest do not.. hence the need to call both sets of APIs.
I am using botium-box. I have the following convo file:
Here the date is a variable and changes everyday so I have to change it everyday in convo file otherwise the testcase is failing.
I have tried few solutions:
setting SCRIPTING_ENABLE_MEMORY to true in advance settings and using
placeholder for variables. For eg.
I tried setting INTENT_CONFIDENCE to 70 in advance settings and using
in convo file. For eg:
I tried INTENT_CONFIDENCE directly in convo file without setting it in advance capabilities. For eg.
I tried using %s in place of variable. For eg.
Testcases are still failing. Is it a bug? Do I have to change any Botium settings? How can I do partial matching of responses?
Solution 1 should be working (see here and here). If it doesn't work, please attach log file for analysis.
Options 2 and 3 are for something totally different (verification of intent resolution confidence), and Option 4 is not a Botium feature.
What you can try as well: Botium by default does substring matching for assertions, so your convo file could look something like this:
#me
what is the date today ?
#bot
Today is
I wonder if there is any way how to access jEdit variables (like the buffer variable) from the beanshell inside SuperAbbrevs plugin template.
When I try to expand following template, the error Attempt to resolve method: getName() on undefined variable or class name: buffer appears int Activity log.
<#= buffer.getName() #>
When I try to run this code in the BeanShell console then it displays the current buffer name:
buffer.getName()
Is it possible to access buffer name from the SuperAbbrevs template?
As far as I can see from a quick look at that plugins sources, those variables are not forwarded to the templates. Only the variables you define in the options of the plugin and additionally filename and selection.
In your example filename is exactly what you want, so <#= filename #> works for inserting the name of the file. If you would need more, you would probably need to issue a plugin feature request.
I'm using toLocalizedTime to output a date, as below
<span tal:content="python:here.toLocalisedTime(date.get('start_date'))"/>
This outputs eg. 2007/08/02, I'm just curious as to how one would alter the output so that it reads 02/08/2007
I'm not having much luck finding much info on toLocalizedTime, would someone point me in the right direction?
This depends on whether you have English selected as the site language (Site Setup >> Language). If so, then the default settings are used. You can change the defaults by dropping down into the ZMI, then into 'portal_properties', then 'site_properties'. The fields to change are either 'localTimeFormat' or 'localLongTimeFormat' depending on whether you pass in 'long_format=1' to the toLocalisedTime function.
If on the other hand, you have translations set up, the format may instead be pulled from the translation file for the locale selected. I'm not sure what is the easy way to change the format in this case (other than switching the site back to English). I guess you can register your own translation file but I've never needed to do that so you're going to have to look up the details.
Date string formatting follows the Python rules (http://docs.python.org/library/time.html#time.strftime).
Perhaps even more detail than you need:
here.toLocalizedTime()
is defined in the plone browser view at...
CMFPlone/browser/ploneview.py
which looks up the 'translation_service' utility, to call its 'ulocalized_time' function, defined at...
CMFPlone/TranslationServiceTool.py
which itself calls the 'ulocalized_time' function defined at...
CMFPlone/i18nl10n.py
As always, you can learn interesting things by grepping the source code ;-)
For an up to date answer for Plone 4.3 (after going through the source code)
These fields are now in the registry found at:
http://localhost:8080/yoursite/portal_registry
Then filter on "i18nl10n", which should give you the 4 fields you need to change.