Assets join problem
Hello, I have problem with join assets. For example: style.css
.red-color {
color: #FF0000;
}
style2.css
.green-color {
color: #00FF00;
}
And it joins wrong final output:
.red-color {
color: #FF0000;
};.green-color {
color: #00FF00;
};
As you can see it adds ';' to the end of each file. The second CSS file does not works. When I add style ".green-color" nothing happens.
Here my php code:
$this->assets
->collection('headerCSS')
->setTargetPath('css/application.min.css')
->setTargetUri('css/application.min.css')
->addCss('../app/resources/css/style.css')
->addCss('../app/resources/css/style2.css')
->join(true)
->addFilter(new CssFilter());
I try fix. Not to judge whether the CSS and js.
As a side note: for JS files have to be joined with a semicolon — this is to make sure that there won't be a syntax error if the first JS file does not end with a semicolon or a newline.
Say, first.js:
alert(1)
second.js:
alert(2)
If joined together without adding a semicolon:
alert(1)alert(2)
this will result in a syntax error.
CSS, on the other hand, does not need such separators.
char op[] = ";";
......
if (zend_is_true(join)) {
if (PHALCON_IS_EQUAL(type, type_css)) {
op = "";
}
if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
PHALCON_INIT_NVAR(filtered_joined_content);
PHALCON_CONCAT_VS(filtered_joined_content, filtered_content, op);
} else {
PHALCON_SCONCAT_VS(filtered_joined_content, filtered_content, op);
}
}
Please check if it is possible to do this:
-char op[] = ";";
+const char *op = ";";
If yes, then op will be a compile time constant and will be initialized at compile time — this will save us one assignment at run time :-)
Also just have thought of this:
if (PHALCON_IS_EQUAL(type, type_css)) {
- op = "";
+ op = NULL;
}
if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
PHALCON_INIT_NVAR(filtered_joined_content);
- PHALCON_CONCAT_VS(filtered_joined_content, filtered_content, op);
+ op ? (PHALCON_CONCAT_VS(filtered_joined_content, filtered_content, op) : phalcon_cpy_wrt(filtered_joined_content, filtered_content TSRMLS_CC);
} else {
PHALCON_SCONCAT_VS(filtered_joined_content, filtered_content, op);
}
This will save us one memory allocation for CSS files :-)
@sjinks I try it fail:
//......
zval *type = NULL, *type_css;
const char *op = ";";
//......
PHALCON_INIT_VAR(type_css);
ZVAL_STRING(type_css, "css", 1);
//......
while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
//......
if (type == NULL) {
PHALCON_INIT_VAR(type);
phalcon_call_method(type, resource, "gettype");
}
//......
if (zend_is_true(join)) {
if (PHALCON_IS_EQUAL(type, type_css)) {
zend_print_zval(type, 1);
op = "";
}
if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
PHALCON_INIT_NVAR(filtered_joined_content);
PHALCON_CONCAT_VS(filtered_joined_content, filtered_content, op);
} else {
PHALCON_SCONCAT_VS(filtered_joined_content, filtered_content, op);
}
}
The file end append "�CREATE", I suspect memory operation error.
I try:
if (zend_is_true(join)) {
if (PHALCON_IS_EQUAL(type, type_css)) {
if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
PHALCON_INIT_NVAR(filtered_joined_content);
PHALCON_CONCAT_VS(filtered_joined_content, filtered_content, "");
} else {
PHALCON_SCONCAT_VS(filtered_joined_content, filtered_content, "");
}
} else {
if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
PHALCON_INIT_NVAR(filtered_joined_content);
PHALCON_CONCAT_VS(filtered_joined_content, filtered_content, ";");
} else {
PHALCON_SCONCAT_VS(filtered_joined_content, filtered_content, ";");
}
}
}
This ok.
Use
op ? (PHALCON_CONCAT_VS(filtered_joined_content, filtered_content, op) : phalcon_cpy_wrt(filtered_joined_content, filtered_content TSRMLS_CC);
Compile time warning