Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Add howto command to show Roxy wiki pages #365

Closed
grtjn opened this issue Feb 5, 2015 · 2 comments
Closed

Add howto command to show Roxy wiki pages #365

grtjn opened this issue Feb 5, 2015 · 2 comments

Comments

@grtjn
Copy link
Contributor

grtjn commented Feb 5, 2015

Something like: ./ml howto or ./ml howto cpf. The latter would search for wiki page titles containing that string. Not as good as searching the page contents, but github has no search for wiki pages.

I experimented a bit with nokogiri and the built-in _pages wiki page:

#!/usr/bin/ruby

begin
  require 'open-uri'
  require 'rubygems'
  require 'nokogiri'

  def howto
    search = ARGV.first
    doc = Nokogiri::HTML(open('https://github.com/marklogic/roxy/wiki/_pages'))

    pages = doc.css('.content').select do |page|
      search == nil or page.text.downcase().include? search
    end

    selected = 1

    if pages.length > 1
      count = 0
      pages.each do |page|
        count = count + 1
        puts "#{count} - #{page.text}\n\thttps://github.com/#{page.xpath('a/@href').text}"
      end

      print "Select a page: "
      selected = STDIN.gets.chomp().to_i
      if selected == 0
        exit
      end

      if selected > pages.length
        selected = pages.length
      end
    end

    count = 0
    pages.each do |page|
      count = count + 1
      if count == selected

        puts "\n#{page.text}\n\thttps://github.com/#{page.xpath('a/@href').text}"

        uri = "https://github.com/#{page.xpath('a/@href').text}"
        doc = Nokogiri::HTML(open(uri))

        puts doc.css('.markdown-body').text.gsub(/\n\n\n+/, "\n\n")

      end
    end
  end

  howto

rescue LoadError => e
  puts "Missing library: #{e}"
end

This is a self-contained script that works. Just need a nice way to integrate into Roxy. Issue is that nokogiri could be missing, and not sure how to gracefully decay when it is embedded in server_config.rb or alike..

@paxtonhare maybe you have an idea how to encapsulate this such that it doesn't break whole ml?

grtjn added a commit to grtjn/roxy that referenced this issue Feb 20, 2015
grtjn added a commit to grtjn/roxy that referenced this issue Feb 20, 2015
@grtjn grtjn modified the milestone: 1.7.2 Feb 20, 2015
@grtjn
Copy link
Contributor Author

grtjn commented Mar 19, 2015

PR pending..

grtjn added a commit to grtjn/roxy that referenced this issue Mar 30, 2015
dmcassel added a commit that referenced this issue Mar 31, 2015
Fixed #365: added howto help based on wiki pages
@grtjn
Copy link
Contributor Author

grtjn commented Mar 31, 2015

Fixed in develop

@grtjn grtjn closed this as completed Mar 31, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant