Class: Path

Inherits:
Object
  • Object
show all
Defined in:
lib/mako/path.rb

Direct Known Subclasses

Build, Scaffold

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject

Returns the value of attribute args.



46
47
48
# File 'lib/mako/path.rb', line 46

def args
  @args
end

#defaultObject

Returns the value of attribute default.



46
47
48
# File 'lib/mako/path.rb', line 46

def default
  @default
end

#settingsObject

Returns the value of attribute settings.



46
47
48
# File 'lib/mako/path.rb', line 46

def settings
  @settings
end

Instance Method Details

#aboslute_paths(hash, base) ⇒ Object



29
30
31
# File 'lib/mako/path.rb', line 29

def aboslute_paths hash, base
  hash.map {|item| absolute_path(item, base)} if !hash.nil? and !hash.empty?
end

#absolute_path(path, base) ⇒ Object

return an abolute path



23
24
25
26
27
# File 'lib/mako/path.rb', line 23

def absolute_path path, base
  return '' if path.nil?
  return path if path[0,1] == '/'
  base+'/'+ path
end

#initalize(settings, default, args) ⇒ Object



7
8
9
10
11
# File 'lib/mako/path.rb', line 7

def initalize settings, default, args
  @settings = settings
  @default = default
  @args = args
end

#prepare_output_path(*hashes) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/mako/path.rb', line 13

def prepare_output_path *hashes

  path = self.prioritize :output_path, *hashes
  # Make sure the output directory exists
  output = absolute_path(path, Dir.pwd)
  FileUtils.mkpath output unless File::exists? output
  output
end

#prioritize(key, *hashes) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mako/path.rb', line 33

def prioritize key, *hashes
  # puts hashes.inspect
  hashes.each do |hash|
    if !hash.nil? and !hash[key].nil?
      if hash[key].respond_to?(:empty) && !hash[key].empty?
        return hash[key]
      else
        return hash[key]
      end
    end
  end
end