Skip to content

chevere/danky

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Oct 14, 2024
a66ef9c Â· Oct 14, 2024

History

51 Commits
Dec 26, 2022
Mar 20, 2024
Dec 26, 2022
Apr 29, 2022
Dec 26, 2022
Dec 26, 2022
Apr 15, 2022
Apr 15, 2022
Apr 13, 2022
Oct 14, 2024
Apr 13, 2022
Dec 26, 2022
Dec 26, 2022
Apr 13, 2022
Apr 13, 2022
Apr 13, 2022

Repository files navigation

Danky

Chevere

Build Code size Apache-2.0 PHPStan Mutation testing badge

Quality Gate Status Maintainability Rating Reliability Rating Security Rating Coverage Technical Debt CodeFactor Codacy Badge

What is Danky?

Danky is a typed template system for PHP. Contrary to all other template systems, in Danky templates are classes.

🦄 Templates explicit declare its scope on construct, the $render property can be of type string or Template.

<?php // Quote.php

use Chevere\Danky\Template;

class Quote extends Template
{
    public function __construct(string $text, string $author) {
        $this->render =
            <<<HTML
            <quote>"$text" --$author</quote>
            HTML;
    }
};

That <<<HTML ... is Heredoc syntax string literal. In Danky, you use all the stuff that has been always there to handle multi-line string literals. Heredoc is great for templates as it evaluates variables, making templates clean to read.

<?php // Home.php

use Chevere\Danky\Template;

class Home extends Template
{
    public function __construct(Template $content) {
        $this->render =
            <<<HTML
            <main>
                $content
            </main>
            HTML;
    }
};

Template classes implements Stringable, you can use any template object within string literals.

<?php // index.php

use function Chevere\Danky\import;
use Home;
use Quote;

echo
    new Home(
        content: new Quote(
            text: 'Hello, world!',
            author: 'Rodolfo'
        )
    );

🥳 Congratulations! You just mastered Danky.

<main>
    <quote>"Hello, world!"</quote>
</main>

Now run php demo/index.php for a more complete example.

License

Copyright 2022 Rodolfo Berrios A.

Chevere is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.