Sha256: e9e07e2417ea1ae1f2a376a8497617aa6ffad720bfe9e395c75608fd10b5535e

Contents?: true

Size: 1.82 KB

Versions: 14

Compression:

Stored size: 1.82 KB

Contents

include Helpers::FilterHelper

def init
  @page_title = options[:title]

  if options[:inline_file]
    @contents = File.read(options[:file])
    sections :diskfile
  elsif @file
    sections :layout, [:diskfile]
  elsif options[:all_resources]
    sections :layout, [T('topic'), T('appendix')]
  elsif options[:controllers]
    sections :layout, [T('topic'), T('appendix')]
  else
    sections :layout, [:contents]
  end
end

def stylesheets
  %w[
    css/common.css
    css/highlight.css
  ]
end

def inline_stylesheets
  [ '_dynamic_styles' ]
end

def javascripts
  %w[
    js/jquery-1.11.1.min.js
    js/highlight/highlight.pack.js
    js/app.js
  ]
end

def inline_javascripts
  []
end

def contents
  @contents
end

def index
  legitimate_objects = @objects.reject do |object|
    object.root? ||
    !is_class?(object) ||
    !object.meths.find { |m| !m.tags('API').empty? }
  end

  @resources = legitimate_objects.sort_by do |object|
    object.tags('API').first.text
  end

  erb(:index)
end

def diskfile(filename=@file)
  if filename.is_a?(String)
    @contents = File.read(filename)
    filename = File.basename(filename)
  elsif filename.is_a?(File)
    @contents = filename.contents
    filename = File.basename(filename.path)
  end

  extension = (File.extname(filename)[1..-1] || '').downcase

  content = "<div id='filecontents'>" +
  case extension
  when 'htm', 'html'
    @contents
  when 'txt'
    "<pre>#{@contents}</pre>"
  when 'textile', 'txtile'
    htmlify(@contents, :textile)
  when 'markdown', 'md', 'mdown', 'mkd'
    htmlify(@contents, :markdown)
  else
    htmlify(@contents, diskfile_shebang_or_default)
  end +
  "</div>"
  options.delete(:no_highlight)
  content
end

def diskfile_shebang_or_default
  if @contents =~ /\A#!(\S+)\s*$/ # Shebang support
    @contents = $'
    $1.to_sym
  else
    options[:markup]
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
yard-api-1.1.2 templates/api/layout/html/setup.rb
yard-api-1.1.1 templates/api/layout/html/setup.rb
yard-api-1.1.0 templates/api/layout/html/setup.rb
yard-api-1.0.1 templates/api/layout/html/setup.rb
yard-api-1.0.0 templates/api/layout/html/setup.rb
yard-api-0.3.7 templates/api/layout/html/setup.rb
yard-api-0.3.6 templates/api/layout/html/setup.rb
yard-api-0.3.5 templates/api/layout/html/setup.rb
yard-api-0.3.4 templates/api/layout/html/setup.rb
yard-api-0.3.3 templates/api/layout/html/setup.rb
yard-api-0.3.2 templates/api/layout/html/setup.rb
yard-api-0.3.1 templates/api/layout/html/setup.rb
yard-api-0.3.0 templates/api/layout/html/setup.rb
yard-api-0.2.3 templates/api/layout/html/setup.rb