lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.94k stars 397 forks source link

url_for generates links differently when using "yard server" and "yardoc" #663

Closed nitinmohan87 closed 8 years ago

nitinmohan87 commented 11 years ago

I have an object which is of type CookbookObject (inherited from ChefObject). This object is under the namespace "ChefObject" (inherited from ClassObject). I am trying to create a link using "url_for" method as follows

class ChefObject < YARD::CodeObjects::ClassObject; end
class CookbookObject < ChefObject; end

chef = ChefObject.new(:root, 'Chef')
cookbook = CookbookObject.new(chef, 'app')

url_for(cookbook, "anchor")  #  returns "Chef/app.html#anchor" 
# when generated via yard server. NOTE: This is the expected output.
url_for(cookbook, "anchor")  #  returns "app.html#anchor" when using yardoc

Why is this difference when using "yardoc" and "yard server"? Or am I doing something wrong here?

lsegal commented 11 years ago

Seems weird. What is the value of object when you call url_for?

nitinmohan87 commented 11 years ago

object is of type ResourceObject inherited from ChefObject. In the case above it would be Chef::Resource::app.

class ResourceObject < ChefObject; end

resource = ResourceObject.new(chef, 'Resource')
new_res = ResourceObject.new(resource, 'app')
lsegal commented 11 years ago

The YARD server shouldn't even be generating URLs with .html, maybe we should back up and talk about what the use case is here, and what exactly is failing?

nitinmohan87 commented 11 years ago

Oops.. sorry.. Yeah. Yard server did not generate '.html' extension. The thing here is in chef DSL, a 'cookbook' may contain a 'resource'. This 'resource' can contain multiple 'providers'. And each of these 'providers' will be implemented on separate 'cookbooks'. I have a page generated for each 'cookbook'. This page will contain a 'resource' section with list of 'providers' or a 'provider' section or both. I have to create a link for each 'provider' in the 'resource' section to its corresponding section in another/same 'cookbook' page.

I am able to achieve this using the 'url_for' as shown above in 'yard server'. But when I download the docs (generated by 'yardoc') and view it on a local machine, the same link goes to an unavailable page (since the link goes to 'app.html' when it must go to 'Chef/app.html').

lsegal commented 8 years ago

I'm marking this as closed since this is extremely old. Feel free to re-open if you are still having this issue, but please try to provide a minimal case that reproduces the problem. Right now there are too many missing details to determine if the root cause is YARD or some plugin code you may have been working on. Running a little test of my own seems to generate correct HTML links for app.html in the class list, which makes me thing url_for is working fine:

require 'yard'

class ChefObject < YARD::CodeObjects::ClassObject; end
class CookbookObject < ChefObject; end

YARD::Registry.delete_from_disk
chef = ChefObject.new(:root, 'Chef')
cookbook = CookbookObject.new(chef, 'app')
YARD::Registry.save(true)
YARD::CLI::Yardoc.run('-c', '--debug')

It's possible you may be doing something with urls, or changing the object in your template. It's also possible you're using url_for in a context where object is set but the page you are generating is not inside of the object's HTML file-- in the latter convoluted case, YARD will generate a relative link to app.html (since it thinks you are in Chef/) but this link might be used elsewhere.