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

Variables with path inside not working #10

Open
roman-holovin opened this issue Aug 4, 2014 · 11 comments
Open

Variables with path inside not working #10

roman-holovin opened this issue Aug 4, 2014 · 11 comments
Assignees

Comments

@roman-holovin
Copy link

In sass you can define variable with path inside, like this $path: "/some_path/" and it will work.

When I'm moving such variables in the json file, sass compiler fails with error like this:
Warning: Syntax error: Invalid CSS after "/": expected expression (e.g. 1px, bold), was ""
for json:
{ root: "/" }

Is there a way to achieve loading such variables?

@nhunzaker
Copy link
Contributor

Hmm. Curious. Would you be willing to provide the JSON file (or similar example) that is causing the error to help me reproduce it?

@nhunzaker
Copy link
Contributor

It is possible that this was corrected when we fixed #11. I can reproduce this issue with sass-json-vars 3.1, however as of 3.2 it is not occurring. All the same, I will add this value to the test suite to ensure we cover it for the future.

This is how I tested:
https://gist.github.com/nhunzaker/a5ece91ceb1785bcf30d

@nhunzaker nhunzaker self-assigned this Aug 8, 2014
@nhunzaker
Copy link
Contributor

Having said that. It certainly looks like this is not the case if you append a file extension. I will look into this.

EDIT: or a simple "/", as you have mentioned

@eurekaa
Copy link

eurekaa commented Oct 24, 2014

Hi there,
i have the same issue working with a file extension.

menu.json

{
    "home": {
        "label": "home",
        "class": "home",
        "link": "#home",
        "color": "#FFBD59",
        "icon": "media/images/avatar.png"
    },
    "etc...":{}
}
@import menu.json
$color: map_get($home, color)

error:
error src/styles/menu.sass (Line 1 of src/data/menu.json: Invalid CSS after "...a/images/avatar": expected ")", was ".png);")

Did you find a solution for that?
Thanks.

@pmowrer
Copy link

pmowrer commented Apr 2, 2015

Having the same problem. @nhunzaker Your test narrowly escaped the issue. Try //foo/bar instead or foo.bar

@pmowrer
Copy link

pmowrer commented Apr 2, 2015

Simply wrapping the uri in single quotes resolved the problem for me. E.g.:

"url": "'//foo/bar'"

@ThePolarCat
Copy link

I have the same issue, any idea how to fix it?
From my JSON file:
"url": "../../lib/images/background/background.jpg",

@ThePolarCat
Copy link

I've modified the importer to wrap strings contains a file extension with single quots " 'file.ext' " so now it won't trigger an error.

def _convert_to_sass(item)
        if item.is_a? String
            if item.scan(/\.[0-9a-z]+$/i).length > 0
                item = "\'" + item + "\'"
            end
        end
        if item.is_a? Array
            _make_list(item)
        elsif item.is_a? Hash
            _make_map(item)
        else
            item.to_s
        end
    end

@esr360
Copy link

esr360 commented Dec 31, 2017

@ThePolarCat this is great, just what I need, do you have a forked version of this repository or something? How can I use this?

@ThePolarCat
Copy link

@esr360 after you clone the repo, navigate to
lib/sass-json-vars/
And edit importer.rb like I mentioned in my comment.

@cfuj
Copy link

cfuj commented Aug 3, 2018

I'm glad I found this issue.

I was having this problem if a string contained a period anywhere or even a comma. Since my task was a cross-compatible source of definitions for server, js, and css, there's some veriables that are defined in my json file but aren't used by the css.

So my core definition file had a line like this Pages are links in navigation bars. If the page does not exist in the file-system, content may be specified here, that I needed the the CSS to be able to parse the file successfully.

Altering @ThePolarCat's regex test to if item.scan(/[[:punct:]]/i).length > 0 fixed the problem.

    def _convert_to_sass(item)
        if item.is_a? String
            if item.scan(/[[:punct:]]/i).length > 0
                item = "\'" + item + "\'"
            end
        end
        if item.is_a? Array
            _make_list(item)
        elsif item.is_a? Hash
            _make_map(item)
        else
            item.to_s
        end
    end

Update: I also found that empty strings also cause a parsing error. Since my purpose is a file that JS/SASS and server-side can share for consistency, sometimes I'll have empty strings.

This fixed it, just changing the regex to [[:punct:]]|^$.

    def _convert_to_sass(item)
        if item.is_a? String
            if item.scan(/[[:punct:]]|^$/i).length > 0
                item = "\'" + item + "\'"
            end
        end
        if item.is_a? Array
            _make_list(item)
        elsif item.is_a? Hash
            _make_map(item)
        else
            item.to_s
        end
    end

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

7 participants