You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: helpers.rb
    path of file: ./repos/gollum/lib/gollum
    
    the code of the file until where you have to start completion: # ~*~ encoding: utf-8 ~*~
require 'gemojione'

module Precious
  module Helpers

    EMOJI_PATHNAME = Pathname.new(Gemojione.images_path).freeze
    
    def find_per_page_upload_subdir(referer, host_with_port, base_path)
      base =
    
    def find_per_page_upload_subdir(referer, host_with_port, base_path)
      base = base_path ? remove_leading_and_trailing_slashes(base_path) : ''
      dir = referer.match(/^https?:\/\/#{host_with_port}\/#{base}\/?(.*)/)[1]
      
      # remove gollum/* subpath if necessary
      dir.sub!(/^gollum\/[-\w]+\//, '')
      # remove file extension
      dir.sub!(/#{::File.extname(dir)}$/, '')
      # revert escaped whitespaces
      dir.gsub!(/%20/, ' ')
      
      return ::File.join('uploads', dir)
    end