Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 37232e39d7
Fetching contributors…

Cannot retrieve contributors at this time

executable file 61 lines (49 sloc) 1.741 kb
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#!/usr/bin/env ruby

# This script converts a YUIDoc raw.json metadata file into a vim language
# syntax. It requires the erubis and json gems.

require 'rubygems'
require 'erubis'
require 'json'

# Words that need to be escaped in the syntax output.
ESCAPE = %w{
contained containedin contains display fold nextgroup oneline skipempty
skipnl skipwhite transparent
}

EXCLUDE_CLASSES = []
EXCLUDE_CONSTANTS = []
EXCLUDE_FUNCTIONS = ['()', 'DEFAULT_GETTER', 'DEFAULT_SETTER']
EXCLUDE_VARIABLES = []

api = JSON.parse(File.read('raw.json'))

classes = []
constants = []
functions = []
variables = []
version = api['version']

api['classmap'].each do |classname, classdata|
  # Classes
  classname.split('.').each do |name|
    classes << name unless name.include?('~') || EXCLUDE_CLASSES.include?(name)
  end

  # Constants/Variables/Properties
  (classdata['properties'] || {}).each do |propname, propdata|
    next if propdata['protected'] || propdata['private']
    propname = $1 if propname =~ /\.([^\.]+)$/

    if propdata['final']
      constants << propname unless EXCLUDE_CONSTANTS.include?(propname)
    else
      variables << propname unless EXCLUDE_VARIABLES.include?(propname)
    end
  end

  # Functions/Methods
  (classdata['methods'] || {}).each do |methodname, methoddata|
    next if methoddata['protected'] || methoddata['private'] || methodname =~ /\s/
    methodname = $1 if methodname =~ /\.([^\.]+)$/
    functions << methodname unless EXCLUDE_FUNCTIONS.include?(methodname)
  end
end

[classes, constants, functions, variables].each do |keywords|
  keywords.uniq!
  keywords.sort!
  keywords.map! {|w| ESCAPE.include?(w) ? "\\#{w}" : w }
end

puts Erubis::Eruby.new(File.read('syntax.erb')).result(binding)
Something went wrong with that request. Please try again.