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

Feature Request: Conditionals (or Empty/Unset Vars) #4

Open
calvinjuarez opened this issue Dec 9, 2013 · 7 comments
Open

Feature Request: Conditionals (or Empty/Unset Vars) #4

calvinjuarez opened this issue Dec 9, 2013 · 7 comments

Comments

@calvinjuarez
Copy link

For example:

page.kit

<!DOCTYPE html>
<!-- @page = Page -->
<html>
<head>...</head>
<body>
    <nav>
<!-- @import nav.kit -->
    </nav>
    ...
</body>
</html>

nav.kit

        <ul>
            <li <!-- @page == Home ? class="active" -->>
                <a href="/">Home</a>
            </li>
            <li <!-- @page == Page ? class="active" -->>
                <a href="/page.html">Page</a>
            </li>
            <li <!-- @page == Other ? class="active" -->>
                <a href="/other.html">Other</a>
            </li>
        </ul>

page.html

<!DOCTYPE html>
<html>
<head>...</head>
<body>
    <nav>
        <ul>
            <li>
                <a href="/">Home</a>
            </li>
            <li class="active">
                <a href="/page.html">Page</a>
            </li>
            <li>
                <a href="/other.html">Other</a>
            </li>
        </ul>
    </nav>
    ...
</body>
</html>
@calvinjuarez
Copy link
Author

Or

Even just some way to make it so if a variable isn't defined, it just replaces the Kit comment with an empty string.

For example:

page.kit

<!DOCTYPE html>
<html>
<head>...</head>
<body>
    <nav>
<!-- @page = class="active" -->
<!-- @import nav.kit -->
    </nav>
    ...
</body>
</html>

nav.kit

        <ul>
            <li <!-- &@home -->>
                <a href="/">Home</a>
            </li>
            <li <!-- &@page -->>
                <a href="/page.html">Page</a>
            </li>
            <li <!-- &@other -->>
                <a href="/other.html">Other</a>
            </li>
        </ul>

(The & here just indicates, "If this variable isn't set, don't error, just skip it.")

page.html

<!DOCTYPE html>
<html>
<head>...</head>
<body>
    <nav>
        <ul>
            <li>
                <a href="/">Home</a>
            </li>
            <li class="active">
                <a href="/page.html">Page</a>
            </li>
            <li>
                <a href="/other.html">Other</a>
            </li>
        </ul>
    </nav>
    ...
</body>
</html>

@sathomas
Copy link

FYI, here's my workaround. In _nav.kit:

  <a class="btn <!--$incidentsActive-->" href="incidents.html">Incidents</a>
  <a class="btn <!--$assetsActive-->"    href="assets.html"   >Assets</a>
  <a class="btn <!--$reportsActive-->"   href="reports.html"  >Reports</a>
  <a class="btn <!--$serviceActive-->"   href="service.html"  >Service</a>
  <a class="btn <!--$intelActive-->"     href="intel.html"    >Intelligence</a>
  <a class="btn <!--$adminActive-->"     href="admin.html"    >Administration</a>

And then, e.g., in admin.kit:

<!-- $incidentsActive: inactive -->
<!-- $assetsActive:    inactive -->
<!-- $reportsActive:   inactive -->
<!-- $serviceActive:   inactive -->
<!-- $intelActive:     inactive -->
<!-- $adminActive:       active -->
<!-- @import "nav.kit" -->

@calvinjuarez calvinjuarez changed the title It'd be nice to have conditionals Feature Request: Conditionals (or Unset Vars) Oct 20, 2014
@calvinjuarez calvinjuarez changed the title Feature Request: Conditionals (or Unset Vars) Feature Request: Conditionals (or Empty Vars) Oct 21, 2014
@calvinjuarez calvinjuarez changed the title Feature Request: Conditionals (or Empty Vars) Feature Request: Conditionals (or Empty/Unset Vars) Oct 21, 2014
@albell
Copy link

albell commented Oct 28, 2014

Hey Bryan, is this feature still on the radar? This would be extremely useful.

@calvinjuarez
Copy link
Author

The answer given by @bdkjones on issue #6:

Yep. This is on deck for implementation.

@calvinjuarez
Copy link
Author

@sathomas
Copy link

sathomas commented Dec 3, 2015

For folks checking the status of this issue, here's a bit of a workaround that gets you conditional functionality.

  • In the main file define variables to hide (or not) conditional content. To hide content, set the value of the variable to the opening HTML comment <!--; to show the content, set the value of the variable to nil.
  • In the included file, prefix the conditional content with the variable. After the end of the conditional content, add any HTML comment.

As an example, here's what goes in the parent file:

<!-- $hideBlockOne: <!-- -->
<!-- $hideBlockTwo: nil -->
<!-- @import "_child.kit" -->

And here's the child file:

<!--$hideBlockOne-->
    <div id="block-one">...</div>
<!-- end of hideBlockOne -->
<!--$hideBlockOne-->
    <div id="block-two">...</div>
<!-- end of hideBlockTwo -->

The resulting compiled file will have block one commented out and block two included:

<!--
    <div id="block-one">...</div>
<!-- end of hideBlockOne -->

    <div id="block-two">...</div>
<!-- end of hideBlockTwo -->

Maybe it's not the most aesthetically pleasing approach, but it does get the job done.

And thanks @bdkjones for CodeKit!

@bdkjones
Copy link
Owner

bdkjones commented Dec 4, 2015

Ha, that's ridiculously clever. Well done.

Sent from my iPhone

On Dec 3, 2015, at 14:16, Stephen A Thomas [email protected] wrote:

For folks checking the status of this issue, here's a bit of a workaround that gets you conditional functionality.

In the main file define variables to hide (or not) conditional content. To hide content, set the value of the variable to the opening HTML comment <!--; to show the content, set the value of the variable to nil.

In the included file, prefix the conditional content with the variable. After the end of the conditional content, add any HTML content.

As an example, here's what goes in the parent file:

And here's the child file:

<div id="block-one">...</div>
<div id="block-two">...</div>

The resulting compiled file will have block one commented out and block two included:

<div id="block-two">...</div>

Maybe it's not the most aesthetically pleasing approach, but it does get the job done.

And thanks @bdkjones for CodeKit!


Reply to this email directly or view it on GitHub.

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