Class: RSpecDocumentation::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_documentation/document.rb

Overview

Translates a Markdown document into a structure of parsed Markdown and embedded RSpec examples.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document:, path:, page_tree:) ⇒ Document

Returns a new instance of Document.



8
9
10
11
12
13
# File 'lib/rspec_documentation/document.rb', line 8

def initialize(document:, path:, page_tree:)
  @document = document
  @path = path
  @page_tree = page_tree
  @failures = []
end

Instance Attribute Details

#failuresObject (readonly)

Returns the value of attribute failures.



6
7
8
# File 'lib/rspec_documentation/document.rb', line 6

def failures
  @failures
end

#page_treeObject (readonly)

Returns the value of attribute page_tree.



6
7
8
# File 'lib/rspec_documentation/document.rb', line 6

def page_tree
  @page_tree
end

Instance Method Details



50
51
52
# File 'lib/rspec_documentation/document.rb', line 50

def footer
  RSpecDocumentation.template('footer').result(binding)
end

#headerObject



46
47
48
# File 'lib/rspec_documentation/document.rb', line 46

def header
  RSpecDocumentation.template('header').result(binding)
end

#homepageObject



42
43
44
# File 'lib/rspec_documentation/document.rb', line 42

def homepage
  gem_spec&.homepage
end

#htmlObject



30
31
32
# File 'lib/rspec_documentation/document.rb', line 30

def html
  parsed_document.html
end

#javascript_bundle_srcObject



58
59
60
# File 'lib/rspec_documentation/document.rb', line 58

def javascript_bundle_src
  Util.assets_root.join('bundle.js')
end

#renderObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/rspec_documentation/document.rb', line 19

def render
  parsed_document.execute_and_substitute_examples!

  if parsed_document.failures.empty?
    RSpecDocumentation.template('layout').result(binding)
  else
    failures.concat(parsed_document.failures)
    nil
  end
end

#specsObject



15
16
17
# File 'lib/rspec_documentation/document.rb', line 15

def specs
  @specs ||= parsed_document.specs
end

#stylesheet_bundle_hrefObject



54
55
56
# File 'lib/rspec_documentation/document.rb', line 54

def stylesheet_bundle_href
  Util.assets_root.join('bundle.css')
end

#titleObject



34
35
36
# File 'lib/rspec_documentation/document.rb', line 34

def title
  gem_spec&.name || 'Documentation'
end

#versionObject



38
39
40
# File 'lib/rspec_documentation/document.rb', line 38

def version
  gem_spec&.version
end