module Erector::Externals::ClassMethods

Constants

INFERABLE_TYPES

Public Instance Methods

dependencies(type) click to toggle source

returns all dependencies of the given type from this class and all its superclasses

# File lib/erector/externals.rb, line 35
def dependencies(type)
  type = type.to_sym
  deps = Dependencies.new
  deps.push(*superclass.dependencies(type)) if superclass.respond_to?(:dependencies)
  deps.push(*my_dependencies.select { |x| x.type == type })
  deps.uniq
end
depends_on(*args) click to toggle source

Express a dependency of this widget Multiple forms:

depends_on(type, text, options = {})

for example

depends_on(:js, '/foo.js', :embed=>true)

Other variants:

depends_on(type, an_io, ... # file to be read
depends_on('blah.js' ... infer :js
depends_on('blah.css' ... infer :css
depends on :js, 'file1.js', 'file2.js'... [options]
depends_on :js => ["foo.js", "bar.js"], :css=>['file.css']
depends_on :js => ["foo.js", "bar.js"], other_option=>:blah
# File lib/erector/externals.rb, line 28
def depends_on(*args)
  x = interpret_args(*args)
  my_dependencies.push(x)
end
my_dependencies() click to toggle source
# File lib/erector/externals.rb, line 43
def my_dependencies
  @my_dependencies ||= Dependencies.new
end

Private Instance Methods

interpret_args(*args) click to toggle source
# File lib/erector/externals.rb, line 50
def interpret_args(*args)
  options =  {}
  options = args.pop if args.last.is_a?(::Hash)
  if args.empty? && options.any?
    deps = []
    texts_hash = {}
    INFERABLE_TYPES.each do |t|
      texts_hash[t] = options.delete(t) if options.has_key? t
    end
    texts_hash.each do |t, texts|
      [texts].flatten.each do |text|
        deps << interpret_args(t, text, options)
      end
    end
    return deps
  elsif args[0].class == Symbol
    type = args.shift
  else
    type = /.+\.js/.match(args[0]) ? :js : :css
  end

  deps = args.map do |text|
    Dependency.new(type, text, options)
  end
  deps.size == 1 ? deps.first : deps
end