From 8f4bc5c19ebf11b0b0bfdd93b89d12117428b9de Mon Sep 17 00:00:00 2001
From: Dzianis Dashkevich <dskecse@gmail.com>
Date: Sun, 29 Nov 2015 16:59:10 +0300
Subject: [PATCH 1/3] Fix loading package data

---
 setup.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index 6088df2..445b505 100755
--- a/setup.py
+++ b/setup.py
@@ -34,5 +34,6 @@
         'pytest==2.5.2',
     ],
     packages=['wok'],
+    package_data={'wok':['contrib/*']},
     scripts=['scripts/wok'],
 )

From 3f55a6e8cff842e1aba2d624f10105be7290773d Mon Sep 17 00:00:00 2001
From: Dzianis Dashkevich <dskecse@gmail.com>
Date: Sun, 29 Nov 2015 17:40:40 +0300
Subject: [PATCH 2/3] Replace SASS with libsass

* libsass is faster as it is written in C
* Drop Ruby dependency
* Add Sass to the test site
* Use libsass-python API to compile Sass files
* Remove .sass/.scss files from output_dir after compilation
---
 test_site/hooks/__hooks__.py                  |  3 +-
 .../media/{friendly.css => friendly.scss}     |  0
 wok/contrib/hooks.py                          | 41 ++++++++++++-------
 3 files changed, 29 insertions(+), 15 deletions(-)
 rename test_site/media/{friendly.css => friendly.scss} (100%)

diff --git a/test_site/hooks/__hooks__.py b/test_site/hooks/__hooks__.py
index 7ee370b..fc9bb2c 100644
--- a/test_site/hooks/__hooks__.py
+++ b/test_site/hooks/__hooks__.py
@@ -1,4 +1,5 @@
 import logging
+from wok.contrib.hooks import compile_sass
 
 hook_count = 0
 def make_hook(name):
