| 1 | package QuadPres::VimIface; | ||
| 2 | $QuadPres::VimIface::VERSION = '0.28.4'; | ||
| 3 | 1 | ▶ | use 5.016; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use autodie; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use Text::VimColor (); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | use Path::Tiny qw/ path /; | ||
| 10 | |||
| 11 | sub _is_newer | ||
| 12 | { | ||
| 13 | my $file1 = shift; | ||
| 14 | my $file2 = shift; | ||
| 15 | my @stat1 = stat($file1); | ||
| 16 | my @stat2 = stat($file2); | ||
| 17 | if ( !@stat2 ) | ||
| 18 | { | ||
| 19 | return 1; | ||
| 20 | } | ||
| 21 | return ( $stat1[9] >= $stat2[9] ); | ||
| 22 | } | ||
| 23 | |||
| 24 | sub get_syntax_highlighted_html_from_file | ||
| 25 | { | ||
| 26 | my ($args) = @_; | ||
| 27 | |||
| 28 | my $filename = $args->{'filename'}; | ||
| 29 | |||
| 30 | my $html_filename = "$filename.html-for-quad-pres"; | ||
| 31 | |||
| 32 | if ( _is_newer( $filename, $html_filename ) ) | ||
| 33 | { | ||
| 34 | my $syntax = Text::VimColor->new( | ||
| 35 | file => $filename, | ||
| 36 | html_full_page => 1, | ||
| 37 | ( $args->{'filetype'} ? ( filetype => $args->{'filetype'} ) : () ), | ||
| 38 | ); | ||
| 39 | |||
| 40 | path($html_filename) | ||
| 41 | ->spew( $syntax->html =~ s#(<meta[^/>]+[^/])>#$1/>#gr ); | ||
| 42 | } | ||
| 43 | |||
| 44 | my $text = path($html_filename)->slurp; | ||
| 45 | |||
| 46 | $text =~ s{\A.*<pre>[\s\n\r]*}{}s; | ||
| 47 | $text =~ s{[\s\n\r]*</pre>.*\z}{}s; | ||
| 48 | $text =~ s{(class=")syn}{$1}g; | ||
| 49 | |||
| 50 | return $text; | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; | ||
| 54 | |||
| 55 | __END__ | ||
| 56 | |||
| 57 | =pod | ||
| 58 | |||
| 59 | =encoding UTF-8 | ||
| 60 | |||
| 61 | =head1 NAME | ||
| 62 | |||
| 63 | QuadPres::VimIface - Vim syntax highlighting interface. | ||
| 64 | |||
| 65 | =head1 VERSION | ||
| 66 | |||
| 67 | version 0.28.4 | ||
| 68 | |||
| 69 | =head1 SYNOPSIS | ||
| 70 | |||
| 71 | use QuadPres::VimIface (); | ||
| 72 | my $code = QuadPres::VimIface::get_syntax_highlighted_html_from_file({filename=>"foo.pl"}); | ||
| 73 | |||
| 74 | =head1 DESCRIPTION | ||
| 75 | |||
| 76 | Vim syntax highlighting interface. | ||
| 77 | |||
| 78 | =head1 FUNCTIONS | ||
| 79 | |||
| 80 | =head2 get_syntax_highlighted_html_from_file({filename=>$filepath, filetype=>"c",}); | ||
| 81 | |||
| 82 | TBD. | ||
| 83 | |||
| 84 | =head2 | ||
| 85 | |||
| 86 | =head1 COPYRIGHT & LICENSE | ||
| 87 | |||
| 88 | Copyright 2018 by Shlomi Fish | ||
| 89 | |||
| 90 | This program is distributed under the MIT / Expat License: | ||
| 91 | L<http://www.opensource.org/licenses/mit-license.php> | ||
| 92 | |||
| 93 | Permission is hereby granted, free of charge, to any person | ||
| 94 | obtaining a copy of this software and associated documentation | ||
| 95 | files (the "Software"), to deal in the Software without | ||
| 96 | restriction, including without limitation the rights to use, | ||
| 97 | copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 98 | copies of the Software, and to permit persons to whom the | ||
| 99 | Software is furnished to do so, subject to the following | ||
| 100 | conditions: | ||
| 101 | |||
| 102 | The above copyright notice and this permission notice shall be | ||
| 103 | included in all copies or substantial portions of the Software. | ||
| 104 | |||
| 105 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 106 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
| 107 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| 108 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
| 109 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| 110 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 111 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| 112 | OTHER DEALINGS IN THE SOFTWARE. | ||
| 113 | |||
| 114 | =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan | ||
| 115 | |||
| 116 | =head1 SUPPORT | ||
| 117 | |||
| 118 | =head2 Websites | ||
| 119 | |||
| 120 | The following websites have more information about this module, and may be of help to you. As always, | ||
| 121 | in addition to those websites please use your favorite search engine to discover more resources. | ||
| 122 | |||
| 123 | =over 4 | ||
| 124 | |||
| 125 | =item * | ||
| 126 | |||
| 127 | MetaCPAN | ||
| 128 | |||
| 129 | A modern, open-source CPAN search engine, useful to view POD in HTML format. | ||
| 130 | |||
| 131 | L<https://metacpan.org/release/QuadPres> | ||
| 132 | |||
| 133 | =item * | ||
| 134 | |||
| 135 | RT: CPAN's Bug Tracker | ||
| 136 | |||
| 137 | The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN. | ||
| 138 | |||
| 139 | L<https://rt.cpan.org/Public/Dist/Display.html?Name=QuadPres> | ||
| 140 | |||
| 141 | =item * | ||
| 142 | |||
| 143 | CPANTS | ||
| 144 | |||
| 145 | The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution. | ||
| 146 | |||
| 147 | L<http://cpants.cpanauthors.org/dist/QuadPres> | ||
| 148 | |||
| 149 | =item * | ||
| 150 | |||
| 151 | CPAN Testers | ||
| 152 | |||
| 153 | The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions. | ||
| 154 | |||
| 155 | L<http://www.cpantesters.org/distro/Q/QuadPres> | ||
| 156 | |||
| 157 | =item * | ||
| 158 | |||
| 159 | CPAN Testers Matrix | ||
| 160 | |||
| 161 | The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. | ||
| 162 | |||
| 163 | L<http://matrix.cpantesters.org/?dist=QuadPres> | ||
| 164 | |||
| 165 | =item * | ||
| 166 | |||
| 167 | CPAN Testers Dependencies | ||
| 168 | |||
| 169 | The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. | ||
| 170 | |||
| 171 | L<http://deps.cpantesters.org/?module=QuadPres> | ||
| 172 | |||
| 173 | =back | ||
| 174 | |||
| 175 | =head2 Bugs / Feature Requests | ||
| 176 | |||
| 177 | Please report any bugs or feature requests by email to C<bug-quadpres at rt.cpan.org>, or through | ||
| 178 | the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=QuadPres>. You will be automatically notified of any | ||
| 179 | progress on the request by the system. | ||
| 180 | |||
| 181 | =head2 Source Code | ||
| 182 | |||
| 183 | The code is open to the world, and available for you to hack on. Please feel free to browse it and play | ||
| 184 | with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull | ||
| 185 | from your repository :) | ||
| 186 | |||
| 187 | L<https://github.com/shlomif/quad-pres> | ||
| 188 | |||
| 189 | git clone https://github.com/shlomif/quad-pres.git | ||
| 190 | |||
| 191 | =head1 AUTHOR | ||
| 192 | |||
| 193 | Shlomi Fish <shlomif@cpan.org> | ||
| 194 | |||
| 195 | =head1 BUGS | ||
| 196 | |||
| 197 | Please report any bugs or feature requests on the bugtracker website | ||
| 198 | L<https://github.com/shlomif/quad-pres/issues> | ||
| 199 | |||
| 200 | When submitting a bug or request, please include a test-file or a | ||
| 201 | patch to an existing test-file that illustrates the bug or desired | ||
| 202 | feature. | ||
| 203 | |||
| 204 | =head1 COPYRIGHT AND LICENSE | ||
| 205 | |||
| 206 | This software is Copyright (c) 2019 by Shlomi Fish. | ||
| 207 | |||
| 208 | This is free software, licensed under: | ||
| 209 | |||
| 210 | The MIT (X11) License | ||
| 211 | |||
| 212 | =cut | ||