private static void FillUnmanagedContextOptions(ref Sass_Options ctx_options, SassContextBase context) { SassOptions options = context.Options; foreach (string importExtension in options.AdditionalImportExtensions) { Sass_Api.sass_option_push_import_extension(ctx_options, importExtension); } Sass_Api.sass_option_set_include_path(ctx_options, options.IncludePath); Sass_Api.sass_option_set_indent(ctx_options, options.Indent); Sass_Api.sass_option_set_input_path(ctx_options, context.InputPath); Sass_Api.sass_option_set_is_indented_syntax_src(ctx_options, context.IsIndentedSyntaxSource); Sass_Api.sass_option_set_linefeed(ctx_options, options.LineFeed); Sass_Api.sass_option_set_omit_source_map_url(ctx_options, options.OmitSourceMapUrl); Sass_Api.sass_option_set_output_path(ctx_options, context.OutputPath); Sass_Api.sass_option_set_output_style(ctx_options, (Sass_Output_Style)options.OutputStyle); Sass_Api.sass_option_set_precision(ctx_options, options.Precision); Sass_Api.sass_option_set_source_comments(ctx_options, options.SourceComments); Sass_Api.sass_option_set_source_map_contents(ctx_options, options.SourceMapContents); Sass_Api.sass_option_set_source_map_embed(ctx_options, options.SourceMapEmbed); Sass_Api.sass_option_set_source_map_file(ctx_options, context.SourceMapFile); Sass_Api.sass_option_set_source_map_file_urls(ctx_options, options.SourceMapFileUrls); Sass_Api.sass_option_set_source_map_root(ctx_options, options.SourceMapRoot); }
public static void UnsetFileManager() { if (!Sass_Api.sass_file_manager_get_is_initialized()) { return; } Sass_Api.sass_file_manager_set_is_initialized(false); Sass_Api.sass_file_manager_set_supports_conversion_to_absolute_path(false); Sass_Api.sass_file_manager_unset_get_current_directory_delegate(); Sass_Api.sass_file_manager_unset_file_exists_delegate(); Sass_Api.sass_file_manager_unset_is_absolute_path_delegate(); Sass_Api.sass_file_manager_unset_to_absolute_path_delegate(); Sass_Api.sass_file_manager_unset_read_file_delegate(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _getCurrentDirectoryDelegateUtf16 = null; _fileExistsDelegateUtf16 = null; _isAbsolutePathDelegateUtf16 = null; _toAbsolutePathDelegateUtf16 = null; _readFileDelegateUtf16 = null; } else { _getCurrentDirectoryDelegateUtf8 = null; _fileExistsDelegateUtf8 = null; _isAbsolutePathDelegateUtf8 = null; _toAbsolutePathDelegateUtf8 = null; _readFileDelegateUtf8 = null; } }
public static void UnsetFileManager() { Sass_Api.sass_file_manager_set_is_initialized(false); Sass_Api.sass_file_manager_set_supports_conversion_to_absolute_path(false); Sass_Api.sass_file_manager_unset_get_current_directory_delegate(); Sass_Api.sass_file_manager_unset_file_exists_delegate(); Sass_Api.sass_file_manager_unset_is_absolute_path_delegate(); Sass_Api.sass_file_manager_unset_to_absolute_path_delegate(); Sass_Api.sass_file_manager_unset_read_file_delegate(); if (Utils.IsWindows()) { _getCurrentDirectoryDelegateUtf16 = null; _fileExistsDelegateUtf16 = null; _isAbsolutePathDelegateUtf16 = null; _toAbsolutePathDelegateUtf16 = null; _readFileDelegateUtf16 = null; } else { _getCurrentDirectoryDelegateUtf8 = null; _fileExistsDelegateUtf8 = null; _isAbsolutePathDelegateUtf8 = null; _toAbsolutePathDelegateUtf8 = null; _readFileDelegateUtf8 = null; } }
public static void CompileFile(SassFileContext fileContext) { Sass_File_Context file_ctx = Sass_Api.sass_make_file_context(fileContext.InputPath); Sass_Options file_ctx_options = Sass_Api.sass_file_context_get_options(file_ctx); FillUnmanagedContextOptions(ref file_ctx_options, fileContext); try { // Compile Sass file by using context int result = Sass_Api.sass_compile_file_context(file_ctx); // Copy resulting fields from unmanaged object to managed Sass_Context base_ctx = Sass_Api.sass_file_context_get_context(file_ctx); if (result == 0) { FillManagedContextOutput(fileContext, ref base_ctx); } else { FillManagedContextError(fileContext, ref base_ctx); } } finally { // Free resources Sass_Api.sass_delete_file_context(file_ctx); } }
public static void Compile(SassDataContext dataContext) { Sass_Data_Context data_ctx = Sass_Api.sass_make_data_context(dataContext.SourceString); Sass_Options data_ctx_options = Sass_Api.sass_data_context_get_options(data_ctx); FillUnmanagedContextOptions(ref data_ctx_options, dataContext); try { // Compile Sass code by using context int result = Sass_Api.sass_compile_data_context(data_ctx); // Copy resulting fields from unmanaged object to managed Sass_Context base_ctx = Sass_Api.sass_data_context_get_context(data_ctx); if (result == 0) { FillManagedContextOutput(dataContext, ref base_ctx); } else { FillManagedContextError(dataContext, ref base_ctx); } } finally { // Free resources Sass_Api.sass_delete_data_context(data_ctx); } }
private static void FillManagedContextOutput(SassContextBase context, ref Sass_Context ctx) { context.OutputString = Sass_Api.sass_context_get_output_string(ctx); context.SourceMapString = Sass_Api.sass_context_get_source_map_string(ctx); context.IncludedFiles = MarshallingHelpers.PtrToStringArray( Sass_Api.sass_context_get_included_files(ctx), Sass_Api.sass_context_get_included_files_size(ctx) ); }
private static unsafe IntPtr CharsToPtr(Encoding encoding, char *chars, int count) { int bufferLength = encoding.GetByteCount(chars, count); IntPtr ptr = Sass_Api.sass_alloc_memory(bufferLength + 1); var pBuffer = (byte *)ptr; encoding.GetBytes(chars, count, pBuffer, bufferLength); pBuffer[bufferLength] = 0; return(ptr); }
private static void FillManagedContextError(SassContextBase context, ref Sass_Context ctx) { var error = new SassErrorInfo { Status = Sass_Api.sass_context_get_error_status(ctx), Text = Sass_Api.sass_context_get_error_text(ctx), Message = Sass_Api.sass_context_get_error_message(ctx), File = Sass_Api.sass_context_get_error_file(ctx), Line = Sass_Api.sass_context_get_error_line(ctx), Column = Sass_Api.sass_context_get_error_column(ctx), Source = Sass_Api.sass_context_get_error_src(ctx) }; context.Error = error; }
public static void CompileFile(SassFileContext fileContext) { Sass_File_Context file_ctx = Sass_Api.sass_make_file_context(fileContext.InputPath); Sass_Options file_ctx_options = Sass_Api.sass_file_context_get_options(file_ctx); FillUnmanagedContextOptions(ref file_ctx_options, fileContext); try { // Compile Sass-file by using context int result = Sass_Api.sass_compile_file_context(file_ctx); // Copy resulting fields from unmanaged object to managed Sass_Context base_ctx = Sass_Api.sass_file_context_get_context(file_ctx); if (result == 0) { FillManagedContextOutput(fileContext, ref base_ctx); } else { FillManagedContextError(fileContext, ref base_ctx); } } catch (TargetInvocationException e) { Exception innerException = e.InnerException; if (innerException != null) { #if NET45 || NETSTANDARD ExceptionDispatchInfo.Capture(innerException).Throw(); #elif NET40 innerException.PreserveStackTrace(); throw innerException; #else #error No implementation for this target #endif } throw; } finally { // Free resources Sass_Api.sass_delete_file_context(file_ctx); } }
public static void SetFileManager(IFileManager fileManager) { if (fileManager != null) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _getCurrentDirectoryDelegateUtf16 = fileManager.GetCurrentDirectory; _fileExistsDelegateUtf16 = fileManager.FileExists; _isAbsolutePathDelegateUtf16 = fileManager.IsAbsolutePath; _toAbsolutePathDelegateUtf16 = fileManager.ToAbsolutePath; _readFileDelegateUtf16 = fileManager.ReadFile; Sass_Api.sass_file_manager_set_get_current_directory_delegate_utf16(_getCurrentDirectoryDelegateUtf16); Sass_Api.sass_file_manager_set_file_exists_delegate_utf16(_fileExistsDelegateUtf16); Sass_Api.sass_file_manager_set_is_absolute_path_delegate_utf16(_isAbsolutePathDelegateUtf16); Sass_Api.sass_file_manager_set_to_absolute_path_delegate_utf16(_toAbsolutePathDelegateUtf16); Sass_Api.sass_file_manager_set_read_file_delegate_utf16(_readFileDelegateUtf16); } else { _getCurrentDirectoryDelegateUtf8 = fileManager.GetCurrentDirectory; _fileExistsDelegateUtf8 = fileManager.FileExists; _isAbsolutePathDelegateUtf8 = fileManager.IsAbsolutePath; _toAbsolutePathDelegateUtf8 = fileManager.ToAbsolutePath; _readFileDelegateUtf8 = fileManager.ReadFile; Sass_Api.sass_file_manager_set_get_current_directory_delegate_utf8(_getCurrentDirectoryDelegateUtf8); Sass_Api.sass_file_manager_set_file_exists_delegate_utf8(_fileExistsDelegateUtf8); Sass_Api.sass_file_manager_set_is_absolute_path_delegate_utf8(_isAbsolutePathDelegateUtf8); Sass_Api.sass_file_manager_set_to_absolute_path_delegate_utf8(_toAbsolutePathDelegateUtf8); Sass_Api.sass_file_manager_set_read_file_delegate_utf8(_readFileDelegateUtf8); } Sass_Api.sass_file_manager_set_supports_conversion_to_absolute_path( fileManager.SupportsConversionToAbsolutePath); Sass_Api.sass_file_manager_set_is_initialized(true); } else { UnsetFileManager(); } }
public static string GetLanguageVersion() { return(Sass_Api.libsass_language_version()); }
public static string GetVersion() { return(Sass_Api.libsass_version()); }
private static void FillManagedContextOutput(SassContextBase context, ref Sass_Context ctx) { context.OutputString = Sass_Api.sass_context_get_output_string(ctx); context.SourceMapString = Sass_Api.sass_context_get_source_map_string(ctx); context.IncludedFiles = Sass_Api.sass_context_get_included_files(ctx); }