Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store extra files in their own directory #1289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/yard/code_objects/extra_file_object.rb
Expand Up @@ -61,6 +61,10 @@ def inspect

def type; :extra_file end

def source_type; :ruby end

def parent; YARD::Registry.root end

def ==(other)
return false unless self.class === other
other.filename == filename
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/serializers/file_system_serializer.rb
Expand Up @@ -51,7 +51,7 @@ def serialized_path(object)
return object if object.is_a?(String)

if object.is_a?(CodeObjects::ExtraFileObject)
fspath = ['file.' + object.name + (extension.empty? ? '' : ".#{extension}")]
fspath = ['_file', object.name + (extension.empty? ? '' : ".#{extension}")]
else
objname = object != YARD::Registry.root ? mapped_name(object) : "top-level-namespace"
objname += '_' + object.scope.to_s[0, 1] if object.is_a?(CodeObjects::MethodObject)
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/server/doc_server_serializer.rb
Expand Up @@ -20,7 +20,7 @@ def serialized_path(object)
when CodeObjects::ConstantObject, CodeObjects::ClassVariableObject
serialized_path(object.namespace) + "##{object.name}-#{object.type}"
when CodeObjects::ExtraFileObject
super(object).gsub(/^file\./, 'file/')
super(object).gsub(/^_file\//, 'file/')
else
super(object)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/serializers/file_system_serializer_spec.rb
Expand Up @@ -66,7 +66,7 @@
it "handles ExtraFileObject's" do
s = Serializers::FileSystemSerializer.new
e = CodeObjects::ExtraFileObject.new('filename.txt', '')
expect(s.serialized_path(e)).to eq 'file.filename.html'
expect(s.serialized_path(e)).to eq '_file/filename.html'
end

it "differentiates instance and class methods from serialized path" do
Expand Down
4 changes: 2 additions & 2 deletions spec/templates/helpers/html_helper_spec.rb
Expand Up @@ -415,12 +415,12 @@ def parse_link(link)
expect(parse_link(resolve_links("{file:TEST.txt#abc}"))).to eq(
:inner_text => "TEST",
:title => "TEST",
:href => "file.TEST.html#abc"
:href => "_file/TEST.html#abc"
)
expect(parse_link(resolve_links("{file:TEST.txt title}"))).to eq(
:inner_text => "title",
:title => "title",
:href => "file.TEST.html"
:href => "_file/TEST.html"
)
end

Expand Down
13 changes: 4 additions & 9 deletions templates/default/fulldoc/html/setup.rb
Expand Up @@ -8,7 +8,7 @@ def init
generate_assets
serialize('_index.html')
options.files.each_with_index do |file, _i|
serialize_file(file, file.title)
serialize_file(file)
end

options.delete(:objects)
Expand Down Expand Up @@ -48,6 +48,7 @@ def serialize_onefile
# Generate the index document for the output
# @params [Hash] options contains data and flags that influence the output
def serialize_index(options)
options.object = Registry.root
Templates::Engine.with_serializer('index.html', options.serializer) do
T('layout').run(options.merge(:index => true))
end
Expand All @@ -57,18 +58,12 @@ def serialize_index(options)
# the README file or files specified on the command-line.
#
# @param [File] file object to be saved to the output
# @param [String] title currently unused
#
# @see layout#diskfile
def serialize_file(file, title = nil) # rubocop:disable Lint/UnusedMethodArgument
options.object = Registry.root
def serialize_file(file)
options.file = file
outfile = 'file.' + file.name + '.html'

serialize_index(options) if file == options.readme
Templates::Engine.with_serializer(outfile, options.serializer) do
T('layout').run(options)
end
serialize(file)
options.delete(:file)
end

Expand Down
2 changes: 1 addition & 1 deletion templates/guide/fulldoc/html/setup.rb
Expand Up @@ -23,7 +23,7 @@ def init
class << options.serializer
define_method(:serialized_path) do |object|
if CodeObjects::ExtraFileObject === object
super(object).sub(/^file\./, '').downcase
super(object).sub(/^_file\//, '').downcase
else
super(object)
end
Expand Down