Commits

Frank Becker committed c7ddf07

added scss to css converter using pyscss

Comments (0)

Files changed (1)

 #!/usr/bin/env python
 
+# -*- coding: utf-8 -*-
+
 # =============================================================================
 #
 #    Poole - A damn simple static website generator.
 # =============================================================================
 
 MKD_PATT = r'\.(?:md|mkd|mdown|markdown)$'
+SCSS_PATT = r'\.(?:scss)$'
 
 class Page(dict):
     """Abstraction of a source page."""
         if not attr.startswith("_"):
             macros[attr] = getattr(macmod, attr)
 
+    # pyScss generation
+    if opts.scss_to_css:
+        try:
+            import scss
+        except ImportError:
+            print("In order to use scss you need to have pyscss installed!")
+            sys.exit(1)
+
     # -------------------------------------------------------------------------
     # process input files
     # -------------------------------------------------------------------------
             elif re.search(MKD_PATT, f):
                 page = Page(page_global, opj(cwd, f), dir_in, opts)
                 pages.append(page)
+            elif re.search(SCSS_PATT, f):
+                scss_file = open(os.sep.join([cwd, f]), 'rt')
+                css_file = open(os.sep.join(
+                    [dir_out, cwd_site, re.split(SCSS_PATT, f)[0]]) + '.css',
+                    'w'
+                )
+                css = scss.Scss()
+                css_file.write(css.compile(scss_file.read()))
             else:
                 shutil.copy(opj(cwd, f), opj(dir_out, cwd_site))
 
                   help="encoding of output pages (default: utf-8)")
     og.add_option("", "--filename-enc", default="utf-8", metavar="ENC",
                   help="encoding of file names (default: utf-8)")
+    og.add_option("", "--scss-to-css", action="store_true", default=False,
+                  help="generate css from scss files while building a project")
     op.add_option_group(og)
 
     og = optparse.OptionGroup(op, "Serve options")