Autocompletion for Sass map-get - intellij-idea

Is it possible to get autocompletion in Intellij for sass variables declared inside a map?
$vars: (
A_VARIABLE: A_VALUE,
ANOTHER_VARIABLE: ANOTHER_VALUE
)
With map-get($vars, A_VARIABLE) we call the value.
We need this map to iterate over each var:
#each $key, $value in $vars {
// some code...
}
Can I configure Intellij in the way that I can autocomplete $vars.A_VARIABLE instead of using map-get($vars, A_VARIABLE)?
Another option is to declare all variables without a map. Maybe there is a possibility to iterate over each variable without a map?

It's not yet supported, please vote for WEB-39072 to be notified on a y progress with it

Related

How to add additional methods to autocomplete in IntelliJ

When I'm coding using IntelliJ I frequently use the auto-completion as a way of speeding up my coding, however there are certain methods that it doesn't seem to suggest. One example is Collectors.toMap - it will suggest toSet, toColletion and toList when I type .collect but never toMap which means I need to type more.
As a 1st question, can I fix this behaviour? As a more general question, can I add my own custom code to be auto completed in these types of circumstance?
One trick which helps me out every time while trying to collect the stream is having a placeholder variable with the expected type. Something like:
// just a placeholder variable with proper types, which I can remove later!
Map<String, String> tempMapVariable = someCollection.stream()
.collect(
// here it will suggest the .toMap(...)
Collectors.toMap(i -> i.getKey(), i -> getValue())
);
Set<String> tempSetVariable = someCollection.stream()
.map(SomeCollection::mapperFn)
.collect(
// here it will suggest the .toSet()
Collectors.toSet()
);

How to check if a riot tag exists?

How can I check if a riot tag has already been loaded and compiled (in-browser with script tag), in order to avoid doing it again, programmatically.
In other words, what should I use instead of doesTagExist function in my simplified code, below?
if (!doesTagExist('my-tag')) {
riot.compile('/path/to/my-tag', function() {
riot.mount('dom-node', 'my-tag');
});
} else {
riot.mount('dom-node', 'my-tag');
}
had same problem. After bit of research I think you can't get it directly. Implementation is stored inside __TAG_IMPL which is not accessible from outside. You can however access selector for all implemented tags via riot.util.tags.selectTags(), which returns comma separated list of selectors i.e. datepicker,[data-is="datepicker"].
Oneliner for convenience
riot.util.tags.selectTags().search(/(^|,)my-tag($|,)/g) >= 0
or depending on your purity inclination
riot.util.tags.selectTags().search('"my-tag"')
Note, that first version is future-proof, if riot decides to start using single commas in selector.

LESS variable concatenation and interpolation

I'm attempting to override Bootstrap's hover effect on the buttons. I'd like to save some space and do it the slick way by simply passing into a mixin the name of a class and have that class' background variable be automatically deduced from just that. So my mixin is:
.btn-hover(#name){
.#{name}:hover{
background: lighten( #~"#{name}-bg", 10% );
}
}
.btn-hover(btn-primary);
But I can't seem to access the variable #btn-primary-bg by concatenating -bg to btn-primary, because #~"#{btn-name}-bg" results in a compiler error. Is what I'm trying to do even possible? It would be pretty slick if it were.
Edit -----------------------------------------------------------------
Just stumbled upon this question and it's definitely related, but I think my question really just boils down to:
In LESS, can you access a variable via interpolation after string concatenation?
#btn-success-bg: #00ff00;
#name: btn-success;
#background: #~"#{name}-bg"; // How do I access #btn-success-bg?
You can do:
#btn-primary-bg: red;
.btn-hover(#name){
.#{name}:hover{
#buttonname: ~"#{name}-bg";
background: lighten( ##buttonname, 10% );
}
}
.btn-hover(btn-primary);
Also see: http://lesscss.org/features/#variables-feature-variable-names

Understanding the evaluate function in CasperJS

