Sha256: e5eaa46a13ca46b1f0c70d476f0e7a0edba156d20440070f06fe3efa05cab511

Contents?: true

Size: 909 Bytes

Versions: 16

Compression:

Stored size: 909 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} = #{self.to_h.to_json};
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

16 entries across 16 versions & 2 rubygems

Version Path
sayso-js-test-driver-rails-0.4.3.002 lib/js_test_driver/html_fixture.rb
sayso-js-test-driver-rails-0.4.3.001 lib/js_test_driver/html_fixture.rb
sayso-js-test-driver-rails-0.4.3 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.5.0.pre2 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.5.0.pre1 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.4.3 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.4.2 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.4.1 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.4.0 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.3.4 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.3.3 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.3.2 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.3.1 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.3.0 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.2.9 lib/js_test_driver/html_fixture.rb
js-test-driver-rails-0.2.8 lib/js_test_driver/html_fixture.rb