Auto reformat conditionals snytax

For support and discussion related to templates, themes, and imagesets in phpBB 3.1.
Scam Warning
zulcom
Registered User
Posts: 3
Joined: Sun Jun 10, 2018 5:46 pm

Auto reformat conditionals snytax

Post by zulcom »

Hello!
Everyday i look at code formated like that:

Code: Select all

<!-- IF S_USER_LOGGED_IN and S_ZEBRA -->
<!-- IF U_REMOVE_FRIEND -->
<dt>&nbsp;</dt> <dd class="zebra"><a href="{U_REMOVE_FRIEND}" data-ajax="zebra"><strong>{L_REMOVE_FRIEND}</strong></a></dd>
<!-- ELSEIF U_REMOVE_FOE -->
<dt>&nbsp;</dt> <dd class="zebra"><a href="{U_REMOVE_FOE}" data-ajax="zebra"><strong>{L_REMOVE_FOE}</strong></a></dd>
<!-- ELSE -->
<!-- IF U_ADD_FRIEND -->
<dt>&nbsp;</dt> <dd class="zebra"><a href="{U_ADD_FRIEND}" data-ajax="zebra"><strong>{L_ADD_FRIEND}</strong></a></dd>
<!-- ENDIF -->
<!-- IF U_ADD_FOE -->
<dt>&nbsp;</dt> <dd class="zebra"><a href="{U_ADD_FOE}" data-ajax="zebra"><strong>{L_ADD_FOE}</strong></a></dd>
<!-- ENDIF -->
<!-- ENDIF -->
<!-- ENDIF -->
And i spend a lot of time to manually reformat this code to human-readable form:

Code: Select all

<!-- IF S_USER_LOGGED_IN and S_ZEBRA -->
			<!-- IF U_REMOVE_FRIEND -->
				<dt>&nbsp;</dt> 
				<dd class="zebra">
				   <a href="{U_REMOVE_FRIEND}" data-ajax="zebra">
				   <strong>{L_REMOVE_FRIEND}</strong></a>
				</dd>
			<!-- ELSEIF U_REMOVE_FOE -->
				<dt>&nbsp;</dt>
				<dd class="zebra">
				  <a href="{U_REMOVE_FOE}" data-ajax="zebra">
				     <strong>{L_REMOVE_FOE}</strong>
				   </a>
				 </dd>
			<!-- ELSE -->
				<!-- IF U_ADD_FRIEND -->
					<dt>&nbsp;</dt>
					<dd class="zebra">
					    <a href="{U_ADD_FRIEND}" data-ajax="zebra">
					    <strong>{L_ADD_FRIEND}</strong>
					    </a>
					  </dd>
				<!-- ENDIF -->
				<!-- IF U_ADD_FOE -->
					<dt>&nbsp;</dt>
					<dd class="zebra">
					  <a href="{U_ADD_FOE}" data-ajax="zebra">
					  <strong>{L_ADD_FOE}</strong>
					  </a>
					</dd>
				<!-- ENDIF -->
			<!-- ENDIF -->
<!-- ENDIF -->
So my IDE can well-format HTML files, but recognizes comments as simple comments, so just ignores all phpbb template syntax.
My question: do you really format all subsilver(or your custom) code manually?
Is any auto reformat tool for template syntax exists?

Hoping for the best
Thank you in advance for any answer
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Auto reformat conditionals snytax

Post by david63 »

zulcom wrote: Sun Jun 10, 2018 6:08 pm Is any auto reformat tool for template syntax exists?
Never seen one - but what difference does it make? The code will still be rendered correctly.
zulcom wrote: Sun Jun 10, 2018 6:08 pm so just ignores all phpbb template syntax.
Why do you want to ignore template syntax - it is an integral part of the template.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
Lumpy Burgertushie
Registered User
Posts: 69228
Joined: Mon May 02, 2005 3:11 am

Re: Auto reformat conditionals snytax

Post by Lumpy Burgertushie »

and what is hard about reading the code in the format you posted in the first box?

I find it easier to read than the other way. at least you don't have to scroll sideways as much.


robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
zulcom
Registered User
Posts: 3
Joined: Sun Jun 10, 2018 5:46 pm

Re: Auto reformat conditionals snytax

Post by zulcom »

