<commit_before>define (require) ->
  $ = require('jquery')
  _ = require('underscore')
  Backbone = require('backbone')
  settings = require('settings')
  linksHelper = require('cs!helpers/links.coffee')

  dispose = (obj) ->
    delete obj.parent
    delete obj.el
    delete obj.$el
    delete obj.regions

  class Region
    constructor: (@el, @parent) ->

    show: (view) ->
      @empty()
      @append(view)

    append: (view) ->
      @appendAs('div', view)

    appendOnce: (options) ->
      if not (_.find @views, (view) -> options.view instanceof view.constructor)
        if options.as.charAt(0) is '.'
          @appendAs("div class=\"#{options.as.substr(1)}\"", options.view)
        else if options.as.charAt(0) is '#'
          @appendAs("div id=\"#{options.as.substr(1)}\"", options.view)
        else
          @appendAs(options.as, options.view)

    appendAs: (type, view) ->
      @$el = @parent.$el
      if @el then @$el = @parent.$el.find(@el)
      view.parent = @parent
      @views ?= []
      @views.push(view)
      view.setElement($("<#{type}>").appendTo(@$el)).render()
      view.onShow()

    empty: () ->
      _.each @views, (view) ->
        view.close()

      @$el?.empty()
      @$el = null
      @views = null

    close: () ->
      @empty()
      dispose(@)

  class Regions
    constructor: (regions = {}, $context) ->
      _.each _.keys(regions), (region) =>
        @[region] = new Region(regions[region], $context)

      # Add a self-referential region to attach views to
      @self = new Region(null, $context)

  return class BaseView extends Backbone.View
    initialize: () ->
      @regions = new Regions(@regions, @)

    renderDom: () ->
      @$el?.html(@getTemplate())

    # Update page title, canonical link and Open Graph tags
    updatePageInfo: () ->
      currentPage = @model.getPageNumber().toString() if @model? and @model.isBook?()
      if Backbone.history.fragment? and linksHelper.getCurrentPathComponents().page?
        historyPage = linksHelper.getCurrentPathComponents().page
      if @pageTitle
        # If it's a page in a book
        if currentPage? and historyPage?
          if currentPage is historyPage or currentPage is '1' and historyPage is ''
            document.title = @pageTitle + settings.titleSuffix
        else
          document.title = @pageTitle + settings.titleSuffix<commit_msg>Fixed updatePageInfo checks to pass test<commit_after>define (require) ->
  $ = require('jquery')
  _ = require('underscore')
  Backbone = require('backbone')
  settings = require('settings')
  linksHelper = require('cs!helpers/links.coffee')

  dispose = (obj) ->
    delete obj.parent
    delete obj.el
    delete obj.$el
    delete obj.regions

  class Region
    constructor: (@el, @parent) ->

    show: (view) ->
      @empty()
      @append(view)

    append: (view) ->
      @appendAs('div', view)

    appendOnce: (options) ->
      if not (_.find @views, (view) -> options.view instanceof view.constructor)
        if options.as.charAt(0) is '.'
          @appendAs("div class=\"#{options.as.substr(1)}\"", options.view)
        else if options.as.charAt(0) is '#'
          @appendAs("div id=\"#{options.as.substr(1)}\"", options.view)
        else
          @appendAs(options.as, options.view)

    appendAs: (type, view) ->
      @$el = @parent.$el
      if @el then @$el = @parent.$el.find(@el)
      view.parent = @parent
      @views ?= []
      @views.push(view)
      view.setElement($("<#{type}>").appendTo(@$el)).render()
      view.onShow()

    empty: () ->
      _.each @views, (view) ->
        view.close()

      @$el?.empty()
      @$el = null
      @views = null

    close: () ->
      @empty()
      dispose(@)

  class Regions
    constructor: (regions = {}, $context) ->
      _.each _.keys(regions), (region) =>
        @[region] = new Region(regions[region], $context)

      # Add a self-referential region to attach views to
      @self = new Region(null, $context)

  return class BaseView extends Backbone.View
    initialize: () ->
      @regions = new Regions(@regions, @)

    renderDom: () ->
      @$el?.html(@getTemplate())

    # Update page title, canonical link and Open Graph tags
    updatePageInfo: () ->
      currentPage = @model.getPageNumber().toString() if @model? and @model.isBook?()
      if Backbone.history.fragment?.match? and linksHelper.getCurrentPathComponents().page?
        historyPage = linksHelper.getCurrentPathComponents().page
      if @pageTitle
        # If it's a page in a book
        if currentPage? and historyPage?
          if currentPage is historyPage or currentPage is '1' and historyPage is ''
            document.title = @pageTitle + settings.titleSuffix
        else
          document.title = @pageTitle + settings.titleSuffix
{'fraction_non_alphanumeric': 0.15221017514595497, 'fraction_numerical': 0.002085070892410342, 'mean_word_length': 2.5091441111923922, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '3623246', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1443, 'n_words': 356}