Class: CTioga2::Commands::Documentation::MarkedUpText
- Inherits:
-
Object
- Object
- CTioga2::Commands::Documentation::MarkedUpText
- Includes:
- Log
- Defined in:
- lib/ctioga2/commands/doc/markup.rb
Overview
The documentation strings are written in a simple markup language.
Defined Under Namespace
Classes: MarkupItem, MarkupItemize, MarkupLink, MarkupParagraph, MarkupText, MarkupVerbatim
Instance Attribute Summary collapse
-
#doc ⇒ Object
The reference Doc object.
-
#elements ⇒ Object
The elements that make up the MarkedUpText.
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(doc, text = nil) ⇒ MarkedUpText
constructor
Creates a MarkedUpText object.
-
#parse_from_string(string) ⇒ Object
Parses the given string and append the results to the MarkedUpText’s elements.
Methods included from Log
debug, error, fatal, #format_exception, #identify, info, init_logger, logger, set_level, #spawn, warn
Constructor Details
#initialize(doc, text = nil) ⇒ MarkedUpText
Creates a MarkedUpText object.
186 187 188 189 190 191 192 |
# File 'lib/ctioga2/commands/doc/markup.rb', line 186 def initialize(doc, text = nil) @elements = [] @doc = doc if text parse_from_string(text) end end |
Instance Attribute Details
#doc ⇒ Object
The reference Doc object
180 181 182 |
# File 'lib/ctioga2/commands/doc/markup.rb', line 180 def doc @doc end |
#elements ⇒ Object
The elements that make up the MarkedUpText
183 184 185 |
# File 'lib/ctioga2/commands/doc/markup.rb', line 183 def elements @elements end |
Instance Method Details
#dump ⇒ Object
195 196 197 198 199 200 |
# File 'lib/ctioga2/commands/doc/markup.rb', line 195 def dump puts "Number of elements: #{@elements.size}" for el in @elements puts "#{el.class} -> #{el.to_s}" end end |
#parse_from_string(string) ⇒ Object
Parses the given string and append the results to the MarkedUpText’s elements.
Markup elements:
-
a line beginning with ‘> ’ is an example for command-line
-
a line beginning with ‘# ’ is an example for use within a command file.
-
a line beginning with ‘@ ’ is a generic verbatim text.
-
a line beginning with ‘ *’ is an element of an itemize. The itemize finishes when a new paragraph is starting.
-
a … or … or … is a link to the element.
-
a blank line marks a paragraph break.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/ctioga2/commands/doc/markup.rb', line 218 def parse_from_string(string) @last_type = nil @last_string = "" lines = string.split(/[ \t]*\n/) for l in lines l.chomp! case l when /^[#>@]\s(.*)/ # a verbatim line case l[0,1] when '#' type = :cmdfile when '>' type = :cmdline else type = :example end if @last_type == type @last_string << "#{$1}\n" else flush_element @last_type = type @last_string = "#{$1}\n" end when /^\s\*\s*(.*)/ flush_element @last_type = :item @last_string = "#{$1}\n" when /^\s*$/ # Blank line: flush_element @last_type = nil @last_string = "" else case @last_type when :item, :paragraph # simply go on @last_string << "#{l}\n" else flush_element @last_type = :paragraph @last_string = "#{l}\n" end end end flush_element end |