Top Level Namespace

Includes:
YARD::Templates::Helpers::HtmlHelper

Defined Under Namespace

Modules: Cucumber, CucumberInTheYARD, YARD

Instance Method Summary collapse

Instance Method Details

Generate a link to the ‘All Features’ in the features_list.html

When there are no feature directories or multiple top-level feature directories then we want to link to the ‘Requirements’ page

When there are is just one feature directory then we want to link to that directory



124
125
126
127
128
129
130
131
132
# File 'lib/templates/default/fulldoc/html/setup.rb', line 124

def all_features_link
  root_feature_directories = YARD::CodeObjects::Cucumber::CUCUMBER_NAMESPACE.children.find_all {|child| child.is_a?(YARD::CodeObjects::Cucumber::FeatureDirectory)}

  if root_feature_directories.length == 0 || root_feature_directories.length > 1
    linkify YARD::CodeObjects::Cucumber::CUCUMBER_NAMESPACE, "All Features"
  else
    linkify root_feature_directories.first, "All Features"
  end
end

#all_tags_by_letterObject



11
12
13
14
15
16
17
# 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) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/templates/default/tag/html/setup.rb', line 17

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

#backgroundObject



11
12
13
14
15
# 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) ⇒ Object

The existing ‘Class List’ search field would normally contain the Cucumber Namespace object that has been added. Here we call the class_list method that is contained in the YARD template and we remove the namespace. Returning it when we are done.



94
95
96
97
98
99
# File 'lib/templates/default/fulldoc/html/setup.rb', line 94

def class_list(root = Registry.root)
  root.instance_eval { children.delete YARD::CodeObjects::Cucumber::CUCUMBER_NAMESPACE } if root == Registry.root
  out = super(root)
  root.instance_eval { children << YARD::CodeObjects::Cucumber::CUCUMBER_NAMESPACE } if root == Registry.root
  out
end

#directoriesObject



15
16
17
# File 'lib/templates/default/featuredirectory/html/setup.rb', line 15

def directories
  @directories ||= @directory.subdirectories
end

#display_comments_for(item) ⇒ Object



55
56
57
58
59
60
61
62
63
# 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_directoriesObject



16
17
18
# 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_subdirectoriesObject



20
21
22
# 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) ⇒ Object



27
28
29
# 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

#featuresObject



8
9
10
# File 'lib/templates/default/tag/html/setup.rb', line 8

def features
  @tag.features
end

#generate_feature_listObject

Note:

this method is called automically by YARD based on the menus defined in the layout

Generate feature list



52
53
54
55
# File 'lib/templates/default/fulldoc/html/setup.rb', line 52

def generate_feature_list
  @features = Registry.all(:feature)
  generate_full_list @features.sort {|x,y| x.value.to_s <=> y.value.to_s }, :feature
end

#generate_full_list(objects, list_type, friendly_name = nil) ⇒ Object

Helpler method to generate a full_list page of the specified objects with the specified type.



80
81
82
83
84
85
86
# File 'lib/templates/default/fulldoc/html/setup.rb', line 80

def generate_full_list(objects,list_type,friendly_name=nil)
  @items = objects
  @list_type = "#{list_type}s"
  @list_title = "#{friendly_name || list_type.to_s.capitalize} List"
  @list_class = "class"
  asset("#{list_type}_list.html",erb(:full_list))
end

#generate_step_listObject

Note:

this menu is not automatically added until yard configuration has this menu added

Generate a step list See the layout template method that loads the menus



74
75
76
# File 'lib/templates/default/fulldoc/html/setup.rb', line 74

def generate_step_list
  generate_full_list YARD::Registry.all(:step), :step
end

#generate_stepdefinition_listObject

Note:

this menu is not automatically added until yard configuration has this menu added

Generate a step definition list See the layout template method that loads the menus



67
68
69
# File 'lib/templates/default/fulldoc/html/setup.rb', line 67

def generate_stepdefinition_list
  generate_full_list YARD::Registry.all(:stepdefinition), :stepdefinition
end

#generate_tag_listObject

Note:

this method is called automically by YARD based on the menus defined in the layout

Generate tag list



59
60
61
62
# File 'lib/templates/default/fulldoc/html/setup.rb', line 59

def generate_tag_list
  @tags = Registry.all(:tag)
  generate_full_list @tags.sort {|x,y| y.all_scenarios.size <=> x.all_scenarios.size }, :tag
