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
4 changes: 2 additions & 2 deletions data/bitclust/template.epub/function
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
entry = @entry
@title = "#{entry.type_label} #{entry.label}"
@title = "#{entry.type_label} #{entry.display_label}"
%>
<p>
<%= manual_home_link() %>
Expand All @@ -10,7 +10,7 @@
</p>

<% headline_init %>
<%= headline("#{entry.type_label} #{entry.label}") %>
<%= headline("#{entry.type_label} #{entry.display_label}") %>
<dl class="functionlist">
<dt>
<code><%= entry.header %></code>
Expand Down
4 changes: 2 additions & 2 deletions data/bitclust/template.epub/method
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
entry = @entries.sort.first
@title = "#{entry.type_label} #{entry.title_labels.join(', ')}"
@title = "#{entry.type_label} #{entry.display_title_labels.join(', ')}"
%>
<p>
<%= manual_home_link() %>
Expand All @@ -12,7 +12,7 @@
</p>

<% headline_init %>
<%= headline("#{entry.type_label} #{entry.label}") %>
<%= headline("#{entry.type_label} #{entry.display_label}") %>
<dl class="methodlist">
<%
headline_push
Expand Down
4 changes: 2 additions & 2 deletions data/bitclust/template.lillia/method
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
entry = @entries.sort.first
@title = "#{entry.type_label} #{entry.title_labels.join(', ')}"
@title = "#{entry.type_label} #{entry.display_title_labels.join(', ')}"
@description = entry.description
%>
<p>
Expand All @@ -13,7 +13,7 @@
</p>

<% headline_init %>
<%= headline("#{entry.type_label} #{entry.label}") %>
<%= headline("#{entry.type_label} #{entry.display_label}") %>
<dl class="methodlist">
<%
headline_push
Expand Down
4 changes: 2 additions & 2 deletions data/bitclust/template.offline/function
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
entry = @entry
@title = "#{entry.type_label} #{entry.label}"
@title = "#{entry.type_label} #{entry.display_label}"
@description = @entry.description
@edit_url = edit_url(@entry.source_location) if @conf[:edit_base_url] && @entry.source_location
%>
Expand Down Expand Up @@ -41,7 +41,7 @@
</ol>
</nav>
<% headline_init %>
<%= headline("#{entry.type_label} #{entry.label}", edit_url: @edit_url) %>
<%= headline("#{entry.type_label} #{entry.display_label}", edit_url: @edit_url) %>
</header>

<main>
Expand Down
4 changes: 2 additions & 2 deletions data/bitclust/template.offline/method
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
entry = @entries.sort.first
@title = entry.title_labels.join(', ')
@title = entry.display_title_labels.join(', ')
@description = entry.description
@edit_url = edit_url(entry.source_location) if @conf[:edit_base_url] && entry.source_location
%>
Expand Down Expand Up @@ -55,7 +55,7 @@
</ol>
</nav>
<% headline_init %>
<%= headline("#{entry.type_label} #{entry.label}") %>
<%= headline("#{entry.type_label} #{entry.display_label}") %>
</header>

<main>
Expand Down
2 changes: 1 addition & 1 deletion data/bitclust/template/class
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<%= headline(_('Inherited Methods')) %>
<p><code>
<% specs.each do |s| %>
<%= method_link(s.to_s, (s.type == '#' ? s.method : s.type + s.method)) %>
<%= method_link(s.to_s, (s.type == '#' ? s.method : display_typemark(s.type, @target_version) + s.method)) %>
<% end %>
</code></p>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions data/bitclust/template/function
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%
@title = "#{@entry.type_label} #{@entry.label}"
@title = "#{@entry.type_label} #{@entry.display_label}"
@description = @entry.description
%>
<p>
Expand All @@ -11,7 +11,7 @@
<%= search_form() %>

<% headline_init %>
<%= headline("#{@entry.type_label} #{@entry.label}") %>
<%= headline("#{@entry.type_label} #{@entry.display_label}") %>
<dl class="functionlist">
<dt>
<code><%=h @entry.header %></code>
Expand Down
4 changes: 2 additions & 2 deletions data/bitclust/template/method
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
entry = @entries.sort.first
@title = "#{entry.type_label} #{entry.title_labels.join(', ')}"
@title = "#{entry.type_label} #{entry.display_title_labels.join(', ')}"
@description = entry.description
%>
<p>
Expand All @@ -15,7 +15,7 @@


