Sha256: 1910c0275017fe9036e66adca1c0abd741ee7e127bd094ce9979328c8fadf726

Contents?: true

Size: 1.02 KB

Versions: 12

Compression:

Stored size: 1.02 KB

Contents

# require 'route_helper'

RouteHelper = YARD::Templates::Helpers::RouteHelper

def init
  sections :header, [:method_signature, T('docstring')]

  super
end

def header
  routes = get_current_routes
  route = options[:current_route] = routes.first

  unless route
    ::YARD::APIPlugin.log(
      "[error] Unable to find route for object: #{object}",
      ::Logger::ERROR
    )

    return
  end

  @props = {}
  @props[:method_link] = url_for(object)

  controller_path = "app/controllers/#{route.requirements[:controller]}_controller.rb"

  # TODO: can't we just test using object.file instead of relying on Rails ?
  controller_path = nil unless File.file?(Rails.root+controller_path)

  if controller_path
    @props[:path] = controller_path
    @props[:controller] = route.requirements[:controller].camelize
    @props[:action] = route.requirements[:action]
  end

  @props[:routes] = routes.map do |route|
    {
      path: RouteHelper.get_route_path(route),
      verb: RouteHelper.get_route_verb(route)
    }
  end

  erb(:header)
end

Version data entries

12 entries across 12 versions & 1 rubygems

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