Top Level Namespace

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

Defined Under Namespace

Modules: Cucumber, CucumberInTheYARD, YARD

Instance Method Summary collapse

Instance Method Details

#all_directories_by_letterObject



30
31
32
33
34
35
36
37
# File 'lib/templates/default/requirements/html/setup.rb', line 30

def all_directories_by_letter
  hash = {}
  objects = feature_directories
  objects = run_verifier(objects)
  objects.each {|o| (hash[o.value.to_s[0,1].upcase] ||= []) << o }
  hash.values.each {|v| v.sort! {|a,b| b.value.to_s <=> a.value.to_s } }
  hash
end

#all_features_by_letterObject



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

def all_features_by_letter
  hash = {}
  @tag.features.each {|o| (hash[o.value.to_s[0,1].upcase] ||= []) << o }
  hash
end

#all_scenarios_by_letterObject



16
17
18
19
20
# File 'lib/templates/default/tag/setup.rb', line 16

def all_scenarios_by_letter
  hash = {}
  @tag.scenarios.each {|o| (hash[o.value.to_s[0,1].upcase] ||= []) << o }
  hash
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

#all_types_by_letter(type) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/templates/default/featuredirectory/html/setup.rb', line 13

def all_types_by_letter(type)
  hash = {}
  objects = @directory.children.find_all {|child| child.is_a?(type) }
  objects = run_verifier(objects)
  objects.each {|o| (hash[o.value.to_s[0,1].upcase] ||= []) << o }
  hash.values.each {|v| v.sort! {|a,b| b.value.to_s <=> a.value.to_s } }
  hash
end

#backgroundObject



11
12
13
14
15
# File 'lib/templates/default/feature/setup.rb', line 11

def background
  @scenario = @feature.background
  @id = "background"
  erb(:scenario)  
end

#class_list(root = Registry.root) ⇒ Object

Remove CUCUMBER namespace from the class list



47
48
49
50
51
52
# File 'lib/templates/default/fulldoc/html/setup.rb', line 47

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

#directoryObject



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

def directory
  @objects_by_letter = all_types_by_letter(YARD::CodeObjects::Cucumber::Feature)
  @directories_by_letter = @directory.children.find_all {|child| child.is_a?(YARD::CodeObjects::Cucumber::FeatureDirectory) }.sort_by {|dir| dir.name.to_s }
  erb(:directory)
end

#feature_directoriesObject



39
40
41
# File 'lib/templates/default/requirements/html/setup.rb', line 39

def feature_directories
  @feature_directories ||= Registry.all(:featuredirectory)
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



23
24
25
# File 'lib/templates/default/featuretags/html/setup.rb', line 23

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

#generate_full_list(objects, friendly_name = nil) ⇒ Object



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

def generate_full_list(objects,friendly_name=nil)
  if !objects.empty?
    @items = objects
    @list_type = "#{objects.first.type.to_s}s"
    @list_title = "#{friendly_name || objects.first.type.to_s.capitalize} List"
    @list_class = "class"
    asset("#{objects.first.type}_list.html",erb(:full_list))
  else
    log.warn "Full List: Failed to create a list because the objects array is empty."
  end
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/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/setup.rb', line 53

def htmlify_with_newlines(text)
  text.split("\n").collect {|c| h(c) }.join("<br/>") 
end

#initObject



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

def init
  super
  @tag = object

  sections.push :tag
  sections.push :feature unless @tag.features.empty?
  sections.push :scenario unless @tag.scenarios.empty?
end


34
35
36
37
38
39
40
41
42
43
# File 'lib/templates/default/steptransformers/setup.rb', line 34

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


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/templates/default/steptransformers/setup.rb', line 46

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

#namespaceObject



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

def namespace
  erb(:namespace)
end

#scenariosObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/templates/default/feature/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(namespaces) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/templates/default/fulldoc/html/setup.rb', line 54

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

#stepdefinitionsObject



6
7
8
9
10
11
# File 'lib/templates/default/steptransformers/setup.rb', line 6

def stepdefinitions
  @item_title = "Step Definitions"
  @item_type = "step definition"
  @items = YARD::Registry.all(:stepdefinition)
  erb(:header) + erb(:transformers)
end

#stepsObject



51
52
53
# File 'lib/templates/default/requirements/html/setup.rb', line 51

def steps
  @steps ||= Registry.all(:step)
end

#steptransformsObject



13
14
15
16
17
18
# File 'lib/templates/default/steptransformers/setup.rb', line 13

def steptransforms
  @item_title = "Step Transforms"
  @item_type = "step transform"
  @items = YARD::Registry.all(:steptransform)
  erb(:header) + erb(:transformers)
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)
end

#undefined_stepsObject



20
21
22
23
24
25
# File 'lib/templates/default/steptransformers/setup.rb', line 20

def undefined_steps
  @item_title = "Undefined Steps"
  @item_type = nil
  @undefined_steps ||= Registry.all(:step).reject {|s| s.definition || s.scenario.outline? }
  erb(:header) + erb(:undefined_steps)
end

#unique_steps(steps) ⇒ Object



28
29
30
31
32
# File 'lib/templates/default/steptransformers/setup.rb', line 28

def unique_steps(steps)
  uniq_steps = {}
  steps.each {|s| (uniq_steps[s.value.to_s] ||= []) << s }
  uniq_steps
end