I have a problem. I don't know how to change settings in Prettier .
This is how it styles now:
if (currentQuestionNum === MAX_QUESTIONS) btnAns.textContent = "End";
How i want it to be styled:
if (currentQuestionNum === MAX_QUESTIONS)
btnAns.textContent = "End";
What setting I need to change?
Related
I want to replace email variable into a hyperlink using template processor and I have used two way to solved this issue but didn't work and here is our below code for replacing email variable into hyperlink but when I used setValue or setComplexValue function for replacement value then document is corrupted.
We have tried below two scenarios for adding hyperlink but didn't work for us.
1. First Way
$pw = new \PhpOffice\PhpWord\PhpWord();
$section = $pw->addSection();
$textrun = $section->addTextRun();
$textrun->addTextBreak(2);
$section->addLink('mailto:demo1#gmail.com?subject=DEMO','demo1#gmail.com', array('color' => 'FF0000', 'underline' =>
\PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
$fullXml = $objWriter->getWriterPart('Document')->write();
$templateProcessor->setValue($var, $this->getBodyBlock($fullXml));
2. Second Way
$pw = new \PhpOffice\PhpWord\PhpWord();
$section = $pw->addSection();
$convertResult = 'demo1#gmail.com';
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $convertResult, false,false);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
$fullXml = $objWriter->getWriterPart('Document')->write();
$templateProcessor->setValue($var, $this->getBodyBlock($fullXml));
protected function getBodyBlock($string) {
if (preg_match('%(?i)(?<=<w:body>)[\s|\S]*?(?=</w:body>)%', $string, $regs)) {
return $regs[0];
} else {
return '';
}
}
Please help us thank in advance.
Prettier formats if statement without curley braces into one line.
This means that this :
function getErrorMessage(response) {
let errorMessage = null;
if (!response.originalError.response)
errorMessage = 'network error';
else
errorMessage = response.originalError.response.data.errorMessage;
return errorMessage;
}
becomes this :
function getErrorMessage(response) {
let errorMessage = null;
if (!response.originalError.response) errorMessage = 'network error';
else errorMessage = response.originalError.response.data.errorMessage;
return errorMessage;
}
which is FAR more unreadable.
Is there a way of disabling this?
As asked in a similar question, it turns out that the answer is that you can not and will not be able to.
As for the WFT that an average senses, well... Apparently, opinionated doesn't mean respected and well-considered in opinion of many. It means that it's implementing the author's opinion.
So, surprisingly, the unexpected thing isn't the lack of configurability but rather that there are any options to be set at all! Go figure... Someone should create a new package called EvenPrettier or FexiblyPrettier and fork in more options. If I only knew how, I'd do it.
I finally ended up using Beautify - HookyQR extension for vscode
https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify
Example Settings
File: .jsbeautifyrc
{
"brace_style": "collapse,preserve-inline",
"max_preserve_newlines": 2,
"end_with_newline": false
}
Example Code
File: a.js
function dfs(start) {
if (start > n)
return;
ans.push(start);
for (let i = 0; i <= 9; i++)
dfs(start * 10 + i);
}
i want to ask something related with php activerecord
here'se my code
public function validate()
{
$log = Login::find(1);
$login = new Login(array(
'id' => 1,
'user' => $_POST['user'],
'pass' => $_POST['pass']
));
if ($this->user = $log->user AND $this->pass = $log->pass | $log->user = $this->user AND $log->pass = $this->pass)
{
APP::redirect('dashboard.index');
}else{
APP::redirect('dashboard.login');
}
}
i wonder why my code always redirect to dahsboard.index although the value from input form and database are different. is there something i missed? and english isn’t my first language, so please excuse any mistakes. thanks before.
You seem to have confused = (assignment) with == (comparison). So you'd get a lot of 'TRUE' in that if.
Are there any worthwhile alternatives for Sinon.js?
Thanks.
Testdouble.js
There is also library called testdouble.js. Which is a kind of more object-oriented than sinon.js.
Also, this article from testdouble guys explain the differences between sinon.js and testdouble.js.
Example
var td = require('testdouble');
var fetch = td.function();
td.when(fetch(42)).thenReturn('Jane User');
fetch(42); // -> 'Jane User'
Not quite as advanced, but you can look at Jack.
I just started a new project called candy-wrapper that may be an alternative to Sinon in some instances:
https://www.npmjs.com/package/candy-wrapper
Here are some examples of how to use it, I would love feedback if anyone has any insights as to how to make it better:
var Wrapper = require("candy-wrapper");
// a simple test object
var myDrone = {
name: "DJI",
fly: function(direction) {
return true;
}
}
new Wrapper(myDrone, "name");
new Wrapper(myDrone, "fly");
myDrone.fly("north");
myDrone.fly("west");
// evaluating previous calls through the 'historyList' and 'Filters'
myDrone.fly.historyList.filterFirst().expectCallArgs("north"); // true
myDrone.fly.historyList.filterSecond().expectCallArgs("east"); // false
myDrone.fly.expectReportAllFailtures(); // throws an error about the "east" expecation failing
// modifying behavior using 'Triggers'
myDrone.fly.triggerOnCallArgs("east").actionReturn(false); // will return 'false' when called with "east"
myDrone.fly("east"); // false
myDrone.fly("west"); // true (the default return value)
// working with properties
myDrone.name.triggerOnSet().actionThrowException(new Error("do not set the name"));
myDrone.name = "Bob"; // throws Error: "do not set the name"
var ret = myDrone.name; // ret = "DJI"
I have a code which works on one server but not on the other. Basically we have written a template file which should be used if URL is discussion_forum but it shows page not found.
/* discussion forum templates */
$querystring=$_GET['q'];
echo $querystring; // THIS PRINTS page-not-found
$querystring=explode('&',$_GET['q']);
if(!isset ($vars['node']) && $querystring[0]=='discussion-forum'){
$vars['template_files'] = array();
$vars['template_files'][] = 'page-discussion_forum';
}
if (!isset ($vars['node']) && $querystring[0]=='discussion_forum_answer') {
$_SESSION['question_id']=$querystring[1];
$vars['template_files'] = array();
$vars['template_files'][] = 'page-discussion_forum_answer';
}
if(!isset ($vars['node']) && $querystring[0]=='discussion_forum_search'){
$vars['template_files'] = array();
$vars['template_files'][] = 'page-discussion_forum_search';
}
when I give page-not-found in place of discussion-forum in $querystring[0]=='discussion-forum'. It shows the the page properly. Don't know whats happening here. Its working fine on other servers.
To add custom tpl I usually add the theme suggestions in the preprocess node.
$vars['theme_hook_suggestions'][] = 'node____'.$vars['view_mode'];
So yours should be
function THEME_preprocess_node(&$vars, $hook)
$vars['theme_hook_suggestions'][] = 'page-discussion_forum_search';
}
It would help if you identify which version of drupal are you using because some of these things change between versions.