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