开发者

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

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.


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


Currently i just use javascript to remove the source html:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