class Rack::App::FrontEnd::FolderMounter

Constants

LAST_MODIFIED_HEADER

Public Class Methods

new(app_class) click to toggle source
# File lib/rack/app/front_end/folder_mounter.rb, line 5
def initialize(app_class)
  @app_class = app_class
end

Public Instance Methods

mount(absolute_folder_path) click to toggle source
# File lib/rack/app/front_end/folder_mounter.rb, line 9
def mount(absolute_folder_path)
  template_paths_for(absolute_folder_path).each do |template_path|

    request_path = request_path_by(absolute_folder_path, template_path)
    create_endpoint_for(request_path, template_path)

  end
end

Protected Instance Methods

create_endpoint_for(request_path, template_path) click to toggle source
# File lib/rack/app/front_end/folder_mounter.rb, line 24
def create_endpoint_for(request_path, template_path)
  @app_class.class_eval do

    get(request_path) do
      render(template_path)
    end

  end
end
request_path_by(source_folder_path, template_path) click to toggle source
# File lib/rack/app/front_end/folder_mounter.rb, line 34
def request_path_by(source_folder_path, template_path)
  Rack::Utils.clean_path_info(template_path.sub(source_folder_path, '').sub(/\..*$/, ''))
end
template_paths_for(source_folder_path) click to toggle source
# File lib/rack/app/front_end/folder_mounter.rb, line 20
def template_paths_for(source_folder_path)
  Dir.glob(File.join(source_folder_path, '**', '*')).select { |p| not File.directory?(p) }
end