Jump to content
hdesigns

Module: Dindent

Recommended Posts

Yesterday I looked at the HTML output of a PW website of mine and thought it looked kind of messed up.

It wasn't because the code was bad or I used the wrong tags. It also wasn't because I somehow forgot to close open tags (w3c validation went fine).

No, it only was because the HTML output wasn't well formatted. I think this is a pretty common "problem" when using PHP to generate your HTML code instead of creating static HTML pages.

To solve my "problem" I searched a bit and stumbled upon https://github.com/gajus/dindent.

The idea behind this remarkable little piece of software is imho great: In opposite to HTML purifier or tidy Dindent doesn't manipulate your HTML code in a sense that it will behave differently. It doesn't close unclosed HTML tags or something like that. No, Dindent only changes the format of the HTML output to make it more readable and appear cleaner.

So, as a developer, you are still responsible for creating proper HTML code!

So I decided to create a simple little ProcessWire module that hooks into the render-method and applies the magic provided by Dindent. That's all!

But I really think it can make a difference in the presentation of your website for everyone that looks a bit deeper into your project and therefore looks at the HTML code your website provides.

Beware: Of course the whole beautifying process is not free. It costs some time, so it works best together with a caching mechanisms (favourably the fantastic ProcessWire ProCache)!

What do you think?

DIndent_v1.0.0.zip

  • Like 12

Share this post


Link to post
Share on other sites

Thanks for sharing!

I will test it later this week when find some time. I think this is helpful to me while developing on the Markup of a page. :)

------

BTW:

I would recomment to add to your getModuleInfo() a "requires" key like:

'requires' => array('ProcessWire>=2.4.0', 'PHP>=5.3.8'),

You use Namespaces with your module and therefore the minimum needed PHP Version should be noted in the required value(s), or the minimum PW version.

At the moment it is not mandatory to note this, but it is helpful anyway.

  • Like 2

Share this post


Link to post
Share on other sites

Thank you horst for pointing out the "requires"-field of the module info.

I've added the line you suggested.

One question thought: Why do you also suggest that the module requires PW 2.4 besides the PHP version?

DIndent_v1.0.1.zip

Share this post


Link to post
Share on other sites

The line is an example, I wanted to suggest that you use one of them, that one that makes most sense. :)  I said use this or that.

If you only use PHP functions that are available with e.g. PHP 5.3, you simply can require PW>=2.4, because PW 2.4 itself requires PHP 5.3.8 or greater. But if you have a module that also would run with PW 2.2 or 2.3 regarding the PW core, but needs PHP version >= 5.4, then you must require PHP >= 5.4.

I always would note the PW version, and only if the needed PHP is higher than the minimum required for PW I would note this additionally. I think the only situation not to note the PW version would be if your module run on all versions from 2.2 - 2.5. :)

EDIT:

Ah, now I understand. I have downloaded your new version: I don't know which versions your module need, sorry for confusion. It was only an example that should provide the typo, not the correct values / versions.

I think you need PHP 5.3.0 because of the namespaces, but which version of PW it works with I don't know. Maybe >= 2.3 or >= 2.2 ?

A hook to page::render is not one of the recently added functions. :)

Edited by horst

Share this post


Link to post
Share on other sites

Ah, ok, no I misunderstood you.

You're right with the namespaces that were introduced with PHP 5.3.0

Anyway, I can't really say which PW version is required for my module, because I've only tested it with PW 2.5

I'm pretty sure thought it would also work with PW 2.2+ (and below was no "requires"-field I think).

Right now I'm tending to let the module only require the PHP version and not the PW version so nobody is restricted unnecessarily.

Is there somewhere a documentation that points out which feature/hooks/methods/etc. were added at which PW version?

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...