Skip to content

Instantly share code, notes, and snippets.

@waseem
Forked from radar/sume_extractor.rb
Created March 31, 2012 15:25
Show Gist options
  • Save waseem/2266187 to your computer and use it in GitHub Desktop.
Save waseem/2266187 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'yard'
require 'json'
# Replace YARD's default with our own
template_path = File.expand_path(File.dirname(__FILE__) + "/templates")
YARD::Templates::Engine.template_paths = [template_path]
YARD::Registry.load(Dir["rails/act*/lib/**/*.rb"])
module Sume
def self.write(object)
File.open(path(object) + ".html", "w+") do |f|
f.write(object.format(:format => :html))
end
end
def self.path(object)
object.path.gsub(/::|#|\./, '/')
end
end
index = []
paths = {}
custom_weights = Hash.new(0)
custom_weights["ActiveRecord::Base.create"] = 2
custom_weights["ActiveRecord::FinderMethods#find"] = 2
custom_weights["ActionDispatch::Routing::Mapper::Resources#resources"] = 2
custom_weights["ActionDispatch::Routing::Mapper::Scoping#namespace"] = 2
FileUtils.mkdir_p("doc")
Dir.chdir("doc") do
classes = YARD::Registry.all(:class)
modules = YARD::Registry.all(:module)
methods = YARD::Registry.all(:method)
(classes + modules).each do |object|
FileUtils.mkdir_p(Sume.path(object))
Sume.write(object)
paths[object.path] = Sume.path(object) + ".html"
end
methods.each do |object|
Sume.write(object)
unless object.docstring.blank? || object.docstring.strip == ":doc"
index << object.path
paths[object.path] = Sume.path(object) + ".html"
custom_weights[object.path] ||= object.visibility == :public ? 1 : 0
end
end
end
File.open("../sume_index.js", "w+") do |f|
f.write %Q{
Sume.index = #{index.to_json}
Sume.paths = #{paths.to_json}
Sume.weights = #{custom_weights.to_json}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment