Guest User

Untitled

a guest
Oct 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. # encoding: utf-8
  2.  
  3. tmpls = ["page_tmpl.html", "menu.html"]
  4. pages_hsh = {"Etusivu"=>"index", "Yritys"=>"yritys", "Tuotteet"=>"tuotteet"}
  5. title_str = " – Galleria Laura, Helsinki"
  6.  
  7. tgt_str_menu = "<§menu>"
  8. tgt_str_page = "<§page>"
  9. tgt_str_title = "<§title>"
  10.  
  11. tgt_path_str = "/"
  12. p File.expand_path(File.dirname(__FILE__)) #??
  13.  
  14. inc_path_str = File.expand_path(File.dirname(__FILE__)) + "/public_html/inc/"
  15.  
  16. #load tmpl
  17. Dir.chdir( inc_path_str )
  18.  
  19. tmpls.map! { |t|
  20. file = File.open(t, "rb")
  21. t = file.read
  22. file.close
  23. t
  24. }
  25.  
  26. #menuet
  27. menu_str = '<li><a href="<§pagepath>"><§pagetitle></a></li>'
  28. pages_hsh.each_pair { |k, v|
  29. menu_str += tmpls[1].gsub("<§pagetitle>", k + title_str)
  30. menu_str += tmpls[1].gsub("<§pagepath>", v+".html")
  31. }
  32. tmpls[1] = '<ul>' + menu_str + '</ul>'
  33.  
  34. #template & save
  35. pages_hsh.each_pair { |tit, fil|
  36. Dir.chdir( inc_path_str )
  37. p Dir.entries( inc_path_str )
  38. fn = fil + ".inc"
  39. file = File.open(fn, "r:UTF-8")
  40. puts file.external_encoding.name
  41.  
  42. page = file.read
  43. file.close
  44.  
  45. page.gsub(tgt_str_menu, tmpls[1])
  46. page.gsub(tgt_str_page, tmpls[0])
  47.  
  48. p File.expand_path(File.dirname(__FILE__)) #??
  49. Dir.chdir( File.expand_path(File.dirname(__FILE__)) + "/public_html/")
  50. exit
  51. file = File.new(fn+".html", "w")
  52. file << page
  53. file.close
  54. }
Add Comment
Please, Sign In to add comment