class Object

Public Instance Methods

all_tags_by_letter() click to toggle source
# File lib/templates/default/featuretags/html/setup.rb, line 11
def all_tags_by_letter
  hash = {}
  objects = tags
  objects = run_verifier(objects)
  objects.each {|o| (hash[o.value.to_s[1,1].upcase] ||= []) << o }
  hash
end
alpha_table(objects) click to toggle source
# 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
background() click to toggle source
# File lib/templates/default/feature/html/setup.rb, line 11
def background
  @scenario = @feature.background
  @id = "background"
  erb(:scenario)  
end
class_list(root = Registry.root, tree = TreeContext.new) click to toggle source

@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.

Calls superclass method
# File lib/templates/default/fulldoc/html/setup.rb, line 166
def class_list(root = Registry.root, tree = TreeContext.new)
  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
current_menu_lists() click to toggle source

By default we want to display the 'features' and 'tags' menu but we will allow the YARD configuration to override that functionality.

# File lib/templates/default/layout/html/setup.rb, line 40
def current_menu_lists
  @current_menu_lists ||= begin
    menus = [ "features", "tags" ]

    if YARD::Config.options["yard-cucumber"] and YARD::Config.options["yard-cucumber"]["menus"]
      menus = YARD::Config.options["yard-cucumber"]["menus"]
    end

    menus
  end
end
directories() click to toggle source
# File lib/templates/default/featuredirectory/html/setup.rb, line 15
def directories
  @directories ||= @directory.subdirectories
end
directory_node(directory,padding,row) click to toggle source

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
display_comments_for(item) click to toggle source
# 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
feature_directories() click to toggle source
# 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
feature_subdirectories() click to toggle source
# File lib/templates/default/requirements/html/setup.rb, line 20
def feature_subdirectories
  @feature_subdirectories ||= Registry.all(:featuredirectory) - feature_directories
end
feature_tags_with_all_scenario_tags(feature) click to toggle source
# File lib/templates/default/featuretags/html/setup.rb, line 27
def feature_tags_with_all_scenario_tags(feature)
  feature.tags.collect {|t| t.value} + feature.scenarios.collect {|s| s.tags.collect {|t| t.value} }.flatten.uniq
end
features() click to toggle source
# 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() click to toggle source

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_featuredirectories_list() click to toggle source

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
generate_full_list(objects,type,options = {}) click to toggle source

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_step_list() click to toggle source

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_stepdefinition_list() click to toggle source

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() click to toggle source

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
highlight_matches(step) click to toggle source
# File lib/templates/default/feature/html/setup.rb, line 36
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
htmlify_with_newlines(text) click to toggle source
# File lib/templates/default/feature/html/setup.rb, line 53
def htmlify_with_newlines(text)
  text.split("\n").collect {|c| h(c).gsub(/\s/,'&nbsp;') }.join("<br/>")
end
init() click to toggle source
# 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
is_yard_cucumber_object?(object) click to toggle source

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
javascripts() click to toggle source

Append yard-cucumber javascript to yard core javascripts

Calls superclass method
# File lib/templates/default/layout/html/setup.rb, line 15
def javascripts
  super + %w(js/cucumber.js)
end
layout() click to toggle source

@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-Cucumber 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
markdown(text) click to toggle source
# File lib/templates/default/featuredirectory/html/setup.rb, line 7
def markdown(text)
  htmlify(text,:markdown) rescue h(text)
end
menu_lists() click to toggle source

Append yard-cucumber specific menus 'features' and 'tags'

'features' and 'tags' are enabled by default.

'step definitions' and 'steps' may be enabled by setting up a value in yard configuration file '~/.yard/config'

@example `~/.yard.config`

yard-cucumber:
  menus: [ 'features', 'directories', 'tags', 'step definitions', 'steps' ]
Calls superclass method
namespace() click to toggle source
# File lib/templates/default/featuretags/html/setup.rb, line 7
def namespace
  erb(:namespace)
