-
Notifications
You must be signed in to change notification settings - Fork 3
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
Compile from string #2
Comments
A workaround for doing this would be function compile_sass(io::IOBuffer, args...; kwargs...)
local css
mktemp(pwd()) do filepath, fileio
sass = String(take!(io))
is_indented = get(kwargs, :is_indented_syntax_src, false)
write(fileio, sass)
close(fileio)
is_indented && mv(filepath, filepath * ".sass")
css = try
Sass.compile_file(filepath * (is_indented ? ".sass" : ""), args...; kwargs...)
catch e
@warn e
finally
is_indented && mv(filepath * ".sass", filepath)
end
end
css
end
compile_sass(s::AbstractString, args...; kwargs...) = compile_sass(IOBuffer(s), args...; kwargs...) At least for me (OS: Windows, Julia: 1.9), calling with |
Inspired by https://github.com/sass/libsass/blob/master/docs/api-context-example.md I found the true solution: function sass_copy_string(s)
ccall((:sass_copy_c_string, Sass.libsass_so),
Ptr{Cstring}, (Cstring,), s)
end
text = sass_copy_string("div { a { color: blue; } }")
context = sass_make_data_context(text)
compiler = sass_make_data_compiler(context)
sass_compiler_parse(compiler)
sass_compiler_execute(compiler)
output = sass_context_get_output_string(context)
sass_delete_data_context(context)
sass_delete_compiler(compiler) I'll submit a PR to make that available in the julia api. |
libsass allows to compile from string, though that currently doesn't work here. If I try:
It segfaults when deleting the compiler as it also tries to deallocate the Julia string. One can either:
The second option seems better but I have no idea how to do it.
The text was updated successfully, but these errors were encountered: