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

POC for patternlab viewer: initial commit #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

POC for patternlab viewer: initial commit #1

wants to merge 4 commits into from

Conversation

sergesemashko
Copy link
Contributor

@beynya @scottnath please review

@sergesemashko
Copy link
Contributor Author

A lot of files are just copies of patternlab, I'll mark which files should be reviewed

@@ -0,0 +1,85 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review this file

@scottnath
Copy link
Member

@sergesemashko
how do I set up patternPaths with the current pattern-library? Is it required?

@sergesemashko
Copy link
Contributor Author

@scottnath all params are optional, but I would recommend pass to custom dest. Also you can provide custom HTML in patternNavHTML or generated object in patternPaths if you want custom menu, for now it's hardcoded.
Examples of usages:

// custom patternPaths object 
patternlabWrapper({
    dest: './app/public',
    patternPaths: {"category":
       {"subcategory": {"patternName1": "00-atoms-01-global-00-colors"},
      {"subcategory2": {"patternName2": "00-atoms-01-global-01-redirect"},
       ...
    }
  });

// OR custom menu html
patternlabWrapper({
    dest: './app/public',
    patternNavHTML: '<ul class="patterns-menu sg-nav">
    <li class="sg-nav-"><a class="sg-acc-handle">base</a>
        <ul class="sg-acc-panel">

            <li class="sg-nav-"><a class="sg-pop" href="app/bower_components/pattern-library/patterns/base/blockquote">Blockquote</a></li>
            <li class="sg-nav-"><a class="sg-pop" href="app/bower_components/pattern-library/patterns/base/body">Body</a></li>
        </ul>
    </li>
    </ul>'
  });

// OR with html hardcoded in _patternlab-files/partials/patterNav.twig
patternlabWrapper({
    dest: './app/public'
});

Let me know if you have any troubles/

@scottnath
Copy link
Member

@sergesemashko Created this:

var patternlabWrapper = require('patternlab-wrapper');
var fs = require('fs');

var navHtml = fs.readFileSync('./menu.html');
console.log(navHtml);
patternlabWrapper({
    dest: './app/public',
    patternPaths: {"atoms":{"colors":"00-atoms-01-global-00-colors","redirect":"00-atoms-01-global-01-redirect"}},
    patternNavHTML: navHtml
});

Getting this:

Buffer 0a 20 20 3c 75 6c 20 63 6c 61 73 73 3d 22 70 61 74 74 65 72 6e 73 2d 6d 65 6e 75 22 3e 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 3c 6c ... >
fs.js:500
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory './_patternlab-files/partials/ishControls.twig'
    at Error (native)
    at Object.fs.openSync (fs.js:500:18)
    at Object.fs.readFileSync (fs.js:352:15)
    at patternlabWrapper (/Users/scottnath/development/gitrepos/pattern-presenter/node_modules/patternlab-wrapper/index.js:80:76)
    at Object.<anonymous> (/Users/scottnath/development/gitrepos/pattern-presenter/test.js:6:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)

@sergesemashko
Copy link
Contributor Author

@scottnath something wrong with relative paths, checking locally

@sergesemashko
Copy link
Contributor Author

@scottnath , that was relative path issue, I fixed it. Please, try again

@scottnath
Copy link
Member

@sergesemashko
screen shot 2015-05-07 at 10 28 44 am
so, the links seem to be in the wrong place. When I click them, they go to the plain html file of the pattern, but not inside the PL interface.

my current code:

var patternlabWrapper = require('patternlab-wrapper');
var fs = require('fs');

var navHtml = fs.readFileSync('./app/PUBLIC/menu.html');
console.log(navHtml);
patternlabWrapper({
    dest: './app',
    patternPaths: {"atoms":{"colors":"00-atoms-01-global-00-colors","redirect":"00-atoms-01-global-01-redirect"}},
    patternNavHTML: navHtml
});

@scottnath
Copy link
Member

how the html for the menu is in there...

screen shot 2015-05-07 at 10 32 23 am

@sergesemashko
Copy link
Contributor Author

@scottnath there is some JS bound on classes to do that kind of logic.
Resulting menu should be something like this:

<ul class="patterns-menu sg-nav">
    <li>
        <a class="sg-acc-handle">base</a>
        <ul class="sg-acc-panel">

            <li ><a class="sg-acc-handle" href="PUBLIC/base/a/a.html">Anchor Link</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/blockquote/blockquote.html">Blockquote</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/body/body.html">Body</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/button/button.html">Button</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/code/code.html">Code</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/em/em.html">Em</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/h1/h1.html">Heading Level 1</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/h2/h2.html">Heading Level 2</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/h3/h3.html">Heading Level 3</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/h4/h4.html">Heading Level 4</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/h5/h5.html">Heading Level 5</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/h6/h6.html">Heading Level 6</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/img/img.html">Base Image</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/label/label.html">Label</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/li/li.html">List Item</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/ol/ol.html">Ordered List</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/option/option.html">Option</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/p/p.html">Paragraph</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/pre/pre.html">Pre</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/select/select.html">Select</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/strong/strong.html">Strong</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/table/table.html">Table</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/tbody/tbody.html">Table body element</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/td/td.html">Table cell</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/test-img/test-img.html">Base Image</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/textarea/textarea.html">Textarea</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/th/th.html">Table header cell</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/thead/thead.html">Table header</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/tr/tr.html">Table row</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/base/ul/ul.html">Unordered List</a></li>
        </ul>
    </li>
    <li><a class="sg-acc-handle">uncategorized</a>
        <ul class="sg-acc-panel">
            <li ><a class="sg-pop"  href="PUBLIC/uncategorized/generic-elm-h2/generic-elm-h2.html">Heading Level 2 Generic H2</a></li>
        </ul>
    </li>
    <li>
        <a class="sg-acc-handle">components</a>
        <ul class="sg-acc-panel">
            <li ><a class="sg-acc-handle" href="PUBLIC/components/figure-image/figure-image.html">Figure Image</a></li>
            <li ><a class="sg-acc-handle" href="PUBLIC/components/message/message.html">Message</a></li>
        </ul>
    </li>
</ul>

This is updated twig template with classes for menu (insert links into href attributes if something is missing):

{% if categories is not empty %}
    <ul class="patterns-menu sg-nav">
        {% for key,value in categories %}
            {% if value.patterns is not empty %}
                <li>
                    <a href="#" class="sg-acc-handle">{{key}}</a>
                    <ul class="sg-acc-panel">
                        {% if value.subcategories is not empty %}
                            {% for key,value in value.subcategories %}
                                {% if value.patterns is not empty %}
                                    <li>
                                        <a href="#" class="sg-acc-handle">{{key}}</a>
                                        <ul class="sg-acc-panel">
                                            {% for item in value.patterns %}
                                                <li><a class="sg-pop" href="{{item.url}}">{{item.name}}</a></li>
                                            {% endfor %}
                                        </ul>
                                    </li>
                                {% endif %}
                            {% endfor %}
                        {% endif %}
                        {% for item in value.patterns %}
                            <li class="sg-nav-"><a class="sg-pop" href="{{item.url}}">{{item.name}}</a></li>
                        {% endfor %}
                    </ul>
                </li>
            {% endif %}
        {% endfor %}
    </ul>
{% endif %}

also both _patterns and index.html should be in the same folder and urls for patterns should be relative to public folder:

public/
|_ index.html
|_ patterns/
    |_ pattern1/pattern.html // URL should be "patterns/pattern1/pattern.html"

Let me know if that doesn't work.

@scottnath
Copy link
Member

@sergesemashko didn't work. I've got the links right, but it just repeats the main interface, so then it just starts to double up.
screen shot 2015-05-07 at 11 52 21 am

Is there any way you could simplify this? We really need drop-in solutions for all of these pieces.

@sergesemashko
Copy link
Contributor Author

@scottnath, simpler solution will be to combine this repo with pattern-presenter and generate view in pattern-presenter only. I can start looking into that. What do you think?

@scottnath
Copy link
Member

@sergesemashko that seems like a possible solution, but really all of this patternlab code seems like very excessive overkill. Other than the familiar interface, what are we gaining brining all this in?

Is something like this pull request workable? What do we lose with a basic version like that (other than the styling of the interface?)

@sergesemashko
Copy link
Contributor Author

Speaking about POC - we do not lose anything. But, obviously, it would be hard to use the tool without some interface features.

@scottnath
Copy link
Member

@sergesemashko agreed. But maybe we can keep it simple and still have an interface. This is what my PR creates:

http://pattern-library.github.io/

it is ugly, but it is simple.

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

Successfully merging this pull request may close these issues.

3 participants