Class: Mint::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/mint/resource.rb

Direct Known Subclasses

Document, Layout, Style

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) {|_self| ... } ⇒ Resource

Returns a new instance of Resource.

Yields:

  • (_self)

Yield Parameters:



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mint/resource.rb', line 67

def initialize(source, options={})
  return nil unless source

  self.type = :resource
  self.source = source
  self.root = options[:root] || source_directory
  self.destination = options[:destination]

  yield self if block_given?

  self.name = Mint.guess_name_from source
  self.renderer = Mint.renderer source
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



45
46
47
# File 'lib/mint/resource.rb', line 45

def destination
  @destination
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/mint/resource.rb', line 7

def name
  @name
end

#rootObject

Returns the value of attribute root.



12
13
14
# File 'lib/mint/resource.rb', line 12

def root
  @root
end

#sourceObject

Returns the value of attribute source.



25
26
27
# File 'lib/mint/resource.rb', line 25

def source
  @source
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/mint/resource.rb', line 5

def type
  @type
end

Instance Method Details

#destination_directoryObject



59
60
61
# File 'lib/mint/resource.rb', line 59

def destination_directory
  destination_directory_path.to_s
end

#destination_directory_pathObject



55
56
57
# File 'lib/mint/resource.rb', line 55

def destination_directory_path
  destination_file_path.dirname
end

#destination_fileObject



51
52
53
# File 'lib/mint/resource.rb', line 51

def destination_file
  destination_file_path.to_s
end

#destination_file_pathObject



47
48
49
# File 'lib/mint/resource.rb', line 47

def destination_file_path
  root_directory_path + (destination || "") + name
end

#equal?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


81
82
83
# File 'lib/mint/resource.rb', line 81

def equal?(other)
  self.destination_file_path == other.destination_file_path
end

#render(context = Object.new, args = {}) ⇒ Object



86
87
88
89
# File 'lib/mint/resource.rb', line 86

def render(context=Object.new, args={})
  # see Tilt TEMPLATES.md for more info
  @renderer.render context, args 
end

#renderer=(renderer) ⇒ Object



63
64
65
# File 'lib/mint/resource.rb', line 63

def renderer=(renderer)
  @renderer = renderer
end

#root_directoryObject



21
22
23
# File 'lib/mint/resource.rb', line 21

def root_directory
  root_directory_path.to_s
end

#root_directory_pathObject



17
18
19
# File 'lib/mint/resource.rb', line 17

def root_directory_path
  Pathname.new(root || Dir.getwd).expand_path
end

#source_directoryObject



41
42
43
# File 'lib/mint/resource.rb', line 41

def source_directory
  source_directory_path.to_s
end

#source_directory_pathObject



37
38
39
# File 'lib/mint/resource.rb', line 37

def source_directory_path
  source_file_path.dirname
end

#source_fileObject



33
34
35
# File 'lib/mint/resource.rb', line 33

def source_file
  source_file_path.to_s
end

#source_file_pathObject



27
28
29
30
31
# File 'lib/mint/resource.rb', line 27

def source_file_path
  path = Pathname.new(source)
  path.absolute? ? 
    path.expand_path : root_directory_path + path
end