V
V
Vladimir Kozhin2015-02-19 04:56:25
JavaScript
Vladimir Kozhin, 2015-02-19 04:56:25

How to specify jsdoc for this in templates (underscore)?

Hello!
I'm trying to make it sane to display underscore templates in the PhpStorm IDE. To highlight the <% ..js here.. %> tags, I found the ejs plugin, it has a similar syntax, so it works. (If you know better - let me know, because it does not suit me 100%).
Next, I try to specify the types of variables that are passed to the template, as well as what this is for this template.
I'm trying like this:

<%
    /** @this Jii.view.WebView this */
    /** @typedef {String} myvar */
%>
<% this.registerJsFile('http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js'); %>
<% this.registerCss('body {background: #eee;}'); %>
<% this.registerJs('console.log(6626)', 'head'); %>

<div>
    <%= myvar %>
</div>

The myvar variable, although it is highlighted crookedly, however, by clicking on it, it refers to a piece of documentation. And here this - in any. Tried using typedef as well - doesn't help either. The this type is very necessary for the hints in the IDE to work.
Who knows how to overcome? Maybe someone else solved the problem?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kozhin, 2015-02-26
@affka

So far I've only solved it this way:

<%
/** @typedef {String} qqq */
/** @this {Jii.view.WebView} */
(function() {
%>

    <% this.registerCssFile('http://api.jquery.com/jquery-wp-content/themes/jquery/css/base.css'); %>
    <% this.registerJsFile('http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js'); %>
    <% this.registerCss('body {background: #eee;}'); %>
    <% this.registerLinkTag({
        rel: 'icon',
        type: 'image/x-icon',
        href: 'https://assets-cdn.github.com/favicon.ico'
    }); %>
    <% this.registerMetaTag({
        authenticity_token: 'csrf-param'
    }); %>

    <div>
        <%= qqq %>
    </div>

<% })(); %>

K
Konstantin Kitmanov, 2015-02-19
@k12th

The obvious solution is to call this variable something else, like thator self.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question