<commit_before>module Tlaloc

export Page,render,addArg,setViewDir,setTemplateDir,viewDir,templateDir

global viewDir = "/"
global templateDir = "/"

keywords = ["extends"] #We'll later add for, endfor, etc...

#Type Page
type Page
  view::ASCIIString # Contains body
  args::Dict # Arguments sent by Julia that need to be added into the body
  #Constructor
  function Page(view::ASCIIString,args::Dict)
    new(view,args)
  end
end

# Adds arguments to page
function addArg(page::Page,name::ASCIIString,value::ASCIIString)
  push!(page.args,(name=>value))
end

# This function parses the view by adding the defined variables into the HTML
function parseView(page::Page)
  response = open(readall,string(viewDir,page.view))
  difference = 0 # We need this because eachMatch collects all the match and then treats them, which means the data concerning indexes starting from the second match needs to be adjusted
  for match in eachmatch(r"\$\{([a-zA-Z0-9_]+)\}",content)
    hasKeyword = false
    if ismatch(r" ",match.match)
      # If there's a space, they probably are keywords, so we'll try to find them
      for keyword in keywords
        if keyword == (match.match)[1:(match(r" ",match.match).offset)]
          hasKeyword = true
          break
        end
      end
    end
    if hasKeyword
      #Then we'll treat it
    elseif isdefined(symbol((match.match)[3:end-1]))
      var = @eval ($(symbol((match.match)[3:end-1])))
      response = string(response[1:(match.offset)-1 + difference],var,response[((match.offset)+difference+(length(match.match))):end] )
      difference = difference + length(var) - length(match.match)
    elseif haskey(page.args,(match.match)[3:end-1])
      var = (page.args)[(match.match)[3:end-1]]
      response = string(response[1:(match.offset)-1 + difference],var,response[((match.offset)+difference+(length(match.match))):end] )
      difference = difference + length(var) - length(match.match)
    end
  end<commit_msg>Temp change<commit_after>module Tlaloc

export Page,render,addArg

keywords = ["extends"] #We'll later add for, endfor, etc...

#Type Page
type Page
  view::ASCIIString # Contains body
  args::Dict # Arguments sent by Julia that need to be added into the body
  #Constructor
  function Page(view::ASCIIString,args::Dict)
    new(view,args)
  end
end

# Adds arguments to page
function addArg(page::Page,name::ASCIIString,value::ASCIIString)
  push!(page.args,(name=>value))
end

# This function parses the view by adding the defined variables into the HTML
function parseView(page::Page)
  response = open(readall,(page.view))
  difference = 0 # We need this because eachMatch collects all the match and then treats them, which means the data concerning indexes starting from the second match needs to be adjusted
  for match in eachmatch(r"\$\{([a-zA-Z0-9_]+)\}",content)
    hasKeyword = false
    if ismatch(r" ",match.match)
      # If there's a space, they probably are keywords, so we'll try to find them
      for keyword in keywords
        if keyword == (match.match)[1:(match(r" ",match.match).offset)]
          hasKeyword = true
          break
        end
      end
    end
    if hasKeyword
      #Then we'll treat it
    elseif isdefined(symbol((match.match)[3:end-1]))
      var = @eval ($(symbol((match.match)[3:end-1])))
      response = string(response[1:(match.offset)-1 + difference],var,response[((match.offset)+difference+(length(match.match))):end] )
      difference = difference + length(var) - length(match.match)
    elseif haskey(page.args,(match.match)[3:end-1])
      var = (page.args)[(match.match)[3:end-1]]
      response = string(response[1:(match.offset)-1 + difference],var,response[((match.offset)+difference+(length(match.match))):end] )
      difference = difference + length(var) - length(match.match)
    end
  end
{'fraction_non_alphanumeric': 0.1311175085056268, 'fraction_numerical': 0.008374771002355404, 'mean_word_length': 3.996078431372549, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1944903', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1149, 'n_words': 326}