<commit_before>require 'shortcodes/handler'

module Shortcodes
  class DocumentCloud < Handler

    def url
      url = shortcode.attributes.fetch('url')
    end

    def document_id
      url =~ /documents\/(\d+)-/
      $1
    end

    def height
      attributes.fetch('height', 550)
    end

    def width
      attributes.fetch('width', 400)
    end

    def document_name
      hyphen_position = url.index('-')
      unless hyphen_position.nil?
        return url[hyphen_position+1..-6]  # -6 to remove the trailing '.html'
      end
    end

    def render
      <<TEMPLATE
<div id="DV-viewer-#{document_id}-#{document_name}" class="DV-container"></div>
<script src="//s3.amazonaws.com/s3.documentcloud.org/viewer/loader.js"></script>
<script>
  DV.load("//www.documentcloud.org/documents/#{document_id}-#{document_name}.js", {
    width: '#{height}',
    height: '#{width}',
    sidebar: false,
    container: "#DV-viewer-#{document_id}-#{document_name}"
  });
</script>
<noscript>
  <a href="http://s3.documentcloud.org/documents/#{document_id}/#{document_name}.pdf" target="_blank">Documento (PDF)</a>
  <br />
  <a href="http://s3.documentcloud.org/documents/#{document_id}/#{document_name}.txt" target="_blank">Documento (Texto)</a>
</noscript>
TEMPLATE
    end

    Shortcodes.register_shortcode('dc', self)
    Shortcodes.register_shortcode('documentcloud', self)
  end
end<commit_msg>Make DocumentCloud embed take all available width. Closes #40<commit_after>require 'shortcodes/handler'

module Shortcodes
  class DocumentCloud < Handler

    def url
      url = shortcode.attributes.fetch('url')
    end

    def document_id
      url =~ /documents\/(\d+)-/
      $1
    end

    def height
      attributes.fetch('height', 550)
    end

    def document_name
      hyphen_position = url.index('-')
      unless hyphen_position.nil?
        return url[hyphen_position+1..-6]  # -6 to remove the trailing '.html'
      end
    end

    def render
      <<TEMPLATE
<div class="documentCloudWrapper" style="position: relative; height: #{height}px;">
<style>
.documentCloudWrapper .DV-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
</style>
<div id="DV-viewer-#{document_id}-#{document_name}" class="DV-container"></div>
<script src="//s3.amazonaws.com/s3.documentcloud.org/viewer/loader.js"></script>
<script>
  DV.load("//www.documentcloud.org/documents/#{document_id}-#{document_name}.js", {
    sidebar: false,
    container: "#DV-viewer-#{document_id}-#{document_name}"
  });
</script>
<noscript>
  <a href="http://s3.documentcloud.org/documents/#{document_id}/#{document_name}.pdf" target="_blank">Documento (PDF)</a>
  <br />
  <a href="http://s3.documentcloud.org/documents/#{document_id}/#{document_name}.txt" target="_blank">Documento (Texto)</a>
</noscript>
</div>
TEMPLATE
    end

    Shortcodes.register_shortcode('dc', self)
    Shortcodes.register_shortcode('documentcloud', self)
  end
end
{'fraction_non_alphanumeric': 0.16418918918918918, 'fraction_numerical': 0.011824324324324325, 'mean_word_length': 3.5765069551777433, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 33, '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': '1053559', 'n_tokens_mistral': 1025, 'n_tokens_neox': 987, 'n_words': 183}