commit 388d868796eb3e466c8e801f82c6bc497b28ca4c Author: Pim Snel Date: Tue Jan 4 23:23:56 2022 +0100 initial import WIP diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5dd23fb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.nix-gems diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..26a4f14 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gem "nokogiri" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..e11ad3f --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,17 @@ +GEM + remote: https://rubygems.org/ + specs: + mini_portile2 (2.6.1) + nokogiri (1.12.5) + mini_portile2 (~> 2.6.1) + racc (~> 1.4) + racc (1.6.0) + +PLATFORMS + ruby + +DEPENDENCIES + nokogiri + +BUNDLED WITH + 2.1.4 diff --git a/README.md b/README.md new file mode 100644 index 0000000..47df3cd --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# home-manager option search + +## TODO + +- finish nokogiri +- write to json +- make search front end +- github actions diff --git a/proto.rb b/proto.rb new file mode 100644 index 0000000..2af4842 --- /dev/null +++ b/proto.rb @@ -0,0 +1,42 @@ +require 'open-uri' +require 'nokogiri' +require 'json' +require 'pp' + +url = 'https://nix-community.github.io/home-manager/options.html' +html = open(url) +doc = Nokogiri::HTML(html) + +#html body div.appendix div.variablelist + +data = doc.search('dl.variablelist') + +data.search('dt').each do |dt| + option_title = dt.text + # ct = dt.xpath('count(following-sibling::dt)') + # dds = dt.xpath("following-sibling::dd[count(following-sibling::dt)=#{ct}]") + dds = dt.xpath("following-sibling::dd[1]") + option_desc = dds.children[0].text + + i = 0 + dds.children.each do | p | + i+=1 + option_example = "" + if i == 1 + option_desc = p.text + elsif i == 2 + option_type = p.text + elsif i == 3 + option_default = p.text + elsif i == 4 and p.text.include? "Example" + option_example = p.text + end + + p "title:" + option_title + p "desc:" + option_desc.to_s + p "type:" + option_type.to_s + p "default:" + option_default.to_s + p "example:" + option_example.to_s + p "" + end +end diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..d3abc6d --- /dev/null +++ b/shell.nix @@ -0,0 +1,16 @@ +with (import {}); +mkShell { + buildInputs = [ + ruby_2_7 + ]; + shellHook = '' + mkdir -p .nix-gems + export GEM_HOME=$PWD/.nix-gems + export GEM_PATH=$GEM_HOME + export PATH=$GEM_HOME/bin:$PATH + export PATH=$PWD/bin:$PATH + + gem list -i ^bundler$ -v 1.17.3 || gem install bundler --version=1.17.3 --no-document + bundle + ''; +}