How to create a nested array in SASS, not SCSS - sass

So I know that you can make an array in SCSS just by this code:
$clr: (
prim: (
step1: #8ef99e,
step2: #76f789,
step3: #5ef674,
step4: #46f460,
step5: #2ef34b,
step6: #0de12c,
step7: #0cc927,
step8: #0ab123,
step9: #09991e,
step10: #078119,
step11: #066814
),
light: (
step1: #ffffff,
step2: #f7f7f7,
step3: #f0f0f0,
step4: #e8e8e8,
step5: #e0e0e0,
step6: #d9d9d9
)
)
but that's only if you're coding in .scss, so how can I make this in SASS?
I tried doing this:
$clr:
prim:
step1: #8ef99e,
step2: #76f789,
step3: #5ef674,
step4: #46f460,
step5: #2ef34b,
step6: #0de12c,
step7: #0cc927,
step8: #0ab123,
step9: #09991e,
step10: #078119,
step11: #066814
light:
step1: #ffffff,
step2: #f7f7f7,
step3: #f0f0f0,
step4: #e8e8e8,
step5: #e0e0e0,
step6: #d9d9d9
but I'm getting an error saying
Error: Expected expression.
|
1 | $clr:
| ^
|
Did I make a mistake or is it really unavailable for .sass to make this kind of array?

