class Object
Public Instance Methods
# File lib/docserver/doc_server/full_list/html/setup.rb, line 16 def all_features_link linkify YARD::CodeObjects::Cucumber::CUCUMBER_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 11 def background @scenario = @feature.background @id = "background" erb(:scenario) end
@note This method overrides YARD's default template class_list
method.
The existing YARD
'Class List' search field contains all the YARD
namespace objects. We, however, do not want the Cucumber
Namespace YARD
Object
(which holds the features, tags, etc.) as it is a meta-object.
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 166 def class_list(root = Registry.root, tree = nil) return super unless root == Registry.root cucumber_namespace = YARD::CodeObjects::Cucumber::CUCUMBER_NAMESPACE root.instance_eval { children.delete cucumber_namespace } out = super(root) root.instance_eval { children.push cucumber_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.
@param directory [FeatureDirectory] this is the FeatureDirectory to display @param padding [Fixnum] this is the pixel value to ident as we want to keep
pushing in the padding to show the parent relationship
@param row [String] 'odd' or 'even' to correctly color the row
# File lib/templates/default/fulldoc/html/setup.rb, line 203 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/requirements/html/setup.rb, line 16 def feature_directories @feature_directories ||= YARD::CodeObjects::Cucumber::CUCUMBER_NAMESPACE.children.find_all {|child| child.is_a?(YARD::CodeObjects::Cucumber::FeatureDirectory)} end
# File lib/templates/default/requirements/html/setup.rb, line 20 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 @note 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_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 @note this menu is not automatically added until yard configuration has this menu added See the layout template method that loads the menus
# File lib/templates/default/fulldoc/html/setup.rb, line 132 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 142 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 @note this menu is not automatically added until yard configuration has this menu added See the layout template method that loads the menus
# File lib/templates/default/fulldoc/html/setup.rb, line 125 def generate_step_list generate_full_list YARD::Registry.all(:step), :steps end
Generate a step definition list @note this menu is not automatically added until yard configuration has this menu added See the layout template method that loads the menus
# File lib/templates/default/fulldoc/html/setup.rb, line 117 def generate_stepdefinition_list generate_full_list YARD::Registry.all(:stepdefinition), :stepdefinitions, :list_title => "Step Definitions List" end
Generate tag list @note this method is called automatically by YARD
based on the menus defined in the layout
# File lib/templates/default/fulldoc/html/setup.rb, line 105 def generate_tag_list tags = Registry.all(:tag) tags_ordered_by_use = Array(tags).sort {|x,y| y.total_scenarios <=> x.total_scenarios } record_tagged_scenarios(tags) generate_full_list tags_ordered_by_use, :tags end
# File lib/templates/default/feature/html/setup.rb, line 36 def highlight_matches(step) step.value.dup.tap do |value| if step.definition matches = step.definition.regex.match(step.value) if matches matches.named_captures.to_a.reverse.each_with_index do |(name,match),index| next if match == nil next unless name.start_with?("placeholder_") highlight = "<span class='match'>#{h(match)}</span>" value[matches.begin((matches.size - 1) - index)..(matches.end((matches.size - 1) - index) - 1)] = highlight end end end end end
# File lib/templates/default/steptransformers/html/setup.rb, line 96 def highlight_transformed_step(step, placeholder) value = step.value.dup if step.definition matches = step.definition.regex.match(value) matches[1..-1].reverse.each_with_index do |match,index| next if match == nil next unless placeholder.regex.match?(match) value[matches.begin((matches.size - 1) - index)..(matches.end((matches.size - 1) - index) - 1)] = "<span class='match'>#{match}</span>" end end value end
# File lib/templates/default/feature/html/setup.rb, line 52 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; here we just default 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.
@note 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.
@return [Boolean] true if the object's class name is one of the CodeObjects
# File lib/templates/default/layout/html/setup.rb, line 108 def is_yard_cucumber_object?(object) YARD::CodeObjects::Cucumber.constants.any? {|constant| object.class.name == "YARD::CodeObjects::Cucumber::#{constant}" } end
Append yard-gherkin-turnip javascript to yard core javascripts
# File lib/templates/default/layout/html/setup.rb, line 15 def javascripts super + %w(js/cucumber.js) end
@note 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-Gherkin-Turnip objects this will default to the class_list.html. which is not what we want for features, tags, etc.
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 79 def layout @nav_url = url_for_list(!@file || options.index ? 'class' : 'file') if is_yard_cucumber_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 65 def link_step_definition_name(step_definition) value = step_definition.literal_value.dup if step_definition.placeholders value.gsub!(/:[\w]+/) do |match| placeholder = step_definition.placeholders.find {|placeholder| placeholder.literal_value == match } placeholder ? "<a href='#{url_for(placeholder)}'>#{h(match)}</a>" : "<span class='match'>#{match}</span>" end end value end
# File lib/templates/default/steptransformers/html/setup.rb, line 78 def link_transformed_step(step) value = step.value.dup if step.definition matches = step.definition.regex.match(step.value) if matches matches[1..-1].reverse.each_with_index do |match,index| next if match == nil placeholder = step.placeholders.find {|placeholder| placeholder.regex.match(match) } value[matches.begin((matches.size - 1) - index)..(matches.end((matches.size - 1) - index) - 1)] = placeholder ? "<a href='#{url_for(placeholder)}'>#{h(match)}</a>" : "<span class='match'>#{h(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
# File lib/templates/default/requirements/html/setup.rb, line 32 def placeholders @placeholders ||= YARD::Registry.all(:placeholder) end
# File lib/templates/default/steptransformers/html/setup.rb, line 32 def placeholders_section @item_title = "Placeholders" @item_anchor_name = "placeholders" @item_type = "placeholder" @items = placeholders erb(:header) + erb(:placeholders) end
Count scenarios for features
# File lib/templates/default/fulldoc/html/setup.rb, line 85 def record_feature_scenarios(features) count_with_examples = 0 features.each do |f| count_with_examples += f.total_scenarios end return count_with_examples end
Count scenarios for tags
# File lib/templates/default/fulldoc/html/setup.rb, line 94 def record_tagged_scenarios(tags) scenario_count = 0 count_with_examples = 0 tags.each do |t| scenario_count += t.all_scenarios.size count_with_examples += t.total_scenarios end 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 'example/**/*' 'example2/**/*'`
@return the feature directories at the root of the Cucumber
Namespace.
# File lib/templates/default/fulldoc/html/setup.rb, line 39 def root_feature_directories @root_feature_directories ||= YARD::CodeObjects::Cucumber::CUCUMBER_NAMESPACE.children.find_all {|child| child.is_a?(YARD::CodeObjects::Cucumber::FeatureDirectory)} end
# File lib/templates/default/feature/html/setup.rb, line 17 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 56 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 66 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::Cucumber::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 47 def serialize_object_type(type) objects = Registry.all(type.to_sym) Array(objects).each {|object| serialize(object) } end
# File lib/templates/default/requirements/html/setup.rb, line 28 def step_definitions @step_definitions ||= YARD::Registry.all(:stepdefinition) end
# File lib/templates/default/steptransformers/html/setup.rb, line 24 def step_definitions_section @item_title = "Step Definitions" @item_anchor_name = "step_definitions" @item_type = "step definition" @items = step_definitions erb(:header) + erb(:step_definitions) end
# File lib/templates/default/requirements/html/setup.rb, line 24 def step_transformers YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE end
Append yard-gherkin-turnip stylesheet to yard core stylesheets
# File lib/templates/default/layout/html/setup.rb, line 8 def stylesheets super + %w(css/cucumber.css) end
# File lib/templates/default/featuretags/html/setup.rb, line 32 def tagify(tag) %{<span class="tag" href="#{url_for tag}">#{tag.value}</span>} end
# File lib/templates/default/requirements/html/setup.rb, line 36 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 undefined_steps_section @item_title = "Undefined Steps" @item_anchor_name = "undefined_steps" @item_type = nil @items = undefined_steps erb(:header) + erb(:undefined_steps) 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