end

#highlight_matches(step) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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) ⇒ Object



53
54
55
# 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

#initObject



1
2
3
4
5
6
# File 'lib/templates/default/tag/html/setup.rb', line 1

def init
  super
  @tag = object

  sections.push :tag
end

#javascriptsObject

Append yard-cucumber javascript to yard core javascripts



15
16
17
# File 'lib/templates/default/layout/html/setup.rb', line 15

def javascripts
  super + %w(js/cucumber.js)
end


65
66
67
68
69
70
71
72
73
74
# File 'lib/templates/default/steptransformers/html/setup.rb', line 65

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


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/templates/default/steptransformers/html/setup.rb', line 77

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

#markdown(text) ⇒ Object



7
8
9
# File 'lib/templates/default/featuredirectory/html/setup.rb', line 7

def markdown(text)
  htmlify(text,:markdown) rescue h(text)
end

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’

Examples:

‘~/.yard.config`


yard-cucumber:
  menus: [ 'features', 'tags', 'step definitions', 'steps' ]


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/templates/default/layout/html/setup.rb', line 32

def menu_lists
  
  menus = [ "features", "tags" ]

  # load the yard-cucumber menus defined in the configuration file
  if YARD::Config.options["yard-cucumber"] and YARD::Config.options["yard-cucumber"]["menus"]
    menus = YARD::Config.options["yard-cucumber"]["menus"]
  end

  menus.map {|menu_name| yard_cucumber_menus[menu_name] }.compact + super
end

#namespaceObject



7
8
9
# File 'lib/templates/default/featuretags/html/setup.rb', line 7

def namespace
  erb(:namespace)
end

#scenariosObject



12
13
14
# File 'lib/templates/default/tag/html/setup.rb', line 12

def scenarios
  @tag.scenarios
end

#serialize_feature_directories(namespaces) ⇒ Object

Generate a page for each Feature Directory. This is called recursively to ensure that all feature directories contained as children are rendered to pages.



106
107
108
109
110
111
112
113
114
# File 'lib/templates/default/fulldoc/html/setup.rb', line 106

def serialize_feature_directories(namespaces)
  namespaces.each do |namespace|
    Templates::Engine.with_serializer(namespace, options[:serializer]) do
      options[:object] = namespace
      T('layout').run(options)
    end
    serialize_feature_directories(namespace.children.find_all {|child| child.is_a?(YARD::CodeObjects::Cucumber::FeatureDirectory)})
  end
end

#step_definitionsObject



28
29
30
# File 'lib/templates/default/requirements/html/setup.rb', line 28

def step_definitions
  @step_definitions ||= YARD::Registry.all(:stepdefinition)
end

#step_transformersObject



24
25
26
# File 'lib/templates/default/requirements/html/setup.rb', line 24

def step_transformers
  YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE
end

#step_transformsObject



12
13
14
15
16
# 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

#stepdefinitionsObject



24
25
26
27
28
29
30
# 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

#steptransformsObject



32
33
34
35
36
37
38
# 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

#stylesheetsObject

Append yard-cucumber stylesheet to yard core stylesheets



8
9
10
# File 'lib/templates/default/layout/html/setup.rb', line 8

def stylesheets
  super + %w(css/cucumber.css)
end

#tagify(tag) ⇒ Object



32
33
34
# File 'lib/templates/default/featuretags/html/setup.rb', line 32

def tagify(tag)
  %{<span class="tag" href="#{url_for tag}">#{tag.value}</span>} 
end

#tagsObject



19
20
21
# File 'lib/templates/default/featuretags/html/setup.rb', line 19

def tags
  @tags ||= Registry.all(:tag).sort_by {|l,o| l.value.to_s }
end

#transformersObject



32
33
34
# File 'lib/templates/default/requirements/html/setup.rb', line 32

def transformers
  @transformers ||= YARD::Registry.all(:steptransform)
end

#undefined_stepsObject



36
37
38
# 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

#undefinedstepsObject



40
41
42
43
44
45
46
# 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) ⇒ Object



49
50
51
52
53
# 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_menusObject

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 Also:



50
51
52
53
54
55
# File 'lib/templates/default/layout/html/setup.rb', line 50

def yard_cucumber_menus
  { "features" => { :type => 'feature', :title => 'Features', :search_title => 'Features' },
    "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