Class: Bridgetown::Resource::Destination
- Inherits:
-
Object
- Object
- Bridgetown::Resource::Destination
- Defined in:
- bridgetown-core/lib/bridgetown-core/resource/destination.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#absolute_url ⇒ Object
-
#final_ext ⇒ Object
-
#initialize(resource) ⇒ Destination
constructor
A new instance of Destination.
-
#output_path ⇒ Object
-
#relative_url ⇒ Object
-
#write(output) ⇒ Object
Constructor Details
#initialize(resource) ⇒ Destination
Returns a new instance of Destination.
13 14 15 16 17 |
# File 'bridgetown-core/lib/bridgetown-core/resource/destination.rb', line 13 def initialize(resource) @resource = resource warn_on_rails_style_extension @output_ext = resource.transformer.final_ext end |
Instance Attribute Details
#output_ext ⇒ String
10 11 12 |
# File 'bridgetown-core/lib/bridgetown-core/resource/destination.rb', line 10 def output_ext @output_ext end |
#resource ⇒ Bridgetown::Resource::Base
7 8 9 |
# File 'bridgetown-core/lib/bridgetown-core/resource/destination.rb', line 7 def resource @resource end |
Instance Method Details
#absolute_url ⇒ Object
19 20 21 22 23 |
# File 'bridgetown-core/lib/bridgetown-core/resource/destination.rb', line 19 def absolute_url Addressable::URI.parse( resource.site.config.url.to_s + relative_url ).normalize.to_s end |
#final_ext ⇒ Object
30 31 32 |
# File 'bridgetown-core/lib/bridgetown-core/resource/destination.rb', line 30 def final_ext output_ext || resource.extname end |
#output_path ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'bridgetown-core/lib/bridgetown-core/resource/destination.rb', line 34 def output_path path = Utils.unencode_uri(relative_url) if resource.site.base_path.present? path = path.delete_prefix resource.site.base_path(strip_slash_only: true) end path = resource.site.in_dest_dir(path) path = File.join(path, "index.html") if relative_url.end_with? "/" path end |
#relative_url ⇒ Object
25 26 27 28 |
# File 'bridgetown-core/lib/bridgetown-core/resource/destination.rb', line 25 def relative_url @processor ||= PermalinkProcessor.new(resource) @processor.transform end |
#write(output) ⇒ Object
44 45 46 47 48 49 |
# File 'bridgetown-core/lib/bridgetown-core/resource/destination.rb', line 44 def write(output) path = output_path FileUtils.mkdir_p(File.dirname(path)) Bridgetown.logger.debug "Writing:", path File.write(path, output, mode: "wb") end |