Sha256: f09eec4aac5e8949d5ce0bab5a46b366dd2f489a5cf6b0ad328a918c0b2a5fe4
Contents?: true
Size: 919 Bytes
Versions: 3
Compression:
Stored size: 919 Bytes
Contents
module JsTestDriver # This is a class that given a directory name, puts all its *.html children # into a javascript file, so that they can later be used in the tests class HtmlFixture attr_reader :name, :namespace def initialize(directory_name, name = nil, namespace = nil) @name = name || "all" @namespace = namespace || "htmlFixtures" @data = {} load_data(directory_name) end def to_h @data end def to_s <<JS if (typeof(#{namespace}) === 'undefined') { #{namespace} = {}; } #{namespace}.#{name} = #{MultiJson.encode(self.to_h)}; JS end private def load_data(directory_name) full_path = File.expand_path(directory_name) files = Dir["#{full_path}/**/*.html"] files.each do |file| name = file.gsub(/^#{full_path}\//, '').gsub(/\.html$/, '') @data[name] = File.read(file) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems