<commit_before>module ProMotion
  module WebScreenModule

    attr_accessor :webview, :external_links, :detector_types, :scale_to_fit

    def screen_setup
      check_content_data
      self.external_links ||= false
      self.scale_to_fit ||= false
      self.detector_types ||= :none
    end

    def on_init
      if self.detector_types.is_a? Array
        detectors = UIDataDetectorTypeNone
        self.detector_types.each { |dt| detectors |= map_detector_symbol(dt) }
        self.detector_types = detectors
      else
        self.detector_types = map_detector_symbol(self.detector_types)
      end

      self.webview ||= add UIWebView.new, {
        frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height),
        delegate: self,
        data_detector_types: self.detector_types
      }
      self.webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
      self.webview.scalesPageToFit = self.scale_to_fit
      self.webview.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal
      set_initial_content
    end

    def web
      self.webview
    end

    def set_initial_content
      return unless self.respond_to?(:content)
      current_content = content
      content.is_a?(NSURL) ? open_url(current_content) : set_content(current_content)
    end

    def set_content(content)
      content_path = File.join(NSBundle.mainBundle.resourcePath, content)

      if File.exists? content_path
        content_string = File.read content_path
        content_base_url = NSURL.fileURLWithPath NSBundle.mainBundle.resourcePath

        self.web.loadHTMLString(convert_retina_images(content_string), baseURL:content_base_url)
      else
        # We assume the user wants to load an arbitrary string into the web view
        self.web.loadHTMLString(content, baseURL:nil)
      end
    end

    def open_url(url)
      request = NSURLRequest.requestWithURL(
        url.is_a?(NSURL) ? url : NSURL.URLWithString(url)
      )
      web.loadRequest request
    end

    def convert_retina_images(content)<commit_msg>remove multiple calls to content()<commit_after>module ProMotion
  module WebScreenModule

    attr_accessor :webview, :external_links, :detector_types, :scale_to_fit

    def screen_setup
      check_content_data
      self.external_links ||= false
      self.scale_to_fit ||= false
      self.detector_types ||= :none
    end

    def on_init
      if self.detector_types.is_a? Array
        detectors = UIDataDetectorTypeNone
        self.detector_types.each { |dt| detectors |= map_detector_symbol(dt) }
        self.detector_types = detectors
      else
        self.detector_types = map_detector_symbol(self.detector_types)
      end

      self.webview ||= add UIWebView.new, {
        frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height),
        delegate: self,
        data_detector_types: self.detector_types
      }
      self.webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
      self.webview.scalesPageToFit = self.scale_to_fit
      self.webview.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal
      set_initial_content
    end

    def web
      self.webview
    end

    def set_initial_content
      return unless self.respond_to?(:content)
      current_content = content
      current_content.is_a?(NSURL) ? open_url(current_content) : set_content(current_content)
    end

    def set_content(content)
      content_path = File.join(NSBundle.mainBundle.resourcePath, content)

      if File.exists? content_path
        content_string = File.read content_path
        content_base_url = NSURL.fileURLWithPath NSBundle.mainBundle.resourcePath

        self.web.loadHTMLString(convert_retina_images(content_string), baseURL:content_base_url)
      else
        # We assume the user wants to load an arbitrary string into the web view
        self.web.loadHTMLString(content, baseURL:nil)
      end
    end

    def open_url(url)
      request = NSURLRequest.requestWithURL(
        url.is_a?(NSURL) ? url : NSURL.URLWithString(url)
      )
      web.loadRequest request
    end

    def convert_retina_images(content)
{'fraction_non_alphanumeric': 0.0714792899408284, 'fraction_numerical': 0.0009467455621301775, 'mean_word_length': 3.122926829268293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5145405', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1282, 'n_words': 241}