Sha256: 76bedc88459a094ad9cb80401642beae48e668c4ce80025c1d4bcfceebaf606e

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 KB

Contents

module Teabag
  class Suite

    attr_accessor :config
    delegate :stylesheets, :helper, to: :config

    def initialize(name = :default)
      @config = suite_configuration(name)
    end

    def javascripts
      [config.javascripts, helper, specs].flatten
    end

    def specs
      Dir[config.matcher.present? ? Teabag.configuration.root.join(config.matcher) : ""].map do |filename|
        asset_path_from_filename(File.expand_path(filename))
      end
    end

    protected

    def suite_configuration(name)
      name ||= :default
      config = Teabag.configuration.suites[name.to_s]
      raise Teabag::UnknownSuite unless config.present?
      Teabag::Configuration::Suite.new(&config)
    end

    def asset_path_from_filename(original)
      filename = original
      Rails.application.config.assets.paths.each do |path|
        filename = filename.gsub(%r(^#{path}[\/|\\]), "")
      end
      raise Teabag::AssetNotServable, "#{filename} is not within an asset path" if filename == original
      filename.gsub(/(\.js\.coffee|\.coffee)$/, ".js")
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
teabag-0.4.0 lib/teabag/suite.rb
teabag-0.3.6 lib/teabag/suite.rb
teabag-0.3.5 lib/teabag/suite.rb
teabag-0.3.4 lib/teabag/suite.rb
teabag-0.3.3 lib/teabag/suite.rb
teabag-0.3.2 lib/teabag/suite.rb
teabag-0.3.1 lib/teabag/suite.rb
teabag-0.3.0 lib/teabag/suite.rb