4

我正在使用 yard 生成项目文档,但我不想在文档中显示 [查看源代码] 链接,我已经深入研究了 yard 官方指南但仍然没有得到解决方案。

有什么想法吗?谢谢。

4

3 回答 3

6

我可能有点晚了,但是您可以通过从 method_details 部分中删除“源”部分来轻松自定义默认模板。您可以通过在项目的根目录中使用以下内容创建文件“my_template/default/method_details/setup.rb”来实现:

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

然后您可以使用自定义模板修改调用 YARD:

$ yardoc -p my_template
于 2012-04-27T06:38:23.693 回答
0

目前我只是使用 javascript 来删除源 html:

$('.showSource').remove();
于 2012-02-09T03:16:20.187 回答
0

我在 yard 中找不到直接执行此操作的方法,但您可以尝试在生成的 yard 文档文件夹中运行以下命令:

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

于 2011-10-22T23:29:23.567 回答