Skip to content

Commit

Permalink
add compile_scss() and compile_sass() plus respective tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed May 21, 2023
1 parent d364507 commit d680ac4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
62 changes: 61 additions & 1 deletion src/julian_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ end
"""
`compile_string(data::AbstractString; kwargs...)`
Compile `filename` from sass or scss to a css string. Possible options, given by keyword
Compile sass or scss string to a css string. Possible options, given by keyword
arguments, are:
- `output_style`: output style for the generated css code. See `Sass.Style` for options. For example `output_style = Sass.nested`
Expand Down Expand Up @@ -145,3 +145,63 @@ function compile_string(data::AbstractString; kwargs...)
sass_delete_data_context(ctx)
return css
end

"""
compile_sass(data; kwargs...)
Compile sass string to a css string. Possible options, given by keyword
arguments, are:
- `output_style`: output style for the generated css code. See `Sass.Style` for options. For example `output_style = Sass.nested`
- `source_comments`: a boolean to specify whether to insert inline source comments
- `indent`: string to be used for indentation
- `linefeed`: string to be used for line feeds
- `precision`: precision for outputting fractional numbers
## Examples
```julia
julia> Sass.compile_sass(raw"
\$font-stack: Helvetica, sans-serif
\$primary-color: #333
body
font: 100% \$font-stack
color: \$primary-color
")
"body {\n font: 100% Helvetica, sans-serif;\n color: #333; }\n"
```
"""
function compile_sass(data; kwargs...)
compile_string(data; is_indented_syntax_src = true, kwargs...)
end

"""
compile_scss(data; kwargs...)
Compile scss string to a css string. Possible options, given by keyword
arguments, are:
- `output_style`: output style for the generated css code. See `Sass.Style` for options. For example `output_style = Sass.nested`
- `source_comments`: a boolean to specify whether to insert inline source comments
- `indent`: string to be used for indentation
- `linefeed`: string to be used for line feeds
- `precision`: precision for outputting fractional numbers
## Examples
```
julia> Sass.compile_scss(raw"
\$font-stack: Helvetica, sans-serif;
\$primary-color: #333;
body {
font: 100% \$font-stack;
color: \$primary-color;
}")
"body {\n font: 100% Helvetica, sans-serif;\n color: #333; }\n"
```
"""
function compile_scss(data; kwargs...)
compile_string(data; is_indented_syntax_src = false, kwargs...)
end
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ end

css = Sass.compile_string(sass; output_style = Sass.nested, is_indented_syntax_src = true)
@test css == "body {\n font: 100% Helvetica, sans-serif;\n color: #333; }\n"

css = Sass.compile_sass(sass)
@test css == "body {\n font: 100% Helvetica, sans-serif;\n color: #333; }\n"

scss = raw"
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}"
css = Sass.compile_scss(scss)
@test css == "body {\n font: 100% Helvetica, sans-serif;\n color: #333; }\n"
end

@testset "wrongpath" begin
Expand Down

0 comments on commit d680ac4

Please sign in to comment.