@@ -11,7 +12,7 @@ def logging_hook(*args):
 hooks = {
     'site.start': make_hook('site.start'),
     'site.output.pre': make_hook('site.output.pre'),
-    'site.output.post': make_hook('site.output.post'),
+    'site.output.post': [compile_sass],
     'site.content.gather.pre': make_hook('site.content.gather.pre'),
     'site.content.gather.post': make_hook('site.content.gather.post'),
     'page.meta.pre': make_hook('page.template.pre'),
diff --git a/test_site/media/friendly.css b/test_site/media/friendly.scss
similarity index 100%
rename from test_site/media/friendly.css
rename to test_site/media/friendly.scss
diff --git a/wok/contrib/hooks.py b/wok/contrib/hooks.py
index 8566078..f7194ce 100644
--- a/wok/contrib/hooks.py
+++ b/wok/contrib/hooks.py
@@ -2,6 +2,7 @@
 """Some hooks that might be useful."""
 
 import os
+import glob
 import subprocess
 from StringIO import StringIO
 import logging
@@ -15,6 +16,10 @@
 except ImportError:
     etree = None
 
+try:
+    import sass
+except ImportError:
+    sass = None
 
 class HeadingAnchors(object):
     """
@@ -59,7 +64,7 @@ def __call__(self, config, page):
 
         sio_destination = StringIO()
 
-	# Use the extension of the template to determine the type of document 
+	# Use the extension of the template to determine the type of document
 	if page.template.filename.endswith(".html") or page.filename.endswith(".htm"):
         	logging.debug('[HeadingAnchors] outputting {0} as HTML'.format(page))
 	        tree.write(sio_destination, method='html')
@@ -84,26 +89,34 @@ def compile_sass(config, output_dir):
         from wok.contrib.hooks import compile_sass
 
         hooks = {
-            'site.output.post':[compile_sass]
+            'site.output.post': [compile_sass]
         }
 
     Dependencies:
 
-        - Ruby
-        - Sass (http://sass-lang.com)
+        - libsass
     '''
     logging.info('Running hook compile_sass on {0}.'.format(output_dir))
     for root, dirs, files in os.walk(output_dir):
         for f in files:
             fname, fext = os.path.splitext(f)
-            if fext == ".scss" or fext == ".sass":
+            # Sass partials should not be compiled
+            if not fname.startswith('_') and fext == '.scss' or fext == '.sass':
                 abspath = os.path.abspath(root)
-                sass_src = "%s/%s"%(abspath, f)
-                sass_dest = "%s/%s.css"%(abspath, fname)
-                sass_arg = "%s:%s"%(sass_src, sass_dest)
-                logging.debug('[hook/sass] sass {0}'.format(sass_arg))
-                try:
-                    subprocess.call(['sass', sass_arg])
-                except OSError:
-                    logging.warning('[hook/compile_sass] Could not run SASS ' +
-                                    'hook. (Is SASS installed?)')
+                sass_src  = '{0}/{1}'.format(abspath, f)
+                sass_dest = '{0}/{1}.css'.format(abspath, fname)
+
+                if sass is None:
+                    logging.warning('To use compile_sass hook, you must install '
+                        'libsass-python package.')
+                    return
+
+                compiled_str = sass.compile(filename=sass_src, output_style='compressed')
+                with open(sass_dest, 'w') as f:
+                    f.write(compiled_str)
+
+    # TODO: Get rid of extra housekeeping by compiling Sass files in
+    #   "site.output.pre" hook
+    abspath = os.path.abspath(output_dir)
+    for f in glob.glob(os.path.join(abspath, '**', '*.s[a,c]ss')):
+        os.remove(f)

From 2cd19ed2a5a7295eb7a249dfd8e3094b33bcffa4 Mon Sep 17 00:00:00 2001
From: matt-garman <matthew.garman@gmail.com>
Date: Mon, 7 Dec 2015 17:10:02 -0600
Subject: [PATCH 3/3] Prepend page content with X newlines, where X is the
 number of lines of metadata.  This is to fix issue #145: reStructuredText
 rendering errors have incorrect line numbers

---
 test_site/content/tests/rest_error.rst | 17 +++++++++++++++++
 wok/page.py                            | 12 +++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)
 create mode 100644 test_site/content/tests/rest_error.rst

diff --git a/test_site/content/tests/rest_error.rst b/test_site/content/tests/rest_error.rst
new file mode 100644
index 0000000..239c184
--- /dev/null
+++ b/test_site/content/tests/rest_error.rst
@@ -0,0 +1,17 @@
+title: reStructuredText Test Page with Deliberate Error
+category: tests
+tags: [rest, sample]
+---
+
+reStructuredText Page with Deliberate Error
+===========================================
+
+For issue #144: reStructuredText rendering errors don't show
+filename, just "string"
+
+The following will trigger a rst rendering error:
+    - Should be an extra newline between the
+    - first bullet point and the preceeding paragraph
+This is line 15 but wok will report line 11 due to four lines of
+metadata above.
+
diff --git a/wok/page.py b/wok/page.py
index 27e84f5..875804c 100644
--- a/wok/page.py
+++ b/wok/page.py
@@ -103,14 +103,20 @@ def from_file(cls, path, options, engine, renderer=renderers.Plain):
             elif len(splits) == 2:
                 header = splits[0]
                 page.meta = yaml.load(header)
-                page.original = splits[1]
+                # prepend X newlines to original document, where X
+                # is number of lines of metadata (including "---"
+                # delimiter).  Fix for issue #145: rendering error
+                # line numbers are incorrect.
+                newlines = '\n' * (2+header.count('\n'))
+                page.original = newlines + splits[1]
                 page.original_preview = page.meta.get('preview', '')
 
             elif len(splits) >= 3:
                 header = splits[0]
                 page.meta = {}
-                page.original = '\n'.join(splits[1:])
-                page.original_preview = splits[1]
+                newlines = '\n' * (2+header.count('\n'))
+                page.original = newlines + '\n'.join(splits[1:])
+                page.original_preview = newlines + splits[1]
                 page.meta.update(yaml.load(header))
                 logging.debug('Got preview')