Skip to content

Commit

Permalink
Store extra files in their own directory
Browse files Browse the repository at this point in the history
When generating HTML, store extra files in their own directory ("_file")
instead of prefixing their names with "file." and writing them to the
web root.
  • Loading branch information
bfad committed Nov 14, 2019
1 parent 4b5c875 commit ec809b5
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 15 deletions.
4 changes: 4 additions & 0 deletions lib/yard/code_objects/extra_file_object.rb
Original file line number Diff line number Diff line change
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
Empty file.
2 changes: 1 addition & 1 deletion lib/yard/serializers/file_system_serializer.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit ec809b5

Please sign in to comment.