Class: Awestruct::Extensions::Gsub

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/extensions/gsub.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern, replacement, options = {}) ⇒ Gsub

Returns a new instance of Gsub.



5
6
7
8
9
# File 'lib/awestruct/extensions/gsub.rb', line 5

def initialize(pattern, replacement, options = {})
  @pattern = pattern
  @replacement = replacement
  @gsub_required = options[:gsub_required] || lambda { |site, page| page.output_path.end_with?(".html") }
end

Instance Method Details

#transform(site, page, rendered) ⇒ Object



11
12
13
14
15
16
# File 'lib/awestruct/extensions/gsub.rb', line 11

def transform(site, page, rendered)
  if (@gsub_required.call(site, page))
    rendered = rendered.gsub(@pattern, @replacement)
  end
  rendered
end