<commit_before>Spine ?= require('spine')
$      = Spine.$

hashStrip    = /^#*/
namedParam   = /:([\w\d]+)/g
splatParam   = /\*([\w\d]+)/g
escapeRegExp = /[-[\]{}()+?.,\\^$|#\s]/g

class Spine.Route extends Spine.Module
  @extend Spine.Events
  
  @historySupport: window.history?.pushState?
  
  @routes: []
        
  @options:
    trigger: true
    history: false
    shim: false
        
  @add: (path, callback) ->
    if (typeof path is "object" and path not instanceof RegExp)
      @add(key, value) for key, value of path
    else
      @routes.push(new @(path, callback))
    
  @setup: (options = {}) ->
    @options = $.extend({}, @options, options)
      
    if (@options.history)
      @history = @historySupport && @options.history
      
    return if @options.shim
        
    if @history 
      $(window).bind("popstate", @change)
    else
      $(window).bind("hashchange", @change)
    @change() 
    
  @unbind: ->
    if @history
      $(window).unbind("popstate", @change)
    else
      $(window).unbind("hashchange", @change)
    
  @navigate: (args...) ->
    options = {}
    
    lastArg = args[args.length - 1]
    if typeof lastArg is "object"
      options = args.pop()
    else if typeof lastArg is "boolean"
      options.trigger = args.pop()
    
    options = $.extend({}, @options, options)
    
    path = args.join("/")
    return if @path is path
    @path = path

    @trigger("navigate", @path)

    @matchRoute(@path, options) if options.trigger

    return if options.shim
    
    if @history
      history.pushState(
        {}, 
        document.title, 
        @path
      )
    else
      window.location.hash = @path
    
  # Private
  
  @getPath: -> if window.location.pathname.substr(0,1) is '/' then window.location.pathname else '/' + window.location.pathname<commit_msg>rewrote @getPath() to multiple lines<commit_after>Spine ?= require('spine')
$      = Spine.$

hashStrip    = /^#*/
namedParam   = /:([\w\d]+)/g
splatParam   = /\*([\w\d]+)/g
escapeRegExp = /[-[\]{}()+?.,\\^$|#\s]/g

class Spine.Route extends Spine.Module
  @extend Spine.Events
  
  @historySupport: window.history?.pushState?
  
  @routes: []
        
  @options:
    trigger: true
    history: false
    shim: false
        
  @add: (path, callback) ->
    if (typeof path is "object" and path not instanceof RegExp)
      @add(key, value) for key, value of path
    else
      @routes.push(new @(path, callback))
    
  @setup: (options = {}) ->
    @options = $.extend({}, @options, options)
      
    if (@options.history)
      @history = @historySupport && @options.history
      
    return if @options.shim
        
    if @history 
      $(window).bind("popstate", @change)
    else
      $(window).bind("hashchange", @change)
    @change() 
    
  @unbind: ->
    if @history
      $(window).unbind("popstate", @change)
    else
      $(window).unbind("hashchange", @change)
    
  @navigate: (args...) ->
    options = {}
    
    lastArg = args[args.length - 1]
    if typeof lastArg is "object"
      options = args.pop()
    else if typeof lastArg is "boolean"
      options.trigger = args.pop()
    
    options = $.extend({}, @options, options)
    
    path = args.join("/")
    return if @path is path
    @path = path

    @trigger("navigate", @path)

    @matchRoute(@path, options) if options.trigger

    return if options.shim
    
    if @history
      history.pushState(
        {}, 
        document.title, 
        @path
      )
    else
      window.location.hash = @path
    
  # Private
  
  @getPath: -> 
    path = window.location.pathname
    if path.substr(0,1) isnt '/' 
      path = '/' + path
    path
{'fraction_non_alphanumeric': 0.1590289143480633, 'fraction_numerical': 0.0016366612111292963, 'mean_word_length': 2.1503436426116838, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6464014', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1212, 'n_words': 284}