<% headline_init %>
<%= headline("#{entry.type_label} #{entry.label}") %>
<%= headline("#{entry.type_label} #{entry.display_label}") %>
<% headline_push %>
<dl class="methodlist">
<% @entries.sort.each do |ent| %>
Expand Down
2 changes: 1 addition & 1 deletion data/bitclust/template/search
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
else
sigs.map {|sig|
method_link(e.spec_string,
e.klass.name + e.typemark + sig.to_s)
e.klass.name + e.display_typemark + sig.to_s)
}
end.join("<br>\n") %></td>
<td class="description"><%= compile_rd(src) %></td>
Expand Down
4 changes: 4 additions & 0 deletions lib/bitclust/functionentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def <=>(other)
remove_method :name
alias name id
alias label id
# bitclust#250: MethodEntry の display_label と同じインターフェースを
# 満たすためのエイリアス。関数には module function の概念(typemark)が
# ないので単に label と同じ(変換なし)
alias display_label label

alias macro? macro
alias private? private
Expand Down
2 changes: 1 addition & 1 deletion lib/bitclust/htmlutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module HTMLUtils

# make method anchor from MethodEntry
def link_to_method(m, specp = false)
label = specp ? m.label : m.short_label
label = specp ? m.display_label : m.display_short_label
a_href(@urlmapper.method_url(methodid2specstring(m.id)), label)
end

Expand Down
32 changes: 32 additions & 0 deletions lib/bitclust/methodentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def typechar
methodid2typechar(@id)
end

# bitclust#250: 表示専用の typemark。DB のバージョンが 4.0 以降なら
# module function の "." を "?." にする(それ以外の typemark は不変)。
# typemark 自体(識別子として使う方)は変えない -- URL・spec 文字列・
# refsdatabase のアンカーキー等はすべて typemark() 経由のまま
def display_typemark
NameUtils.display_typemark(typemark(), @db.propget('version'))
end

def type_label
case typemark()
when '.' then 'singleton method'
Expand Down Expand Up @@ -131,11 +139,29 @@ def label
"#{t == '$' ? '' : c}#{t}#{m}"
end

# bitclust#250: label の表示専用版(module function は 4.0 以降 "?." で
# 表示)。label 自身は refsdatabase.rb の [[a:...]] アンカーキーや
# `bitclust methods --diff` の突き合わせが literal ".#" 前提で使うので
# 変えない -- テンプレート側の実際の表示箇所だけがこちらを呼ぶ
def display_label
c, t, m, _lib = methodid2specparts(@id)
"#{t == '$' ? '' : c}#{display_typemark}#{m}"
end

def short_label
_c, t, m, _lib = methodid2specparts(@id)
"#{t == '#' ? '' : t}#{m}"
end

# bitclust#250: short_label の表示専用版。short_label 自身の唯一の
# 呼び出し元(htmlutils.rb の link_to_method)は display_short_label に
# 切り替え済みだが、short_label 自体は同じ理由(識別子的な使い方をする
# 将来のコードのため)で変えない
def display_short_label
_c, t, m, _lib = methodid2specparts(@id)
"#{t == '#' ? '' : display_typemark}#{m}"
end

def index_id
"#{methodid2typechar(@id)}_#{encodename_fs(name).gsub(/=/, '--')}".upcase
end
Expand All @@ -154,6 +180,12 @@ def title_labels
names().map {|name| "#{t == '$' ? '' : c}#{t}#{name}" }
end

# bitclust#250: title_labels の表示専用版(<title> タグ・見出しで使う)
def display_title_labels
c, t, _m, _lib = methodid2specparts(@id)
names().map {|name| "#{t == '$' ? '' : c}#{display_typemark}#{name}" }
end

def name?(name)
names().include?(name)
end
Expand Down
15 changes: 15 additions & 0 deletions lib/bitclust/nameutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ def typemark2char(mark)
raise "must not happen: #{mark.inspect}"
end

