Sha256: 37a33db9151b67b1e2ec3a3ec53432052fb4914a9e260f39e21a4a4abe20c0a5

Contents?: true

Size: 978 Bytes

Versions: 15

Compression:

Stored size: 978 Bytes

Contents

# frozen_string_literal: true
module YARD
  module Server
    module Commands
      # Displays a README or extra file.
      #
      # @todo Implement better support for detecting binary (image) filetypes
      class DisplayFileCommand < LibraryCommand
        attr_accessor :index

        def run
          filename = File.cleanpath(File.join(library.source_path, path))
          raise NotFoundError unless File.file?(filename)
          if filename =~ /\.(jpe?g|gif|png|bmp)$/i
            headers['Content-Type'] = StaticFileCommand::DefaultMimeTypes[$1.downcase] || 'text/html'
            render File.read_binary(filename)
          else
            file = CodeObjects::ExtraFileObject.new(filename)
            options.update :object => Registry.root,
                           :type => :layout,
                           :file => file,
                           :index => index ? true : false
            render
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 14 versions & 4 rubygems

Version Path
yard-0.9.16 lib/yard/server/commands/display_file_command.rb
yard-0.9.15 lib/yard/server/commands/display_file_command.rb
yard-0.9.14 lib/yard/server/commands/display_file_command.rb
yard-0.9.13 lib/yard/server/commands/display_file_command.rb
yard-0.9.12 lib/yard/server/commands/display_file_command.rb
yard-0.9.11 lib/yard/server/commands/display_file_command.rb
yard-0.9.10 lib/yard/server/commands/display_file_command.rb
yard-0.9.9 lib/yard/server/commands/display_file_command.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/lib/yard/server/commands/display_file_command.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/lib/yard/server/commands/display_file_command.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/lib/yard/server/commands/display_file_command.rb
yard-0.9.8 lib/yard/server/commands/display_file_command.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.7/lib/yard/server/commands/display_file_command.rb
yard-0.9.7 lib/yard/server/commands/display_file_command.rb
yard-0.9.6 lib/yard/server/commands/display_file_command.rb