colinta / StrangeCase

It's yet another static site generator. Have you seen jekyll? hyde? Yup. Like those.
http://colinta.com/projects/StrangeCase.html
Other
49 stars 7 forks source link

Extension stripping is a bit too agressive #46

Closed wichert closed 12 years ago

wichert commented 12 years ago

I had a file named contact.html, but all links to it were rendered as contac which was a bit unexpected. This turns out to be due to the use of rstrip:

>>> 'contact.html'.rstrip('.html')
'contac'

rstrip probably does not do what you were expecting: it looks for all characters in the supplied string, it does not look for the string itself. I suggest using a standard slicing:

>>> 'contact.html'[:-len('.html')]
'contact'
colinta commented 12 years ago

Thanks again! Fixed in v4.5.19.

wichert commented 12 years ago

Can you upload 4.5.19 to pypi as well?

colinta commented 12 years ago

oops, forgot to bump version in setup.py.

it's ready now

On Sep 6, 2012, at 8:03 AM, Wichert Akkerman wrote:

Can you upload 4.5.19 to pypi as well?

— Reply to this email directly or view it on GitHub.

wichert commented 12 years ago

Seems this change broke something else: the contact.j2 template can now no longer be found. When I run scase I get the following:


Traceback (most recent call last):
  File "bin/scase", line 20, in <module>
    strange_case.__main__.run()
  File "/srv/website/src/eggs/StrangeCase-v4.5.19-py2.7.egg/strange_case/__main__.py", line 185, in run
    strange_case(CONFIG)
  File "/srv/website/src/eggs/StrangeCase-v4.5.19-py2.7.egg/strange_case/__init__.py", line 154, in strange_case
    root_node.generate()
  File "/srv/website/src/eggs/StrangeCase-v4.5.19-py2.7.egg/strange_case/nodes/root_folder.py", line 37, in generate
    child.generate(self)
  File "/srv/website/src/eggs/StrangeCase-v4.5.19-py2.7.egg/strange_case/nodes/file.py", line 20, in generate
    self.generate_file(site, self.source_path, target_path)
  File "/srv/website/src/eggs/StrangeCase-v4.5.19-py2.7.egg/strange_case/nodes/jinja.py", line 10, in generate_file
    content = self.render(site)
  File "/srv/website/src/eggs/StrangeCase-v4.5.19-py2.7.egg/strange_case/nodes/jinja.py", line 21, in render
    template = Registry.get('jinja_environment').get_template(fix_path(self.source_path))
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 719, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 693, in _load_template
    template = self.loader.load(self, name, globals)
  File "/srv/website/src/eggs/StrangeCase-v4.5.19-py2.7.egg/strange_case/support/jinja.py", line 107, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/srv/website/src/eggs/StrangeCase-v4.5.19-py2.7.egg/strange_case/support/jinja.py", line 77, in get_source
    contents, filename, uptodate = super(YamlFrontMatterLoader, self).get_source(environment, template)
  File "/usr/lib/python2.7/dist-packages/jinja2/loaders.py", line 180, in get_source
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: /srv/website/src/site/contact.j2

the file does exist though:

wichert@code:/srv/website/src$ ls site/
asset  contact.j2  index.j2  media  portfolio.j2
colinta commented 12 years ago

yikes. I wonder if this is related to the "windows support" fixes that have been coming in recently.

Do you know what version you were using before? The fix_path function was added in version v4.5.18.

wichert commented 12 years ago

Previous version was 4.5.17.

colinta commented 12 years ago

that version of jinja looks different from mine:

raise TemplateNotFound('{0} in {1}'.format(template, ','.join(self.searchpath)))

searchpath is a list of paths, and os.getcwd() is included in that list.

does pip install -U jinja2 fix it?

colinta commented 12 years ago

(oops - make sure to pip install jinja2)

colinta commented 12 years ago

mine is at 2.6, btw

wichert commented 12 years ago

I don't use pip or virtualenv, so pip install doesn't do anything for me. The exact versions I am running are:

Jinja2 = 2.6
Pillow = 1.7.7
PyYAML = 3.10
Pygments = 1.5
StrangeCase = v4.5.19
Unidecode = 0.04.9
misaka = 1.0.2
argh = 0.15.1
buildout-versions = 1.7
markdown2 = 1.4.2
misaka = 1.0.2
pathtools = 0.1.2
python-dateutil = 2.1
setuptools = 0.6c11
six = 1.1.0
watchdog = 0.6.0
z3c.recipe.scripts = 1.0.1
zc.buildout = 1.5.2
zc.recipe.egg = 1.3.2
wichert commented 12 years ago

There does appear to be an OS-installed jinja first in the path, but that also happens to be version 2.6 (as included in Ubuntu 12.04 precise).

wichert commented 12 years ago

Your jinja must be a different version. You can see the code from the 2.6 release as you can see in the jinja2 git tag for 2.6.

colinta commented 12 years ago

Well I'll be damned. So I was. That's not very nice of me.

Pushed v4.5.20. Adds '/' to the jinja2 search paths.

colinta commented 12 years ago

(and on pypi)

wichert commented 12 years ago

Thanks, that indeed fixes it.

colinta commented 12 years ago

yay! thanks for your patience.