Why is there no space after "Hello" in my Closure template? - google-closure-templates

I am trying to teach myself Closure templates. I made a simple file simply.soy:
{namespace examples.simple}
/**
* says hello to the world
* #param? name Optional parameter specifying who you are greeting.
*/
{template .hiWorld}
Hello
{if $name}
{$name}!
{else}
world!
{/if}
{/template}
After I compile and call document.write(examples.simple.hiWorld();, however, the displayed string has no space between "Hello" and "world": Helloworld!
Why not?

Closure Templates handle line joining as follows:
Within the body of a template, you can indent the lines as much as you want because the template compiler removes all line terminators and whitespace at the beginning and end of lines, including spaces preceding a rest-of-line comment. The compiler completely removes empty lines that consist of only whitespace. Consecutive lines are joined according to the following heuristic: if the join location borders a template or HTML tag on either side, the lines are joined with no space. If the join location does not border a template or HTML tag on either side, the lines are joined with exactly one space.
To add a space in a Closure Templates where one is needed, use the special character command {sp}. In cases where an unwanted space is inserted, you may remove it using the command {nil}. For line joining examples, see features.soy.
simple.soy would become:
{namespace examples.simple}
/**
* says hello to the world
* #param? name Optional parameter specifying who you are greeting.
*/
{template .hiWorld}
Hello{sp}
{if $name}
{$name}!
{else}
world!
{/if}
{/template}

Related

Place plaintext right beside variables (without whitespace) in VS Code User Snippets

I would like to create a User Snipper in VS Code that is a combination of variables and plaint text. This can typically be achieved by combining variables and plain text with a whitespace between then. But I would like to ad a variable next to a text without a whitespace.
For Example, I would like to create the current timestamp like this:
2022-02-19T21:02:24-0530
Below is what I tried
$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATET$CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND-0530
Notice the T in between $CURRENT_DATE & $CURRENT_HOUR
OUTPUT:
2022-02-CURRENT_DATET21:06:12-0530
You can add $ symbol before the plain-text you want to add.
In this case, you need at add $T instead of T
$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE$T$CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND-0530
Note that $T will get considered as a placeholder, and it will be the last item selected while tabbing through the inserted snippet.

Regex without spaces [duplicate]

I am writing a regular expression(regex) for adding multiple email ids in an input box with following conditions:
Multiple email ids must be separated with comma ,
Need to have atleast one email id
There should not be any whitespaces in input field.
So i created this regex:
^(([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([,.](([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$
I tested it in regex101.com and its working like a charm https://regex101.com/r/bU7rU8/1
But when i integrate it with code, it works, but fails on leading and trailing whitespace.
Here is the demo link: http://jsfiddle.net/2G8gA/330/
AngularJS trims the input by default, so you need to use ng-trim="false" in order to pass leading and trailing whitespace to your pattern regex.
See documentation:
ngTrim (optional)
If set to false Angular will not automatically trim the input. This parameter is ignored for input[type=password] controls, which will never trim the input.
(default: true)
Do you want leading/trailing spaces allowed on the whole string, or around each individual address?
For the former your regex should be
/^(\s*([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([,.](([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+\s*)*$/
and for the latter
/^(\s*([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25}\s*)+([,.](\s*([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+\s*)*$/

In there a convenient way to have multiline input in libedit/editline

Using libedit/editline, and trying to figure out a good way to do multiline input/editing. The target is an SQL client, where queries will often span multiple lines and terminate with ;.
I can call el_gets, and process each line of input, stopping when I see the terminating ;. I can even concatenate those and store them as a single entry in el_history - and it will correctly access them when using the arrows to scroll through history.
However, when entering the command and after starting a new line, I can no longer use the arrows to move up and edit the previous line. E.g.:
prompt> SELECT * FROM table
WHERE 🀫
At that point, I'd like to be able to use the up-arrow, to move up and edit the text already entered on the first line. Is this possible? How would one do so? I assume that using el_gets isn't correct in this case, since it would remove the line from the editline buffering, yet I don't see an alternative API that would work.
Thoughts?

Sublime Text Snippet: Create camelcased string from the hyphenated file name

I am trying to create a Sublime Text snippet for AngularJs. This snippet should expand to AngularJs controller (or service, etc or any ng component). In the resulting code, it should construct the controller name in camelCase from the hyphenated file name.
For example:
when I type the snippets strings, say, ngctrl in an empty file called employee-benefits-controller.js, it should expand as given below:
angular.module('').controller('EmployeeBenefitsController', ['', function(){
}]);
I am trying to use the $TM_FILENAME variable by applying a regex on it to achieve this conversion. If anyone has already done this, please let us know.
You could use something like this:
<snippet>
<content><![CDATA[
angular.module('${1:moduleName}').controller('${TM_FILENAME/(^|-|\.js)(.?)|/\U\2\E/g}', ['', function(){
${2://functionCode}
}]);
]]></content>
<tabTrigger>ngctrl</tabTrigger>
</snippet>
Notes:
Note 1: maybe you want to change the scope so that the snippet its only triggered in javascript context.
Note 2: I'm not familiar with angularjs, so I don't know its naming conventions (I have supposed that an uppercase letter its needed after a hyphen [-] character and at the begining of the name, but I don't know if a uppercase character its needed after a dot character for example). So, you'll probablly have to adapt the snippet.
Note 3: expression explained:
${TM_FILENAME/(^|-|.js)(.?)/\U\2\E/g}
TM_FILENAME its the var_name item
(^|-|.js)(.?) its the regex (the parts of the variable we select).
\U\2\E its the format_string (how we format what we have selected).
g its the options (g means globally, so every time something its selected the format its given).
TM_FILENAME: the file name with the extension included.
\U => init uppercase conversion. \E => finish uppercase conversion. \2 => second group, i.e. second parénthesis, (.?), its a single char or an empty string.
(^|-|.js)(.?) First we look for the beginning of the word (^), or for a hypen character (-), or for the extension (.js).
(.?) Then we select in a parenthesis group (second group) the character (if any) after that hypen (or at the beginning of the word or after the extension).
Finally we use the uppercase conversion over that selected character as explained. Note that as there is not character after the extension, we are simply removing the extension from the output.
Note 4: as you probablly know, using ${1:moduleName} and ${2://functionCode} allows you to quickly move (using tab) and edit the important parts of the snippet once it has been triggered, such as the module or the function code.

extJS didnt see too big text with many <br>'s

extJS didnt see too big text with many <\br>'s..
If i write text something like "lalal lalalal lsadsdhas afjhjhj";
Its okei, works.
If i write text with \n (<\br>) something like:
"hello,
my name
is Polly!";
ExtJS didnt see those lines. How i can avoid this?
Thank you!
This is because Javascript doesn't allow multi-line strings. If you want a linebreak in your string, it has to be coded with an escape sequence like '\r\n'. So,
alert("hello, \r\nmy name\r\nis Polly!");
will display as 3 lines. If the string is going into an html element, then insert '<br />' in place of the '\r\n'.
finally, if you need a long string with lots of blank spaces between the words, for some reason, you can either keep typing on the same line, or break it up into several lines and combine the lines with the '+' operator, like this:
var longstring =
'hello \r\n'
+'my name \r\n'
+'is Polly!';

Resources