Class: Cup::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/cup/directory.rb

Overview

Represents the directory that holds a cup

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Directory

Returns a new instance of Directory.



12
13
14
# File 'lib/cup/directory.rb', line 12

def initialize path
  @path = Pathname.new File.expand_path(path.to_s)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/cup/directory.rb', line 10

def path
  @path
end

Class Method Details

.__current__Object

so that current can be overridden for all tests



17
18
19
# File 'lib/cup/directory.rb', line 17

def self.__current__
  new('.')
end

.currentObject



21
22
23
# File 'lib/cup/directory.rb', line 21

def self.current
  __current__
end

Instance Method Details

#concatenated(opts = {}) ⇒ Object



39
40
41
42
# File 'lib/cup/directory.rb', line 39

def concatenated(opts={})
  output = "build/#{name}-#{cupfile.version}.js"
  opts[:relative] ? output : "#{self.path}/#{output}"
end

#cupfileObject



25
26
27
28
29
30
31
32
33
# File 'lib/cup/directory.rb', line 25

def cupfile
  @cupfile ||= Cup::Cupfile.new(path + 'Cupfile')

  unless @cupfile.valid?
    fail Cup::Cupfile::CupfileError.new("Cupfile not valid: #{@cupfile.path.to_s}\n#{@cupfile.error_messages("\n")}")
  end

  @cupfile
end

#javascripts(scheme = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cup/directory.rb', line 54

def javascripts scheme=nil

  load_paths = case scheme
  when :spec
    ['vendor', 'spec', 'lib', 'src']
  when :build_input
    ['lib', 'src']
  when :spec_concatenated, :spec_minified
    ['vendor', 'spec', 'build']
  when :debug
    ['vendor', 'lib', 'src']
  else
    raise "scheme not known: #{scheme}"
  end

  javascripts = load_paths.map do |load_path|
    if load_path == 'build'
      build_for scheme
    else
      cupfile.javascripts[load_path.to_sym].map{|filepath| Pathname.new(filepath).to_s}
    end
  end.flatten

  javascripts
end

#licence(opts = {}) ⇒ Object



49
50
51
52
# File 'lib/cup/directory.rb', line 49

def licence(opts={})
  licence = "#{cupfile.licence}"
  opts[:relative] ? licence : "#{self.path}/#{licence}"
end

#minified(opts = {}) ⇒ Object



44
45
46
47
# File 'lib/cup/directory.rb', line 44

def minified(opts={})
  output = "build/#{name}-#{cupfile.version}.min.js"
  opts[:relative] ? output : "#{self.path}/#{output}"
end

#nameObject



35
36
37
# File 'lib/cup/directory.rb', line 35

def name
  File.basename path.to_s
end

#stylesheetsObject



80
81
82
# File 'lib/cup/directory.rb', line 80

def stylesheets
  FileList['**/*.css'].map{|f| Pathname.new(f).expand_path}
end