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 8
def background
  @scenario = @feature.background
  @id = "background"
  erb(:scenario)
end
class_list(root = Registry.root, tree = TreeContext.new) click to toggle source

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.

Calls superclass method
# 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
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 31
def current_menu_lists
  @current_menu_lists ||= begin
    menus = [ "features", "tags" ]

    if YARD::Config.options["yard-lucid"] and YARD::Config.options["yard-lucid"]["menus"]
      menus = YARD::Config.options["yard-lucid"]["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.

# 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
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/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
feature_subdirectories() click to toggle source
# File lib/templates/default/specifications/html/setup.rb, line 19
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. 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_featuredirectories_list() click to toggle source

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

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

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

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
highlight_matches(step) click to toggle source
# 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
htmlify_with_newlines(text) click to toggle source
# File lib/templates/default/feature/html/setup.rb, line 49
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; 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
is_yard_lucid_object?(object) click to toggle source

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

Append yard-lucid javascript to yard core javascripts

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

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
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-lucid 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-lucid:
  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
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 Lucid 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 97
def rewrite_nav_url(nav_url)
  if object.is_a?(YARD::CodeObjects::Lucid::Feature) && current_menu_lists.include?('features')
    nav_url.gsub('class_list.html','feature_list.html')
  elsif object.is_a?(YARD::CodeObjects::Lucid::FeatureDirectory) && current_menu_lists.include?('directories')
    nav_url.gsub('class_list.html','featuredirectories_list.html')
  elsif object.is_a?(YARD::CodeObjects::Lucid::Tag) && current_menu_lists.include?('tags')
    nav_url.gsub('class_list.html','tag_list.html')
  elsif object.is_a?(YARD::CodeObjects::Lucid::Step) && current_menu_lists.include?('steps')
    nav_url.gsub('class_list.html','step_list.html')
  elsif object.is_a?(YARD::CodeObjects::Lucid::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 '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
scenarios() click to toggle source
# 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
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 50
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 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
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 42
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/specifications/html/setup.rb, line 27
def step_definitions
  @step_definitions ||= YARD::Registry.all(:stepdefinition)
end
step_transformers() click to toggle source
# File lib/templates/default/specifications/html/setup.rb, line 23
def step_transformers
  YARD::CodeObjects::Lucid::LUCID_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-lucid stylesheet to yard core stylesheets

Calls superclass method
# File lib/templates/default/layout/html/setup.rb, line 6
def stylesheets
  super + %w(css/lucid.css)
end
tagify(tag) click to toggle source
# File lib/templates/default/featuretags/html/setup.rb, line 31
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/specifications/html/setup.rb, line 31
def transformers
  @transformers ||= YARD::Registry.all(:steptransform)
end
undefined_steps() click to toggle source
# 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
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_lucid_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 47
def yard_lucid_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