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

render tag <%=%> replaced with [object Object] when used in img tag #50

Open
karthikkasturi opened this issue May 27, 2021 · 16 comments
Open

Comments

@karthikkasturi
Copy link

Eg:
in my erb file, formatting

<img src="<%= logo %>" />

gives output

<img src="[object Object]"/>

@karthikkasturi
Copy link
Author

Current config:
"@prettier/plugin-ruby": "^1.5.5",
"prettier": "2.2.0",
"prettier-plugin-erb": "^0.2.0",

@gbp
Copy link

gbp commented May 27, 2021

Also seeing this, appears to be when the ERB tag is within double quotes:

      =====================================input======================================
      <a href="mailto:<%= contact_email %>"><%= contact_email %></a>

      =====================================output=====================================
    - <a href="mailto:<%= contact_email %>"><%= contact_email %></a>
    + <a href="mailto:[object Object]"><%= contact_email %></a>

      ================================================================================

@adamzapasnik
Copy link
Owner

I have located the problem, will fix it tomorrow hopefully. Thanks guys for reporting.

@karthikkasturi
Copy link
Author

any update on this? or a workaround?

@adamzapasnik
Copy link
Owner

sorry for the wait, @karthikkasturi

I've just released a fix, please check the version 0.3.0

@marcuslilja
Copy link

I'm seeing the issue with [object Object] as well. But in another context.

With the following versions

{
  "@prettier/plugin-ruby": "1.5.5",
  "prettier": "2.2.1",
  "prettier-plugin-erb": "0.3.0"
}

Running prettier on this

<script>
  var custom = '<%= data.to_json %>';
</script>

would result in the following

<script>
  var custom = '[object Object]';
</script>

@adamzapasnik
Copy link
Owner

@marcuslilja I'll try to resolve this one over the weekend, sorry for trouble

@marcuslilja
Copy link

@marcuslilja I'll try to resolve this one over the weekend, sorry for trouble

Thanks 👍

@michaelzim
Copy link

Same issue also happens with <pre> elements.

Input:
<pre><%= 123 %></pre>

Output:
<pre>[object Object]</pre>

@julienma
Copy link

Hey, chiming in to report the same issue, in another context:

Versions:

    "@prettier/plugin-ruby": "^1.5.5",
    "prettier": "^2.3.1",
    "prettier-plugin-erb": "^0.3.0",

Source:

  <div
    class="form-group mb-3"
    data-controller="avatar-field"
    data-avatar-field-fallback-image-value="<%= image_path "icons/user-astronaut-regular.svg" %>"
  >

Formatted output:

  <div
    class="form-group mb-3"
    data-controller="avatar-field"
    data-avatar-field-fallback-image-value="[object Object]"
  >

@adamzapasnik
Copy link
Owner

Released a fix, please check 0.4.0.

@julienma
Copy link

Thank you @adamzapasnik... but this seems worse :/

package.json:

   "devDependencies": {
-   "@prettier/plugin-ruby": "^1.5.5",
+   "@prettier/plugin-ruby": "^1.6.0",
    "prettier": "^2.3.1",
-   "prettier-plugin-erb": "^0.3.0",
+   "prettier-plugin-erb": "^0.4.0",
    "webpack-dev-server": "^3.11.2"
  },

Input:

  <div class="form-group mb-3">
    <%= form.label :name, "Full name" %>
    <%= form.text_field :name, value: params[:name] || customer.name, class: "form-control", placeholder: "First name + last name" %>
  </div>

  <div
    class="form-group mb-3" 
    data-controller="avatar-field"
    data-avatar-field-fallback-image-value="<%= image_path "icons/user-astronaut-regular.svg" %>"
  >

Output:

  <div class="form-group mb-3">
    <eext7 />
    <eext8 />
  </div>

  <div
    class="form-group mb-3"
    data-controller="avatar-field"
    data-avatar-field-fallback-image-value="eex9eex"
  >

@julienma
Copy link

julienma commented Jun 24, 2021

Downgrading prettier to 2.2.1 did the trick:

   "devDependencies": {
-   "@prettier/plugin-ruby": "^1.5.5",
-   "prettier": "^2.3.1",
-   "prettier-plugin-erb": "^0.3.0",
+   "@prettier/plugin-ruby": "^1.6.0",
+   "prettier": "2.2.1",
+   "prettier-plugin-erb": "^0.4.0",
  },

Actually I also tried without upgrading prettier-plugin-erb to 0.4.0, and it still worked as expected (no [object Object] issue):

   "devDependencies": {
    "@prettier/plugin-ruby": "^1.5.5",
-   "prettier": "^2.3.1",
+   "prettier": "2.2.1",
    "prettier-plugin-erb": "^0.3.0",
  },

@kblicharski
Copy link

kblicharski commented Feb 4, 2022

I am still having this problem even with the above package versions. It seems to only apply for ERB tags nested inside of specific other tags.

EDIT: Maybe it's broken for specific tag types? If I have an ERB tag inside of a <p> it's fine, but inside of a <title> it breaks.

@kblicharski
Copy link

This issue is still present for all tag types present in this array.

https://github.com/adamzapasnik/prettier-html-templates/blob/master/lib/tokenizer.js#L39

@kvnloughead
Copy link

Still an issue inside <title> tags for these deps

{
  "devDependencies": {
    "@prettier/plugin-ruby": "1.5.5",
    "prettier": "2.2.0",
    "prettier-plugin-erb": "0.2.0"
  }
}

Also for 0.3.0. But it seems to work with 0.4.0.

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

8 participants