<commit_before>require_dependency 'stash_engine/application_controller'

module StashEngine
  class LandingController < ApplicationController
    include StashEngine.app.metadata_engine.constantize::LandingMixin

    def show
      render('not_available') && return if params[:id].blank?
      @type, @id = params[:id].split(':', 2)
      @identifiers = Identifier.where(identifier_type: @type).where(identifier: @id)
      render('not_available') && return if @identifiers.count < 1
      @id = @identifiers.first
      @resource = @id.last_submitted_version
      render('not_available') && return if @resource.blank?
      @resource_id = @resource.id
      @resource.increment_views
      setup_show_variables(@resource_id) #sets up the specific metadata view variables from <meta_engine>::LandingMixin
    end

    def data_paper
      #request.format = 'pdf'
      render('not_available') && return if params[:id].blank?
      @type, @id = params[:id].split(':', 2)

      @identifiers = Identifier.where(identifier_type: @type).where(identifier: @id)
      render('not_available') && return if @identifiers.count < 1
      @id = @identifiers.first
      @resource = @id.last_submitted_version
      render('not_available') && return if @resource.blank?
      @resource_id = @resource.id
      setup_show_variables(@resource_id) #sets up the specific metadata view variables from <meta_engine>::LandingMixin

      # lots of problems getting all styles and javascript to load with wicked pdf
      # https://github.com/mileszs/wicked_pdf/issues/257
      # https://github.com/mileszs/wicked_pdf
      my_debug = params[:debug] ? true : false
      respond_to do |format|
        format.any(:html, :pdf){
          render pdf: "test_data_paper",
                 page_size: 'letter',
                 title: 'my test title',
                 javascript_delay: 3000,
                 'viewport-size': '1600x1024',
                 show_as_html: my_debug
        }
      end
    end
  end
end<commit_msg>Adding headers/footers to the pdf<commit_after>require_dependency 'stash_engine/application_controller'

module StashEngine
  class LandingController < ApplicationController
    include StashEngine.app.metadata_engine.constantize::LandingMixin

    def show
      render('not_available') && return if params[:id].blank?
      @type, @id = params[:id].split(':', 2)
      @identifiers = Identifier.where(identifier_type: @type).where(identifier: @id)
      render('not_available') && return if @identifiers.count < 1
      @id = @identifiers.first
      @resource = @id.last_submitted_version
      render('not_available') && return if @resource.blank?
      @resource_id = @resource.id
      @resource.increment_views
      setup_show_variables(@resource_id) #sets up the specific metadata view variables from <meta_engine>::LandingMixin
    end

    def data_paper
      #request.format = 'pdf'
      render('not_available') && return if params[:id].blank?
      @type, @id = params[:id].split(':', 2)

      @identifiers = Identifier.where(identifier_type: @type).where(identifier: @id)
      render('not_available') && return if @identifiers.count < 1
      @id = @identifiers.first
      @resource = @id.last_submitted_version
      render('not_available') && return if @resource.blank?
      @resource_id = @resource.id
      setup_show_variables(@resource_id) #sets up the specific metadata view variables from <meta_engine>::LandingMixin
      # TODO: we need to fix the way we mixin/set up variables and the citation is too complicated to deal with
      pdf_meta = metadata_engine::ResourcesController::PdfMetadata.new(@resource, @id, plain_citation)

      # lots of problems getting all styles and javascript to load with wicked pdf
      # https://github.com/mileszs/wicked_pdf/issues/257
      # https://github.com/mileszs/wicked_pdf
      my_debug = params[:debug] ? true : false
      respond_to do |format|
        format.any(:html, :pdf){
          render pdf: "test_data_paper",
                 page_size: 'letter',
                 title: 'my test title',
                 javascript_delay: 3000,
                 'viewport-size': '1600x1024',
                 header: {
                     left: pdf_meta.top_left,
                     right: pdf_meta.top_right },
                 footer: {
                     left: pdf_meta.bottom_left,
                     right: pdf_meta.bottom_right },
                 show_as_html: my_debug
        }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10713491887086019, 'fraction_numerical': 0.008446321404756613, 'mean_word_length': 2.8461538461538463, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 4, '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': '4548994', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1264, 'n_words': 305}