EnglishРусский  

   ..

   STYLES

   gtpublisher.g

   utils.g

Ads

Perfect Automation tool
All-In-One: Script editor, Launcher, Scheduler, Keyboard & Mouse Recorder. Try now!

CreateInstall
Freeware and commercial installers.

Cell Phone Batteries
Batteries Plus offers batteries for laptop, camcorder, cell phone, camera.

Gentee needs your help!
How to advertise with us
 
laptop battery

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       curitem.get( "style", cstyle )
169       cstyle.upper()
170       if cstyle.findch( style[0] ) >= *cstyle : continue
171       if curitem.find("text")
172       {
173          outfunc = getid( "T_default", 0, %{ gtitem } )   
174       }
175       elif !( outfunc = getid( "\( style )_default", 0, %{ gtitem } )) : continue
176       
177       preout@outfunc->func( curitem )
178       if preout %== "nofile" : continue               
179       curitem.process( preout, out, 0->arrstr )
180       this.getfilename( curitem, filename )
181       if style[0] == 'H'
182       {
183          ustr ustemp
184          
185          ustemp.fromutf8( out )
186          out = ustemp
187       }
188       if fileupdate( filename, out )
189       {
190          print("Processing \(curitem.name) => \(filename)\n")
191       }
192    }
193 }
194 
195 func main<main>
196 {
197    // Загружаем настройки проекта
198    str prjdata
199    
200    prjdata.read( $"..\..\..\scriptius\web.gt")           
201    _gtp.utf8 = 1
202    _gtp.prj += prjdata
203    _gtp.prj.get( "project/output", _gtp.output )
204    _gtp.prj.get( "project/root", _gtp.root )
205    _gtp.prj.get( "project/ext", _gtp.ext )
206    _gtp.prj.get("project/lang", _gtp.lang )   
207    // Читаем все входящие файлы
208    _gtp.load()
209    // Предварительная обработка
210 //   _gtp.prepare( gtp.data.root())    
211    // Вывод данных
212    _gtp.output()
213  
214    print("Press any key...")
215    Sleep( 2000 )
216 //   getch()   
217 }
Edit