Parse .tt2 files as HTML #19

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@guillaumeaubert

.tt2 is the extension commonly used for Template Toolkit v2 files. While you can generate any type of file based off TT2 template files, the most common use appears to be generating HTML files and as such, I think it makes sense to parse them as HTML.

I used my project as a test case: https://www.ohloh.net/p/perl-audit-dbi

Here's the output of ohcount before the change:

                          Ohloh Line Count Summary

Language          Files       Code    Comment  Comment %      Blank      Total
----------------  -----  ---------  ---------  ---------  ---------  ---------
javascript            5       1894        391      17.1%        107       2392
perl                 22       1400        575      29.1%        643       2618
css                   4        360          4       1.1%          7        371
----------------  -----  ---------  ---------  ---------  ---------  ---------
Total                31       3654        970      21.0%        757       5381

And here's the output of ohcount after the change in the attached commit:

                          Ohloh Line Count Summary

Language          Files       Code    Comment  Comment %      Blank      Total
----------------  -----  ---------  ---------  ---------  ---------  ---------
javascript            5       1894        391      17.1%        107       2392
perl                 22       1400        575      29.1%        643       2618
css                   6        363          4       1.1%          7        374
html                  3        234          7       2.9%         21        262
----------------  -----  ---------  ---------  ---------  ---------  ---------
Total                36       3891        977      20.1%        778       5646
@amujumdar

Can tt2 file include Perl code, conditions? What I am trying figure out if it should be counted as its own language, HTML or Perl.

@guillaumeaubert

Dear Abhay,

My apologies for the delayed reply, thank you for taking a look at my pull request and for the improvements the Ohloh team has been making to ohcount.

TT2 templates can evaluate Perl code, with the "| eval" filter, but I believe that including Perl code inside TT2 files is extremely rare as it breaks the separation of code and formatting (which is what draws people to TT2 in the first place).

TT2 however has its own formatting language, with conditions, loops, filters, etc. Here is an example:

[% IF some_array.size() != 0 %]
    <ul>
        [% FOREACH element IN some_array %]
            <li>[% element | html %]</li>
        [% END %]
    </ul>
[% END %]

I would definitely not count TT2 files under Perl, however you will have to decide if you prefer to:

  • create a new language for TT2;
  • create a specific parser for ".tt2" files to determine their content line by line;
  • pass them through the HTML parser (since generating HTML is AFAIK the most common use case and TT2-specific lines are typically not the bulk of the file).

Please let me know if you have any questions, I'm certainly happy to clarify further.

Best,

Guillaume

@amujumdar amujumdar closed this Dec 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment