Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern subdir property contains incorrect directory separator on windows #559

Closed
sandrojohanides opened this issue Nov 14, 2016 · 6 comments

Comments

@sandrojohanides
Copy link

sandrojohanides commented Nov 14, 2016

I am using Pattern Lab Node v1.3.4 on Windows, with Node v6.9.1, using the Gulp Edition.

Expected Behavior

Pattern object subdir property should contain forward slash /

Actual Behavior

Pattern object subdir property contains backslash \\ showing an error Could not find pattern referenced with partial syntax ' + partialName + '. This can occur when a pattern was renamed, moved, or no longer exists but it still called within a different template somewhere.

Steps to Reproduce

Try to include partial in mustache template using Default Include Syntax {{> dir/subdir/partial }} on windows

@sandrojohanides sandrojohanides changed the title Pattern subdir property contais incorrect directory separator on windows Pattern subdir property contains incorrect directory separator on windows Nov 14, 2016
@somatonic
Copy link

somatonic commented Jan 21, 2017

Hi, I´m working with PL on MacOSX and now tried my project on Windows and run into this bug. Ißm also using verbose mustache include syntax.

I investigated and found it´s a dir separator issue. I added a line in pattern_assembler.js to get it working, I´m sure this is not the correct fix but gives a hint.

    //else look by verbose syntax
    for (var i = 0; i < patternlab.patterns.length; i++) {
      switch (partialName) {
        case patternlab.patterns[i].relPath:
        case patternlab.patterns[i].subdir.replace("\\","/") + '/' + patternlab.patterns[i].fileName:
        case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName:
          return patternlab.patterns[i];
      }
    }

Now when I get that fixed, there´s a new issue with those partial includes. It only allows me to include a pattern that is further up in the file ordering. So a structure like

00-pattern
pattern1
pattern2

I can´t include pattern2 in pattern1. Once I change it to different order it works like:

00-pattern
_pattern2
pattern1

This happened to me only on Windows using verbose include syntax once I added my fix. It seems that when using the shorthand syntax it works fine. Not sure what is happening. Thanks, any help appereciated to fix this.

@sandrojohanides
Copy link
Author

sandrojohanides commented Jan 21, 2017

@somatonic we (seemingly) managed to fix it with adding 2 lines in \node_modules\patternengine-node-mustache\lib\engine_mustache.js":

 22 var path = require('path');
113 foundPatternPartial = foundPatternPartial.replace("/", path.sep);

It should replace the slashes found in partials with correct path separators. But I haven't gotten around to sumbit a PR :/

@somatonic
Copy link

Thanks @sandrojohanides. I tried this out and it's not working. This replaces only the first occurence of "/" and if you have subdirs it ends up "00-pattern\pattern1/pattern1". I changed it to:

foundPatternPartial = foundPatternPartial.replace(/\//g, path.sep);

But then the check in pattern_assembler.js will fail for certain patterns still. So I added my code path.sep there and it started working all again,

40 case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName:

to

40 case patternlab.patterns[i].subdir + path.sep + patternlab.patterns[i].fileName:

Also the wierd behaviour I have is gone with file order of partials playing a role.

Thanks

@sandrojohanides
Copy link
Author

No, thank you, it's great to have an all-around working solution. I'll try it out on monday.

@greenthoms
Copy link

Hey @sandrojohanides @somatonic nice work. Any issues with the fix mentioned? Will you be creating a pull request?

gergan pushed a commit to gergan/patternlab-node that referenced this issue Aug 11, 2017
gergan pushed a commit to gergan/patternlab-node that referenced this issue Aug 11, 2017
@bmuenzenmeyer
Copy link
Member

closing this due to inactivity. OP or anyone still experiencing an issue - feel free to bump this again.

bmuenzenmeyer added a commit that referenced this issue Sep 11, 2017
Fix the verbose partial 
closes #559
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants