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

痞子三分冷 提交于 2019-12-04 11:18:28

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

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

rockllei

Currently i just use javascript to remove the source html:

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