Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/bitclust/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,17 @@ def display_text(text)
def description_text(text)
text = display_text(text)
return text unless text
# module function の ".#" は表示専用なので、DB バージョンが 4.0 以降なら
# "?." で表示する(RDCompiler#display_spec と同じ #250/#282 の規則。
# ここは可視ページを通さない meta description 用の経路なので、bracket_link
# と同じ変換を独立に適用する必要がある。spec・URL・アンカーキーは不変)
version = @db&.propget('version')
text = text.split("\n").map(&:strip).join("\n")
.gsub(/(\P{ascii})\n(?=\P{ascii})/) { $1 || raise }
.tr("\n", ' ')
text.gsub(BracketLink) {|link|
((link[2..-3] || raise).split(':', 2).last || raise).rstrip
label = ((link[2..-3] || raise).split(':', 2).last || raise).rstrip
label.include?('.#') ? label.sub('.#', NameUtils.display_typemark('.#', version)) : label
}
end
private :description_text
Expand Down
33 changes: 33 additions & 0 deletions test/test_methodentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,39 @@ def test_instance_method_and_special_variable_display_are_unaffected_by_version
end
end

# meta description(コンパイラを通さない表示テキスト)内の module function
# 参照 [[m:Kernel.#mf2]] のラベルも、可視ページの bracket_link と同様に
# DB バージョン 4.0 以降では "?." で表示する(bitclust#282/#283 の続き。
# 従来この経路だけ ".#" のまま残っていた)
class TestMethodEntryDescriptionQdot < Test::Unit::TestCase
SRC = <<HERE
= module Kernel

== Module Functions

--- mf

[[m:Kernel.#mf2]] を参照してください。

--- mf2

説明。
HERE

def description(version)
_lib, db = BitClust::RRDParser.parse(SRC, 'testlib', {'version' => version})
db.get_method(BitClust::MethodSpec.parse('Kernel.#mf')).description
end

def test_meta_description_keeps_dot_hash_before_4_0
assert_equal('Kernel.#mf2 を参照してください。', description('3.4'))
end

def test_meta_description_uses_question_dot_at_4_0
assert_equal('Kernel?.mf2 を参照してください。', description('4.0'))
end
end

# メソッド名別の since/until (bitclust#132 P1)。
#
# テストリスト:
Expand Down
Loading