Class: AwsMust::Docu
- Inherits:
-
Object
- Object
- AwsMust::Docu
- Includes:
- Utils::MyLogger
- Defined in:
- lib/aws-must/docu.rb
Constant Summary collapse
- PROGNAME =
progname for logger
"docu"- DEFAULT_OPEN_TAG =
constants
"+++start+++"- DEFAULT_CLOSE_TAG =
"+++close+++"- DEFAULT_FOLD_ON_TAG =
"+++fold-on+++"- DEFAULT_FOLD_OFF_TAG =
"+++fold-off+++"- DEFAULT_INCLUDE_TAG =
">"
Constants included from Utils::MyLogger
Instance Attribute Summary collapse
-
#fold_off ⇒ Object
Returns the value of attribute fold_off.
-
#fold_on ⇒ Object
command line option define lines to output for directive.
Instance Method Summary collapse
-
#directive_close(line) ⇒ Object
return bool, line_pre, line.
-
#directive_include(line) ⇒ Object
return include ‘template’ to include if it is include directive.
-
#directive_open(line) ⇒ Object
—————————————————————— Check if line satisfies tag.
-
#document(template_name) ⇒ Object
—————————————————————— docu - output documentation to stdout.
-
#get_tag(tag) ⇒ Object
—————————————————————— get tag value.
-
#initialize(template, options = {}) ⇒ Docu
constructor
—————————————————————— Constructor - template: which knows how to return template files.
-
#output(line) ⇒ Object
—————————————————————— output - document output.
Methods included from Utils::MyLogger
Constructor Details
#initialize(template, options = {}) ⇒ Docu
Constructor
-
template: which knows how to return template files
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aws-must/docu.rb', line 36 def initialize( template, ={} ) @logger = getLogger( PROGNAME, ) @logger.info( "#{__method__}, options=#{}" ) @template = template # command line option define lines to output for directive @fold_on = [:fold_on] if [:fold_on] @fold_off = [:fold_off] if [:fold_off] @directives = { :open => DEFAULT_OPEN_TAG, :close => DEFAULT_CLOSE_TAG, :fold_on => DEFAULT_FOLD_ON_TAG, :fold_off => DEFAULT_FOLD_OFF_TAG, :include => DEFAULT_INCLUDE_TAG, } end |
Instance Attribute Details
#fold_off ⇒ Object
Returns the value of attribute fold_off.
30 31 32 |
# File 'lib/aws-must/docu.rb', line 30 def fold_off @fold_off end |
#fold_on ⇒ Object
command line option define lines to output for directive
29 30 31 |
# File 'lib/aws-must/docu.rb', line 29 def fold_on @fold_on end |
Instance Method Details
#directive_close(line) ⇒ Object
return bool, line_pre, line
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/aws-must/docu.rb', line 144 def directive_close( line ) #return line && line.include?( get_tag( :close ) ) if line && line.include?( get_tag( :close ) ) then # index = line.index( get_tag(:close) ) # return true, index == 0 ? nil : line[0..index-1], line[ index+ get_tag(:close).length..-1] # do not output anythin on line for directive return true, nil, nil elsif line && line.include?( get_tag(:fold_off) ) then # replace fold-off direcive line with fold_off text return true, self.fold_off, nil else return false, nil, line end end |
#directive_include(line) ⇒ Object
return include ‘template’ to include if it is include directive
162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/aws-must/docu.rb', line 162 def directive_include( line ) # not valid input return nil unless line # extract template_name using regexp parse_regexp=/^#{get_tag(:include)}\s+(?<template>[\w]*)\s*/ parsed = line.match( parse_regexp ) # not found return nil unless parsed return parsed['template'] end |
#directive_open(line) ⇒ Object
Check if line satisfies tag
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/aws-must/docu.rb', line 123 def directive_open( line ) # return line && line.include?( get_tag(:open) ) if line && line.include?( get_tag(:open) ) then # find index pointing _after_ :open tag # index = line.index( get_tag(:open) ) + get_tag(:open).length # # return text after directtive # return true, line[ index..-1] # do not output anything for the line return true, nil elsif line && line.include?( get_tag(:fold_on) ) then # output fold_on text instread return true, self.fold_on else return false, nil end end |
#document(template_name) ⇒ Object
docu - output documentation to stdout
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/aws-must/docu.rb', line 62 def document( template_name ) @logger.debug( "#{__method__}, template_name '#{template_name}'" ) # template_string = @template.get_template( template_name ) @logger.debug( "#{__method__}, template_string= '#{template_string}'" ) # state_opened=false # iterate lines template_string && template_string.split( "\n" ).each do | line | if !state_opened then # waiting for +++open+++ or +++fold_on+++ open_found, line = directive_open( line ) if open_found then state_opened = true # something follows the start -tag redo if line && ! line.empty? end else # seen +++open+++ or +++fold_on+++, waiting for +++close+++, +++fold_off+++ close_found, line_pre, line = directive_close( line ) # puts "close_found=#{close_found}, #{close_found.class}, line=#{line}" if close_found then output( line_pre ) if line_pre && !line_pre.empty? state_opened = false redo if line && ! line.empty? elsif template_name = directive_include( line ) then document( template_name ) else output( line ) end end # state_opened end # each line end |
#get_tag(tag) ⇒ Object
get tag value
180 181 182 183 |
# File 'lib/aws-must/docu.rb', line 180 def get_tag( tag ) raise "Unknown tag" unless @directives[tag] return @directives[tag] end |
#output(line) ⇒ Object
output - document output
114 115 116 117 |
# File 'lib/aws-must/docu.rb', line 114 def output( line ) puts( line ) end |