Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets join problem #951

Closed
ddenysov opened this issue Jul 29, 2013 · 6 comments
Closed

Assets join problem #951

ddenysov opened this issue Jul 29, 2013 · 6 comments

Comments

@ddenysov
Copy link

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());
@dreamsxin
Copy link
Contributor

I try fix. Not to judge whether the CSS and js.

@ghost
Copy link

ghost commented Jul 30, 2013

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.

@dreamsxin
Copy link
Contributor

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);
          }
 }

@ghost
Copy link

ghost commented Jul 30, 2013

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 :-)

@ghost
Copy link

ghost commented Jul 30, 2013

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 :-)

@dreamsxin
Copy link
Contributor

@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

phalcon pushed a commit that referenced this issue Jul 31, 2013
phalcon pushed a commit that referenced this issue Jul 31, 2013
@phalcon phalcon closed this as completed Aug 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants