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, root: nil, destination: nil, context: nil, name: nil) {|_self| ... } ⇒ Resource

Returns a new instance of Resource.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(source, root: nil, destination: nil, context: nil, name: nil, &block)
  return nil unless source

  self.type = :resource
  self.source = source
  self.root = root || source_directory
  self.destination = destination
  self.context = context

  yield self if block

  self.name = name || Mint.guess_name_from(source)
  self.renderer = Mint.renderer source
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



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

def context
  @context
end

#destinationObject

Returns the value of attribute destination.



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

def destination
  @destination
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/mint/resource.rb', line 9

def name
  @name
end

#rootObject

Returns the value of attribute root.



14
15
16
# File 'lib/mint/resource.rb', line 14

def root
  @root
end

#sourceObject

Returns the value of attribute source.



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

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



61
62
63
# File 'lib/mint/resource.rb', line 61

def destination_directory
  destination_directory_path.to_s
end

#destination_directory_pathObject



57
58
59
# File 'lib/mint/resource.rb', line 57

def destination_directory_path
  destination_file_path.dirname
end

#destination_fileObject



53
54
55
# File 'lib/mint/resource.rb', line 53

def destination_file
  destination_file_path.to_s
end

#destination_file_pathObject



49
50
51
# File 'lib/mint/resource.rb', line 49

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

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



84
85
86
# File 'lib/mint/resource.rb', line 84

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

#publish!(opts = {}) ⇒ Object



94
95
96
97
98
99
# File 'lib/mint/resource.rb', line 94

def publish!(opts={})
  FileUtils.mkdir_p self.destination_directory
  File.open(self.destination_file, "w+") do |f|
    f << self.render
  end
end

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



89
90
91
92
# File 'lib/mint/resource.rb', line 89

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

#renderer=(renderer) ⇒ Object



65
66
67
# File 'lib/mint/resource.rb', line 65

def renderer=(renderer)
  @renderer = renderer
end

#root_directoryObject



23
24
25
# File 'lib/mint/resource.rb', line 23

def root_directory
  root_directory_path.to_s
end

#root_directory_pathObject



19
20
21
# File 'lib/mint/resource.rb', line 19

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

#source_directoryObject



43
44
45
# File 'lib/mint/resource.rb', line 43

def source_directory
  source_directory_path.to_s
end

#source_directory_pathObject



39
40
41
# File 'lib/mint/resource.rb', line 39

def source_directory_path
  source_file_path.dirname
end

#source_fileObject



35
36
37
# File 'lib/mint/resource.rb', line 35

def source_file
  source_file_path.to_s
end

#source_file_pathObject



29
30
31
32
33
# File 'lib/mint/resource.rb', line 29

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