Class: Mint::Resource
- Inherits:
-
Object
- Object
- Mint::Resource
- Defined in:
- lib/mint/resource.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#name ⇒ Object
Returns the value of attribute name.
-
#root ⇒ Object
Returns the value of attribute root.
-
#source ⇒ Object
Returns the value of attribute source.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #destination_directory ⇒ Object
- #destination_directory_path ⇒ Object
- #destination_file ⇒ Object
- #destination_file_path ⇒ Object
- #equal?(other) ⇒ Boolean (also: #==)
-
#initialize(source, root: nil, destination: nil, context: nil, name: nil) {|_self| ... } ⇒ Resource
constructor
A new instance of Resource.
- #publish!(opts = {}) ⇒ Object
- #render(context = self, args = {}) ⇒ Object
- #renderer=(renderer) ⇒ Object
- #root_directory ⇒ Object
- #root_directory_path ⇒ Object
- #source_directory ⇒ Object
- #source_directory_path ⇒ Object
- #source_file ⇒ Object
- #source_file_path ⇒ Object
Constructor Details
#initialize(source, root: nil, destination: nil, context: nil, name: nil) {|_self| ... } ⇒ Resource
Returns a new instance of Resource.
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
#context ⇒ Object
Returns the value of attribute context.
7 8 9 |
# File 'lib/mint/resource.rb', line 7 def context @context end |
#destination ⇒ Object
Returns the value of attribute destination.
47 48 49 |
# File 'lib/mint/resource.rb', line 47 def destination @destination end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/mint/resource.rb', line 9 def name @name end |
#root ⇒ Object
Returns the value of attribute root.
14 15 16 |
# File 'lib/mint/resource.rb', line 14 def root @root end |
#source ⇒ Object
Returns the value of attribute source.
27 28 29 |
# File 'lib/mint/resource.rb', line 27 def source @source end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/mint/resource.rb', line 5 def type @type end |
Instance Method Details
#destination_directory ⇒ Object
61 62 63 |
# File 'lib/mint/resource.rb', line 61 def destination_directory destination_directory_path.to_s end |
#destination_directory_path ⇒ Object
57 58 59 |
# File 'lib/mint/resource.rb', line 57 def destination_directory_path destination_file_path.dirname end |
#destination_file ⇒ Object
53 54 55 |
# File 'lib/mint/resource.rb', line 53 def destination_file destination_file_path.to_s end |
#destination_file_path ⇒ Object
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_directory ⇒ Object
23 24 25 |
# File 'lib/mint/resource.rb', line 23 def root_directory root_directory_path.to_s end |
#root_directory_path ⇒ Object
19 20 21 |
# File 'lib/mint/resource.rb', line 19 def root_directory_path Pathname.new(root || Dir.getwd). end |
#source_directory ⇒ Object
43 44 45 |
# File 'lib/mint/resource.rb', line 43 def source_directory source_directory_path.to_s end |
#source_directory_path ⇒ Object
39 40 41 |
# File 'lib/mint/resource.rb', line 39 def source_directory_path source_file_path.dirname end |
#source_file ⇒ Object
35 36 37 |
# File 'lib/mint/resource.rb', line 35 def source_file source_file_path.to_s end |
#source_file_path ⇒ Object
29 30 31 32 33 |
# File 'lib/mint/resource.rb', line 29 def source_file_path path = Pathname.new(source) path.absolute? ? path. : root_directory_path + path end |