end
record_feature_scenarios(features) click to toggle source

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
record_tagged_scenarios(tags) click to toggle source

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
rewrite_nav_url(nav_url) click to toggle source

The re-write rules will only change the nav link to a new menu if it is a a Cucumber CodeObject that we care about and that we have also generated a menu for that item.

# File lib/templates/default/layout/html/setup.rb, line 117
def rewrite_nav_url(nav_url)
  if object.is_a?(YARD::CodeObjects::Cucumber::Feature) && current_menu_lists.include?('features')
    nav_url.gsub('class_list.html','feature_list.html')
  elsif object.is_a?(YARD::CodeObjects::Cucumber::FeatureDirectory) && current_menu_lists.include?('directories')
    nav_url.gsub('class_list.html','featuredirectories_list.html')
  elsif object.is_a?(YARD::CodeObjects::Cucumber::Tag) && current_menu_lists.include?('tags')
    nav_url.gsub('class_list.html','tag_list.html')
  elsif object.is_a?(YARD::CodeObjects::Cucumber::Step) && current_menu_lists.include?('steps')
    nav_url.gsub('class_list.html','step_list.html')
  elsif object.is_a?(YARD::CodeObjects::Cucumber::StepTransformersObject) && current_menu_lists.include?('step definitions')
    nav_url.gsub('class_list.html','stepdefinition_list.html')
  else
    nav_url
  end
end
root_feature_directories() click to toggle source

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
scenarios() click to toggle source
# 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
serialize_feature_directories() click to toggle source

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
serialize_feature_directories_recursively(namespaces) click to toggle source

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
serialize_object_type(type) click to toggle source

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
step_definitions() click to toggle source
# File lib/templates/default/requirements/html/setup.rb, line 28
def step_definitions
  @step_definitions ||= YARD::Registry.all(:stepdefinition)
end
step_transformers() click to toggle source
# File lib/templates/default/requirements/html/setup.rb, line 24
def step_transformers
  YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE
end
step_transforms() click to toggle source
# 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
stepdefinitions() click to toggle source
# 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
steptransforms() click to toggle source
# 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
stylesheets() click to toggle source

Append yard-cucumber stylesheet to yard core stylesheets

Calls superclass method
# File lib/templates/default/layout/html/setup.rb, line 8
def stylesheets
  super + %w(css/cucumber.css)
end
tagify(tag) click to toggle source
# File lib/templates/default/featuretags/html/setup.rb, line 32
def tagify(tag)
  %{<span class="tag" href="#{url_for tag}">#{tag.value}</span>}
end
tags() click to toggle source
# File lib/templates/default/featuredirectory/html/setup.rb, line 27
def tags
  @tags ||= (features.collect{|feature| feature.tags } + scenarios.collect {|scenario| scenario.tags }).flatten.uniq.sort_by {|l| l.value.to_s }
end
transformers() click to toggle source
# File lib/templates/default/requirements/html/setup.rb, line 32
def transformers
  @transformers ||= YARD::Registry.all(:steptransform)
end
undefined_steps() click to toggle source
# 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
undefinedsteps() click to toggle source
# 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
unique_steps(steps) click to toggle source
# 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
yard_cucumber_menus() click to toggle source

When a menu is specified in the yard configuration file, this hash contains the details about the menu necessary for it to be displayed.

@see menu_lists

# File lib/templates/default/layout/html/setup.rb, line 58
def yard_cucumber_menus
  { "features" => { :type => 'feature', :title => 'Features', :search_title => 'Features' },
    "directories" => { :type => 'featuredirectories', :title => 'Features by Directory', :search_title => 'Features by Directory' },
    "tags" => { :type => 'tag', :title => 'Tags', :search_title => 'Tags' },
    "step definitions" => { :type => 'stepdefinition', :title => 'Step Definitions', :search_title => 'Step Defs' },
    "steps" => { :type => 'step', :title => 'Steps', :search_title => 'Steps' } }
end