Updated all templates to use the var function instead of cgi- variables.
[gruta.git] / examples / g.pl
blob280591d2a2b7f953c7189d2f7c2bd67334c858e5
1 use Gruta;
3 use Gruta::Data;
5 use Gruta::Source::DBI;
6 use Gruta::Source::FS;
7 use Gruta::Source::Mbox;
8 use Gruta::Renderer::Grutatxt;
9 use Gruta::Renderer::HTML;
10 use Gruta::Template::Artemus;
11 use Gruta::Template::TT;
13 use Gruta::CGI;
15 my $base = '/var/www/webon';
17 my $src = Gruta::Source::DBI->new(
18 string => "dbi:SQLite:g.db",
19 user => 'coco',
20 passwd => 'caca'
23 my $src2 = Gruta::Source::FS->new(
24 path => 'var'
27 my $src3 = Gruta::Source::Mbox->new(
28 file => './url.mbox',
29 topic_id => 'links',
30 topic_name => 'Links',
31 index_file => '/tmp/url.mbox.idx'
34 my $rndr = Gruta::Renderer::Grutatxt->new();
35 my $rndr2 = Gruta::Renderer::HTML->new();
36 my $rndr3 = Gruta::Renderer::HTML->new( valid_tags => undef );
38 my $tmpl = Gruta::Template::Artemus->new(
39 path => "./templates/artemus"
42 my $tmpl2 = Gruta::Template::TT->new(
43 path => "./templates/tt"
46 my $w = Gruta->new(
47 # base => $base,
48 # upload => [ "${base}/img" ],
49 # templates => [ "${base}/templates" ],
50 sources => [ $src2, $src3 ],
51 renderers => [ $rndr, $rndr2, $rndr3 ],
52 template => $tmpl,
53 cgi => Gruta::CGI->new()
56 my $ret = $tmpl->process('{-foreach|a1,a2;b1,b2;c1,c2|[-l/STORY/%0/%1]|,}');
58 $w->login('angel', 'test');
59 $w->logout();
61 $w->template->cgi_vars( { t => 'LOGIN', topic => 'alimentos', userid => 'angel', pass => 'test' } );
63 #my $str = $w->template->process("{-story_part|alimentos|200609200001|content}");
64 #my $str = $w->template->process("{-loop_topics|_topics_as_option|\n}");
65 #$str = $w->template->process("{-story_loop_by_date|noticias|10|0|_story_link_as_item_with_hits|\n}");
66 #$str = $w->template->process("{-loop_renderers||\n}");
68 my @t = $w->tags();
69 my @sbt = $w->search_stories_by_tag('cocina de autor');
71 my $str = $w->template->process('LOGIN');
73 my @ts = $w->topics();
75 my $topic = $w->topic('pruebas');
76 my $topic2 = $w->topic('noticias');
77 my $topic3 = $w->topic('links');
79 $topic->set('editors', 'coco');
80 $topic->save( );
82 my $u = $w->user('basurilla');
84 my @ss = $w->stories_by_date( 'noticias', num => 10 );
86 @ss = $w->stories('links');
87 my $story_n = $w->story('links', $ss[0]);
88 my @t = $story_n->tags();
90 my $story = $w->story('alimentos', '200609200001');
91 my @tags = $story->tags();
92 my $v;
93 $story = $w->story('art', '200210040002');
94 $story = $w->story('art', '200210040002');
95 $story = $w->story('rec', '200209020002');
96 $v = $story->is_visible($w->auth());
97 $story = $w->story('noticias', 'a60cc163');
98 $v = $story->is_visible($w->auth());
100 $story = $w->story('pruebas', '200707250001');
102 $story = $w->story('tbl', '200202270001');
104 my $hits = $story->get('hits');
105 $story->set('hits', $hits + 1);
106 $story->save( );
108 my $story = Gruta::Data::Story->new( topic_id => 'pruebas',
109 title => 'Testing', format => 'raw_html' );
110 $w->insert_story($story);
112 @ss = $w->search_stories('noticias', 'dieta');
114 #my $data = Gruta::Data->new(
115 # sources => [
116 # Gruta::Source::DBI->new(
117 # string => "dbi:SQLite:${base}/blabla.db",
118 # user => 'coco',
119 # passwd => 'caca'
120 # ),
124 #my $src2 = Webon::Source::FS->new(
125 # path => "${base}/var"
128 my @l = $w->stories_top_ten(10);
130 $w->run();