phpFashion

Rubrika Texy!

Add the `{texy}` Tag to Latte

As of version 3.1.6, the Texy library adds support for Latte 3 in the form of the {texy} tag. What can it do and how do you deploy it?

The {texy} tag represents an easy way to write directly in Texy syntax in Latte templates:

{texy}
You Already Know the Syntax
----------

No kidding, you know Latte syntax already. **It is the same as PHP syntax.**
{/texy}

Simply install the extension in Latte and pass it a Texy object configured as needed:

$texy = new Texy\Texy;
$latte = new Latte\Engine;
$latte->addExtension(new Texy\Bridges\Latte\TexyExtension($texy));

If there is static text between the {texy}...{/texy} tags, it is translated using Texy during the template compilation and the result is stored in it. If the content is dynamic (i.e., there are Latte tags inside), the processing using Texy is performed each time the template is rendered.

If it is desirable to disable Latte tags inside, it can be done like this:

{texy syntax: off} ... {/texy}

In addition to the Texy object, a custom function can also be passed to the extension, thus allowing parameters to be passed from the template. For instance, we might want to pass the parameters locale and heading:

$processor = function (string $text, int $heading = 1, string $locale = 'cs'): string {
	$texy = new Texy\Texy;
	$texy->headingModule->top = $heading;
	$texy->typographyModule->locale = $locale;
	return $texy->process($text);
};

$latte = new Latte\Engine;
$latte->addExtension(new Texy\Bridges\Latte\TexyExtension($processor));

Parameters in the template are passed like this:

{texy locale: en, heading: 3}
...
{/texy}

If you want to format text stored in a variable using Texy, you can use a filter:

{$description|texy}

Texy 3.0: Perfection Remains Untouched

It's a bit like when you spot a poster for a concert by a band you remember from your youth. Are they still playing? Or did they get back together after years because they need the money? Perhaps to cash in on the strings of nostalgia? [perex]

Texy is my first open-source project. I started writing it fifteen years ago. Texy has survived several version control systems. Numerous web services hosting repositories. Several string encodings. Various markup languages for creating websites. Several of my life relationships. A number of cities I've lived in.

Texy is still here because there is nothing better.

So, I have kept it up-to-date for fifteen years. We started in PHP 4, which was the worst programming language in the world and thus a challenge, then moved on to PHP 5 with relief, a few years later we transitioned to namespaces (Texy::Parser instead of TexyParser, wow), watched PHP stop being the worst language in the world, which frustrated many programmers who then turned to JavaScript, then God created PHP 7 and with it type hints (Texy::process(string $text): string megawow), and strictness came into fashion with declare(strict_types=1) and we honor that.

And so here is Texy 3.0.. It's the same as the previous versions, but with all the bells and whistles of PHP 7.1. It's the same because you don't mess with perfection.

Texy was here when you were born, in programming terms. Someday, Texy might even format your epitaph. And it will insert a non-breaking space between a and room.

6 years ago in section Texy!


Texy2 – Even More Sexy!

Texy2 is a huge leap forward. More perfect, cleverer, highly customizable. And above all – even more sexy! Web application developers can chuckle in contentment.

Initially, Texy2 wasn’t even supposed to be released. But let's not get ahead of ourselves…

How Software Is Designed

The best analysis of a program is done by programming it. Only then do you realize what you really need from it. And only then can you write it perfectly.

I was aware of this while writing Texy 1. I didn’t want to write API documentation, I didn’t translate the website into other languages. I knew that was just a rehearsal for the real Texy.

The first version was a labor because I had to crack a ton of nuts. Figure out how to even do it. It’s not a joke. For instance, you might say: “Texy will insert non-breaking spaces between a preposition and a word.” And one might think a regular expression that finds v lese and replaces it with v lese would suffice.

But, can it handle this too: v <strong>lese</strong>? Yes, a non-breaking space belongs there too. Why wouldn’t it? Should we filter strings in angle brackets? Okay, but what about this input:

v <span title="3 > 2">lese</span>

You'd suggest more cunning HTML tag filtering? Wait, but if there’s a <br> tag, then the non-breaking space shouldn’t be there. So no filtering, but analysis instead.

Or… or just consider this! 🙂

&#x76; <span title="les > obora"> &#x0020;
<!-- hehe --></span> &#32; &#x6C;ese

