examples/yard/generate.rb in orthoses-yard-0.1.0 vs examples/yard/generate.rb in orthoses-yard-0.2.0
- old
+ new
@@ -1,14 +1,21 @@
require 'orthoses-yard'
require 'fileutils'
require 'pathname'
+require 'erb'
-FileUtils.rm_rf('out')
+output_dir = 'out'
+FileUtils.rm_rf(output_dir)
Orthoses.logger.level = :warn
+
+gem_path = Gem::Specification.find_by_name("yard").load_paths.first
+notice = "# !!! GENERATED FILE !!!\n# Please see generators/yard-generator/README.md\n"
+
Orthoses::Builder.new do
use Orthoses::CreateFileByName,
- base_dir: 'out'
+ base_dir: output_dir,
+ header: notice
use Orthoses::Filter do |name, content|
name.start_with?('YARD') ||
name.start_with?('Ripper') ||
name.start_with?('OpenStruct') ||
name.start_with?('SymbolHash') ||
@@ -23,49 +30,52 @@
store['YARD::Handlers::C'].header = 'module YARD::Handlers::C'
store['YARD::Handlers::Common'].header = 'module YARD::Handlers::Common'
store['YARD::Handlers::Ruby'].header = 'module YARD::Handlers::Ruby'
# TODO: support generics
store['YARD::Tags::Library'] << 'def self.labels: () -> SymbolHash'
+
+ # FIXME: YARD's issue?
+ store['YARD::CLI::YardocOptions'].delete("# @return [Numeric] An index value for rendering sequentially related templates\nattr_accessor index: Numeric")
end
use Orthoses::YARD,
- globs: [
- 'src/lib/yard.rb',
- 'src/lib/yard/**/*.rb'
+ parse: [
+ "#{gem_path}/yard.rb",
+ "#{gem_path}/yard/**/*.rb",
]
use Orthoses::Autoload
run -> {
require 'yard'
YARD::Tags::Library.define_tag("YARD Tag Signature", 'yard.signature'.to_sym, nil)
YARD::Tags::Library.define_tag("YARD Tag", 'yard.tag'.to_sym, :with_types_and_name)
YARD::Tags::Library.define_tag("YARD Directive", 'yard.directive'.to_sym, :with_types_and_name)
- # YARD::Tags::Library.visible_tags -= ['yard.tag'].map(&:to_sym)
}
end.call
-Pathname("out").join("EXTERNAL_TODO.rbs").write(<<~RBS)
- # !!! GENERATED CODE !!!
- class OpenStruct
- end
+stdlib_dependencies = %w[
+ set
+ optparse
+ logger
+ monitor
+]
- class Ripper
- end
+def erb(template_filename, **vars)
+ "templates/#{template_filename}.erb"
+ .then { File.expand_path(_1) }
+ .then { File.read(_1) }
+ .then { ERB.new(_1, trim_mode: '<>').result_with_hash(vars) }
+end
- module Rake
- class TaskLib
- end
+out = Pathname(output_dir)
+out.join("EXTERNAL_TODO.rbs").write(erb("EXTERNAL_TODO.rbs", notice: notice))
+out.join("manifest.yaml").write(erb("manifest.yaml", notice: notice, stdlib_dependencies: stdlib_dependencies))
+out.join('_scripts').tap do |scripts|
+ scripts.mkpath
+ scripts.join("test").tap do |test|
+ test.write(erb("_scripts/test", notice: notice, stdlib_dependencies: stdlib_dependencies))
+ test.chmod(0o755)
end
-
-
- module WEBrick
- module HTTPServlet
- class AbstractServlet
- end
- end
- end
-
- module RDoc
- module Markup
- class ToHtml
- end
- end
- end
-RBS
+end
+out.join('_test').tap do |test|
+ test.mkpath
+ test.join("yard.rb").write(erb("_test/yard.rb", notice: notice))
+ test.join('Steepfile').write(erb("_test/Steepfile", notice: notice, stdlib_dependencies: stdlib_dependencies))
+end