How to get file name while creating snippets (Live Templates) - webstorm

I am creating a snippet for my templates in Meteor and the only thing left to be perfect would be to know the file name in which that snippet was called.
What I have:
type: temp + tab
What I get:
<template name="">
</template>
What I want:
<template name="">
file_name.html
</template>

Live Templates is how "snippets" are called in WebStorm and other IDEA-based IDEs.
There is filename() function (fileNameWithoutExtension() has been added a few version later) that can provide such info/text for a variable. Official documentation.
Knowing that: add a variable into your template and then use the aforementioned function on it:
<template name="$END$">
$FILE$
</template>
Now click on "Edit Variables" button and use it there. Selecting "Skip if defined" will make that variable "non-editable" during template expansion.

Related

how to use custom templates for same classes in field plugin, grails

For example I have 2 class:
Person {
String name
String descriptionOfPerson
}
Company {
String name
String descriptionOfCompany
}
Normally, fields plugin will use the same template /_fields/string/_field.gsp for all of them.
But I want to use /_fields/string/_field.gsp template for String name and /_fields/ckeditor/_field.gsp (to render ckeditor) for descriptionOfPerson and descriptionOfCompany
Is it possible to do like that? And how ?
As far as I know the plugin and it's documentation this is not possible without modifications on your side.
The default order in which the plugin searches for the templates is:
grails-app/views/controllerName/actionName/propertyName/
grails-app/views/controllerName/actionName/propertyType/
grails-app/views/controllerName/actionName/ (not applicable here)
grails-app/views/controllerName/propertyName/
grails-app/views/controllerName/propertyType/ (not applicable here)
grails-app/views/controllerName/ (not applicable here)
grails-app/views/_fields/class/propertyName/
grails-app/views/_fields/superclass/propertyName/
grails-app/views/_fields/associationType/ (not applicable here)
grails-app/views/_fields/propertyType/
grails-app/views/_fields/propertySuperclass/ (not applicable here)
grails-app/views/_fields/default/
Neither is there a possibility to pass a custom template, nor to distinguish between between the property name when the template is found via the property's class.
However, there are some possibilities to realize your case.
A) Template condition
You could include a condition into the /_fields/string/_field.gsp template and make use of the provided template parameters, such as:
<g:if test="${property == 'descriptionOfPerson' || property == 'descriptionOfCompany' }">
<!-- render your ckeditor here or include another template via g:render -->
</g:if>
<g:else>
<!-- render your normal input here or include another template via g:render -->
</g:else>
B) Template for each controller property
for instance:
grails-app/views/_fields/person/description/ and
grails-app/views/_fields/company/description/.
Both templates could include another template via g:render, being place at grails-app/views/_fields/ckeditor/
Applying this to your example, you could place the template in any of the bold paths and it would be preferred to the /_fields/string/_field.gsp template.
Personally I would stick with B), which allows a more fine-grained control and is easier to understand for others that are not familiar with your code. I would also rename both of your fields to description. As always, this decision depends on your complete application and its overall complexity.
The default rendering mechanism of the fields plugin (without using the override template stuff) uses the widget constraint of grails to render a textarea instead of a <input type="text" /> (as you see in the source of the fields plugin).
With an unobtrusive javascript library (ckeditor seems to have these capabilities as described in their dev guide), that replaces a <textarea> with something more exciting, the only thing you have to do is the following:
Person {
String name
String descriptionOfPerson
static constraints = {
descriptionOfPerson widget: 'textarea'
}
}
Company {
String name
String descriptionOfCompany
static constraints = {
descriptionOfCompany widget: 'textarea'
}
}
At least now (2 years after initial post) I found 2 working solutions for me:
(1) specify for every field I want to have wysiwyg editor functionality a sub-folder in views (like grails-app/views/myDomainObject/myWysiwygField/_wrapper.gsp) with the following content:
<div class="fieldcontain${required ? ' required' : ''}">
<label for="${property}">${label}<g:if test="${required}"> <span class="required-indicator">*</span></g:if></label>
<ckeditor:config var="toolbar_Mytoolbar">
[
[ 'Undo', 'Redo', '-', 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList']
]
</ckeditor:config>
<ckeditor:editor name="${property}" width="40%" toolbar="Mytoolbar">${value}</ckeditor:editor> <!-- toolbar="Basic" -->
</div>
(2) declare the wysiwyg fields as textarea
static constraints = {
myWysiwygField widget: "textarea"
}
and define (once) grails-app/views/_fields/textarea/_wrapper.gsp with the same content than above.
So the first one is more fine-granular while the second one is more appealing for simpler problems.

Bigcommerce: %%SNIPPET_SideCategoryList%% - where is the underlying template file?

In the file template/Panels/SideCategoryList.html there is line %%SNIPPET_SideCategoryList%%.
When I modify the file I think this line is referring to (template/Snippets/SideCategoryList.html) I see no change in the resulting output at all.
Any idea where the underlying template file is?
UPDATE: according to this post it could be a 'hidden snippet' which can't be edited. Can anyone confirm this? If so, what is the purpose of template/Snippets/SideCategoryList.html?
template/Panels/SideCategoryList.html
<div class="CategoryList" id="SideCategoryList">
<h3>Categories</h3>
<div class="BlockContent">
<div class="%%GLOBAL_SideCategoryListTypeClass%%">
%%SNIPPET_SideCategoryList%%
</div>
</div>
</div>
template/Snippets/SideCategoryList.html
<li class="%%GLOBAL_LastChildClass%%">
%%GLOBAL_CategoryName%%
%%GLOBAL_SubCategoryList%%
</li>
As you can see from the above template code, between the Panels and Snippets SideCategoryList.html there isn't a <ul>. Making changes to template/Snippets/SideCategoryList.html makes no difference. This seems to point to %%SNIPPET_SideCategoryList%% pulling in code from elsewhere.
Judging by the superfish classes being present on the ul, it sounds like you're using the 'Flyout menu' as the 'Category Menu Style' (This option can be found in Setup & Tools > Store Settings > Display).
When using the Flyout menu, the snippet that is being referenced is not 'Snippets/SideCategoryList.html'. Instead, try using the 'Snippets/FlyoutTree.html' and 'Snippets/FlyoutNode.html' templates.

How to extensively configure an Ember.Component

I am creating an Ember.Component which displays a CRUD table. As the component shall be reusable it needs a lot configuration, such as columns to display, pagination options, etc. ...
At the moment I am inserting the component using handlebars:
<div class="some-div">
{{power-table items=this.model columns='...'}}
</div>
I wouldn't want to use this nice way of inserting a component. However, it is pot really possible to extensively configure a component here, is it? I found out it's not even possible to pass an object as parameter, e.g. the following it not possible:
<div class="some-div">
{{power-table items=this.model columns=[id, name, foo, bar] }}
</div>
How and where should I configure the component?
What you can do is that instead of setting columns=[id,name,foo,bar] in the handlebar like this:
<div class="some-div">
{{power-table items=this.model columns=[id, name, foo, bar] }}
</div>
You can set the columns property in the controller for the handlebar template and use the name of the property in the handlebar file. So all the logic would come from the controller and the handlebar would just tell which property is accessible in the component and by what name. So the controller for the enclosing template would be the best place to heavily configure the component. Have a look at the following page for more info:
http://emberjs.com/guides/components/passing-properties-to-a-component/
I am not sure if I understood your problem correctly.

Nested template overwrite ui:default with ui:insert

Is there a rule on how to overwrite template definitions <ui:define> with <ui:insert>.
Template A:
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets">
template A content<br/>
<ui:insert name="content"/>
</ui:composition>
Template B:
<ui:composition template="/resources/templates/A.xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:define name="content">
template B content<br/>
<ui:insert name="content"/>
</ui:define>
</ui:composition>
Site 1:
<ui:composition template="/resources/templates/B.xhtml">
Site 1<br/>
<ui:define name="content">
site content<br/>
</ui:define>
</ui:composition>
Output:
Site 1
site content
Content for the <ui:define> is taken from Site 1, the content of the templates is not rendered.
Site 2:
<ui:composition template="/resources/templates/B.xhtml">
Site 2<br/>
</ui:composition>
Output:
Site 2
template B content
template A content
Content for the <ui:define> is taken from template B and template A, where strangely template B content is rendered before content of template A.
Is it possible to overwrite <ui:define> with a new <ui:insert> using same name?
Creating new names for the nested <ui:insert> is one possibility but its hard to keep track of the hierarchy and where insert's are used at all.
Unfortunately Facelets doesn't allow you to 'chain' insert/define.
In your first example (Site 1), there is single insert in Template A called "content". There are two definitions being considered; that of the direct template client (Template B) and that of the template client of Template B (Site 1). For this case, Facelets does not see that Template B has another insert. It just considers two competing definitions for "content", and the rule is that the top-most one wins, which is Site 1.
You did forgot to put the namespace on the template client though. The output you should be seeing is:
template A content
site content
Namely "template A content" is in the lowest template, outside the insert tag. It will be rendered directly. "site content" is in the top-most definition of "content".
In the second example (Site 2), there is no definition at all in the top-most template client. There is only one definition, and that's in Template B, so that one will be used. The output you should be seeing is:
template A content
template B content
You'll see "template A content" for the same reasons as in the first example, and "template B content" since it's the only definition. The nested second insert after that will be ignored.
Creating new names for the nested is one possibility but its hard to keep track of the hierarchy and where insert's are used at all.
It is indeed. Precisely for this reason I created a spec issue over a year ago for this at: https://github.com/eclipse-ee4j/faces-api/issues/1008
If this particular functionality is important to you please vote and/or leave a comment.

How can I add the filename of each used templates and includes in freemarker templates as HTML comments?

Is there a way to configure freemarker so that the Freemarker template engine automatically inserts the name of the current template as an HTML comment?
Example HTML output I would like to see:
<!-- template file: main.ftl -->
normal template code of the file main.ftl
<!-- template file: myinclude.ftl -->
This is the code from myinclude.ftl
I would like to use such functionality for debugging purposes only so that it is easier to find out which HTML fragments where rendered in which template.
Any hints?
You could write a TemplateLoader implementation that just delegates to another TemplateLoader (to the one that you are using when not in debug-mode), but captures the stream that it returns, and inserts the HTML comment after the <#ftl ...> directive. (But don't add line-break to the comment, or else it will offset the line number in error messages; use ${'\n'}<!-- ... -->${'\n'} instead.)