Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[mowyw] introduced [% ... %] as tag delimiter

git-svn-id: svn+ssh://faui2k3.org/var/lib/svn/moritz/mowyw@579 addfbb1e-f4f9-0310-b6f0-bccd0f9b8dc6
  • Loading branch information...
commit 519560800f601b3a1622f2e1290eeb0d53be4971 1 parent 9564f19
moritz authored
6 Changelog
... ... @@ -1,3 +1,9 @@
  1 +mowyw (0.4.0)
  2 + * mowyw: Added support for new delimiters: [% ... %] instead of [[[
  3 + ... ]]]. Currently they are interchangable, so [% .. ]]] works, but
  4 + this is considered a bug rather than a feature.
  5 + * README: update accordingly
  6 + * example/source/foo2.shtml: added example [% ... %] tags
1 7 mowyw (0.3.0)
2 8 * mowyw: Added support for syntax highliting, variables and comments
3 9 * README: update accordingly
6 README
@@ -81,11 +81,17 @@ Just use the line
81 81
82 82 [[[include foo]]]
83 83
  84 +or
  85 +
  86 +[% include foo %]
  87 +
84 88 in your files, and the line will be replaced with the content of the file
85 89 `includes/foo'. It works pretty much like #inlcude "includes/foo" with a C pre
86 90 processor or <!-- #include virtual="includes/foo"--> with Server Side Includes
87 91 (SSI).
88 92
  93 +Note that everywhere the [[[ ... ]]] delimiters can be exchanged by [% .. %].
  94 +
89 95 MENUS:
90 96
91 97 Suppose you want to write a navigation menu in your html files that look like
6 example/source/foo2.shtml
... ... @@ -1,10 +1,14 @@
1 1 <title>Mowyw example: page foo1</title>
2   -[[[include head2]]]
  2 +[% include head2 %]
3 3
4 4 <h2>foo2 is another sub item of foo</h2>
5 5
6 6 <p>And now I'm running out of ideas what to write</p>
7 7
  8 +<p>New style markup (if you don't see anything it means all works fine):
  9 + [% setvar mytest <p>All worked fine!</p> %]</p>
  10 +[% readvar mytest %]
  11 +
8 12 </div>
9 13
10 14 [[[menu nav foo foo2]]]
29 mowyw
@@ -65,8 +65,10 @@ my $result = GetOptions(
65 65
66 66 my @input_tokens = (
67 67 [ 'TAG_START', qr/\[\[\[\s*/],
68   - [ 'KEYWORD', qr/(?:include|menu|option|item|endverbatim|verbatim|comment|setvar|readvar|syntax|endsyntax)/],
  68 + [ 'TAG_START', qr/\[\%\s*/],
  69 + [ 'KEYWORD', qr/(?:include|menu|option|item|endverbatim|verbatim|comment|setvar|readvar|synatxfile|syntax|endsyntax)/],
69 70 [ 'TAG_END', qr/\s*\]\]\]/],
  71 + [ 'TAG_END', qr/\s*\%\]/],
70 72 [ 'BRACES_START', qr/{{/],
71 73 [ 'BRACES_END', qr/}}/],
72 74 );
@@ -204,6 +206,7 @@ sub parse_tokens {
204 206 if ($tokens->[0]->[0] eq "TAG_START"){
205 207 p_expect($tokens, "TAG_START", $meta);
206 208 my $key = p_expect($tokens, 'KEYWORD', $meta);
  209 +# warn "Found keyword $key\n";
207 210 my %dispatch = (
208 211 include => \&p_include,
209 212 menu => \&p_menu,
@@ -220,7 +223,8 @@ sub parse_tokens {
220 223 setvar => \&p_setvar,
221 224 readvar => \&p_readvar,
222 225 syntax => \&p_syntax,
223   - endvsyntax => sub {
  226 + syntaxfile => \&p_syntaxfile,
  227 + endsyntax => sub {
224 228 # p_syntax reads until it finds endsyntax, so it
225 229 # may never occur here
226 230 my ($tokens, $meta) = @_;
@@ -284,6 +288,7 @@ sub p_include {
284 288 # a keyword as well as file name
285 289 if ($tokens->[0]->[0] eq "UNMATCHED" or $tokens->[0]->[0] eq "KEYWORD"){
286 290 my $fn = strip_ws($tokens->[0]->[1]);
  291 +# warn "Including file $fn\n";
287 292 $fn = $includes_prefix . $fn . $postfix;
288 293 shift @$tokens;
289 294 p_expect($tokens, "TAG_END", $meta);
@@ -292,7 +297,7 @@ sub p_include {
292 297 unshift @{$m->{FILES}}, $fn;
293 298 return parse_file($fn, $m);
294 299 } else {
295   - cloak("Expected: File name. Got: $tokens->[0]->[1]");
  300 + confess("Expected: File name. Got: $tokens->[0]->[1]");
296 301 }
297 302 }
298 303
@@ -446,6 +451,19 @@ sub p_readvar {
446 451 }
447 452 }
448 453
  454 +sub p_syntaxfile {
  455 + my $tokens = shift;
  456 + my $meta = shift;
  457 + my $tag_content = shift @$tokens;
  458 + $tag_content = strip_ws($tag_content->[1]);
  459 + p_expect($tokens, "TAG_END", $meta);
  460 + my @t = split m/\s+/, $tag_content;
  461 + if (scalar @t != 2){
  462 + parse_error("Usage of syntaxfile tag: [[[syntaxfile <filename> <language>", @{$meta->{FILES}});
  463 + }
  464 +
  465 +}
  466 +
449 467 sub p_syntax {
450 468 my $tokens = shift;
451 469 my $meta = shift;
@@ -461,6 +479,11 @@ sub p_syntax {
461 479 p_expect($tokens, "KEYWORD", $meta);
462 480 p_expect($tokens, "TAG_END", $meta);
463 481
  482 + return do_hilight($str, $lang);
  483 +}
  484 +
  485 +sub do_hilight {
  486 + my ($str, $lang) = @_;
464 487 eval {
465 488 no warnings "all";
466 489 require Text::VimColor;

0 comments on commit 5195608

Please sign in to comment.
Something went wrong with that request. Please try again.