Differences between revisions 2 and 3
Revision 2 as of 2005-08-15 03:37:49
Size: 1775
Editor: qingfeng
Comment:
Revision 3 as of 2005-08-22 16:34:52
Size: 3425
Editor: qingfeng
Comment: Hello World的加入
Deletions are marked like this. Additions are marked like this.
Line 26: Line 26:


= 教程 =
== 一切从Hello World开始 ==
clearsilver是一个高性能的模版系统,让我们看看他的使用网站,就知道他的表现有多好。
 1. Bloglines
 2. Google Groups
 3. Yahoo Groups

其他的应用请到这里http://www.clearsilver.net/examples.hdf

clearsilver由3各部分组成:hdf数据描述,cst模版文件,py逻辑处理向hdf赋值

http://www.clearsilver.net/img/misc/Clearsilver-Architecture.gif

编写hdf文件:hello.hdf
{{{
# This is my static data for Hello World (and this is a comment)

Hello = Hello World!

WeekDays {
 0 = Sunday
 1 = Monday
 2 = Tuesday
 3 = Wednesday
 4 = Thursday
 5 = Friday
 6 = Saturday
}
}}}

编写模版文件:hello.cst
{{{
<?cs var:Hello ?>
<br>

<?cs each:day = WeekDays ?>
    On <?cs var:day ?>, <?cs var:Hello ?> <br>
<?cs /each ?>

<?cs if:?Query.day ?>
    <font color="red">On <?cs var:WeekDays[Query.day] ?>, <?cs var:Hello ?> </font><br>
<?cs /if ?>

Hey <?cs var:html_escape(Query.name) ?>, <?cs var:Hello ?>
}}}
这个模版文件唯一要注意的就是'''cs if:?Query.day''',是用来处理链接参数的:cgi-bin/hello.py?day=1

模版语法详见:
http://www.clearsilver.net/docs/

然后将这两部分合二为一:
{{{#!python
#!/usr/bin/python
#
# Hello World using the ClearSilver CGI Kit and Python

import neo_cgi

# create a CGI handler context
ncgi = neo_cgi.CGI()

# parse the form data (and post upload data)
ncgi.parse()

# Load our static data
ncgi.hdf.readFile("hello.hdf")

ncgi.display("hello.cst")
}}}

P.S:
测试环境winXP+IIS5(懒得装apache了)

::-- qingfeng [DateTime(2005-08-15T03:37:14Z)] TableOfContents

1. 什么是ClearSilver

  • Clearsilver is a fast, powerful, and language-neutral HTML template system. In both static content sites and dynamic HTML applications, it provides a separation between presentation code and application logic which makes working with your project easier. The design of Clearsilver began in 1999, and evolved during its use at onelist.com, egroups.com, and Yahoo! Groups. Today many other projects and websites using it.

2. 为什么使用ClearSilver

  • High Performance and Language Neutral. Because Clearsilver is written as a C-library, and exported to scripting languages like Python, Perl, Java and Ruby via modules, it is extremely fast. This also means you can work with the same template system independent of the language your project is in.

    Pluggable Look and Feel. Clearsilver makes it easy to face lift a site by providing a new set of templates. It is possible to easily run more than one look and feel at once, and share components with a base look and feel to reduce maintenance.

    Internationalization Support. Clearsilver makes it trivial to support internationlization. You write your templates in your native language and included tools automatically extract and catalog language strings for translation.

    Advanced features. Built in support for advanced features such as gzip compression, smart whitespace stripping, parametric macros, online debugging mode, url and javascript string escaping, and more.

3. 文档

http://www.clearsilver.net/docs/

4. 下载

http://www.clearsilver.net/downloads/

5. 教程

5.1. 一切从Hello World开始

clearsilver是一个高性能的模版系统,让我们看看他的使用网站,就知道他的表现有多好。

  1. Bloglines
  2. Google Groups
  3. Yahoo Groups

其他的应用请到这里http://www.clearsilver.net/examples.hdf

clearsilver由3各部分组成:hdf数据描述,cst模版文件,py逻辑处理向hdf赋值

http://www.clearsilver.net/img/misc/Clearsilver-Architecture.gif

编写hdf文件:hello.hdf

# This is my static data for Hello World (and this is a comment)

Hello = Hello World!

WeekDays {
        0 = Sunday
        1 = Monday
        2 = Tuesday
        3 = Wednesday
        4 = Thursday
        5 = Friday
        6 = Saturday
}

编写模版文件:hello.cst

<?cs var:Hello ?>
<br>

<?cs each:day = WeekDays ?>
    On <?cs var:day ?>, <?cs var:Hello ?> <br>
<?cs /each ?>

<?cs if:?Query.day ?>
    <font color="red">On <?cs var:WeekDays[Query.day] ?>, <?cs var:Hello ?> </font><br>
<?cs /if ?>

Hey <?cs var:html_escape(Query.name) ?>, <?cs var:Hello ?>

这个模版文件唯一要注意的就是cs if:?Query.day,是用来处理链接参数的:cgi-bin/hello.py?day=1

模版语法详见: http://www.clearsilver.net/docs/

然后将这两部分合二为一:

   1 #!/usr/bin/python
   2 #
   3 # Hello World using the ClearSilver CGI Kit and Python
   4 
   5 import neo_cgi
   6 
   7 # create a CGI handler context
   8 ncgi = neo_cgi.CGI() 
   9 
  10 # parse the form data (and post upload data)
  11 ncgi.parse()
  12 
  13 # Load our static data
  14 ncgi.hdf.readFile("hello.hdf")
  15 
  16 ncgi.display("hello.cst") 

P.S: 测试环境winXP+IIS5(懒得装apache了)

ClearSilver (last edited 2009-12-25 07:09:36 by localhost)