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

question: string value? #24

Closed
tupton opened this issue Mar 19, 2014 · 7 comments
Closed

question: string value? #24

tupton opened this issue Mar 19, 2014 · 7 comments

Comments

@tupton
Copy link

tupton commented Mar 19, 2014

I'm trying to replace all strings so that they have a consistent quote style.

Things I've tried:

grasp 'str' --replace "{{ str }}" path/to/script.js
grasp 'str' --replace "{{ str | wrap \' }}" path/to/script.js
grasp 'str' --replace "{{ .value | wrap \' }}" path/to/script.js
grasp 'str' --replace "{{ {{}} | slice 1 -1 | wrap \' }}" path/to/script.js
grasp 'str' --replace "{{ .value | slice 1 -1 | wrap \' }}" path/to/script.js

And probably some more. I cannot figure this out. How can I match and filter a string's value? What's the best way to do this?

@gkz
Copy link
Owner

gkz commented Mar 19, 2014

slice works on the array of matched values if there is more than one, not on the resulting string of code (eg. {{ .els | slice .... }}. I see that this is confusing, maybe the name of slice should be changed.

You can't access primitive values, just other nodes, so you can't get the string's value as that is a primitive value. Maybe you should be able to do this, but we would need to do something to make it work.

Currently there is no way to modify the outputted string of code. In Grasp 0.3.0 I will add a replace filter which you can use to make any regex replacement on the outputted string of code and do what you want.

Also, if you want to do filters on the object itself, you can do {{:root | filter ...}} - maybe we should make this implicit if you simply do {{ | filter }}.

@tupton
Copy link
Author

tupton commented Mar 19, 2014

Also, if you want to do filters on the object itself, you can do {{:root | filter ...}}

That's something I was certainly looking for. It was not obvious how to do that; the str workaround seemed a little unnecessary.

Currently there is no way to modify the outputted string of code. In Grasp 0.3.0 I will add a replace filter which you can use to make any regex replacement on the outputted string of code and do what you want.

That would be great for this case, and I'm sure many others. What's the status of this? Is there an in-progress version of replace? What's the eta for Grasp 0.3.0?

gkz added a commit that referenced this issue Mar 21, 2014
@gkz
Copy link
Owner

gkz commented Mar 21, 2014

@tupton
I want to release LiveScript 1.3 before Grasp 3.0, but I've just added the replace filter functionality to the repo (along with uppercase, lowercase, trim, substring, and substr filters). You can clone the repo and install it to get the latest functionality before I make a release.

@tupton
Copy link
Author

tupton commented Mar 21, 2014

Awesome, thanks for the quick response. This (replace) does exactly what I need.

@tupton tupton closed this as completed Mar 21, 2014
@gkz
Copy link
Owner

gkz commented Mar 21, 2014

Note that filter arguments are now required to be separated by commas.

@gkz
Copy link
Owner

gkz commented Mar 22, 2014

I'm going to reopen this as we still have several unresolved issues:

  • slice working on the array of node matches only, not on the resulting string
  • can't access primitive values
  • having to use :root when referencing the element itself

@gkz gkz reopened this Mar 22, 2014
gkz added a commit that referenced this issue Mar 29, 2014
can just write `{{| filter}}` or `{{ | filter}}`
instead of `{{ :root | filter}}` or equivalent

ref #24
@gkz
Copy link
Owner

gkz commented Mar 29, 2014

Added str-slice filter to slice string output with 4bcd698

Just added implied root selector (see referenced commit above).

Will close this issue and create new ones for any remaining tasks.

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