lib/roboto/content_provider.rb in roboto-0.0.2 vs lib/roboto/content_provider.rb in roboto-0.1.0

- old
+ new

@@ -1,12 +1,20 @@ +require 'erb' + module Roboto #provides the content of effective robots.txt file class ContentProvider # Reads the contents of the effective robots.txt file # @return [String] the contents of the effective robots.txt file - def contents - @contents ||= File.read(path) + def contents(custom_binding = nil) + return @contents unless @contents.nil? + + @contents = File.read(path) + if path.extname == '.erb' + @contents = ERB.new(@contents).result(custom_binding ? custom_binding : binding) + end + @contents end # Determines the most relevant robots.txt file. # # It checks for the paths in the following order @@ -28,10 +36,12 @@ protected def lookup_paths [ Rails.root.join("config/robots/#{Rails.env}.txt"), + Rails.root.join("config/robots/#{Rails.env}.txt.erb"), Rails.root.join(relative_path_to_default), + Rails.root.join("#{relative_path_to_default}.erb"), Roboto::Engine.root.join(relative_path_to_default) ] end def relative_path_to_default