|
| 1 | +package Local::VimColor; |
| 2 | + |
| 3 | +use strict; |
| 4 | +use warnings; |
| 5 | + |
| 6 | +use File::Spec; |
| 7 | +use Text::VimColor; |
| 8 | + |
| 9 | +{ |
| 10 | + package TrueHash; |
| 11 | + use base 'Tie::StdHash'; |
| 12 | + sub EXISTS { return 1 }; |
| 13 | +} |
| 14 | +tie %Text::VimColor::SYNTAX_TYPE, 'TrueHash'; |
| 15 | + |
| 16 | +sub new { |
| 17 | + my ( $class, %params ) = @_; |
| 18 | + |
| 19 | + my $lang = $params{'language'}; |
| 20 | + |
| 21 | + my $syntax_file = File::Spec->catfile('syntax', "$lang.vim"); |
| 22 | + my $ftplugin_file = File::Spec->catfile('ftplugin', "$lang.vim"); |
| 23 | + # XXX ??? |
| 24 | + my $css_url = join('/', '..', '..', 't', 'vim_syntax.css'); |
| 25 | + my $color_file = File::Spec->catfile('t', 'define_all.vim'); |
| 26 | + |
| 27 | + my $hilite = Text::VimColor->new( |
| 28 | + html_full_page => 1, |
| 29 | + html_inline_stylesheet => 0, |
| 30 | + html_stylesheet_url => $css_url, |
| 31 | + vim_options => [ |
| 32 | + qw(-RXZ -i NONE -u NONE -U NONE -N -n), # for performance |
| 33 | + '+set nomodeline', # for performance |
| 34 | + '+set runtimepath=.', # don't consider system runtime files |
| 35 | + '+let perl_include_pod=1', |
| 36 | + "+source $ftplugin_file", |
| 37 | + "+source $syntax_file", |
| 38 | + "+source $color_file", # all syntax classes should be defined |
| 39 | + ], |
| 40 | + ); |
| 41 | + |
| 42 | + return bless { |
| 43 | + hilite => $hilite, |
| 44 | + }, $class; |
| 45 | +} |
| 46 | + |
| 47 | +sub color_file { |
| 48 | + my ( $self, $filename ) = @_; |
| 49 | + |
| 50 | + return $self->{'hilite'}->syntax_mark_file($filename)->html; |
| 51 | +} |
| 52 | + |
| 53 | +1; |
0 commit comments