class Tcms::Publisher

Public Class Methods

new(name,data,project) click to toggle source

初始化

# File lib/tcms/publisher.rb, line 11
def initialize(name,data,project)
  @project = project
  templates = project["templates"]
  @encoding = project["encoding"]
  @name = name
  @data = self.extend_data(data)
  @template = File.read("#{templates['folder']}/#{name}.html.erb",:encoding=>@encoding)
end

Public Instance Methods

extend_data(data) click to toggle source
# File lib/tcms/publisher.rb, line 20
def extend_data data
  class<<data
    include Tcms::Helper
    def method_missing name,*args
      self[name.to_s]
    end
  end
  data
end
render(type) click to toggle source

直接输出页面地址

# File lib/tcms/publisher.rb, line 30
def render type
  page = ERB.new(@template)
  project = @project

  bd = @data.instance_eval{
    @_build_type = type
    @_project = project

    binding();
  }
  content = page.result(bd)
  
  write_file_path = @project["pages"]["folder"]+"/"+@name+'.html'
  if File.exist? write_file_path
    File.delete write_file_path
  end

  write_file = File.new(write_file_path,'w+')
  write_file.puts content
  write_file.close

  puts "已生成页面#{write_file_path}"
end