vigetlabs/sass-json-vars

Empty JSON Strings cause an error

Opened this issue · 0 comments

cfuj commented

Just adding this issue so people see it in Google.

Although not actually null, I'll add the phrase here too for google: Null json strings cause an error

I use this gem to utilize a core definition file for my site that Javascript, CSS, and the Server can all share. One file to update.

Because of this, it's likely have a lot of values that the CSS has no use for, like descriptive strings and sometimes empty values.

Tweaking ThePolarCat's revised code from Issue #10, I end up with a solution.

    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