<commit_before>--------------------------------------------------------------------------------
-- sailor.lua, v0.4.11: core functionalities of the framework
-- This file is a part of Sailor project
-- Copyright (c) 2014 <NAME> <<EMAIL>>
-- License: MIT
-- http://sailorproject.org
--------------------------------------------------------------------------------

local conf = require "conf.conf"
local remy = require "remy"

local sailor = {
    conf = conf.sailor,
    _COPYRIGHT = "Copyright (C) 2014-2015 <NAME>",
    _DESCRIPTION = "Sailor is a framework for creating MVC web applications.",
    _VERSION = "Sailor 0.4.11",
}

-- Loads Lua@client's settings from Sailor conf.
-- If lua_at_client table is missing, use default Lua@client settings
local lp = require "web_utils.lp_ex"
lp.lat.conf.lua_at_client = conf.lua_at_client or require"latclient.conf".lua_at_client

local lfs = require "lfs"
local open,assert,loadstring,setfenv,load,random = io.open,assert,loadstring,setfenv,load,math.random
local match,tostring,gsub = string.match,tostring,string.gsub
local traceback,xpcall = debug.traceback,xpcall
local Page = {}
local httpd = {}

-- Cross-environment compatible launcher. Makes Sailor adapt to
-- different web server environments
function sailor.launch(native_request)
    if apr_table ~= nil then
        -- This is Apache with mod_lua
        -- Sets a handle function to be called by mod_lua
        httpd = apache2
        handle = sailor.handle_request
    else
        -- This is a non-Apache (such as Nginx, Lighttpd, etc) or
        -- Apache with CGILua or mod_pLua
        httpd = remy.httpd
        sailor.remy_mode = remy.init(sailor.remy_mode, native_request)
        remy.contentheader('text/html')
        remy.run(sailor.handle_request)
    end
end

function sailor.handle_request(r)
    r.content_type = "text/html"
    local page = sailor.init(r)
    return sailor.route(page)
end

function sailor.get_filename_path(r)
    local filename = r.uri:match( "([^/]+)$")
    return r.filename:match("^@?(.-)/"..filename.."$")
end

-- Stores the path of the application in sailor.path
function sailor.set_application_path(r)
    if sailor.remy_mode ~= nil then
        sailor.path = sailor.get_filename_path(r)
    else
        local dir = lfs.currentdir()
        if dir == '/' or not dir then
            sailor.path = sailor.get_filename_path(r)
        else
            sailor.path = dir
        end
    end
end

-- Encapsulates request_rec functions inside the Page object
-- Useful for posterior compatibility with other servers<commit_msg>Make set_application_path() simple again (compat fix for apache-win)<commit_after>--------------------------------------------------------------------------------
-- sailor.lua, v0.4.11: core functionalities of the framework
-- This file is a part of Sailor project
-- Copyright (c) 2014 <NAME> <<EMAIL>>
-- License: MIT
-- http://sailorproject.org
--------------------------------------------------------------------------------

local conf = require "conf.conf"
local remy = require "remy"

local sailor = {
    conf = conf.sailor,
    _COPYRIGHT = "Copyright (C) 2014-2015 <NAME>",
    _DESCRIPTION = "Sailor is a framework for creating MVC web applications.",
    _VERSION = "Sailor 0.4.11",
}

-- Loads Lua@client's settings from Sailor conf.
-- If lua_at_client table is missing, use default Lua@client settings
local lp = require "web_utils.lp_ex"
lp.lat.conf.lua_at_client = conf.lua_at_client or require"latclient.conf".lua_at_client

local lfs = require "lfs"
local open,assert,loadstring,setfenv,load,random = io.open,assert,loadstring,setfenv,load,math.random
local match,tostring,gsub = string.match,tostring,string.gsub
local traceback,xpcall = debug.traceback,xpcall
local Page = {}
local httpd = {}

-- Cross-environment compatible launcher. Makes Sailor adapt to
-- different web server environments
function sailor.launch(native_request)
    if apr_table ~= nil then
        -- This is Apache with mod_lua
        -- Sets a handle function to be called by mod_lua
        httpd = apache2
        handle = sailor.handle_request
    else
        -- This is a non-Apache (such as Nginx, Lighttpd, etc) or
        -- Apache with CGILua or mod_pLua
        httpd = remy.httpd
        sailor.remy_mode = remy.init(sailor.remy_mode, native_request)
        remy.contentheader('text/html')
        remy.run(sailor.handle_request)
    end
end

function sailor.handle_request(r)
    r.content_type = "text/html"
    local page = sailor.init(r)
    return sailor.route(page)
end

-- Stores the path of the application in sailor.path
function sailor.set_application_path(r)
    local filename = r.uri:match( "([^/]+)$")
    sailor.path = r.filename:match("^@?(.-)/"..filename.."$")
end

-- Encapsulates request_rec functions inside the Page object
-- Useful for posterior compatibility with other servers
{'fraction_non_alphanumeric': 0.16492735829752406, 'fraction_numerical': 0.008594229588704727, 'mean_word_length': 2.56268221574344, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4175972', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1461, 'n_words': 420}