diff --git a/.gitignore b/.gitignore index 6015c70763a071c41b91160bb835fc99c67a176a..7ae3835ea6015badd0a917b1aa28339b4bef5f7d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ sass.c *.o plib/ refdoc/ +*.css +*.map diff --git a/module.pmod.in b/module.pmod.in index 4f084dd799978c5aa0c1fe98b0413aa2b09f5c1f..0bcc451775223d55cf7956f8635df383e9835476 100644 --- a/module.pmod.in +++ b/module.pmod.in @@ -18,10 +18,6 @@ class SCSS { inherit Tools@module@._Api; - protected multiset(string) known_opts = (< - "output_style", "include_path", "source_map_file", "source_comments", - "source_map_embed" >); - //! Set options to the SASS compiler //! //! @param opts @@ -45,10 +41,6 @@ class SCSS void set_options(mapping(string:string|int) opts) { foreach (opts; string opt; string|int val) { - if (!known_opts[opt]) { - error("Unknown option %O!\n", opt); - } - switch (opt) { case "output_style": @@ -74,17 +66,34 @@ class SCSS case "source_map_embed": if (!intp(val)) { - error("Value to set_source_map_embed() must be an int(0..1)\n"); + error("Value to set_source_map_embed() must be an int(0..1)!\n"); } set_source_map_embed(val); break; + case "source_map_root": + if (!stringp(val)) { + error("Value to set_source_map_root() must be a string!\n"); + } + set_source_map_root(val); + break; + + case "omit_source_map": + if (!intp(val)) { + error("Value to set_omit_source_map_url() must be an integer!\n"); + } + set_omit_source_map_url(val); + break; + case "source_comments": if (!intp(val)) { error("Value to set_source_comments() must be an integer!\n"); } set_source_comments(val); break; + + default: + error("Unknown option %O!\n", opt); } } } diff --git a/sass.cmod b/sass.cmod index e375efe3eab297c6db74259e519027a5400ab3b5..81d51b8345e7d01f1728c56d03c60fb868e242bd 100644 --- a/sass.cmod +++ b/sass.cmod @@ -42,6 +42,8 @@ typedef struct sass_opts { bool comments; char* map_path; bool map_embed; + char* map_root; + bool omit_map_url; } sass_opts; @@ -56,17 +58,25 @@ void set_options (sass_opts *opts, struct Sass_Context *ctx) sass_option_set_include_path (s_opts, opts->include_path); } + sass_option_set_omit_source_map_url (s_opts, opts->omit_map_url); sass_option_set_source_comments (s_opts, opts->comments); // if (opts->comments) { + // sass_option_set_omit_source_map_url (s_opts, false); // } if (opts->map_path != NULL) { sass_option_set_source_map_file (s_opts, opts->map_path); + // sass_option_set_omit_source_map_url (s_opts, false); + sass_option_set_source_map_contents (s_opts, true); } else { sass_option_set_source_map_embed (s_opts, opts->map_embed); } + + if (opts->map_root != NULL) { + sass_option_set_source_map_root (s_opts, opts->map_root); + } } PIKECLASS _Api @@ -115,7 +125,8 @@ PIKECLASS _Api /*! @decl void get_output_style(int style) *! - *! Set the output style. Default is @[Tools.Sass.STYLE_NESTED] + *! Set the output style for the generated CSS code. + *! Default is @[Tools.Sass.STYLE_NESTED]. *! *! @seealso *! @[get_output_style()] @@ -131,7 +142,7 @@ PIKECLASS _Api /*! @decl int get_output_style(int style) *! - *! Returns the output style. + *! Returns the output style of the generated CSS code. *! *! @seealso *! @[set_output_style()] @@ -143,8 +154,8 @@ PIKECLASS _Api /*! @decl void set_source_comments(bool set) *! - *! Set whether comments of source line number should be printed in the - *! generated CSS or not. Default is @code{false@}. + *! Emit comments in the generated CSS indicating the corresponding + *! source line. Default is @code{false@}. *! *! @seealso *! @[get_source_comments()] @@ -168,8 +179,9 @@ PIKECLASS _Api /*! @decl void set_source_map_file(string path) *! - *! Set the path of where to write the source map file. If this isn't set - *! no source map will be generated. + *! Path to source map file. Enables the source map generating. + *! Used to create sourceMappingUrl. If this isn't set no source map will + *! be generated. *! *! @note *! This only has effect in @[compile_file()]. @@ -207,7 +219,7 @@ PIKECLASS _Api /*! @decl void set_source_map_embed(bool embed) *! - *! Should a source map be embedded in the compiled output? + *! Set whether embedding sourceMappingUrl as data uri or not. *! *! @seealso *! @[get_source_map_embed()], @[set_source_map_file()], @@ -233,10 +245,74 @@ PIKECLASS _Api RETURN (THIS->options->map_embed); } + /*! @decl void set_source_map_root(string path) + *! + *! Directly inserted in source maps. + *! + *! @seealso + *! @[set_source_map_file()], @[get_source_map_file()] + *! + *! @param path + */ + PIKEFUN void set_source_map_root (string path) + { + THIS->options->map_root = strdup (path->str); + } + + + /*! @decl string get_source_map_root() + *! + *! Returns the path of the source maps root. + *! + *! @seealso + *! @[set_source_map_root()], @[set_source_map_file()], + *! @[set_source_map_file()] + */ + PIKEFUN string get_source_map_root () + { + if (THIS->options->map_root) { + push_text (THIS->options->map_root); + } + else { + push_int (0); + } + } + + + /*! @decl void set_omit_source_map_url(bool embed) + *! + *! Set whether writing sourceMappingUrl or not. + *! + *! @seealso + *! @[set_source_map_embed()], @[set_source_map_file()], + *! @[get_source_map_embed()], @[get_source_map_file()] + *! + *! @param embed + */ + PIKEFUN void set_omit_source_map_url (int(0..1) omit) + { + THIS->options->omit_map_url = omit; + } + + + /*! @decl int(0..1) get_omit_source_map_url() + *! + *! Getter for @[set_omit_source_map_url()]. + *! + *! @seealso + *! @[set_omit_source_map_url()], + *! @[set_source_map_embed()], @[set_source_map_file()], + *! @[get_source_map_embed()], @[get_source_map_file()] + */ + PIKEFUN int(0..1) get_omit_source_map_url () + { + RETURN (THIS->options->omit_map_url); + } + /*! @decl void set_precision(int(0..) p) *! - *! Set the precision of floating point values + *! Set the precision of fractional numbers. Default is @{5}. *! *! @seealso *! @[get_precision()] @@ -379,11 +455,11 @@ PIKECLASS _Api THIS->options->include_path = NULL; THIS->options->precision = 5; THIS->options->map_path = NULL; - // THIS->options->map_root = NULL; + THIS->options->map_root = NULL; THIS->options->comments = false; THIS->options->map_embed = false; // THIS->options->map_contents = false; - // THIS->options->omit_map_url = true; + THIS->options->omit_map_url = true; } EXIT { @@ -397,6 +473,10 @@ PIKECLASS _Api free (THIS->options->map_path); } + if (THIS->options->map_root != NULL) { + free (THIS->options->map_root); + } + free (THIS->options); } }