With SASS, you need to write maps on a single line:
$clr: (prim: (step1: #8ef99e, step2: #76f789, step3: #5ef674, step4: #46f460, step5: #2ef34b, step6: #0de12c, step7: #0cc927, step8: #0ab123, step9: #09991e, step10: #078119, step11: #066814), light: (step1: #ffffff, step2: #f7f7f7, step3: #f0f0f0, step4: #e8e8e8, step5: #e0e0e0, step6: #d9d9d9))

Related

why Php increment count session twice per page load?

My wordpress php script is incremented by two instead one.
++$_SESSION['visitor'] is incremented by two !
In functions.php
if ( !isset( $_SESSION['visitor'] ) ) $_SESSION['visitor'] = 1; else ++$_SESSION['visitor'];
I have to do this in echo to have Session + 1 otherwise I get Session + 2: In any php file
`<?php echo --$_SESSION['visitor'] ; ?>`
I don't know what can cause this.
If I increment when I echo The session is well incremented by 1 , why ?.
if ( !isset( $_SESSION['visitor'] ) ) $_SESSION['visitor'] = 1; else $_SESSION['visitor'];
<?= $_SESSION['visitor'] .' + ' . ++$_SESSION['visitor']; ?>
The increment add well +1 only on any php file inside theme but add +2 every time using it in functions.php. For both I use the same syntax ++$_SESSION['visitor']
I have add params to session to allow subdomains in functions.php:
session_set_cookie_params(0, '/', '.website.com');

Nuxt color-mode SassError: argument `$color` of `lightness($color)` must be a color

My Nuxt SSR project uses Bulma/Buefy and I am trying to use the #nuxtjs/color-mode module with it
Here is my vars.scss file where I define the light-mode and dark-mode classes
// Import Bulma's core
#import '~bulma/sass/utilities/_all';
$primary-light-color: #0075f2;
$primary-dark-color: #0015f2;
html {
&.light-mode {
--primary-color: #{$primary-light-color};
}
&.dark-mode {
--primary-color: #{$primary-dark-color};
}
}
// Set your colors
$white: #fdfffc;
$black: #272932;
$primary: var(--primary-color);
$primary-invert: findcolorinvert($primary);
$link: #004ba8;
$link-invert: findcolorinvert($link);
$info: #00b4d8;
$info-invert: findcolorinvert($info);
$success: #4cb944;
$success-invert: findcolorinvert($success);
$warning: #ffba08;
$warning-invert: findcolorinvert($warning);
$danger: #f06543;
$danger-invert: findcolorinvert($danger);
$facebook: #3b5998;
$facebook-invert: findcolorinvert($facebook);
$twitter: #4099ff;
$twitter-invert: findcolorinvert($twitter);
$google: #dd4b39;
$google-invert: findcolorinvert($google);
$github: #333;
$github-invert: findcolorinvert($github);
// Setup $colors to use as bulma classes (e.g. 'is-twitter')
$colors: (
'white': (
$white,
$black,
),
'black': (
$black,
$white,
),
'light': (
$light,
$light-invert,
),
'dark': (
$dark,
$dark-invert,
),
'primary': (
$primary,
$primary-invert,
),
'info': (
$info,
$info-invert,
),
'success': (
$success,
$success-invert,
),
'warning': (
$warning,
$warning-invert,
),
'danger': (
$danger,
$danger-invert,
),
'facebook': (
$facebook,
$facebook-invert,
),
'twitter': (
$twitter,
$twitter-invert,
),
'google': (
$google,
$google-invert,
),
'github': (
$github,
$github-invert,
),
);
$navbar-height: 3.5rem;
// https://bulma.io/documentation/components/pagination/#variables
// Removed to make the pagination at the bottom of any table appear without vertical scrollbar
$pagination-margin: 0;
It gives me the following error
ERROR in ./assets/app.scss (./node_modules/css-loader/dist/cjs.js??ref--7-oneOf-1-1!./node_modules/postcss-loader/src??ref--7-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--7-oneOf-1-3!./node_modules/sass-resources-loader/lib/loader.js??ref--7-oneOf-1-4!./assets/app.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: argument `$color` of `lightness($color)` must be a color
on line 58 of node_modules/bulma/sass/components/message.sass, in function `lightness`
from line 58 of node_modules/bulma/sass/components/message.sass
from line 10 of node_modules/bulma/sass/components/_all.sass
from line 7 of node_modules/bulma/bulma.sass
from line 101 of assets/app.scss
>> $color-lightning: max((100% - lightness($color)) - 2%, 0%);
------------------------------------^
Here is my link to CodeSandbox Can someone kindly tell me how to fix this?
You are passing a var() ($primary: var(--primary-color);) instead of a color (HEX, HSL, RGB, etc).
I ran into a similar problem and got the same Error: SassError: argument '$color' of 'lightness($color)' must be a color.
found out that according to #PirateApp this error occurs because we gave to lightness() method a variable "that references to another variable instead of a color" as an argument.
this means that we can provide a variable as an argument, only if our variable references to a color. So the solution I came up with, is a little trick;
When defining a variable, make it as an adjusted color, instead of referencing to another variable.
so instead of this:
'white': (
$white,
$black,
),
we can write it this way:
'white': (
adjust-hue($white,0deg),
adjust-hue($black,0deg),
),

Sphinx/RST: Include another RST file without adding it to the TOC?

I'm improving some technical docs (Sphinx) and would like to include the contents of an RST file in multiple places; however, in doing so, that RST file is being added to the TOC multiple times. How can I include the file where I want but only reference the section in the TOC once?
Here's what the index.rst file looks like:
Documentation
=================
.. toctree::
:maxdepth: 4
../path/to/releasenotes.rst
../path/to/general_api_usage.rst
main_content.rst
Next, here's main_content.rst:
============
Main Content
============
These docs reference:
- :ref:`section-1`.
- :ref:`section-2`.
- :ref:`section-3`.
- :ref:`section-4`.
.. include:: section1.rst
.. include:: section2.rst
.. include:: section3.rst
.. include:: section4.rst
"Section 4" is a reference table; I'd like to include it in "Section 2", for example, but also keep it at the bottom of the docs like an appendix.
Here's what section2.rst looks like:
.. _section-2:
This is Section 2
********************
.. include: section4.rst
Some other Section 2 content.
And finally, what section4.rst might look like:
.. _section-4:
This is Section 4
********************
+------------------+-------------------------+
| Heading | Heading 2 |
+==================+=========================+
| This is what I | want to reference |
+------------------+-------------------------+
| in other rst | files. |
+------------------+-------------------------+
When I do this, my table of contents includes "Section 4" twice. Any insights? Thanks!
Thanks to a suggestion from #sinoroc, I've come up with a solution:
I removed the following from section4.rst, and kept only the table:
.. _section-4:
This is Section 4
********************
I added it to the top of a new file, appendix.rst, and added a reference to section4.rst:
.. _section-4:
This is Section 4
********************
.. include:: section4.rst
I then modified my main_content.rst to refer to appendix.rst instead of section4.rst.
My main learning point: The TOC reflects the headings in the referenced files.

Stop PhpStorm from aligning associative arrays

How can I tell PhpStorm (using version 8.0.3) to keep the following array as is when clicking Cmd+Alt+L to reformat my code:
$array = [
'short' => 1, // I want this...
'veryVeryVeryIncrediblyLong' => 123456789,
];
Instead of doing this:
$array = [
'short' => 1, // Not this...
'veryVeryVeryIncrediblyLong' => 123456789,
];
Settings (Preferences on Mac) | Editor | Code Style | PHP | Other | Array declaration style -> Align key-value pairs
Since PhpStorm 2017.x version it is now located at Settings (Preferences on Mac) | Editor | Code Style | PHP | Wrapping and Braces --> Array initializer | Align key-value pairs
In Phpstorm 2017.3 & later , This setting is located at
File | Settings | Editor | Code Style | PHP | Wrapping and Braces | Array initializer | Align key-value pairs
Preferences → Editor → Code Style → PHP → Other → Align key-value pairs
PhpStorm 2019 and up: Settings -> editor -> PHP -> Wrapping and Braces -> Array initializer -> Align key-value pairs [*] (Linux OS)
In phpstorm 2019 it goes somewhere like this:
(settings > editor > php > Wrapping and Braces > Assignment statement > Align consecutive assignments)
PHPStorm 9 align assignments in PHP

magento category tree menu query being called on every page

I have this query being called on every page in Magento CE 1.6.2. To find out where is it being called from, I have disabled all modules, removed the customizations done but it's still being called, this query is slowing up the page loading time and am at my wit's end trying to find out how can I stop it from being executed.
The query is given below, for simplcitiy, I have removed lot of category id' to keep the sql short. It would be great if I could get solutions or hints to stop this query being called.
SELECT `e`.*, IF(at_is_active.value_id > 0, at_is_active.value, at_is_active_default.value) AS `is_active`, IF(at_include_in_menu.value_id > 0, at_include_in_menu.value, at_include_in_menu_default.value) AS `include_in_menu`, `core_url_rewrite`.`request_path` FROM `catalog_category_entity` AS `e`
INNER JOIN `catalog_category_entity_int` AS `at_is_active_default` ON (`at_is_active_default`.`entity_id` = `e`.`entity_id`) AND (`at_is_active_default`.`attribute_id` = '119') AND `at_is_active_default`.`store_id` = 0
LEFT JOIN `catalog_category_entity_int` AS `at_is_active` ON (`at_is_active`.`entity_id` = `e`.`entity_id`) AND (`at_is_active`.`attribute_id` = '119') AND (`at_is_active`.`store_id` = 1)
INNER JOIN `catalog_category_entity_int` AS `at_include_in_menu_default` ON (`at_include_in_menu_default`.`entity_id` = `e`.`entity_id`) AND (`at_include_in_menu_default`.`attribute_id` = '934') AND `at_include_in_menu_default`.`store_id` = 0
LEFT JOIN `catalog_category_entity_int` AS `at_include_in_menu` ON (`at_include_in_menu`.`entity_id` = `e`.`entity_id`) AND (`at_include_in_menu`.`attribute_id` = '934') AND (`at_include_in_menu`.`store_id` = 1)
LEFT JOIN `core_url_rewrite` ON (core_url_rewrite.category_id=e.entity_id) AND (core_url_rewrite.is_system=1 AND core_url_rewrite.product_id IS NULL AND core_url_rewrite.store_id='1' AND id_path LIKE 'category/%') WHERE (`e`.`entity_type_id` = '9') AND (`e`.`entity_id` IN('105', '125', '284', '285', '286', '288', '289', '185', '463', '464', '465', '625')) AND (`e`.`entity_id` NOT IN('140', '145', '530', '531', '775')) AND (IF(at_is_active.value_id > 0, at_is_active.value, at_is_active_default.value) = '1') AND (IF(at_include_in_menu.value_id > 0, at_include_in_menu.value, at_include_in_menu_default.value) = '1')
Cheers
Arjun
This can be caused by index catalogue_url
A quick fix is to set all indexing to manual.
Then run this shell script via cron hourly:
php shell/indexer.php --reindex catalog_product_attribute
php shell/indexer.php --reindex catalog_product_price
php shell/indexer.php --reindex tag_summary
php shell/indexer.php --reindex cataloginventory_stock
php shell/indexer.php --reindex catalogsearch_fulltext
php shell/indexer.php --reindex catalog_category_product
php shell/indexer.php --reindex catalog_category_flat
php shell/indexer.php --reindex catalog_product_flat
It indexes all but urls.
Then run this nightly:
<?php
echo "clearing core_url_rewrite so that indexer can repopulate immediately\n";
require_once "/home/path/to/store/app/Mage.php";
umask( 0 );
Mage::App('default');
$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$query = "TRUNCATE `core_url_rewrite`";
$writeConnection->query($query);
echo "cleared\n";
$start = time();
echo "reindexing catalog_url start \n";
$process = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_url');
$process->reindexEverything();
$finish = time() - $start;
echo "reindexing catalog_url finished in ".$finish." seconds \n";
?>
Seems like a query that would be used for the navigation. The magento default theme pulls the categories for the dynamic top nav in:
/app/code/core/Mage/Catalog/Block/Navigation.php
renderCategoriesMenuHtml() is called from (by default) from:
base/default/template/catalog/navigation/top.phtml
Replace the top.phtml code with a regularly updated static version of the menus.
Create a file menu.php in your magento root folder:
#!/usr/bin/php
<?php
require_once('app/Mage.php');
Mage::app();
$block = new Mage_Catalog_Block_Navigation();
$_menu = $block->renderCategoriesMenuHtml(0,'level-top');
echo "
<div class='nav-container'>
<ul id='nav'>
$_menu
</ul>
</div>
";
?>
Then, in your ./shell directory create another file, create-category-menus.sh.
#!/bin/bash
/[path to magento root]/menu.php > /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml.temp
rm -f /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml
mv /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml.temp /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml
chown [webserver-user].[webserver-group] /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml
Now, just add the create-category-menus.sh to your crontab at regular intervals, say 15 minutes or so.
You'll probably need to create the folder structure for the output file, and this also assumes that your using a linux server. If you're not then you should be. :)
Enable the Blocks HTML output cache. Thus the menu has to be rendered only the first pagecall. Since magento 1.7 this block isn't cached anymore and the caching needs to be enabled programmatically.

Resources