source\lib\gtpublisher\styles\s-sources\default.g
1 /******************************************************************************
2 *
3 * Copyright (C) 2006, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * ID: default 17.11.06 0.0.A.
11 *
12 * Author: Alexey Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15
16 global
17 {
18 str srcdir
19 uint srcgti prevsrc
20 }
21
22 method str str.srcurl( gtitem gti, uint mode )
23 {
24 uint dir
25 str filename srcout aname
26
27 gti.getsubitem( "src", srcout )
28 aname.fnameext( srcout )
29 dir = getfileattrib( srcout ) & $FILE_ATTRIBUTE_DIRECTORY
30 if dir : filename = "\(gti.name)\\index.htm"
31 else : filename = "\(gti.name).htm"
32
33 srcout.fgetdir( srcout ).del( 0, *srcdir )
34
35 switch mode
36 {
37 case 0
38 {
39 aname.replacech( srcout, '.', "_" )
40 this = "\(_gtp.output )\\source\( aname )\\\(filename)"
41 }
42 case 1 // url
43 {
44 if gti.find( "level" )
45 {
46 aname.replacech( srcout, '.', "_" )
47 this.replacech( "/source\( aname )/\(filename)", '\', "/" )
48 }
49 else : this = "/source/index.htm"
50 }
51 case 2 // url name
52 {
53 if dir
54 {
55 aname.fgetdir( filename ).upper()
56 this.replacech( aname, '_', "." )
57 }
58 else : this = aname
59 }
60 case 3 // src title
61 {
62 _gtp.prj.get("project/name", aname )
63 if gti.find( "level" )
64 {
65 gti.getsubitem( "src", srcout )
66 srcout.del( 0, *srcdir )
67 if dir : srcout.appendch('\')
68 }
69 else : gti.getsubitem( "title", srcout )
70 this = "\( aname ): \( srcout )"
71 }
72 case 4 // src
73 {
74 if gti.find( "level" )
75 {
76 gti.getsubitem( "src", this )
77 this.del( 0, *srcdir )
78 // if dir : this.appendch('\')
79 }
80 else : this.clear()
81 }
82 }
83 return this
84 }
85
86 text grainsrc( gtitem gti )
87 \{
88 if !gti.find( "level" ) : return
89
90 }<div class="box subsrc">\{
91 arrstr st
92 str url
93 int i
94
95 url.srcurl( gti, 4 )
96 do
97 {
98 str stemp
99
100 stemp.fnameext( url )
101 url.fgetdir( url )
102 st += stemp
103 } while *url
104
105 @"<span><a href = \"/source/index.htm\">source</a>"
106 url = "/source"
107
108 for i = *st - 1, i >= 0, i--
109 {
110 @"<span class=\"orange\">\\</span>"
111 url += "/\(st[i])"
112 if !i : @"\( st[i] )"
113 else : @"<a href = \"\(url)/index.htm\">\( st[i] )</a>"
114 }
115 @"</span>"
116
117 }</div>
118 \!
119
120
121 func loadsources( gt gtdir, str dirname )
122 {
123 arrstr dirs
124 arrstr files
125 ffind fd
126
127 // print("dir=\(dirname)\n")
128 fd.init( "\(dirname)\\*.*", $FIND_FILE | $FIND_DIR )
129 foreach curfile, fd
130 {
131 curfile as finfo
132
133 if !( curfile.attrib & $FILE_ATTRIBUTE_ARCHIVE ) : continue
134 if curfile.attrib & $FILE_ATTRIBUTE_DIRECTORY : dirs += curfile.name
135 else : files += curfile.name
136 // print( "Found = \( curfile.name )\n")
137 }
138 dirs.sort( 0 )
139 files.sort( 0 )
140 foreach curf, files : dirs += curf
141
142 foreach cur, dirs
143 {
144 str name ext dir
145 uint nofile
146
147 // print( "Files = \(cur)\n")
148 ext = cur.fgetext()
149 if direxist( "\(dirname)\\\(cur)" )
150 {
151 dir = "dir"
152 }
153 elif ext %!= "g" && ext %!= "gt" && ext %!= "c" && ext %!= "h" && *ext
154 {
155 nofile = 1
156 }
157 if ext %== "ncb" || ext %== "plg" || ext %== "opt" : continue
158
159 name.replacech( cur, '.', "_" )
160 gtdir += "<\( name ) style = S level = 1 \( ?( nofile, "nofile", "" )) \(dir)>
161 <src = \"\(dirname)\\\(cur)\" />
162 <content ></>
163 </>"
164 }
165 }
166
167 text srcdirout( gtitem gti, gt gtdir )
168 \{
169 arrstr aout[1]
170 str date cont
171
172 gti.getsubitem( "content", cont )
173 if *cont : @"<p>\(cont)</p>"
174 _gtp.get( "lng/srchead", aout[0] )
175 _gtp.get( "lng/date", date )
176 aout[0] += "\l"
177 // aout += "Filename|Size|Date|Description\l"
178 foreach curgti, gtdir.root()
179 {
180 str sout src
181 str link atext
182 finfo fi
183
184 curgti as gtitem
185 atext.srcurl( curgti, 2 )
186 link.srcurl( curgti, 1 )
187 if curgti.find( "nofile" )
188 {
189 sout = "\( atext )"
190 }
191 else : sout = "<a href = \"\( link )\">\( atext )</a><br>"
192 curgti.getsubitem( "src", src )
193 if curgti.find("dir")
194 {
195 sout += "| | | \l"
196 }
197 else
198 {
199 datetime dt
200
201 getfileinfo( src, fi )
202 ftimetodatetime( fi.lastwrite, dt, 0)
203 getdateformat( dt, date, atext )
204 // getfiledatetime( fi.lastwrite, atext, 0->str )
205 sout += "|\(fi.sizelo)|\(atext)| \l"
206 }
207 aout[0] += sout
208 }
209 @tbllines( aout )
210 }\!
211
212 text anchors( str in )
213 \{
214 spattern pattern
215 uint off newoff
216
217 pattern.init( "\02A Id: ", 0 )
218 if ( newoff = pattern.search( in, off )) < *in
219 {
220 do
221 {
222 uint end
223 str name
224
225 this.append( in.ptr() + off, newoff - off + 1 )
226 end = newoff + 6 // must be '\02A Id: <name>'
227 while in[end] > ' ' : end++
228 name.substr( in, newoff + 6, end - newoff - 6 )
229 this@"<a name=\"\(name)\"></a>"
230 off = newoff + 1
231 newoff = pattern.search( in, off )
232 } while newoff < *in
233 this.append( in.ptr() + off - 1, *in - off + 1 )
234 }
235 else : @in
236 }\!
237
238 text srcfile( gtitem gti )
239 <pre><code>\{
240 uint flag
241 str src in out ext
242
243 gti.getsubitem( "src", src )
244 ext = src.fgetext()
245 switch ext
246 {
247 case "c", "h" : flag = $S2H_C
248 default : flag = $S2H_GENTEE
249 }
250 in.read( src )
251 out@src2html( in, flag | $S2H_UTF8 | $S2H_LINES )
252 @anchors( out )
253 }</code></pre>\!
254
255 text navsrc( gt gtdir, gtitem curgti )
256 <div class="left-menu">
257 <div class="lvl l1"><p> <a href="\(
258 ?( curgti.find("dir"), "../index.htm", "index.htm" ))">..</a></p></div>\{
259 foreach gti, gtdir.root()
260 {
261 str name
262 gti as gtitem
263
264 name.srcurl( gti, 2 )
265 if gti.name %== curgti.name
266 {
267 @"<div class=\"lvl l1 act\"><p class=\"act\"> \( name )</p></div>"
268 }
269 else
270 {
271 if !gti.find("nofile")
272 {
273 str link
274
275 link.srcurl( gti, 1 )
276 name = "<a href=\"\(link)\">\( name )</a>"
277 }
278 @"<div class=\"lvl l1\"><p> \( name )</p></div>"
279 }
280 }
281 }</div>\!
282
283
284 text S_default( gtitem gti )
285 \{
286 gt gtdir
287 uint attrib
288 str src url ed
289 str desc title lang prjname
290
291 _gtp.get( "lng/edit", ed )
292
293 gti.getsubitem( "src", src )
294 if !*srcdir
295 {
296 srcgti = >i
297 srcdir = src
298 }
299
300 attrib = getfileattrib( src )
301 if attrib & $FILE_ATTRIBUTE_DIRECTORY
302 {
303 uint oldgt = prevsrc
304 loadsources( gtdir, src )
305 attrib = 1
306 prevsrc = >dir
307 foreach fgti, gtdir.root()
308 {
309 str out filename
310
311 fgti as gtitem
312
313 if fgti.find("nofile") : continue
314
315 out@S_default( fgti )
316
317 filename.srcurl( fgti, 0 )
318
319 if fileupdate( filename, out )
320 {
321 print("Processing \(fgti.name) => \(filename)\n")
322 }
323 }
324 prevsrc = oldgt
325 }
326 else : attrib = 0
327 _gtp.prj.get("project/lang", lang )
328 _gtp.prj.get("project/name", prjname )
329
330 /* gti.getsubitem( "desc", desc )
331 if !*desc : desc = "#/title#"
332
333 gti.getsubitem( "keywords", keys )
334 if !*keys : keys = "#/title#"
335 */
336 title.srcurl( gti, 3 )
337 url.srcurl( gti, 1 )
338
339 }<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>
340 <head>
341 <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
342 <!--meta http-equiv="Content-Language" content="\( lang )"-->
343 <meta NAME="DESCRIPTION" CONTENT="\( desc )">
344 <link rel="icon" href="/favicon.ico" type="image/x-icon">
345 <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
346 <link rel="stylesheet" type="text/css" href="/css/default/styles.css">
347 <script language="JavaScript1.2" src="/css/ddnmenu.js" type="text/javascript"></script>
348 <title>\( title )</title></head>
349 <body>
350 \@header( srcgti->gtitem, url )
351
352 <div id="center" >
353 <div class="left-column">
354 \{
355 if gti.find( "level" ) : @navsrc( prevsrc->gt, gti )
356 }
357 <!--#include virtual="/adv.php" -->
358 </div>
359 <div class="content">
360 \{
361 @grainsrc( gti )
362 }
363 <div class="box"><!--EDIT-->\{
364 if attrib : @srcdirout( gti, gtdir )
365 else : @srcfile( gti )
366 }<!--EDIT-->
367 </div>
368 <a href="/admin/edit.phtml?url=\(url)">\(ed)</a>
369 </div>
370 <br style="clear:left">
371 </div>
372
373 <!--#include virtual="/footer.html" -->
374 </body></html>
375 \!
376
377