Top Level Namespace

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

Defined Under Namespace

Modules: Cucumber, CucumberInTheYARD, YARD

Instance Method Summary collapse

Instance Method Details



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

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

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

#directoriesObject



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

def directories
  @directories ||= @directory.subdirectories
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_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/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


56
57
58
59
60
61
62
63
64
65
# File 'lib/templates/default/steptransformers/html/setup.rb', line 56

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


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/templates/default/steptransformers/html/setup.rb', line 68

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

#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



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

#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

#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