class Object
Constants
- CAMELCASE_CONSTANT
- MANIFEST_FILENAME
- MANUAL_CONSTANT_GROUPS
- VERSION_MATCH
Public Instance Methods
all_objects()
click to toggle source
# File lib/yard-sketchup/templates/changelog/fulldoc/text/setup.rb, line 12 def all_objects run_verifier(Registry.all()) end
changelog_filename()
click to toggle source
# File lib/yard-sketchup/templates/changelog/fulldoc/text/setup.rb, line 26 def changelog_filename 'Changelog SU201x.log' end
class_objects()
click to toggle source
# File lib/yard-sketchup/templates/inheritance/fulldoc/text/setup.rb, line 16 def class_objects run_verifier(Registry.all(:class)) end
copy(source, target = nil)
click to toggle source
Copy verbatim an asset file to the target output. By default it uses the same relative path as the source for the target path.
# File lib/yard-sketchup/templates/default/fulldoc/html/setup.rb, line 5 def copy(source, target = nil) path = self.class.find_file(source) # puts "copy(#{source}, #{target})" # puts "> path: #{path}" raise ArgumentError, "no file for '#{source}' in #{self.class.path}" unless path target ||= source asset(target, File.binread(path)) end
ensure_exist(path)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 275 def ensure_exist(path) unless File.directory?(path) FileUtils.mkdir_p(path) end path end
file_header(object)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 63 def file_header(object) header = StringIO.new header.puts "# Copyright:: Copyright #{Time.now.year} Trimble Inc." header.puts "# License:: The MIT License (MIT)" #header.puts "# Generated:: #{Time.now.strftime('%F %R')}" header.string end
find_all_versions()
click to toggle source
# File lib/yard-sketchup/templates/versions/fulldoc/text/setup.rb, line 17 def find_all_versions versions = Set.new all_objects.each { |object| version_tag = object.tag(:version) versions << version_tag.text if version_tag } puts versions.sort.join("\n") exit # Avoid the YARD summary end
generate_assets()
click to toggle source
Calls superclass method
# File lib/yard-sketchup/templates/default/fulldoc/html/setup.rb, line 20 def generate_assets super copy('favicon.ico') copy('images/sketchup-logo.svg') copy('images/trimble-logo-white.svg') copy('images/Ruby.svg') end
generate_autoloader(namespace_objects)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 29 def generate_autoloader(namespace_objects) generator = SketchUpYARD::Stubs::AutoLoadGenerator.new autoload_file = File.join(stubs_gem_path, 'sketchup.rb') File.open(autoload_file, 'w') do |file| generator.generate(namespace_objects, file) end end
generate_changelog()
click to toggle source
# File lib/yard-sketchup/templates/changelog/fulldoc/text/setup.rb, line 30 def generate_changelog #p (methods - Object.instance_methods).sort #p ARGV puts "Generating #{changelog_filename}..." output = StringIO.new new_objects = all_objects.sort { |a, b| a.path <=> b.path } new_objects.each do |object| #object.meths.each { |method| #methods << "#{method.namespace}##{method.name}" #} output.puts "Added #{object.type} #{object.path}" end changelog_path = File.join(output_path, changelog_filename) File.write(changelog_path, output.string) end
generate_class_methods(object)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 188 def generate_class_methods(object) generate_methods(object, :class, 'self.') end
generate_constants(object)
click to toggle source
Sort constants without grouping.
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 167 def generate_constants(object) output = StringIO.new constants = run_verifier(object.constants(object_options)) constants = stable_sort_by(constants, &:name) constants.each { |constant| output.puts " #{constant.name} = nil # Stub value." } output.string end
generate_constants_grouped(object)
click to toggle source
Sorts and groups constants for easier reading.
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 143 def generate_constants_grouped(object) constants = run_verifier(object.constants(object_options)) # The constants are not sorted before chunking. This is because `chunk` groups # consecutive items - and we want to chunk them based their relationship # with each other. This ensure that constants that doesn't follow the normal # pattern of PREFIX_SOME_NAME will still be grouped next to each other. groups = constants.chunk { |constant| group_constant(constant) } grouped_output = groups.map { |group, group_constants| output = StringIO.new # Each group itself is sorted in order to more easily scan the list. sorted = stable_sort_by(group_constants, &:name) sorted.each { |constant| output.puts " #{constant.name} = nil # Stub value." } output.string } # Finally each group is also sorted, again to ease scanning for a particular # name. We simply use the first character of each group. stable_sort_by(grouped_output) { |item| item.lstrip[0] }.join("\n") end
generate_docstring(object, indent_step = 0)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 243 def generate_docstring(object, indent_step = 0) output = StringIO.new indent = ' ' * indent_step docstring = object.docstring docstring.delete_tags(:par) # Remove obsolete @par tags. docstring.to_raw.lines.each { |line| # Naive check for tags with no indent - if it is we insert an extra line # in order to get some space for easier reader. Doing it this way in order # to avoid hacking YARD too much. output.puts "#{indent}#" if line.start_with?('@') # This is the original docstring line. output.puts "#{indent}# #{line}" } output.string end
generate_instance_methods(object)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 192 def generate_instance_methods(object) generate_methods(object, :instance) end
generate_manifest()
click to toggle source
# File lib/yard-sketchup/templates/coverage/fulldoc/text/setup.rb, line 23 def generate_manifest puts "Generating #{MANIFEST_FILENAME}..." methods = Set.new namespace_objects.each do |object| run_verifier(object.meths).each { |method| # TODO(thomthom): Currently the manifest doesn't distinguish between # class and instance methods. This should be addressed, but we need to # update TestUp to handle this first. # TODO(thomthom): Make this a configurable filter. # Layout has its own tests - and should be isolated so its own suite. next if method.namespace.to_s.start_with?('Layout') methods << "#{method.namespace}.#{method.name}" } end manifest = methods.sort.join("\n") manifest_path = File.join(output_path, MANIFEST_FILENAME) puts manifest_path File.write(manifest_path, manifest) end
generate_method_signature(object)
click to toggle source
NOTE: This may modify the docstring of the object.
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 219 def generate_method_signature(object) signature = "#{object.name}" # If there is a single overload then use that as the parameter list. Many of # the SketchUp Ruby API methods will have this as it was safer to add an # @overload tag instead of renaming the function argument names. overloads = object.docstring.tags(:overload) if overloads.size == 1 overload = overloads.first parameters = overload.parameters # Move the tags from the @overload tag to the root of the docstring. No need # for a single overload tag - it's unexpected when reading the source. object.docstring.add_tag(*overload.tags) object.docstring.delete_tags(:overload) else parameters = object.parameters end # Compile the signature for the arguments and default values. params = parameters.map { |param| param.last.nil? ? param.first : param.join(' = ') }.join(', ') signature << "(#{params})" unless params.empty? signature end
generate_methods(object, scope, prefix = '')
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 196 def generate_methods(object, scope, prefix = '') methods = sort_methods(object, scope) signatures = methods.map { |method| output = StringIO.new # Cannot use `methods.signature` here as it would return the C/C++ function # signature. Must generate one from the YARD data. signature = generate_method_signature(method) # NOTE: We must call `generate_docstring` after `generate_method_signature` # because `generate_method_signature` will also clean up docstrings with # a single @overload tag. output.puts generate_docstring(method, 1) output.puts " def #{prefix}#{signature}" output.puts " end" # Include aliases. method.aliases.each { |method_alias| output.puts " alias_method :#{method_alias.name}, :#{method.name}" } output.string } signatures.join("\n") end
generate_mixins(object, scope)
click to toggle source
# File lib/yard-sketchup/templates/inheritance/fulldoc/text/setup.rb, line 32 def generate_mixins(object, scope) output = StringIO.new mixin_type = (scope == :class) ? 'extend' : 'include' mixins = run_verifier(object.mixins(scope)) mixins = stable_sort_by(mixins, &:path) mixins.each { |mixin| output.puts " #{mixin_type} #{mixin.path}" } output.string end
generate_module_stubs(object)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 45 def generate_module_stubs(object) filename = stub_filename(object) ensure_exist(File.dirname(filename)) StubFile.open(filename, 'w') { |file| file.puts file_header(object) file.puts file.puts namespace_definition(object) print_section(file, 'Extends', generate_mixins(object, :class)) print_section(file, 'Includes', generate_mixins(object, :instance)) print_section(file, 'Constants', generate_constants_grouped(object)) print_section(file, 'Class Methods', generate_class_methods(object)) print_section(file, 'Instance Methods', generate_instance_methods(object)) file.puts file.puts file_footer(object) } #trim_trailing_white_space(filename) end
generate_object_types_list()
click to toggle source
Custom search list grouping the classes in the API into similar groups. TODO(thomthom): This file is just a stub.
# File lib/yard-sketchup/templates/default/fulldoc/html/setup.rb, line 31 def generate_object_types_list #@items = options.objects if options.objects @items = [ "App Level Classes", "Entity Classes", "Collection Classes", "Geom Classes", "UI Classes", "Observer Classes", "Core Ruby Classes" ] @list_title = "Object Index" @list_type = "object_types" # optional: the specified stylesheet class # when not specified it will default to the value of @list_type @list_class = "class" # Generate the full list html file with named feature_list.html # @note this file must be match the name of the type asset(url_for_list(@list_type), erb(:full_list)) end
generate_stubs()
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 20 def generate_stubs puts "Generating stubs..." generate_module_stubs(Registry.root) namespace_objects.each do |object| generate_module_stubs(object) end generate_autoloader(namespace_objects) end
group_constant(constant)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 126 def group_constant(constant) constant_name = constant.name.to_s MANUAL_CONSTANT_GROUPS.each { |rule| if rule[:constants] return rule[:group] if rule[:constants].include?(constant_name) else return rule[:group] if rule[:regex].match(constant_name) end } if constant_name.include?('_') constant_name.split('_').first else constant_name[CAMELCASE_CONSTANT] || constant_name end end
init()
click to toggle source
# File lib/yard-sketchup/templates/changelog/fulldoc/text/setup.rb, line 7 def init generate_changelog end
javascripts()
click to toggle source
TODO(thomthom): Temporarily disabled until we have time to fully implement this. def menu_lists
# Load the existing menus super + [ { :type => 'object_types', :title => 'Object Reference', :search_title => 'Object Reference List' } ]
end
end¶ ↑
# File lib/yard-sketchup/templates/default/layout/html/setup.rb, line 11 def javascripts # Using the latest 1.x jQuery from CDN broke the YARD js. For now we must # continue to use the version shipping with the YARD template we use as base. # # UPDATE: jQuery 1.9 removed a number of functions. # GitHub report security warnings for jQuery older than 1.9. In order to # upgrade we vendor jQuery of a newer version (1.x branch) along with their # migration plugin to allow YARD to continue to work. # https://github.com/lsegal/yard/pull/1351 %w(js/jquery.js js/jquery-migrate.js js/app.js) end
javascripts_full_list()
click to toggle source
Template overrides:
# File lib/yard-sketchup/templates/default/fulldoc/html/setup.rb, line 16 def javascripts_full_list %w(js/jquery.js js/jquery-migrate.js js/full_list.js js/sketchup.js) end
list_all_classes()
click to toggle source
# File lib/yard-sketchup/templates/inheritance/fulldoc/text/setup.rb, line 43 def list_all_classes # versions = Set.new klasses = [] class_objects.each { |object| # version_tag = object.tag(:version) # versions << version_tag.text if version_tag klasses << namespace_definition(object) } # puts klasses.sort.join("\n") puts klasses.sort.join exit # Avoid the YARD summary end
namespace_definition(object)
click to toggle source
# File lib/yard-sketchup/templates/inheritance/fulldoc/text/setup.rb, line 20 def namespace_definition(object) return if object.root? definition = "#{object.type} #{object.path}" if object.type == :class && object.superclass.name != :Object definition << " < #{object.superclass.path}" end output = StringIO.new # output.puts generate_docstring(object) output.puts definition output.string end
namespace_objects()
click to toggle source
# File lib/yard-sketchup/templates/changelog/fulldoc/text/setup.rb, line 16 def namespace_objects run_verifier(Registry.all(:class, :module)) end
object_options()
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 267 def object_options { :inherited => false, :included => false } end
output_path()
click to toggle source
# File lib/yard-sketchup/templates/changelog/fulldoc/text/setup.rb, line 21 def output_path options.serializer.options[:basepath] || Dir.pwd end
print_section(io, title, content)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 37 def print_section(io, title, content) return if content.strip.empty? io.puts io.puts " # #{title}" io.puts io.puts content end
reference_list()
click to toggle source
See `class_list` in fulldoc/html.
# File lib/yard-sketchup/templates/default/fulldoc/html/setup.rb, line 56 def reference_list even_odd = "odd" out = "" @items.each { |item| out << "<li class='#{even_odd}'>" out << "<a class='toggle'></a>" out << item out << "</li>" even_odd = (even_odd == 'even' ? 'odd' : 'even') } out end
sort_methods(object, scope)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 259 def sort_methods(object, scope) methods = run_verifier(object.meths(object_options)) objects = methods.select { |method| !method.is_alias? && method.scope == scope } stable_sort_by(objects, &:name) end
source()
click to toggle source
groups.google.com/forum/#!topic/yardoc/-HH48h-aifs
# File lib/yard-sketchup/templates/default/method_details/setup.rb, line 4 def source return end
stable_sort_by(list) { |item| ... }
click to toggle source
A stable sort_by method.
@param [Enumerable] @return [Array]
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 120 def stable_sort_by(list) list.each_with_index.sort_by { |item, i| [yield(item), i] }.map(&:first) end
stub_filename(object)
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 110 def stub_filename(object) basename = object.path.gsub('::', '/') basename = '_top_level' if basename.empty? File.join(stubs_path, "#{basename}.rb") end
stubs_gem_path()
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 102 def stubs_gem_path ensure_exist(File.join(stubs_lib_path, 'sketchup-api-stubs')) end
stubs_lib_path()
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 98 def stubs_lib_path ensure_exist(File.join(stubs_root_path, 'lib')) end
stubs_path()
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 106 def stubs_path ensure_exist(File.join(stubs_gem_path, 'stubs')) end
stubs_root_path()
click to toggle source
# File lib/yard-sketchup/templates/stubs/fulldoc/text/setup.rb, line 94 def stubs_root_path ensure_exist(output_path) end
stylesheets()
click to toggle source
# File lib/yard-sketchup/templates/default/layout/html/setup.rb, line 23 def stylesheets %w(css/style.css css/sketchup.css css/rubyapi.css) end