Class: Bridgetown::Resource::Transformer
- Inherits:
-
Object
- Object
- Bridgetown::Resource::Transformer
show all
- Includes:
- Transformable
- Defined in:
- lib/bridgetown-core/resource/transformer.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#transform_content, #transform_with_layout
Constructor Details
#initialize(resource) ⇒ Transformer
Returns a new instance of Transformer.
17
18
19
20
21
|
# File 'lib/bridgetown-core/resource/transformer.rb', line 17
def initialize(resource)
@resource = resource
@site = resource.site
@conversions = []
end
|
Instance Attribute Details
#conversions ⇒ Array<Hash>
9
10
11
|
# File 'lib/bridgetown-core/resource/transformer.rb', line 9
def conversions
@conversions
end
|
12
13
14
|
# File 'lib/bridgetown-core/resource/transformer.rb', line 12
def resource
@resource
end
|
15
16
17
|
# File 'lib/bridgetown-core/resource/transformer.rb', line 15
def site
@site
end
|
Instance Method Details
#execute_inline_ruby! ⇒ Object
#final_ext ⇒ String
29
30
31
32
33
|
# File 'lib/bridgetown-core/resource/transformer.rb', line 29
def final_ext
output_ext
permalink_ext || output_ext
end
|
#inspect ⇒ Object
57
58
59
|
# File 'lib/bridgetown-core/resource/transformer.rb', line 57
def inspect
"#<#{self.class} Conversion Steps: #{conversions.length}>"
end
|
#output_ext ⇒ String
24
25
26
|
# File 'lib/bridgetown-core/resource/transformer.rb', line 24
def output_ext
@output_ext ||= output_ext_from_converters
end
|
#process! ⇒ Object
rubocop:disable Metrics/AbcSize
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/bridgetown-core/resource/transformer.rb', line 35
def process! Bridgetown.logger.debug "Transforming:", resource.relative_path
resource.around_hook :render do
resource.content = transform_content(resource) do |converter, index, output|
conversions[index] = {
type: :content,
converter:,
output: Bridgetown.env.production? ? nil : output,
output_ext: conversions[index]&.dig(:output_ext) ||
converter.output_ext(resource.extname),
}
end
resource.place_in_layout? ? place_into_layouts : resource.output = resource.content.dup
end
end
|