Class: AsciidoctorRequirements::Asciidoctor::RequirementBlock

Inherits:
Asciidoctor::Extensions::BlockProcessor
  • Object
show all
Defined in:
lib/asciidoctor-requirements/extension.rb

Instance Method Summary collapse

Instance Method Details

#process(parent, reader, attrs) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/asciidoctor-requirements/extension.rb', line 15

def process(parent, reader, attrs)
    raw_data = reader.readlines.join("\n")
    yaml_req = YAML.load(raw_data)

    req_create_section(parent, yaml_req, attrs)                           
    req_create_description(parent, yaml_req, attrs)
    req_create_tabs_table(parent, yaml_req, attrs)
    req_create_rationale(parent, yaml_req, attrs)
    req_create_break(parent)
   
    parent

end

#req_create_break(parent) ⇒ Object



85
86
87
# File 'lib/asciidoctor-requirements/extension.rb', line 85

def req_create_break(parent)
    parse_content(parent, "'''", {})
end

#req_create_description(parent, yaml, attrs) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/asciidoctor-requirements/extension.rb', line 47

def req_create_description(parent, yaml, attrs)
    if yaml["description"].nil?
        raise "Description missing in requirement yaml.\n" + req_usage() 
    end

    description_text = "[.lead]\n" +  yaml["description"]

    parse_content(parent, description_text, {})
end

#req_create_rationale(parent, yaml, attrs) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/asciidoctor-requirements/extension.rb', line 57

def req_create_rationale(parent, yaml, attrs)
    if yaml["rationale"].nil?
        return
    end

    table_delimiter = "|==="
    rationale = "[cols='.^1,6', frame=none, grid=none]\n" + table_delimiter + "\ns|Rationale a|[.rationale]\n" + yaml["rationale"].strip + "\n" + table_delimiter

    parse_content(parent, rationale, {})
end

#req_create_section(parent, yaml, attrs) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/asciidoctor-requirements/extension.rb', line 29

def req_create_section(parent, yaml, attrs)
    if yaml["title"].nil?
        raise "Title missing in requirement yaml.\n" + req_usage() 
    end

    if yaml["rev"].nil?
        raise "Revision missing in requirement yaml.\n" + req_usage() 
    end

    if yaml["id"].nil?
        raise "id missing in requirement yaml.\n" + req_usage() 
    end

    section_title = String(parent.document.attributes["reqprefix"] + "_" +yaml["id"] + "_" + yaml["rev"] + " : " + yaml["title"])

    parent << create_section(parent, section_title, {})
end

#req_create_tabs_table(parent, yaml, attrs) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/asciidoctor-requirements/extension.rb', line 68

def req_create_tabs_table(parent, yaml, attrs)
    if yaml["tags"].empty?
        return ""
    end

    tag_lines = ""
    table_delimiter = "|==="

    yaml["tags"].each do |k, v|
        tag_lines += "|" + k + "|" + v + "\n"
    end

    tag_lines = "[%autowidth.stretch]\n" + table_delimiter + "\n" + tag_lines + table_delimiter

    parse_content(parent, tag_lines, {})
end

#req_usageObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/asciidoctor-requirements/extension.rb', line 89

def req_usage()
    usage = '
    USAGE : 
    
    [requirement]
    ====
    id: "0170"
    rev: a
    status: valid
    title: Document Capability
    description: The STRS platform provider shall describe, in the HID document, the reconfigurability behavior and capability of each reconfigurable component. 
    rationale: |
        Waveform developers need to know the features and limitations of the platform for their applications.
        Once the radio has been procured, NASA has the knowledge to procure or produce new or additional modules using HID information.
        Also, future module replacement or additions will be possible without designing a new platform.
    
    
    tags:
        key1: value1
        key2: value2
    ====
    
    '


    usage
end