class WWWCHTMLConverter::Index

Attributes

css_theme_path[RW]
day[RW]
db[RW]
hiduke[RW]
keyword[RW]
keywords[RW]
title[RW]

Public Class Methods

new() click to toggle source
# File lib/WWWCHtmlConverter/WWWCHTMLConverterLib.rb, line 225
def initialize()
  # コンフィング
  # main file
  @thml_path = "./../../html/"           # 出力ディレクトリ
  @file_name = "index.html"              # 出力ファイル
  @css_path = "./theme/"           # テーマディレクトリ
  @css_theme = "3minutes"                # テーマ
  @day_hach_path = "./../../html/index/" # コラム出力ディレクトリ
  @day_hach = {}                         # コラムを入れる

  dir_css = Dir.glob('./../../html/theme/*')
  @css_theme = dir_css[rand(dir_css.size)].sub!("./../../html/theme/", "")

  # データベース
  @db_file_name = ARGV[0]
  #@db = Sequel.sqlite(@db_file_name)

  # データベースからデータ取得
  dataset = @db[:index].where(:Private => false).order(:Datetime)
  datas = dataset.all

  @days = Days.new(datas)

  @css_theme_path = @css_path + @css_theme + "/" + @css_theme + ".css"

  moto = []
  Dir.glob("./*.jpg").each{|i| moto << i}
  Dir.glob("./*.png").each{|i| moto << i}
  Dir.glob("./*.gif").each{|i| moto << i}
  #FileUtils.cp(moto, @thml_pach)

  @header   = File.open("./../header.erb").read
  @footer   = File.open("./../footer.erb").read
  @body     = File.open("./../body.erb").read
  @day_body = File.open("./../day_body.erb").read
  @all_body = File.open("./../all_body.erb").read

end

Public Instance Methods

all_create_body() click to toggle source
# File lib/WWWCHtmlConverter/WWWCHTMLConverterLib.rb, line 306
def all_create_body()

  htmls = @header + @all_body + @footer

  erb = ERB.new(htmls)
  html = erb.result(binding)

  # ファイル書き込み
  File.write(@thml_path + @file_name, html)
end
create_body() click to toggle source
# File lib/WWWCHtmlConverter/WWWCHTMLConverterLib.rb, line 264
def create_body()
  # くっつける

  @htmls = []
  @days.get_days().each{|day|
    html = @header + @body + @footer
    @htmls << [day.get_day_s(), day.get_tile(), html] # くっつける
  }

  @htmls.each{|day_time, tile, body|
    erb = ERB.new(body)
    @htmls << [day_time, tile, erb.result(binding)] # ファイル名とhtmlの配列
  }
  file_save()
end
create_html() click to toggle source
# File lib/WWWCHtmlConverter/WWWCHTMLConverterLib.rb, line 317
def create_html()
  keyword()     # キーワード作成

  p "HTMLデータ作成".encode(Encoding::SJIS)
  #create_body() # html作成
  all_create_body() # 日付ごとのHTML作成
  day_create_body()    # 日付ごとのHTML作成

end
day_create_body() click to toggle source
# File lib/WWWCHtmlConverter/WWWCHTMLConverterLib.rb, line 280
def day_create_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(@thml_path + "index/" + day_s + ".html", html)
      rescue
        p day_s + ".html"
        p "ファイル書き込みエラー".encode(Encoding::SJIS)
      end
    }
  }
end
file_save() click to toggle source
# File lib/WWWCHtmlConverter/WWWCHTMLConverterLib.rb, line 327
def file_save()
  # ファイル書き込み
  @days.get_days.each{|day_name, title, html|
    File.write(@thml_path + @file_name, html)
  }
end