Top Level Namespace
- Includes:
- YARD::Templates::Helpers::HtmlHelper
Defined Under Namespace
Modules: Cucumber, CucumberInTheYARD, YARD
Instance Method Summary
collapse
Instance Method Details
#all_features_link ⇒ Object
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
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
|
#background ⇒ Object
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
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.
146
147
148
149
150
151
152
153
154
|
# File 'lib/templates/default/fulldoc/html/setup.rb', line 146
def class_list(root = Registry.root)
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
|
#directories ⇒ Object
15
16
17
|
# File 'lib/templates/default/featuredirectory/html/setup.rb', line 15
def directories
@directories ||= @directory.subdirectories
end
|
#directory_node(directory) ⇒ Object
172
173
174
175
|
# File 'lib/templates/default/fulldoc/html/setup.rb', line 172
def directory_node(directory)
@directory = directory
erb(:directories)
end
|
55
56
57
58
59
60
61
62
63
|
# File 'lib/templates/default/steptransformers/html/setup.rb', line 55
def (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 ⇒ Object
#feature_subdirectories ⇒ Object
20
21
22
|
# File 'lib/templates/default/requirements/html/setup.rb', line 20
def feature_subdirectories
@feature_subdirectories ||= Registry.all(:featuredirectory) - feature_directories
end
|
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
|
#features ⇒ Object
8
9
10
|
# File 'lib/templates/default/tag/html/setup.rb', line 8
def features
@tag.features
end
|
#generate_feature_list ⇒ Object
Note:
this method is called automatically by YARD based on the menus defined in the layout
Generate feature list
79
80
81
82
83
|
# File 'lib/templates/default/fulldoc/html/setup.rb', line 79
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 ⇒ Object
Note:
this menu is not automatically added until yard configuration has this menu added
Generate feature list See the layout template method that loads the menus
112
113
114
115
116
117
|
# File 'lib/templates/default/fulldoc/html/setup.rb', line 112
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 = {}) ⇒ Object
Helpler method to generate a full_list page of the specified objects with the specified type.
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/templates/default/fulldoc/html/setup.rb', line 122
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 ⇒ Object
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
105
106
107
|
# File 'lib/templates/default/fulldoc/html/setup.rb', line 105
def generate_step_list
generate_full_list YARD::Registry.all(:step), :steps
end
|
#generate_stepdefinition_list ⇒ Object
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
97
98
99
100
|
# File 'lib/templates/default/fulldoc/html/setup.rb', line 97
def generate_stepdefinition_list
generate_full_list YARD::Registry.all(:stepdefinition), :stepdefinitions,
:list_title => "Step Definitions List"
end
|
#generate_tag_list ⇒ Object
Note:
this method is called automatically by YARD based on the menus defined in the layout
Generate tag list
87
88
89
90
91
92
|
# File 'lib/templates/default/fulldoc/html/setup.rb', line 87
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) ⇒ 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/,' ') }.join("<br/>")
end
|
#init ⇒ Object
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
|
#javascripts ⇒ Object
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
|
#link_constants(definition) ⇒ Object
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’
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/templates/default/layout/html/setup.rb', line 32
def
= [ "features", "tags" ]
if YARD::Config.options["yard-cucumber"] and YARD::Config.options["yard-cucumber"]["menus"]
= YARD::Config.options["yard-cucumber"]["menus"]
end
.map {|| [] }.compact + super
end
|
#namespace ⇒ Object
7
8
9
|
# File 'lib/templates/default/featuretags/html/setup.rb', line 7
def namespace
erb(:namespace)
end
|
#root_feature_directories ⇒ Object
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.
#scenarios ⇒ Object
12
13
14
|
# File 'lib/templates/default/tag/html/setup.rb', line 12
def scenarios
@tag.scenarios
end
|
#serialize_feature_directories ⇒ Object
Generates pages for the feature directories found. Starting with all root-level feature directories and then recursively finding all child feature directories.
#serialize_feature_directories_recursively(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.
66
67
68
69
70
71
72
73
74
|
# 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) ⇒ Object
Generate pages for the objects if there are objects of this type contained within the Registry.
47
48
49
50
|
# 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 ⇒ Object
28
29
30
|
# File 'lib/templates/default/requirements/html/setup.rb', line 28
def step_definitions
@step_definitions ||= YARD::Registry.all(:stepdefinition)
end
|
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
|
#stepdefinitions ⇒ Object
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
|
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
|
#stylesheets ⇒ Object
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
|
19
20
21
|
# File 'lib/templates/default/featuretags/html/setup.rb', line 19
def tags
@tags ||= Registry.all(:tag).sort_by {|l| l.value.to_s }
end
|
32
33
34
|
# File 'lib/templates/default/requirements/html/setup.rb', line 32
def transformers
@transformers ||= YARD::Registry.all(:steptransform)
end
|
#undefined_steps ⇒ Object
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
|
#undefinedsteps ⇒ Object
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
|
When a menu is specified in the yard configuration file, this hash contains the details about the menu necessary for it to be displayed.
50
51
52
53
54
55
56
|
# File 'lib/templates/default/layout/html/setup.rb', line 50
def
{ "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
|