<commit_before># encoding: UTF-8

# Copyright 2012-2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'socket'
require 'net/http'

require 'sinatra/base'
require 'sass'
require 'coffee-script'

module Ki

  class WebContext
    attr_accessor :ki_home
    attr_accessor :development
    attr_chain :started, -> { Time.now.to_i }
    attr_chain :resource_hash, -> { started.to_s(16) }
  end

  module KiWebBase
    def web_ctx
      RackCommand.web_ctx
    end

    def ki_home
      web_ctx.ki_home
    end

    def res_url(path)
      if path.include?("..")
        raise "File '#{path}' cannot reference parent directories with '..'!"
      end
      "/file/web/#{ RackCommand.web_ctx.resource_hash}/#{self.class.name}:#{path}"
    end
  end

  # When starting up, looks for /web extension classes loaded from ki-scripts and starts up a web site
  #    class MyApp2 < Sinatra::Base
  #      get '/' do
  #        "MyApp2"
  #      end
  #    end
  #    KiCommand.register("/web/test", MyApp2)<commit_msg>KiWebBase.res_url supports other classes<commit_after># encoding: UTF-8

# Copyright 2012-2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'socket'
require 'net/http'

require 'sinatra/base'
require 'sass'
require 'coffee-script'

module Ki

  class WebContext
    attr_accessor :ki_home
    attr_accessor :development
    attr_chain :started, -> { Time.now.to_i }
    attr_chain :resource_hash, -> { started.to_s(16) }
  end

  module KiWebBase
    def web_ctx
      RackCommand.web_ctx
    end

    def ki_home
      web_ctx.ki_home
    end

    def res_url(path, clazz = self.class)
      if path.include?("..")
        raise "File '#{path}' cannot reference parent directories with '..'!"
      end
      "/file/web/#{ RackCommand.web_ctx.resource_hash}/#{clazz.name}:#{path}"
    end
  end

  # When starting up, looks for /web extension classes loaded from ki-scripts and starts up a web site
  #    class MyApp2 < Sinatra::Base
  #      get '/' do
  #        "MyApp2"
  #      end
  #    end
  #    KiCommand.register("/web/test", MyApp2)
{'fraction_non_alphanumeric': 0.09701492537313433, 'fraction_numerical': 0.011680726800778715, 'mean_word_length': 3.0997340425531914, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '190844', 'n_tokens_mistral': 973, 'n_tokens_neox': 934, 'n_words': 332}