<commit_before>require 'sinatra'
require 'rack/cache'

require 'haml'
require 'mime/types'
require 'diffy'

require '../lib/gaucho'

require 'pp'
require 'awesome_print'

$cache_path = '/tmp/ba-cache'
FileUtils.rm_rf $cache_path
FileUtils.mkdir_p $cache_path

#def p(*args); nil; end

# Diffy limitation workaround (the inability to specify an actual diff)
module Diffy
  class Diff
    attr_writer :diff
  end
end

module Gaucho
  module Renderer
    # Flickr photo.
    def self.flickr(o)
      img = %Q{<img src="#{o.name}"/>}
      o.args ? %Q{<a href="http://www.flickr.com/photos/rj3/#{o.args}">#{img}</a>} : img
    end

    # Soundcloud player.
    def self.soundcloud(o)
      url = CGI::escape(o.name)
      unindent(<<-EOF)
      <object height="81" width="100%">
        <param name="movie" value="http://player.soundcloud.com/player.swf?url=#{url}&amp;show_comments=true&amp;auto_play=false&amp;color=ff7700"></param>
        <param name="allowscriptaccess" value="always"></param>
        <param name="wmode" value="window"></param>
        <embed wmode="window" allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=#{url}&amp;show_comments=true&amp;auto_play=false&amp;color=ff7700" type="application/x-shockwave-flash" width="100%"></embed>
      </object>
      EOF
    end
  end

  class PageNotFound < Sinatra::NotFound
  end

  class FileNotFound < Sinatra::NotFound
    def initialize(name)
      #p "FileNotFound: #{name}"<commit_msg>Minor sample app custom renderer tweaks.<commit_after>require 'sinatra'
require 'rack/cache'

require 'haml'
require 'mime/types'
require 'diffy'
require 'uri'

require '../lib/gaucho'

require 'pp'
require 'awesome_print'

$cache_path = '/tmp/ba-cache'
FileUtils.rm_rf $cache_path
FileUtils.mkdir_p $cache_path

#def p(*args); nil; end

# Diffy limitation workaround (the inability to specify an actual diff)
module Diffy
  class Diff
    attr_writer :diff
  end
end

module Gaucho
  module Renderer
    # Flickr photo.
    def self.flickr(o)
      img = %Q{<img src="#{o.name}"/>}
      o.args ? %Q{<a href="http://www.flickr.com/photos/rj3/#{o.args}">#{img}</a>} : img
    end

    # Soundcloud player.
    def self.soundcloud(o)
      url = CGI::escape(o.name)
      unindent(<<-EOF)
      <object height="81" width="100%">
        <param name="movie" value="http://player.soundcloud.com/player.swf?url=#{url}&amp;show_comments=true&amp;auto_play=false&amp;color=ff7700"></param>
        <param name="allowscriptaccess" value="always"></param>
        <param name="wmode" value="window"></param>
        <embed wmode="window" src="http://player.soundcloud.com/player.swf?url=#{url}&amp;show_comments=true&amp;auto_play=false&amp;color=ff7700"
        allowscriptaccess="always" height="81" type="application/x-shockwave-flash" width="100%"></embed>
      </object>
      EOF
    end

    # Open AppleScript in Script Editor.
    self.filter_map[:applescript] = [:applescript]
    def self.applescript(o)
      script = URI.escape(o.data)
      %Q{<a href="applescript://com.apple.scripteditor?action=new&script=#{script}">} +
        %Q{Click here</a> to open this AppleScript in Script Editor. #{code(o)}}
    end
  end

  class PageNotFound < Sinatra::NotFound
  end

  class FileNotFound < Sinatra::NotFound
    def initialize(name)
      #p "FileNotFound: #{name}"
{'fraction_non_alphanumeric': 0.15819209039548024, 'fraction_numerical': 0.011299435028248588, 'mean_word_length': 3.910948905109489, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 31, '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': '6841279', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1154, 'n_words': 234}