extract-api.rb 716 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
require 'set'

paths = Dir[File.join(__dir__, 'content', 'en', 'methods', '**', '*.md')]

def str_to_params(str)
  params = {}

  str.scan(/([a-z]+)="([^"]*)"/i).each do |(key, value)|
    params[key] = value
  end

  params
end

found_methods = Set.new

paths.each do |path|
  text = File.read(path)

  text.scan(/^\{% api-method (.*) %\}$/).each do |(params)|
    entry = str_to_params(params)

    start_pos = text.index(params)
    end_pos   = text.index('{% endapi-method %}', start_pos)
    body      = text[start_pos...end_pos]

    body.scan(/^\{% ([a-z\-]+)(.*) %\}$/).each do |(method_name, rest)|
      found_methods << method_name unless method_name.start_with?('end')
    end
  end
end

p found_methods