Class: Juicer::Command::List

Inherits:
CmdParse::Command
  • Object
show all
Includes:
Util
Defined in:
lib/juicer/command/list.rb

Overview

Displays a list of files that make up the dependency chain for the input files/patterns.

Instance Method Summary collapse

Methods included from Util

#files, #relative

Constructor Details

#initialize(io = STDOUT) ⇒ List

Initializes command



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/juicer/command/list.rb', line 15

def initialize(io = STDOUT)
  super('list', false, true)
  @io = io
  self.short_desc = "Lists all dependencies for all input files/patterns"
  self.description = <<-EOF
Dependencies are looked up recursively. The dependency chain reveals which files
will be joined by juicer merge.

Input parameters may be:
  * Single file, ie $ juicer list myfile.css
  * Single glob pattern, ie $ juicer list **/*.css
  * Multiple mixed arguments, ie $ juicer list **/*.js **/*.css
  EOF
end

Instance Method Details

#execute(args) ⇒ Object

Execute command



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/juicer/command/list.rb', line 32

def execute(args)
  if args.length == 0
    raise ArgumentError.new('Please provide atleast one input file/pattern')
  end

  types = { :js => Juicer::Merger::JavaScriptDependencyResolver.new,
            :css => Juicer::Merger::CssDependencyResolver.new }

  files(args).each do |file|
    type = file.split(".").pop.to_sym
    raise FileNotFoundError.new("Unable to guess type (CSS/JavaScript) of file #{relative(file)}") unless types[type]

    @io.puts "Dependency chain for #{relative file}:"
    @io.puts "  #{relative(types[type].resolve(file)).join("\n  ")}\n\n"
  end
end