require 'fileutils' require 'erb' module CukePages class Site attr_reader :features def initialize(output_dir_path, features = []) @site_dir_path = File.join(output_dir_path, "cukepages-site") @features = features end def generate copy_resources index_template_path = File.join(TEMPLATES_DIR, "index.erb") feature_template_path = File.join(TEMPLATES_DIR, "feature.erb") index_file_path = File.join(@site_dir_path, "index.html") File.open(index_file_path, "w") { |f| content = ERB.new(File.read(index_template_path)).result(binding) f.syswrite(content) } @features.each { |feature| feature_file_path = File.join(@site_dir_path, "#{feature.ref}.html") File.open(feature_file_path, "w") { |f| content = ERB.new(File.read(feature_template_path)).result(binding) f.syswrite(content) } } end private def copy_resources FileUtils.cp_r("#{RESOURCES_DIR}/.", @site_dir_path) end end end