I want to understand in which case I should or have to use the evaluate function.
I have read the API doc about the evaluate function of CasperJS, but I'm unsure in which case I should use this function. And what does DOM context mean? Can somebody provide an example?
The CasperJS documentation has a pretty good description of what casper.evaluate() does.
To recap: You pass a function that will be executed in the DOM context (you can also call it the page context). You can pass some primitives as arguments to this function and return one primitive back. Keep in mind that this function that you pass to evaluate must be self contained. It cannot use variables or functions that are defined outside of this function.
CasperJS provides many good functions for everyday tasks, but you may run into a situation when you need a custom function to do something. evaluate is basically there to do
Retrieve some value from the page to take action based on it in your script
Manipulate the page in some way other than clicking or filling out a form
Combinations of points 1. and 2.
Examples
You may need a generic function to get the checked property from a checkbox. CasperJS currently only provides getElementAttribute function which will not work in this case.
function getChecked(cssSelector){
return document.querySelector(cssSelector).checked;
}
if (casper.evaluate(getChecked, selector)){
// do something
} else {
// do something else
}
In most of the cases it is just preference of what you want to use. If you have a list of users with data-uid on each li element then you have at least 2 possibilities to retrieve the uids.
Casper-only:
var uids = casper.getElementsAttribute('ul#user-list > li', 'data-uid');
Casper-Evaluate:
var uids = casper.evaluate(function(){
return Array.prototype.map.call(document.querySelectorAll('ul#user-list > li'), function(li){ return li["data-uid"]});
});
Regarding manipulation everything is possible but depends on what you want to do. Let's say you want to take screenshots of web pages, but there are some elements that you don't want to be there. Or you could add your own CSS to the document.
Remove elements:
function removeSelector(cssSelector){
var elements = document.querySelectorAll(cssSelector);
Array.prototype.forEach.call(elements, function(el){
el.parent.removeChild(el);
});
}
casper.evaluate(removeSelector, '.ad'); // if it would be that easy :)
Change site appearance through CSS:
function applyCSS(yourCss){
var style = document.createElement("style");
style.innerHTML = yourCss;
document.head.appendChild(style);
}
casper.evaluate(applyCSS, 'body { background-color: black; }'); // non-sense
Roots
CasperJS is built on top of PhantomJS and as such inherits some of its quirks. The PhantomJS documentation for page.evaluate() says this:
Note: The arguments and the return value to the evaluate function must be a simple primitive object. The rule of thumb: if it can be serialized via JSON, then it is fine.
Closures, functions, DOM nodes, etc. will not work!

can Velocity set a default value for a variable when no value found in VelocityContext?

Velocity just print the tag name if no value was found in VelocityContext, ie, $name in my template file, but there is no value for "name" in VelocityContext, so just "$name" was printed. I want Velocity to print a default value if there is no value for the variable, I just tried to extends AbstractCotnext and override internalGet() method, but the return value of internalGet() will be cast to Node object, I don't know how to create a new Node object in my internalGet() method, and also I think this way is very complex.
is there a simple way to set a default value (default value is just a string) ?
thanks.
Not easily for all variables as far as I see, I only managed to do it for some variables specifically as follows:
Template:
#if ( !$somevar )
#set ( $somevar = "mycontent" )
#end
Var is: $somevar
Result:
Var is: mycontent
Create a velocimacro in your template:
#macro(defaultValue $parm)
#if (!$!parm || $!parm == "")
i-like-will
#else
$parm
#end
#end
And call it like this in the same template:
#defaultValue($name)
Check Apache Velocity - Velocity User Guide for more info on velocimacros (and velocity in general).
A little late to the party, but you could also perform a check when defining a variable. I had to compress this to one line to remove excess space in the output, but here is an example from one of my projects:
#set ( $qlDefault = "qlinks" )
#set ( $qlClass = "#if($sharedCtaImage.getChild('path').value != '/')$qlDefault#else$qlDefault full#end" )
Default class is defined, then I check if another, specific value is filled in to determine if I keep the default class or append an additional class. This could also work for swapping out classes as well.
Google around for Velocity ReferenceInsertionEventHandler for a way to do it broadly.
Consider the DisplayTool's alt() method for individual cases (part of the VelocityTools project)
For an empty default value, $!name will do. Otherwise,
#{if}($name)${name}#{else}${default_value}#{end}
See http://velocity.apache.org/engine/2.0/user-guide.html#quiet-reference-notation
There are a couple things you can do short of hacking Velocity internals. Have a look at this question.