Class: JsDependency::Report::Markdown

Inherits:
Object
  • Object
show all
Defined in:
lib/js_dependency/report/markdown.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orphan_list, mermaid_markdown, identifier: nil) ⇒ Markdown

Returns a new instance of Markdown.

Parameters:

  • orphan_list (Array)
  • mermaid_markdown (String)
  • identifier (nil, String) (defaults to: nil)


11
12
13
14
15
# File 'lib/js_dependency/report/markdown.rb', line 11

def initialize(orphan_list, mermaid_markdown, identifier: nil)
  @orphan_list = orphan_list || []
  @mermaid_markdown = mermaid_markdown
  @identifier = identifier || "js_dependency_report_identifier"
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



6
7
8
# File 'lib/js_dependency/report/markdown.rb', line 6

def identifier
  @identifier
end

#mermaid_markdownObject (readonly)

Returns the value of attribute mermaid_markdown.



6
7
8
# File 'lib/js_dependency/report/markdown.rb', line 6

def mermaid_markdown
  @mermaid_markdown
end

#orphan_listObject (readonly)

Returns the value of attribute orphan_list.



6
7
8
# File 'lib/js_dependency/report/markdown.rb', line 6

def orphan_list
  @orphan_list
end

Instance Method Details

#exportString

Returns:

  • (String)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/js_dependency/report/markdown.rb', line 18

def export
  markdown = <<~MAKRDOWNTEXT
    ## JsDependency Reports

    ### Orphan modules

  MAKRDOWNTEXT

  if @orphan_list.empty?
    markdown += "No orphaned module !\n\n"
  else
    markdown += "#{@orphan_list.size} orphaned modules.\n\n"
    markdown += "#{@orphan_list.map { |str| "* ``#{str}``" }.join("\n")}\n\n"
  end

  markdown += "### Module dependency\n\n"

  if @mermaid_markdown.nil? || @mermaid_markdown.empty?
    markdown += ".vue or .js or .jsx files are not changed.\n\n"
  else
    markdown += <<~MAKRDOWNTEXT
      ```mermaid
    MAKRDOWNTEXT

    markdown += @mermaid_markdown.to_s

    markdown += <<~MAKRDOWNTEXT
      ```

    MAKRDOWNTEXT
  end

  markdown += "<!-- #{@identifier} -->"
  markdown
end