How to prevent [view source] link when creating documentation using yard?

你离开我真会死。 提交于 2019-12-06 05:46:38

问题


I am using yard to generate project documentation, but i don't want to display the [view source] link in the documentation, i have dived into the yard official guides but still don't get the solution.

Anything ideas? Thanks.


回答1:


I might be a little late but you can trivially customize the default template by removing the "source" section from the method_details partial. You can do so by creating the file "my_template/default/method_details/setup.rb" in the root of your project with the contents:

def init
  super
  sections.first.delete(:source)
end

Then you can call YARD with your custom template modifications:

$ yardoc -p my_template



回答2:


I could not find a direct way to do this in yard, but you can try running the following on the generated yard documentation folder:

require "find"

Find.find(".") do |file|
  if file.match(/\.html$/)
    puts "Filtering #{file}"
    content = File.read(file)
    no_source_content = content.gsub(/<table class="source_code".*?<\/table>/m, "")
    File.open(file, "w") { |io| io.write no_source_content }
  end
end

unless File.read("css/common.css").match(/Hide source links/)
  File.open("css/common.css", "a+") { |io| io.write("\n/* Hide source links */\n.toggleSource { display:none }") }
end

https://gist.github.com/1306615




回答3:


Currently i just use javascript to remove the source html:

$('.showSource').remove();


来源:https://stackoverflow.com/questions/7116207/how-to-prevent-view-source-link-when-creating-documentation-using-yard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!