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.



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

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.__current__Object

so that current can be overridden for all tests



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

def self.__current__
  new('.')
end

.currentObject



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

def self.current
  __current__
end

Instance Method Details

#concatenated(opts = {}) ⇒ Object



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

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

#cupfileObject



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

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



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

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



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

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

#minified(opts = {}) ⇒ Object



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

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

#nameObject



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

def name
  File.basename path.to_s
end

#stylesheetsObject



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

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