Sha256: 82f22918382c5ddd28d87345a4248296fea6a1f7f8227813acaa82a5b2f58dcd

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Frozen
  module Rack
    class RequestController
      attr_accessor :site
      def initialize(site)
        @site = site
      end
      def call(env)
        file_path = env["PATH_INFO"]
        engine = get_stylesheet(file_path) if get_stylesheet(file_path)
        engine = get_view(file_path) if get_view(file_path)
        engine = get_javascript(file_path) if get_javascript(file_path)
        return [200, {"Content-Type" => "text/html"}, [engine.render]]
      end
      def get_stylesheet(file_path)
        site.stylesheets.find { |s|
          s.build_file_path == file_path.sub(/^\//,'')
        }
      end
      def get_view(file_path)
        site.views.find { |v|
          v.build_file_path ==  file_path.sub(/^\//,'') ||
            v.build_file_path == File.join(file_path, "index.html").sub(/^\//,'')
        }
      end

      def get_javascript(file_path)
        site.javascripts.find { |v|
          site.javascripts.find { |i|
            i.build_file_path == file_path.sub(/^\//,'')
          }
        }
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frozen-0.0.1 lib/frozen/rack/request_controller.rb