Fix Pelican rendering and unit tests on Windows.

* Fix {filename} links on Windows.
  Otherwise '{filename}/foo/bar.jpg' doesn't work
* Clean up relative Posix path handling in contents.
* Use Posix paths in readers
* Environment for Popen must be strs, not unicodes.
* Ignore Git CRLF warnings.
* Replace CRLFs with LFs in inputs on Windows.
* Fix importer tests
* Fix test_contents
* Fix one last backslash in paginated output
* Skip the remaining failing locale tests on Windows.
* Document the use of forward slashes on Windows.
* Add some Fabric and ghp-import notes
This commit is contained in:
George V. Reilly 2015-01-02 23:45:44 -08:00
commit 4c25610cd8
14 changed files with 104 additions and 52 deletions

View file

@ -11,6 +11,7 @@ import os
import pytz
import re
import shutil
import sys
import traceback
import pickle
import hashlib
@ -23,6 +24,7 @@ from functools import partial
from itertools import groupby
from jinja2 import Markup
from operator import attrgetter
from posixpath import join as posix_join
logger = logging.getLogger(__name__)
@ -230,13 +232,15 @@ def get_date(string):
@contextmanager
def pelican_open(filename):
def pelican_open(filename, mode='rb', strip_crs=(sys.platform == 'win32')):
"""Open a file and return its content"""
with codecs.open(filename, encoding='utf-8') as infile:
with codecs.open(filename, mode, encoding='utf-8') as infile:
content = infile.read()
if content[0] == codecs.BOM_UTF8.decode('utf8'):
content = content[1:]
if strip_crs:
content = content.replace('\r\n', '\n')
yield content
@ -370,6 +374,13 @@ def path_to_url(path):
return '/'.join(split_all(path))
def posixize_path(rel_path):
"""Use '/' as path separator, so that source references,
like '{filename}/foo/bar.jpg' or 'extras/favicon.ico',
will work on Windows as well as on Mac and Linux."""
return rel_path.replace(os.sep, '/')
def truncate_html_words(s, num, end_text='...'):
"""Truncates HTML to a certain number of words.
@ -750,4 +761,9 @@ def is_selected_for_writing(settings, path):
return path in settings['WRITE_SELECTED']
else:
return True
def path_to_file_url(path):
'''Convert file-system path to file:// URL'''
return six.moves.urllib_parse.urljoin(
"file://", six.moves.urllib.request.pathname2url(path))