<commit_before>queryParams = () ->
  res = {}
  params = window.location.search.substring(1).split("&")
  for p in params
    [k,v] = p.split("=")
    res[k] = v
  res

window.queryParams = queryParams

class CircleViewModel
  constructor: ->
    @ab = (new ABTests(ab_test_definitions)).ab_tests

window.CircleVM = new CircleViewModel

circle = $.sammy "body", ->

  # Page
  class Page
    constructor: (@name, @title) ->

    display: (cx) =>
      document.title = "Circle - " + @title

      # Render content
      @render(cx)

      # Land at the right anchor on the page
      @scroll window.location.hash

      # Fetch page-specific libraries
      @lib() if @lib?

      ko.applyBindings(CircleVM)

    render: (cx) =>
      $("body").attr("id","#{@name}-page").html HAML['header'](renderContext)
      $("body").append HAML[@name](renderContext)
      $("body").append HAML['footer'](renderContext)

    scroll: (hash) =>
      if hash == '' or hash == '#' then hash = "body"
      $('html, body').animate({scrollTop: $(hash).offset().top}, 0)


  class Home extends Page
    render: (cx) =>
      super(cx)
      _kmq.push(['trackClickOnOutboundLink', '#join', 'hero join link clicked'])
      _kmq.push(['trackClickOnOutboundLink', '.kissAuthGithub', 'join link clicked'])
      _kmq.push(['trackClickOnOutboundLink', '#second-join', 'footer join link clicked'])
      _kmq.push(['trackSubmit', '#beta', 'beta form submitted'])
      _gaq.push(['_trackPageview', '/homepage'])

  # Doc
  class Docs extends Page
    rewrite_old_name: (name) =>
      console.log name
      switch name
        when "/configuration" then "/reference/configuration"
        when "/configuration#overview" then "/reference/configuration#overview"
        when "/configuration#phases" then "/reference/configuration#phases"
        when "/configuration#machine" then "/reference/configuration#machine"
        when "/configuration#checkout" then "/reference/configuration#checkout"
        when "/configuration#dependencies" then "/reference/configuration#dependencies"
        when "/configuration#database" then "/reference/configuration#database"
        when "/configuration#test" then "/reference/configuration#test"
        when "/configuration#notify" then "/reference/configuration#notify"
        when "/configuration#deployment" then "/reference/configuration#deployment"

        when "/config-sample" then "/config_sample"
        when "/config-sample#overview" then "/config_sample#overview"
        when "/config-sample#sample" then "/config_sample#sample"

        when "/common-problems" then "/troubleshooting/common_problems"
        when "/common-problems#intro" then "/troubleshooting/common_problems"
        when "/common-problems#file-ordering" then "/file_ordering"
        when "/common-problems#missing-log-dir" then "/missing_log_dir"
        when "/common-problems#missing-file" then "/missing_file"
        when "/common-problems#time-day" then "/time_day"
        when "/common-problems#time-seconds" then "/time_seconds"
        when "/common-problems#requires-admin" then "/requires_admin"
        when "/common-problems#oom" then "/oom"
        when "/common-problems#wrong-ruby-version" then "/wrong_ruby_version"
        when "/common-problems#dont-run" then "/dont_run"
        when "/common-problems#git-bundle-install" then "/git_bundle_install"
        when "/common-problems#git-pip-install" then "/git_pip_install"
        when "/common-problems#wrong-commands" then "/wrong_commands"
        when "/common-problems#bundler-latest" then "/bundler_latest"
        when "/common-problems#capybara-timeout" then "/capybara_timeout"
        when "/common-problems#clojure-12" then "/clojure_12"

        when "/environment" then "/reference/environment"
        when "/environment#linux" then "/reference/environment#linux"
        when "/environment#env-vars" then "/reference/environment#env-vars"
        when "/environment#browsers" then "/reference/environment#browsers"
        when "/environment#languages" then "/reference/environment#languages"
        when "/environment#databases" then "/reference/environment#databases"

        when "/faq" then "/troubleshooting/common_problems"
        when "/faq#permissions" then "/permissions"
        when "/faq#what-happens" then "/what_happens"
        when "/faq#look-at-code" then "/look_at_code"
        when "/faq#parallelism" then "/parallelism"
        when "/faq#versions" then "/reference/environment"
        when "/faq#external-resources" then "/external_resources"
        when "/faq#cant-follow" then "/cant_follow"

        when "/manually" then "/getting_started/manually"
        when "/manually#standard" then "/getting_started/manually#standard"
        when "/manually#overview" then "/getting_started/manually#overview"
        when "/manually#circle-yml" then "/getting_started/manually#circle-yml"
        when "/manually#machine" then "/getting_started/manually#machine"
        when "/manually#checkout" then "/getting_started/manually#checkout"
        when "/manually#dependencies" then "/getting_started/manually#dependencies"
        when "/manually#databases" then "/getting_started/manually#databases"
        when "/manually#tests" then "/getting_started/manually#tests"
        when "/manually#next" then "/getting_started/manually#next"

        when "/getting-started" then "/getting_started/general"
        when "/getting-started#overview" then "/getting_started/general#overview"
        when "/getting-started#what-next" then "/getting_started/general#what-next"

        else false

    filename: (cx) =>
      name = cx.params.splat[0]
      if name
        name.replace(/^\//, '').replace(/\//g, '_').replace(/#.*/, '')
      else
        "docs"

    article_info: (slug) =>
      node = $(window.HAML[slug]())
      {
        url: "/docs/#{slug}",
        slug: slug,
        title: node.find('.title > h1').text().trim()
        subtitle: node.find('.title > h4').text().trim()
        icon: node.find('.title > h1 > i').attr('class')
      }

    find_articles_by_tag: (tag) =>
      articles = []
      for slug of HAML
        article_tags = null

        try
          ## a bit of a hack: tagged article templates are expected to *write* into their context,
          ## and here we read what's written.<commit_msg>hyphens in urls<commit_after>queryParams = () ->
  res = {}
  params = window.location.search.substring(1).split("&")
  for p in params
    [k,v] = p.split("=")
    res[k] = v
  res

window.queryParams = queryParams

class CircleViewModel
  constructor: ->
    @ab = (new ABTests(ab_test_definitions)).ab_tests

window.CircleVM = new CircleViewModel

circle = $.sammy "body", ->

  # Page
  class Page
    constructor: (@name, @title) ->

    display: (cx) =>
      document.title = "Circle - " + @title

      # Render content
      @render(cx)

      # Land at the right anchor on the page
      @scroll window.location.hash

      # Fetch page-specific libraries
      @lib() if @lib?

      ko.applyBindings(CircleVM)

    render: (cx) =>
      $("body").attr("id","#{@name}-page").html HAML['header'](renderContext)
      $("body").append HAML[@name](renderContext)
      $("body").append HAML['footer'](renderContext)

    scroll: (hash) =>
      if hash == '' or hash == '#' then hash = "body"
      $('html, body').animate({scrollTop: $(hash).offset().top}, 0)


  class Home extends Page
    render: (cx) =>
      super(cx)
      _kmq.push(['trackClickOnOutboundLink', '#join', 'hero join link clicked'])
      _kmq.push(['trackClickOnOutboundLink', '.kissAuthGithub', 'join link clicked'])
      _kmq.push(['trackClickOnOutboundLink', '#second-join', 'footer join link clicked'])
      _kmq.push(['trackSubmit', '#beta', 'beta form submitted'])
      _gaq.push(['_trackPageview', '/homepage'])

  # Doc
  class Docs extends Page
    rewrite_old_name: (name) =>
      console.log name
      switch name
        when "/configuration" then "/reference/configuration"
        when "/configuration#overview" then "/reference/configuration#overview"
        when "/configuration#phases" then "/reference/configuration#phases"
        when "/configuration#machine" then "/reference/configuration#machine"
        when "/configuration#checkout" then "/reference/configuration#checkout"
        when "/configuration#dependencies" then "/reference/configuration#dependencies"
        when "/configuration#database" then "/reference/configuration#database"
        when "/configuration#test" then "/reference/configuration#test"
        when "/configuration#notify" then "/reference/configuration#notify"
        when "/configuration#deployment" then "/reference/configuration#deployment"

        when "/config-sample" then "/config_sample"
        when "/config-sample#overview" then "/config_sample#overview"
        when "/config-sample#sample" then "/config_sample#sample"

        when "/common-problems" then "/troubleshooting/common_problems"
        when "/common-problems#intro" then "/troubleshooting/common_problems"
        when "/common-problems#file-ordering" then "/file_ordering"
        when "/common-problems#missing-log-dir" then "/missing_log_dir"
        when "/common-problems#missing-file" then "/missing_file"
        when "/common-problems#time-day" then "/time_day"
        when "/common-problems#time-seconds" then "/time_seconds"
        when "/common-problems#requires-admin" then "/requires_admin"
        when "/common-problems#oom" then "/oom"
        when "/common-problems#wrong-ruby-version" then "/wrong_ruby_version"
        when "/common-problems#dont-run" then "/dont_run"
        when "/common-problems#git-bundle-install" then "/git_bundle_install"
        when "/common-problems#git-pip-install" then "/git_pip_install"
        when "/common-problems#wrong-commands" then "/wrong_commands"
        when "/common-problems#bundler-latest" then "/bundler_latest"
        when "/common-problems#capybara-timeout" then "/capybara_timeout"
        when "/common-problems#clojure-12" then "/clojure_12"

        when "/environment" then "/reference/environment"
        when "/environment#linux" then "/reference/environment#linux"
        when "/environment#env-vars" then "/reference/environment#env-vars"
        when "/environment#browsers" then "/reference/environment#browsers"
        when "/environment#languages" then "/reference/environment#languages"
        when "/environment#databases" then "/reference/environment#databases"

        when "/faq" then "/troubleshooting/common_problems"
        when "/faq#permissions" then "/permissions"
        when "/faq#what-happens" then "/what_happens"
        when "/faq#look-at-code" then "/look_at_code"
        when "/faq#parallelism" then "/parallelism"
        when "/faq#versions" then "/reference/environment"
        when "/faq#external-resources" then "/external_resources"
        when "/faq#cant-follow" then "/cant_follow"

        when "/manually" then "/getting_started/manually"
        when "/manually#standard" then "/getting_started/manually#standard"
        when "/manually#overview" then "/getting_started/manually#overview"
        when "/manually#circle-yml" then "/getting_started/manually#circle-yml"
        when "/manually#machine" then "/getting_started/manually#machine"
        when "/manually#checkout" then "/getting_started/manually#checkout"
        when "/manually#dependencies" then "/getting_started/manually#dependencies"
        when "/manually#databases" then "/getting_started/manually#databases"
        when "/manually#tests" then "/getting_started/manually#tests"
        when "/manually#next" then "/getting_started/manually#next"

        when "/getting-started" then "/getting_started/general"
        when "/getting-started#overview" then "/getting_started/general#overview"
        when "/getting-started#what-next" then "/getting_started/general#what-next"

        else false

    filename: (cx) =>
      name = cx.params.splat[0]
      if name
        name.replace(/^\//, '').replace(/\//g, '_').replace(/-/g, '_').replace(/#.*/, '')
      else
        "docs"

    article_info: (slug) =>
      node = $(window.HAML[slug]())
      uriFragment = slug.replace(/_/g, '-')
      {
        url: "/docs/#{uriFragment}",
        slug: slug,
        title: node.find('.title > h1').text().trim()
        subtitle: node.find('.title > h4').text().trim()
        icon: node.find('.title > h1 > i').attr('class')
      }

    find_articles_by_tag: (tag) =>
      articles = []
      for slug of HAML
        article_tags = null

        try
          ## a bit of a hack: tagged article templates are expected to *write* into their context,
          ## and here we read what's written.
{'fraction_non_alphanumeric': 0.1433385579937304, 'fraction_numerical': 0.001567398119122257, 'mean_word_length': 3.0848271446862996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '3573295', 'n_tokens_mistral': 3910, 'n_tokens_neox': 3670, 'n_words': 826}