Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # encoding: utf-8
- tmpls = ["page_tmpl.html", "menu.html"]
- pages_hsh = {"Etusivu"=>"index", "Yritys"=>"yritys", "Tuotteet"=>"tuotteet"}
- title_str = " – Galleria Laura, Helsinki"
- tgt_str_menu = "<§menu>"
- tgt_str_page = "<§page>"
- tgt_str_title = "<§title>"
- tgt_path_str = "/"
- p File.expand_path(File.dirname(__FILE__)) #??
- inc_path_str = File.expand_path(File.dirname(__FILE__)) + "/public_html/inc/"
- #load tmpl
- Dir.chdir( inc_path_str )
- tmpls.map! { |t|
- file = File.open(t, "rb")
- t = file.read
- file.close
- t
- }
- #menuet
- menu_str = '<li><a href="<§pagepath>"><§pagetitle></a></li>'
- pages_hsh.each_pair { |k, v|
- menu_str += tmpls[1].gsub("<§pagetitle>", k + title_str)
- menu_str += tmpls[1].gsub("<§pagepath>", v+".html")
- }
- tmpls[1] = '<ul>' + menu_str + '</ul>'
- #template & save
- pages_hsh.each_pair { |tit, fil|
- Dir.chdir( inc_path_str )
- p Dir.entries( inc_path_str )
- fn = fil + ".inc"
- file = File.open(fn, "r:UTF-8")
- puts file.external_encoding.name
- page = file.read
- file.close
- page.gsub(tgt_str_menu, tmpls[1])
- page.gsub(tgt_str_page, tmpls[0])
- p File.expand_path(File.dirname(__FILE__)) #??
- Dir.chdir( File.expand_path(File.dirname(__FILE__)) + "/public_html/")
- exit
- file = File.new(fn+".html", "w")
- file << page
- file.close
- }
Add Comment
Please, Sign In to add comment