# -*- encoding: utf-8 -*- require "erb" module Charu class PageCounter def initialize() changelogmemo = Charu::ChangeLogMemo.new() @max_page = changelogmemo.article_size_max() p "Page MAX " + @max_page.to_s i = 0 @pages = [] while i <= @max_page do if i == 0 then @pages << [[i, "index.html", changelogmemo.get_item_sort_reverse(1)]] else @pages << [[i, "index" + i.to_s + ".html", changelogmemo.get_item_sort_reverse(i)]] end p "Page " + i.to_s i = i + 1 end end def create_html() p "pages.size " + @pages.size.to_s @pages.each{|page| create_html = Charu::CreateHtml.new(page) } end end class CreateHtml attr_accessor :keyword, :css_theme_path, :link, :hiduke, :day, :title, :config def initialize(page) @config = Charu::Config.new() @page = page @header = File.open("./CharuConfig/template/header.erb").read @footer = File.open("./CharuConfig/template/footer.erb").read @body = File.open("./CharuConfig/template/body.erb").read @day_body = File.open("./CharuConfig/template/day_body.erb").read self.keyword() self.create_body() end def keyword() @keyword = "" @config.home_category.each{|key| @keyword = "#{@keyword}, " + "#{key}" } return @keyword.encode!("UTF-8") end def create_body() # くっつける @htmls = [] @page.each{|page, file_name, changelogmemo| p "page " + page.to_s + " 作成中" #p file_name @changelogmemo = changelogmemo @html = @header + @body + @footer #p changelogmemo erb = ERB.new(@html) =begin changelogmemo.each{|key, items| items.each{|item| p item.date p item.get_item_title#.encode(Encoding::SJIS) p i.get_item_category() } } =end @html = erb.result(binding) begin File.write(@config.www_html_out_path + file_name, @html) rescue p "書き込みエラー" end } end def create_day_body() @days.sort_data().each{|day_s| # 文字列だけのデータ @daydata = [] @days.get_days.each{|day| if day_s == day.get_day_s() then @daydata << day else #@daydata << day end @daydata.sort!{|a, b| a.get_Datetime() <=> b.get_Datetime() } @css_path = "./../theme/" @css_theme_path = @css_path + @css_theme + "/" + @css_theme + ".css" htmls = @header + @body + @footer erb = ERB.new(htmls) html = erb.result(binding) # ファイル書き込み begin File.write(@config.www_html_out_path + "index/" + day_s + ".html", html) rescue p day_s + ".html" p "ファイル書き込みエラー".encode(Encoding::SJIS) end } } end def file_save() # ファイル書き込み @days.get_days.each{|day_name, title, html| File.write(@config.www_html_out_path + @file_name, html) } end end end