PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/awestruct/extensions/gsub.rb

https://github.com/bbrowning/awestruct
Ruby | 20 lines | 17 code | 3 blank | 0 comment | 2 complexity | 0fa3e158c48e7c0c96a13a5c62fa6a3a MD5 | raw file
  1. module Awestruct
  2. module Extensions
  3. class Gsub
  4. def initialize(pattern, replacement, options = {})
  5. @pattern = pattern
  6. @replacement = replacement
  7. @gsub_required = options[:gsub_required] || lambda { |site, page| page.output_path.end_with?(".html") }
  8. end
  9. def transform(site, page, rendered)
  10. if (@gsub_required.call(site, page))
  11. rendered = rendered.gsub(@pattern, @replacement)
  12. end
  13. rendered
  14. end
  15. end
  16. end
  17. end