当前位置: 首页 > 工具软件 > cl-who > 使用案例 >

类似于html的语言,其他语言的类似CL-WHO的HTML模板?

宋伯寅
2023-12-01

draegtun..

12

对于CPAN产品,请查看以下内容(按字母顺序排列)......

使用CL-WHO示例提供的表格部分(减去罗马数字和s /背景颜色/颜色/将代码压缩到屏幕宽度!)....

生成器

use Builder;

my $builder = Builder->new;

my $h = $builder->block( 'Builder::XML' );

$h->table( { border => 0, cellpadding => 4 }, sub {

for ( my $i = 1; $i < 25; $i += 5 ) {

$h->tr( { align => 'right' }, sub {

for my $j (0..4) {

$h->td( { color => $j % 2 ? 'pink' : 'green' }, $i + $j );

}

});

}

});

say $builder->render;

HTML :: AsSubs

use HTML::AsSubs;

my $td = sub {

my $i = shift;

return map {

td( { color => $_ % 2 ? 'pink' : 'green' }, $i + $_ )

} 0..4;

};

say table( { border => 0, cellpadding => 4 },

map {

&tr( { align => 'right' }, $td->( $_ ) )

} loop( below => 25, by => 5 )

)->as_HTML;

HTML ::微小

use HTML::Tiny;

my $h = HTML::Tiny->new;

my $td = sub {

my $i = shift;

return map {

$h->td( { 'color' => $_ % 2 ? 'pink' : 'green' }, $i + $_ )

} 0..4;

};

say $h->table(

{ border => 0, cellpadding => 4 },

[

map {

$h->tr( { align => 'right' }, [ $td->( $_ ) ] )

} loop( below => 25, by => 5 )

]

);

Markapl

use Markapl;

template 'MyTable' => sub {

table ( border => 0, cellpadding => 4 ) {

for ( my $i = 1; $i < 25; $i += 5 ) {

row ( align => 'right' ) {

for my $j ( 0.. 4 ) {

td ( color => $j % 2 ? 'pink' : 'green' ) { $i + $j }

}

}

}

}

};

print main->render( 'MyTable' );

模板::声明

package MyTemplates;

use Template::Declare::Tags;

use base 'Template::Declare';

template 'MyTable' => sub {

table {

attr { border => 0, cellpadding => 4 };

for ( my $i = 1; $i < 25; $i += 5 ) {

row {

attr { align => 'right' };

for my $j ( 0..4 ) {

cell {

attr { color => $j % 2 ? 'pink' : 'green' }

outs $i + $j;

}

}

}

}

}

};

package main;

use Template::Declare;

Template::Declare->init( roots => ['MyTemplates'] );

print Template::Declare->show( 'MyTable' );

XML ::发电机

use XML::Generator;

my $x = XML::Generator->new( pretty => 2 );

my $td = sub {

my $i = shift;

return map {

$x->td( { 'color' => $_ % 2 ? 'pink' : 'green' }, $i + $_ )

} 0..4;

};

say $x->table(

{ border => 0, cellpadding => 4 },

map {

$x->tr( { align => 'right' }, $td->( $_ ) )

} loop( below => 25, by => 5 )

);

以下内容可用于在HTML :: AsSubs/HTML :: Tiny/XML :: Generator示例中生成"循环"....

sub loop {

my ( %p ) = @_;

my @list;

for ( my $i = $p{start} || 1; $i < $p{below}; $i += $p{by} ) {

push @list, $i;

}

return @list;

}

 类似资料: