source\lib\gtpublisher\gtpublisher.g
1 /******************************************************************************
2 *
3 * Copyright (C) 2007, 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: gtpublisher 23.03.07 0.0.A.
11 *
12 * Author: Alexey Krivonogov ( gentee )
13 *
14 * Summary: Библиотека для вывода информации в различные форматы документов
15 *
16 ******************************************************************************/
17
18 include
19 {
20 $"..\stdlib\stdlib.g"
21 $"..\gt\gt.g"
22 $"..\thread\thread.g"
23 "utils.g"
24 }
25
26 type gtpub< inherit = gt >
27 {
28 gt prj // Настройки проекта
29 // gt data // Данные в виде gt дерева
30 // hash alias // hash of gtitem objects
31 str output
32 str root
33 str ext
34 str lang
35 }
36
37 global
38 {
39 gtpub _gtp
40 str style
41 }
42
43 /*
44 Стили style
45 С - Копирование файлов по списку
46 T - Вывод текста как есть
47 W - вывод для web-сайта
48 */
49
50 method str gtpub.getfilename( gtitem gti, str ret )
51 {
52 str stemp
53
54 ret = .output
55
56 gti.get( "path", stemp )
57 ret.faddname( stemp )
58 gti.get( "filename", stemp )
59 this.process( stemp )
60 ret.faddname( stemp )
61 if gti.find( "ext" ) : gti.get( "ext", stemp )
62 else : stemp = .ext
63 ret.fsetext( ret, stemp )
64
65 return ret
66 }
67
68 method str gtpub.geturlname( str name ret )
69 {
70 uint mgti
71
72 ret.clear()
73 mgti as _gtp.find( name )
74 if !&mgti : return ret
75
76 mgti.getsubitem( "urlname", ret )
77 if !*ret : mgti.getsubitem( "title", ret )
78 return ret
79 }
80
81
82 method str gtpub.geturl( gtitem gti, str ret )
83 {
84 gti.getsubitem( "url", ret )
85
86 if !*ret
87 {
88 str stemp
89
90 this.getfilename( gti, stemp )
91 stemp.replace( 0, *.output + 1, .root )
92 ret.replacech( stemp, '\', "/")
93 }
94
95 return ret
96 }
97
98 include
99 {
100 $"styles\c-copy\default.g"
101 $"styles\t-text\default.g"
102 $"styles\w-website\default.g"
103 $"styles\l-phtml\default.g"
104 $"styles\s-sources\default.g"
105 $"styles\r-lib\default.g"
106 $"styles\h-chm\default.g"
107 }
108
109 method gtpub.load
110 {
111 str input
112 arrstr ain
113 uint last newlast
114 str dir filename
115
116 .prj.get( "project/input", input )
117
118 ain.loadtrim( input )
119 foreach curin, ain
120 {
121 ffind fd
122 fd.init( "\(curin)\\*.gt", $FIND_FILE | $FIND_RECURSE )
123 foreach curfile, fd
124 {
125 print( "\(curfile.fullname)\n" )
126 last as this.root().lastchild()
127 this.read( curfile.fullname )
128 newlast as this.root().lastchild()
129 curfile.fullname.fgetparts( dir, filename, 0->str )
130 dir.del( 0, *curin + 1 )
131
132 while &newlast != &last
133 {
134 newlast.set( "fullpath", "\(curin)\\\(dir)" )
135 if !newlast.find( "path" ) : newlast.set( "path", dir )
136 if !newlast.find( "filename" ) : newlast.set( "filename", filename )
137 if !newlast.find( "ext" )
138 {
139 str ext = "ext_"
140 str stemp
141
142 newlast.get("style", stemp )
143 ( ext += stemp ).lower()
144 _gtp.prj.get( "project/\(ext)", stemp )
145
146 newlast.set( "ext", ?( *stemp, stemp, .ext ))
147 }
148 newlast as newlast.getprev()
149 }
150 }
151 }
152 }
153
154 method gtpub.output
155 {
156 uint outfunc
157
158 .prj.get( "project/style", style )
159
160 style.upper()
161 // verifypath( folder, 0->arr )
162 foreach curitem, this.root()
163 {
164 str cstyle preout out filename
165
166 curitem as gtitem
167
168 // print("1 \(curitem.name)\n")
169 curitem.get( "style", cstyle )
170 cstyle.upper()
171 if cstyle.findch( style[0] ) >= *cstyle : continue
172 if curitem.find("text")
173 {
174 outfunc = getid( "T_default", 0, %{ gtitem } )
175 }
176 elif !( outfunc = getid( "\( style )_default", 0, %{ gtitem } )) : continue
177
178 preout@outfunc->func( curitem )
179
180 if preout %== "nofile" : continue
181 curitem.process( preout, out, 0->arrstr )
182 this.getfilename( curitem, filename )
183
184 if style[0] == 'H'
185 {
186 ustr ustemp
187
188 ustemp.fromutf8( out )
189 out = ustemp
190 }
191 if fileupdate( filename, out )
192 {
193 print("Processing \(curitem.name) => \(filename)\n")
194 }
195 }
196 }
197
198 func main<main>
199 {
200 // Загружаем настройки проекта
201 str prjdata
202
203 prjdata.read( $"..\..\..\scriptius\web.gt")
204 _gtp.utf8 = 1
205 _gtp.prj += prjdata
206 _gtp.prj.get( "project/output", _gtp.output )
207 _gtp.prj.get( "project/root", _gtp.root )
208 _gtp.prj.get( "project/ext", _gtp.ext )
209 _gtp.prj.get("project/lang", _gtp.lang )
210 // Читаем все входящие файлы
211 _gtp.load()
212 // Предварительная обработка
213 // _gtp.prepare( gtp.data.root())
214 // Вывод данных
215 _gtp.output()
216
217 print("Press any key...")
218 Sleep( 2000 )
219 // getch()
220 }