class Object
Public Instance Methods
# File lib/docserver/doc_server/full_list/html/setup.rb, line 17 def all_features_link linkify YARD::CodeObjects::Lucid::LUCID_NAMESPACE, "All Features" end
# File lib/templates/default/featuredirectory/html/setup.rb, line 31 def alpha_table(objects) @elements = Hash.new objects = run_verifier(objects) objects.each { |o| (@elements[o.value.to_s[0,1].upcase] ||= []) << o } @elements.values.each { |v| v.sort! {|a,b| b.value.to_s <=> a.value.to_s } } @elements = @elements.sort_by { |l,o| l.to_s } @elements.each {|letter,objects| objects.sort! { |a,b| b.value.to_s <=> a.value.to_s } } erb(:alpha_table) end
# File lib/templates/default/feature/html/setup.rb, line 8 def background @scenario = @feature.background @id = "background" erb(:scenario) end
This method overrides YARD's default template class_list
method.
The existing YARD
'Class List' search field contains all the YARD
namespace objects. In the context of this parsing, the Lucid
Namespace YARD
Object
is a meta-object, so that should not be considered.
This method removes the namespace from the root node, generates the class list, and then adds it back into the root node.
# File lib/templates/default/fulldoc/html/setup.rb, line 168 def class_list(root = Registry.root, tree = TreeContext.new) return super unless root == Registry.root lucid_namespace = YARD::CodeObjects::Lucid::LUCID_NAMESPACE root.instance_eval { children.delete lucid_namespace } out = super(root) root.instance_eval { children.push lucid_namespace } out end
# File lib/templates/default/featuredirectory/html/setup.rb, line 15 def directories @directories ||= @directory.subdirectories end
This method is used to generate a feature directory. This template may call this method as well to generate any child feature directories as well.
# File lib/templates/default/fulldoc/html/setup.rb, line 194 def directory_node(directory,padding,row) @directory = directory @padding = padding @row = row erb(:directories) end
# File lib/templates/default/steptransformers/html/setup.rb, line 55 def display_comments_for(item) begin T('docstring').run(options.dup.merge({:object => item})) rescue log.warn %{An error occurred while attempting to render the comments for: #{item.location} } return "" end end
# File lib/templates/default/specifications/html/setup.rb, line 15 def feature_directories @feature_directories ||= YARD::CodeObjects::Lucid::LUCID_NAMESPACE.children.find_all { |child| child.is_a?(YARD::CodeObjects::Lucid::FeatureDirectory) } end
# File lib/templates/default/specifications/html/setup.rb, line 19 def feature_subdirectories @feature_subdirectories ||= Registry.all(:featuredirectory) - feature_directories end
# File lib/templates/default/featuredirectory/html/setup.rb, line 19 def features @features ||= @directory.features + directories.collect { |d| d.features }.flatten end
Generate feature list. This method is called automatically by YARD
based on the menus defined in the layout.
# File lib/templates/default/fulldoc/html/setup.rb, line 70 def generate_feature_list features = Registry.all(:feature) features_ordered_by_name = features.sort {|x,y| x.value.to_s <=> y.value.to_s } generate_full_list features_ordered_by_name, :features end
Generate feature list. This menu is not automatically added until yard configuration has this menu added.
# File lib/templates/default/fulldoc/html/setup.rb, line 100 def generate_featuredirectories_list directories_ordered_by_name = root_feature_directories.sort { |x,y| x.value.to_s <=> y.value.to_s } generate_full_list directories_ordered_by_name, :featuredirectories, :list_title => "Features by Directory", :list_filename => "featuredirectories_list.html" end
Helpler method to generate a full_list page of the specified objects with the specified type.
# File lib/templates/default/fulldoc/html/setup.rb, line 109 def generate_full_list(objects,type,options = {}) defaults = { :list_title => "#{type.to_s.capitalize} List", :css_class => "class", :list_filename => "#{type.to_s.gsub(/s$/,'')}_list.html" } options = defaults.merge(options) @items = objects @list_type = type @list_title = options[:list_title] @list_class = options[:css_class] asset options[:list_filename], erb(:full_list) end
Generate a step list. This menu is not automatically added until yard configuration has this menu added.
# File lib/templates/default/fulldoc/html/setup.rb, line 94 def generate_step_list generate_full_list YARD::Registry.all(:step), :steps end
Generate a step definition list. This menu is not automatically added until yard configuration has this menu added.
# File lib/templates/default/fulldoc/html/setup.rb, line 87 def generate_stepdefinition_list generate_full_list YARD::Registry.all(:stepdefinition), :stepdefinitions, :list_title => "Step Definitions List" end
Generate tag list. This method is called automatically by YARD
based on the menus defined in the layout
# File lib/templates/default/fulldoc/html/setup.rb, line 78 def generate_tag_list tags = Registry.all(:tag) tags_ordered_by_use = Array(tags).sort {|x,y| y.all_scenarios.size <=> x.all_scenarios.size } generate_full_list tags_ordered_by_use, :tags end
# File lib/templates/default/feature/html/setup.rb, line 32 def highlight_matches(step) value = step.value.dup if step.definition matches = step.value.match(step.definition.regex) if matches matches[1..-1].reverse.each_with_index do |match,index| next if match == nil value[matches.begin((matches.size - 1) - index)..(matches.end((matches.size - 1) - index) - 1)] = "<span class='match'>#{h(match)}</span>" end end end value end
# File lib/templates/default/feature/html/setup.rb, line 49 def htmlify_with_newlines(text) text.split("\n").collect {|c| h(c).gsub(/\s/,' ') }.join("<br/>") end
# File lib/docserver/doc_server/full_list/html/setup.rb, line 3 def init # This is the css class type; defaulting to class. @list_class = "class" case @list_type.to_sym when :features; @list_title = "Features" when :tags; @list_title = "Tags" when :class; @list_title = "Class List" when :methods; @list_title = "Method List" when :files; @list_title = "File List" end sections :full_list end
Determine if the object happens to be a CodeObject defined in this gem.
Quite a few of the classes/modules defined here are not object that we would never want to display but it's alright if we match on them.
# File lib/templates/default/layout/html/setup.rb, line 90 def is_yard_lucid_object?(object) YARD::CodeObjects::Lucid.constants.any? { |constant| object.class.name == "YARD::CodeObjects::Lucid::#{constant}" } end
Append yard-lucid javascript to yard core javascripts
# File lib/templates/default/layout/html/setup.rb, line 11 def javascripts super + %w(js/lucid.js) end
This method overrides YARD's default layout template's layout method.
The existing YARD
layout method generates the url for the nav menu on the left side. For Yard-Lucid objects this will default to the class_list.html. which is not what we want for features, tags, and so forth.
So we override this method and put in some additional logic to figure out the correct list to appear in the search. This can be particularly tricky because
This method removes the namespace from the root node, generates the class list, and then adds it back into the root node.
# File lib/templates/default/layout/html/setup.rb, line 66 def layout @nav_url = url_for_list(!@file || options.index ? 'class' : 'file') if is_yard_lucid_object?(object) @nav_url = rewrite_nav_url(@nav_url) end if !object || object.is_a?(String) @path = nil elsif @file @path = @file.path elsif !object.is_a?(YARD::CodeObjects::NamespaceObject) @path = object.parent.path else @path = object.path end erb(:layout) end
# File lib/templates/default/steptransformers/html/setup.rb, line 64 def link_constants(definition) value = definition.literal_value.dup definition.constants_from_value(value).each do |name| constant = YARD::Registry.all(:constant).find{|c| c.name == name.to_sym } value.gsub!(/\b#{name}\b/,"<a href='#{url_for(constant)}'>#{name}</a>") if constant end value end
# File lib/templates/default/steptransformers/html/setup.rb, line 75 def link_transformed_step(step) value = step.value.dup if step.definition matches = step.value.match(step.definition.regex) if matches matches[1..-1].reverse.each_with_index do |match,index| next if match == nil transform = step.transforms.find {|transform| transform.regex.match(match) } value[matches.begin((matches.size - 1) - index)..(matches.end((matches.size - 1) - index) - 1)] = transform ? "<a href='#{url_for(transform)}'>#{h(match)}</a>" : "<span class='match'>#{match}</span>" end end end value end
# File lib/templates/default/featuredirectory/html/setup.rb, line 7 def markdown(text) htmlify(text,:markdown) rescue h(text) end
# File lib/templates/default/featuretags/html/setup.rb, line 7 def namespace erb(:namespace) end
The top-level feature directories. This is affected by the directories that YARD
is told to parse. All other features in sub-directories are contained under each of these top-level directories.
@example Generating one feature directory
`yardoc 'example/**/*'`
@example Generating two feature directories
`yardoc 'features/**/*' 'specs/**/*'`
# File lib/templates/default/fulldoc/html/setup.rb, line 36 def root_feature_directories @root_feature_directories ||= YARD::CodeObjects::Lucid::LUCID_NAMESPACE.children.find_all { |child| child.is_a?(YARD::CodeObjects::Lucid::FeatureDirectory) } end
# File lib/templates/default/feature/html/setup.rb, line 14 def scenarios scenarios = "" if @feature.background @scenario = @feature.background @id = "background" scenarios += erb(:scenario) end @feature.scenarios.each_with_index do |scenario,index| @scenario = scenario @id = "scenario_#{index}" scenarios += erb(:scenario) end scenarios end
Generates pages for the feature directories found. Starting with all root-level feature directories and then recursively finding all child feature directories.
# File lib/templates/default/fulldoc/html/setup.rb, line 50 def serialize_feature_directories serialize_feature_directories_recursively(root_feature_directories) root_feature_directories.each { |directory| serialize(directory) } end
Generate a page for each Feature directory. This is called recursively to ensure that all feature directories contained as children are rendered to pages.
# File lib/templates/default/fulldoc/html/setup.rb, line 58 def serialize_feature_directories_recursively(namespaces) namespaces.each do |namespace| Templates::Engine.with_serializer(namespace, options[:serializer]) do options[:object] = namespace T('layout').run(options) end serialize_feature_directories_recursively(namespace.children.find_all { |child| child.is_a?(YARD::CodeObjects::Lucid::FeatureDirectory) }) end end
Generate pages for the objects if there are objects of this type contained within the Registry.
# File lib/templates/default/fulldoc/html/setup.rb, line 42 def serialize_object_type(type) objects = Registry.all(type.to_sym) Array(objects).each { |object| serialize(object) } end
# File lib/templates/default/specifications/html/setup.rb, line 27 def step_definitions @step_definitions ||= YARD::Registry.all(:stepdefinition) end
# File lib/templates/default/specifications/html/setup.rb, line 23 def step_transformers YARD::CodeObjects::Lucid::LUCID_STEPTRANSFORM_NAMESPACE end
# File lib/templates/default/steptransformers/html/setup.rb, line 12 def step_transforms @step_transforms ||= begin YARD::Registry.all(:steptransform).sort_by { |definition| definition.steps.length * -1 } end end
# File lib/templates/default/steptransformers/html/setup.rb, line 24 def stepdefinitions @item_title = "Step Definitions" @item_anchor_name = "step_definitions" @item_type = "step definition" @items = step_definitions erb(:header) + erb(:transformers) end
# File lib/templates/default/steptransformers/html/setup.rb, line 32 def steptransforms @item_title = "Step Transforms" @item_anchor_name = "step_transforms" @item_type = "step transform" @items = step_transforms erb(:header) + erb(:transformers) end
Append yard-lucid stylesheet to yard core stylesheets
# File lib/templates/default/layout/html/setup.rb, line 6 def stylesheets super + %w(css/lucid.css) end
# File lib/templates/default/featuretags/html/setup.rb, line 31 def tagify(tag) %{<span class="tag" href="#{url_for tag}">#{tag.value}</span>} end
# File lib/templates/default/specifications/html/setup.rb, line 31 def transformers @transformers ||= YARD::Registry.all(:steptransform) end
# File lib/templates/default/specifications/html/setup.rb, line 35 def undefined_steps @undefined_steps ||= Registry.all(:step).reject { |s| s.definition || s.scenario.outline? } end
# File lib/templates/default/steptransformers/html/setup.rb, line 40 def undefinedsteps @item_title = "Undefined Steps" @item_anchor_name = "undefined_steps" @item_type = nil @items = undefined_steps erb(:header) + erb(:undefinedsteps) end
# File lib/templates/default/steptransformers/html/setup.rb, line 49 def unique_steps(steps) uniq_steps = {} steps.each {|s| (uniq_steps[s.value.to_s] ||= []) << s } uniq_steps end