It’s still about the letter v followed by a space and the word lese. Now, just try to design that regular expression in rough outline ;)

Texy2 of course can do it. And that's just one of thousands of features.

However, the precision of conversion is not the main attraction of Texy2. Nope, that’s just a manifestation of maturing older ideas. The real bombshell is the maximum customizability.

Texy is Flexible and Billable

Now you can easily change the behavior of any document element. Need to build a wiki over Texy2? I.e., control all the links on the page? It took me just a few lines of code.

Need to generate content based on headings? Want to insert flash animations using [* movie.swf *]? Want to automatically add a CSS class to all phrases "hello .(description)"? You can! And extremely easily.

Some solutions are found directly in the distribution, but mostly in the documentation, which is not yet available 🙂 At least there’s a brief changelog. I’m sorry, I have such important tasks now that there’s no time to write the manual. However, the Texy website is now designed so that creating documentation does not have to depend only on me.

Texy2 is Here

Texy2 wasn’t meant to be released. I realized that I had no motivation to release my software as open source. It comes with many limitations, in the comfort zone you won’t find (i.e., in the Czech Republic), everyone bothers with support, you encounter idiots. If it weren’t for the Giraffe & co. at the last HBWBH, I would’ve probably kept it to myself.

The revision released today with the beautiful number 111 is the first official beta version of Texy2. Download it, play around, test it.

18 years ago in section Texy!


Texy! and it's out!

Texy is sexy Texy! is now live and is lively engaging with the world!

As I was reading your emails and feedback about Texy!, I realized that an interesting phenomenon has been born. Texy! has become a symbol, a Godot that many people have been waiting for, often impatiently. Some websites are counting on Texy! as the path of future development, others have even already deployed it. I read an opinion that Texy! will start a revolution in the CMS field and replace WYSIWYG editors. Conversely, another guy is asking whether Texy! will also have WYSIWYG? “I'm waiting for it like death!” was mentioned in the comments.

Given that until recently only one single article about Texy! was published and no one had seen it, this is an excellent score 🙂

Texy! is now sexy

So, from today, Texy! is officially out. Still in beta version, we need to iron out some bugs and fine-tune the syntax. Therefore, I will appreciate it if you put it through rigorous tests. The website itself is also in beta. I want to improve the texts, divide the Syntax page into several smaller ones, and maybe even add a forum.

I previously informed about choosing a license and eventually chose a dual model – GPL + commercial license. So you can use it for free for your needs (I would appreciate a link) and you can include it in your GPL applications. And if you want to implement it in your commercial CMS, contact me and we will arrange the conditions for a special license.

And not to forget: is there anyone with excellent knowledge of English (or another language) who would help me with translation for the price of publishing their name with a link and the ensuing eternal glory? Thanks 🙂

And a few more links:

20 years ago in section Texy!


Texy! is Sexy!

Texy is sexy Texy! is a text converter and formatter outputting in XHTML. It uses a set of fairly simple, yet very effective rules that guide the conversion. I finally made a plugin for BLOG:CMS and now I can write all articles in Texy! It saves me a lot of time and you, dear readers, will see a typographically cleaner result.

You can try Texy! at the mentioned address or even here in the comments. These also run on a new engine.

Maybe I'm too big of a fan 🙂 but I would say that Texy! is the most complex formatter. It can process images, links, nested lists, tables, and also CSS (Cascading Styles). It doesn't get fooled and generates valid, high-quality code. Additionally, it adjusts the format to national specifics:

  • inserts non-breaking spaces after single-letter consonantal prepositions and conjunctions (the most uncrystallizable ones)
  • breaks overly long words according to syllables
  • uses “double” and ‘single’ typographic quotes
  • converts a hyphen to an en dash: 10–15 vs. Czech-Slovak

Unfortunately, I developed the system at a time when I was not aware of any alternatives, making it completely incompatible with anything else. However, thoughts of slightly adapting it, perhaps to Textile, were ultimately dismissed. Simply put, Texy! just makes more sense to me. Texy! is sexy!

20 years ago in section Texy!


phpFashion © 2004, 2025 David Grudl | o blogu

Ukázky zdrojových kódů smíte používat s uvedením autora a URL tohoto webu bez dalších omezení.