From 9d760980a7cf5c5d5712c84c5b3821c248fbdee4 Mon Sep 17 00:00:00 2001 From: Vít Ondruch Date: Fri, 11 Nov 2022 13:28:54 +0100 Subject: Explore RubyGems plugin idea. --- darkfish.spec | 36 +++++++++++++++---- fedora_darkfish.gemspec | 26 ++++++++++++++ rubygems_plugin.rb | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 fedora_darkfish.gemspec create mode 100644 rubygems_plugin.rb diff --git a/darkfish.spec b/darkfish.spec index bb749ba..b5713a5 100644 --- a/darkfish.spec +++ b/darkfish.spec @@ -1,3 +1,5 @@ +%global gem_name fedora_darkfish + Name: darkfish-rdoc Version: 6.4.0 Release: 1%{?dist} @@ -7,12 +9,15 @@ Summary: Darkfish RDoc Generator License: GPL-2.0 AND Ruby AND BSD-3-Clause AND CC-BY-2.5 URL: https://ruby.github.io/rdoc Source0: https://rubygems.org/gems/rdoc-%{version}.gem -Source1: fedora_darkfish.rb +Source1: fedora_darkfish.gemspec +Source2: fedora_darkfish.rb +Source3: rubygems_plugin.rb # Because the fonts are not embedded, do not refer to them in the font.css # file. Patch0: rdoc-6.4.0-Drop-the-font-URLs-from-css.patch Requires: %{name}-assets BuildRequires: %{_bindir}/gem +BuildRequires: rubygems-devel BuildArch: noarch %description @@ -34,14 +39,30 @@ This package provides Darkfish template shared assets for documentaion generated for rubygem- packages on Fedora. %prep -%setup -q -n rdoc-%{version} +#%%setup -q -n rdoc-%{version} +%setup -q -c +pushd rdoc-%{version} %patch0 -p1 +popd + +mkdir -p lib +pushd lib +cp -a %{SOURCE2} . +cp -a %{SOURCE3} . +popd %build +gem build %{SOURCE1} +%gem_install + %install -pushd lib/rdoc/generator/template/ +mkdir -p %{buildroot}%{gem_dir} +cp -a .%{gem_dir}/* \ + %{buildroot}%{gem_dir}/ + +pushd rdoc-%{version}/lib/rdoc/generator/template/ find . -mindepth 2 -type d \ -exec install -d %{buildroot}%{_datadir}/darkfish-rdoc/{} \; find . -type f \ @@ -53,14 +74,17 @@ rm %{buildroot}%{_datadir}/darkfish-rdoc/{darkfish,json_index}/.document # Drop fonts. System fonts are going to be pulled in instead. rm -rf %{buildroot}%{_datadir}/darkfish-rdoc/darkfish/fonts -install -p -m 644 %{SOURCE1} %{buildroot}%{_datadir}/darkfish-rdoc/ - %check # Not test ATM. Not clear if there is actually something to test. %files +%dir %{gem_instdir} +%{gem_libdir} +%{gem_plugin} +%{gem_spec} +%exclude %{gem_docdir} +%exclude %{gem_cache} %{_datadir}/darkfish-rdoc/darkfish/*.rhtml -%{_datadir}/darkfish-rdoc/fedora_darkfish.rb %files assets %dir %{_datadir}/darkfish-rdoc/ diff --git a/fedora_darkfish.gemspec b/fedora_darkfish.gemspec new file mode 100644 index 0000000..2244fb1 --- /dev/null +++ b/fedora_darkfish.gemspec @@ -0,0 +1,26 @@ +Gem::Specification.new do |spec| + spec.name = 'fedora_darkfish' + spec.version = '6.4.0' + spec.authors = ['Jaroslav Prokop'] + spec.email = ['jar.prokop@volny.cz'] + + spec.summary = 'RDoc plugin for Fedora leveraging the Darkfish template' + spec.description = 'RDoc plugin for Fedora leveraging the Darkfish template' \ + 'that symlinks common files.' + spec.homepage = 'https://fedorapeople.org/cgit/jackorp/public_git/fedora_darkfish.git/commit/?h=rawhide' + spec.license = 'MIT' + + # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' + # to allow pushing to a single host or delete this section to allow pushing to any host. + if spec.respond_to?(:metadata) + spec.metadata['allowed_push_host'] = 'https://rubygems.org' + else + raise 'RubyGems 2.0 or newer is required to protect against ' \ + 'public gem pushes.' + end + + spec.files = Dir["lib/*.rb"] + + spec.add_development_dependency 'rake', '>= 12' + spec.add_development_dependency 'test_unit' +end diff --git a/rubygems_plugin.rb b/rubygems_plugin.rb new file mode 100644 index 0000000..f003ae3 --- /dev/null +++ b/rubygems_plugin.rb @@ -0,0 +1,93 @@ +[:pre_install, :pre_reset, :pre_uninstall, :post_build, :post_install, :post_reset, :post_uninstall].each do |meth| + block = Proc.new { puts 'This is ' + meth.to_s } + Gem.send(meth, &block) +end + +# class RDoc::RubygemsHook::Fedora < Rdoc::RubygemsHook +# def document options, destination +# +# end +# end +Gem.pre_install do + module RDoc + class RubygemsHook + alias generate_default generate + + def self.load_rdoc + return if @fedora_darkfish_version + + require_relative 'rdoc/generator/fedora_darkfish' + + @fedora_darkfish_version = Gem::Version.new '1.0.0' + end + + # def generate + # if Gem.rpmbuild? + # generate_fedora + # else + # generate_default + # end + # end + + def generate #_fedora + # Unfortunately the generator option for RDoc is not parametrized so + # this has been Copied from RDoc::RubygemsHook#generate + # and darkfish was replaced with fedora at the end of this method. + return if @spec.default_gem? + return unless @generate_ri or @generate_rdoc + + setup + + options = nil + + args = @spec.rdoc_options + args.concat @spec.source_paths + args.concat @spec.extra_rdoc_files + + case config_args = Gem.configuration[:rdoc] + when String then + args = args.concat config_args.split(' ') + when Array then + args = args.concat config_args + end + + delete_legacy_args args + + Dir.chdir @spec.full_gem_path do + options = ::RDoc::Options.new + options.default_title = "#{@spec.full_name} Documentation" + options.parse args + end + + options.quiet = !Gem.configuration.really_verbose + + @rdoc = new_rdoc + @rdoc.options = options + + store = ::RDoc::Store.new + store.encoding = options.encoding + store.dry_run = options.dry_run + store.main = options.main_page + store.title = options.title + + @rdoc.store = store + + say "Parsing documentation for #{@spec.full_name}" + + Dir.chdir @spec.full_gem_path do + @rdoc.parse_files options.files + end + + document 'ri', options, @ri_dir if + @generate_ri and (@force or not File.exist? @ri_dir) + + document 'fedora', options, @rdoc_dir if + @generate_rdoc and (@force or not File.exist? @rdoc_dir) + end + end + end +end + +# Gem.post_install do +# puts require 'fedora_darkfish' +# end -- cgit