home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Internet / Folder to HTML next >
Encoding:
Text File  |  1999-03-04  |  4.6 KB  |  169 lines  |  [TEXT/ToyS]

  1. property kasWinDims : {256, 128}
  2. property kasHtHead1 : {"<HTML>", "<HEAD>", "<TITLE>"}
  3. property kasHtHead2 : {"</TITLE>", "</HEAD>", "<BODY bgColor=white>"}
  4. property kasHtTail : {"</BODY>", "</HTML>"}
  5. property kasTblHead : {"<TABLE BORDER=4 CELLPADDING=4 CELLSPACING=2>"}
  6. property kasRowHead : {"<TR>", "<TD>"} -- Img tag goes after this
  7. property kasRowDiv : {"</TD>", "<TD VALIGN=top>"} -- Name/Link goes after this
  8. property kasRowTail : {"</A>", "</TD>", "</TR>"}
  9. property kasTblTail : {"</TABLE>"}
  10.  
  11. property kasImgTag : "<IMG"
  12. property kasImgH : "HEIGHT"
  13. property kasImgW : "WIDTH"
  14. property kasImgSrc : "SRC"
  15.  
  16. property kasHRefTag : "<A"
  17. property kasHRefSrc : "HREF"
  18.  
  19. property kasExportFormat : "JPEG" -- QT Supports JPEG, BMP or QTIF but not GIF
  20. property kasExtension : ".jpg"
  21.  
  22. global gasDrawWin
  23.  
  24.  
  25. on run
  26.     open {"◊MAXI◊:Desktop Folder:Thrash"}
  27. end run
  28.  
  29.  
  30. on open fsObjs
  31.     -- Initialize
  32.     set winBox to {0, 0} & kasWinDims
  33.     set icnBox to {0, 16} & kasWinDims
  34.     set txtBox to {0, 0, item 1 of kasWinDims, 16}
  35.     
  36.     if true then -- Runtime?
  37.         -- Display window
  38.         set gasDrawWin to ¬
  39.             display drawing titled ¬
  40.                 "Folder to HTML" with dimensions kasWinDims
  41.         -- Black background
  42.         draw a box into gasDrawWin ¬
  43.             inside of winBox ¬
  44.             filling it with the pen
  45.     end if
  46.     
  47.     repeat while fsObjs is not {}
  48.         -- Pop #1 off list
  49.         set fsObj to item 1 of fsObjs
  50.         set fsObjs to edit list fsObjs with edits {-1}
  51.         
  52.         -- Only do folders!
  53.         set fsInf to extended info for fsObj
  54.         if (catalog kind of fsInf is not a folder) then
  55.             display dialog "Only Folders!" default button 1 with icon stop
  56.             return
  57.         end if
  58.         
  59.         -- Create output folder
  60.         set fsPath to (fsObj as string)
  61.         set fsName to catalog name of fsInf
  62.         set fsDad to (parent spec of fsInf) as string
  63.         set outPath to fsName & ".img"
  64.         set outFold to («event ÅkuFƒNew» fsDad given «class NAME»:outPath) as string
  65.         set outPath to catalog name of (basic info for outFold) -- Update in case name changed when creating
  66.         
  67.         -- Start html page and table
  68.         set html to kasHtHead1 & ("Folder " & fsName) & kasHtHead2 & kasTblHead
  69.         
  70.         -- List folder
  71.         set dirFiles to the entries in fsObj
  72.         
  73.         -- Get icons
  74.         repeat with dirFile in dirFiles
  75.             -- Break it down
  76.             set itemPath to fsPath & dirFile
  77.             set isFold to (catalog kind of (basic info for itemPath) is a folder)
  78.             
  79.             -- Create sub folder html?
  80.             if (isFold) then set fsObjs to fsObjs & {itemPath & ":"}
  81.             
  82.             -- Convert to picture, get bounds        
  83.             set ciPic to (the icon for itemPath) as picture
  84.             set ciBox to picture bounds of (the picture info for ciPic)
  85.             set ciDrawBox to CenterBox(ciBox, icnBox)
  86.             
  87.             -- Add row to table
  88.             set html to html & kasRowHead
  89.             
  90.             -- Add Image
  91.             set ciW to compile tag val {kasImgW, (item 3 of ciBox) - (item 1 of ciBox)}
  92.             set ciH to compile tag val {kasImgH, (item 4 of ciBox) - (item 1 of ciBox)}
  93.             set ciS to compile tag val {kasImgSrc, outPath & "/" & dirFile & kasExtension}
  94.             set imgTag to compile tag {kasImgTag, ciW, ciH, ciS}
  95.             set html to html & imgTag & kasRowDiv
  96.             
  97.             -- Add file/folder link to table
  98.             if (isFold) then
  99.                 set href to compile tag val {kasHRefSrc, fsName & "/" & dirFile & ".html"}
  100.             else
  101.                 set href to compile tag val {kasHRefSrc, fsName & "/" & dirFile}
  102.             end if
  103.             set ciTag to compile tag {kasHRefTag, href}
  104.             set html to html & ciTag & dirFile
  105.             
  106.             -- End table row
  107.             set html to html & kasRowTail
  108.             
  109.             -- Erase background
  110.             draw a box into gasDrawWin ¬
  111.                 inside of winBox ¬
  112.                 filling it with the pen ¬
  113.                 without recording
  114.             
  115.             -- Show name
  116.             draw a text box into gasDrawWin ¬
  117.                 inside of txtBox ¬
  118.                 using data dirFile ¬
  119.                 using state {text mode:2} ¬
  120.                 without recording
  121.             
  122.             -- Draw Icon
  123.             draw a picture into gasDrawWin ¬
  124.                 inside of ciDrawBox ¬
  125.                 using data ciPic ¬
  126.                 without recording
  127.             
  128.             -- Save file
  129.             store image ciPic ¬
  130.                 in (outFold & dirFile & kasExtension) ¬
  131.                 given «class îKnd»:kasExportFormat
  132.         end repeat
  133.         
  134.         set html to html & kasTblTail & kasHtTail
  135.         set htTxt to compile ML html
  136.         
  137.         -- Write html to file
  138.         set fRef to ¬
  139.             open fork from fsDad ¬
  140.                 named (fsName & ".html") ¬
  141.                 of type "TEXT" of creator "R*ch" with write access
  142.         write data to fRef from buffer htTxt
  143.         close fork fRef
  144.     end repeat
  145. end open
  146.  
  147.  
  148. on quit
  149.     display drawing gasDrawWin with disposal
  150.     return (continue quit)
  151. end quit
  152.  
  153.  
  154. on CenterBox(src, dst)
  155.     -- Place src in dst w/o scaling
  156.     set dX to (item 1 of dst)
  157.     set dY to (item 2 of dst)
  158.     set sW to (item 3 of src) - (item 1 of src)
  159.     set sH to (item 4 of src) - (item 2 of src)
  160.     set dW to (item 3 of dst) - dX
  161.     set dH to (item 4 of dst) - dY
  162.     
  163.     set bW to dX + (dW - sW) / 2
  164.     set bH to dY + (dH - sH) / 2
  165.     
  166.     -- Center it
  167.     return {bW, bH, bW + sW, bH + sH}
  168. end CenterBox
  169.