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 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); } }
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); }
[DllImport(LibSassDll, CallingConvention = CallingConvention.Cdecl)] public static extern Sass_Options sass_context_get_options(Sass_Context ctx);
[DllImport(LibSassDll, CallingConvention = CallingConvention.Cdecl)] public static extern StringUtf8 *sass_context_take_included_files(Sass_Context ctx);
[DllImport(LibSassDll, CallingConvention = CallingConvention.Cdecl)] public static extern StringUtf8 sass_context_take_source_map_string(Sass_Context ctx);
[DllImport(LibSassDll, CallingConvention = CallingConvention.Cdecl)] public static extern StringUtf8 sass_context_take_error_file(Sass_Context ctx);
[DllImport(LibSassDll, CallingConvention = CallingConvention.Cdecl)] public static extern size_t sass_context_get_included_files_size(Sass_Context ctx);
[DllImport(LibSassDll, CallingConvention = CallingConvention.Cdecl)] public static extern size_t sass_context_get_error_column(Sass_Context ctx);
[DllImport(LibSassDll, CallingConvention = CallingConvention.Cdecl)] public static extern int sass_context_get_error_status(Sass_Context ctx);
[DllImport(LibSassDll, CallingConvention = CallingConvention.Cdecl)] public static extern StringUtf8 sass_context_get_output_string(Sass_Context ctx);