david63 wrote: Sun Jun 10, 2018 9:05 pm
zulcom wrote: Sun Jun 10, 2018 6:08 pm Is any auto reformat tool for template syntax exists?
Never seen one - but what difference does it make? The code will still be rendered correctly.
zulcom wrote: Sun Jun 10, 2018 6:08 pm so just ignores all phpbb template syntax.
Why do you want to ignore template syntax - it is an integral part of the template.
Sorry for my bad English, I mean that the IDE ignores the syntax of the templates, not me.
I use template syntax and each time I spend tons of time understanding unformatted code.
I'm very upset with the lack of any tools, but in any case, thanks for the answer
zulcom
Registered User
Posts: 3
Joined: Sun Jun 10, 2018 5:46 pm

Re: Auto reformat conditionals snytax

Post by zulcom »

Lumpy Burgertushie wrote: Sun Jun 10, 2018 9:54 pm and what is hard about reading the code in the format you posted in the first box?

I find it easier to read than the other way. at least you don't have to scroll sideways as much.


robert
I break lines every time when i exceed 120 symbols per line, so any screen can display all line without sideway scroll.
But when you read conditional block you need to remember all of condtitionals, where it starts and where it ends.
Besides, space formatting conditional block is industry standard of code style.
You can remove all gaps from start of every line in for example PHP code and say that is fantastic useful and human-readable,
your team can deal with it, but that means nothing when you see tears of new devepoler in your crew.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53523
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Auto reformat conditionals snytax

Post by Brf »

There are not any tools because the phpBB pages are all generated dynamically, using the data in the database. Your "tool" would have to run all of the PHP scripts to generate the page. It is simpler just to browse to it and let the phpBB code do all the work.
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs

Re: Auto reformat conditionals snytax

Post by canonknipser »

Brf, I think you're missing one part: the OP is talking about working as a style developer, adapting and changing style files.
As a developer, it is a big advantage to have proper formatted code in your editor.
For automatic code formatting, it is bad that phpBB-template syntax is written as html comments, so commands following conditionals like IF, ELSE are not indented as in "normal" code.

Maybe if the OP would switch to TWIG syntax when creating styles - TWIG is commonly used an often available as a code highlighter for editors.
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53523
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Auto reformat conditionals snytax

Post by Brf »

Ah. So all he is looking for is the highlighting and indents. I get it.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco

Re: Auto reformat conditionals snytax

Post by 3Di »

Lumpy Burgertushie wrote: Sun Jun 10, 2018 9:54 pm and what is hard about reading the code in the format you posted in the first box?
It's hard, not a good practise at all as well.
When a code becomes unreadable (coder-wise speaking) it's badly coded, also if it does what's written on the tin.
Lumpy Burgertushie wrote: Sun Jun 10, 2018 9:54 pm I find it easier to read than the other way. at least you don't have to scroll sideways as much.
Exception I can say. Also it seems to me you missed till now to use the word-wrap facility in your editor.
zulcom wrote: Mon Jun 11, 2018 3:01 am But when you read conditional block you need to remember all of condtitionals, where it starts and where it ends.
Besides, space formatting conditional block is industry standard of code style.
You can remove all gaps from start of every line in for example PHP code and say that is fantastic useful and human-readable,
your team can deal with it, but that means nothing when you see tears of new devepoler in your crew.
Correct.
canonknipser wrote: Mon Jun 11, 2018 3:53 pm As a developer, it is a big advantage to have proper formatted code in your editor.
For automatic code formatting, it is bad that phpBB-template syntax is written as html comments, so commands following conditionals like IF, ELSE are not indented as in "normal" code.

Maybe if the OP would switch to TWIG syntax when creating styles - TWIG is commonly used an often available as a code highlighter for editors.
Exactly.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs

Re: Auto reformat conditionals snytax

Post by canonknipser »

phpBB, as the name gives a hint, written in php, some parts in the html based fronted (templated files) contain small javascript snipplets. So this
zamakli wrote: Tue Jun 12, 2018 12:05 pm sonar violations in a large legacy java code-base
has nothing to do with phpBB and it's coding of template files, esp. when it comes to sonar (cube / source /...) product checks.
For your question
zamakli wrote: Tue Jun 12, 2018 12:05 pm Does anybody know of a tool that could perform a bulk operation like this?
I would recommend to look at sonar support sides
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Auto reformat conditionals snytax

Post by david63 »

Also bear in mind that phpBB templates will be moving over to Twig syntax
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here

Return to “[3.1.x] Styles Support & Discussion”