# bitclust#250: Ruby 4.0 以降のドキュメントでは module function の表記を
# るりま独自の ".#" から "?." に変える(表示のみ。ソース側は既に "?."
# 記法に対応済みで、内部的には従来どおり ".#" に変換される)。
#
# これは見た目だけの変換であり、method id・URL・spec 文字列など識別子と
# して使う ".#" 自体は一切変えない。typemark が '.#' 以外、または version
# が不明(nil/空)な場合はそのまま返す。バージョン比較は文字列比較では
# なく Gem::Version で行う("10.0" を文字列比較すると "4.0" より小さく
# 見えてしまうため)。
def display_typemark(mark, version)
return mark unless mark == '.#'
return mark unless version && !version.empty?
Gem::Version.new(version) >= Gem::Version.new('4.0') ? '?.' : mark
end

def functionname?(n)
/\A\w+\z/ =~ n ? true : false
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bitclust/rdcompiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def method_signature(sig_line, first)
string %Q(<dt class="method-heading")
string %Q( id="#{@method.index_id}") if first
string '><code>'
string @method.klass.name + @method.typemark if @opt
string @method.klass.name + @method.display_typemark if @opt
string escape_html(sig.friendly_string)
string '</code>'
string heading_version_badges(@method, sig.name, first) if @method
Expand Down
5 changes: 4 additions & 1 deletion lib/bitclust/search_index_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ def method_entries(db)
next unless type

cname = entry.klass.name
tmark = entry.typemark
# bitclust#250: 検索結果に出る表示ラベル(name/full_name)は 4.0
# 以降のドキュメントでは module function を "?." で表示する。path
# は識別子なので typechar(常に不変)のまま
tmark = entry.display_typemark
tchar = entry.typechar
entry.names.each do |mname|
path = "method/#{encode(cname)}/#{tchar}/#{encode(mname)}#{@suffix}"
Expand Down
4 changes: 3 additions & 1 deletion lib/bitclust/subcommands/chm_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ def exec(argv, options)
name = e.typename == :special_variable ? "$#{e_name}" : e_name
@index_contents <<
Sitemap::Content.new("#{name} (#{e.library.name} - #{e.klass.name})", filename)
# bitclust#250: CHM の索引(.hhk)に出る表示ラベル。4.0 以降の
# ドキュメントでは module function を "?." で表示する
@index_contents <<
Sitemap::Content.new("#{e.klass.name}#{e.typemark}#{name} (#{e.library.name})", filename)
Sitemap::Content.new("#{e.klass.name}#{e.display_typemark}#{name} (#{e.library.name})", filename)
end
end
pb.title = align_progress_bar_title(e.name)
Expand Down
1 change: 1 addition & 0 deletions sig/bitclust/functionentry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module BitClust
attr_accessor source_location: Location?

alias label id
alias display_label label
alias macro? macro
alias private? private

Expand Down
8 changes: 8 additions & 0 deletions sig/bitclust/methodentry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module BitClust

def typechar: () -> NameUtils::typechar

def display_typemark: () -> String

def type_label: () -> String

def library: () -> LibraryEntry
Expand All @@ -54,14 +56,20 @@ module BitClust

def label: () -> String

def display_label: () -> String

def short_label: () -> String

def display_short_label: () -> String

def index_id: () -> String

def labels: () -> Array[String]

def title_labels: () -> Array[String]

def display_title_labels: () -> Array[String]

def name?: (String name) -> bool

def since_of: (String name) -> String?
Expand Down
4 changes: 4 additions & 0 deletions sig/bitclust/nameutils.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ module BitClust

def self?.typemark2char: (typemark mark) -> typechar

# bitclust#250: 表示専用の変換。戻り値は '?.' も取り得るので typemark
# 型ではなく String にする(識別子として使ってはいけない)。
def self?.display_typemark: (typemark mark, String? version) -> String

def self?.functionname?: (String n) -> bool

# string -> case-sensitive ID
Expand Down
2 changes: 1 addition & 1 deletion sig/bitclust/rdcompiler.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module BitClust

type opt = bool?

# method_signature で `string @method.klass.name + @method.typemark` を実行するかどうか
# method_signature で `string @method.klass.name + @method.display_typemark` を実行するかどうか
@opt: opt

@f: LineInput
Expand Down
Loading
Loading