Rocío Alvarado
Rocío Alvarado

Reputation: 89

Omit quotes when generating .ex file

I'm currently trying to generate the file api.ex from template.exs. I have a function that returns a string value of "name" but I want it to be printed into the api.ex as only name

I already tried: String.replace(~s("name"), ~s("), "")

The code that returns my still quoted string is: <%= inspect type |> Inflex.underscore |> erase_quotes %>

Upvotes: 0

Views: 56

Answers (1)

Dogbert
Dogbert

Reputation: 222108

The issue is of the precedence of function calls and pipes.

inspect x |> f is the same as inspect(x |> f), not inspect(x) |> f.

This should work:

<%= inspect(type) |> Inflex.underscore |> erase_quotes %>

but.. the reason you're getting the double quotes in the first place is that you're using inspect which adds those. Removing the call to inspectwill remove the quotes. The following should work:

<%= type |> Inflex.underscore %>

Upvotes: 1

Related Questions