core: add functionality to compress output
This commit is contained in:
parent
f4784d0da0
commit
09fdb5d052
|
@ -24,8 +24,10 @@
|
|||
(parameter/c (listof path-string?))
|
||||
(make-parameter null))
|
||||
|
||||
(define (prepare-context! context)
|
||||
(define (prepare-context! context compressed)
|
||||
(define options (sass_context_get_options context))
|
||||
(when compressed
|
||||
(sass_option_set_output_style options 'SASS_STYLE_COMPRESSED))
|
||||
(for ([path (reverse (current-include-paths))])
|
||||
;; Unlike sass_make_data_context, this function does not take
|
||||
;; ownership of path. Cool.
|
||||
|
@ -34,7 +36,7 @@
|
|||
(define ((make-compiler #:constructor make-wrapper
|
||||
#:destructor free-wrapper
|
||||
#:context-accessor get-context
|
||||
#:compilation-fn compile-sass) input)
|
||||
#:compilation-fn compile-sass) input [compressed #f])
|
||||
(define wrapper #f)
|
||||
(define context #f)
|
||||
|
||||
|
@ -42,7 +44,7 @@
|
|||
(lambda _
|
||||
(set! wrapper (make-wrapper input))
|
||||
(set! context (get-context wrapper))
|
||||
(prepare-context! context))
|
||||
(prepare-context! context compressed))
|
||||
(lambda _
|
||||
(define code (compile-sass wrapper))
|
||||
(case code
|
||||
|
@ -52,14 +54,14 @@
|
|||
(free-wrapper wrapper))))
|
||||
|
||||
(define/contract compile/file
|
||||
(-> path-string? string?)
|
||||
(->* (path-string?) (boolean?) string?)
|
||||
(make-compiler #:constructor (compose1 sass_make_file_context path->complete-path)
|
||||
#:destructor sass_delete_file_context
|
||||
#:context-accessor sass_file_context_get_context
|
||||
#:compilation-fn sass_compile_file_context))
|
||||
|
||||
(define/contract compile/bytes
|
||||
(-> bytes? string?)
|
||||
(->* (bytes?) (boolean?) string?)
|
||||
;; Sass_Data_Context frees the string that gets passed into it after
|
||||
;; compilation so we have to copy the input string and ensure that the
|
||||
;; resulting copy isn't managed by the GC.
|
||||
|
@ -68,9 +70,9 @@
|
|||
#:context-accessor sass_data_context_get_context
|
||||
#:compilation-fn sass_compile_data_context))
|
||||
|
||||
(define/contract (compile/string data)
|
||||
(-> non-empty-string? string?)
|
||||
(compile/bytes (string->bytes/utf-8 data)))
|
||||
(define/contract (compile/string data [compressed #f])
|
||||
(->* (non-empty-string?) (boolean?) string?)
|
||||
(compile/bytes (string->bytes/utf-8 data) compressed))
|
||||
|
||||
|
||||
(module+ test
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
libsass_language_version
|
||||
|
||||
sass_option_push_include_path
|
||||
sass_option_set_output_style
|
||||
|
||||
sass_context_get_options
|
||||
sass_context_get_output_string
|
||||
|
@ -45,6 +46,12 @@
|
|||
(define _Sass_Options-pointer (_cpointer 'Sass_Options))
|
||||
(define-sass sass_option_push_include_path (_fun _Sass_Options-pointer _path -> _void))
|
||||
|
||||
(define _Sass_Output_Style
|
||||
(_enum '(SASS_STYLE_NESTED = 0
|
||||
SASS_STYLE_EXPANDED
|
||||
SASS_STYLE_COMPACT
|
||||
SASS_STYLE_COMPRESSED)))
|
||||
(define-sass sass_option_set_output_style (_fun _Sass_Options-pointer _Sass_Output_Style -> _void))
|
||||
|
||||
;; Sass_Context ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
|
Loading…
Reference in New Issue