Class: Spirit::Render::Processors::ProblemsProcessor
- Defined in:
- lib/spirit/render/processors/problems_processor.rb
Overview
Pre-processes problem markup in YAML. Dependent on renderer#problems and renderer#nesting.
Constant Summary collapse
- REGEX =
Paragraphs that start and end with “”“ are treated as embedded YAML and are parsed for questions/answers.
/^"""$(.*?)^"""$/m
- MARKER =
/\A<!-- %%(\d+)%% -->\z/
Instance Attribute Summary collapse
-
#problems ⇒ Object
readonly
Returns the value of attribute problems.
-
#solutions ⇒ Object
readonly
Returns the value of attribute solutions.
Instance Method Summary collapse
-
#filter(document) ⇒ String
Replaces YAML markup in document with <!– %%index%% –>.
-
#initialize(renderer, *args) ⇒ ProblemsProcessor
constructor
A new instance of ProblemsProcessor.
- #replace(html) ⇒ Object
Methods inherited from Base
events, inherited, #invoke_callbacks_for, process
Constructor Details
#initialize(renderer, *args) ⇒ ProblemsProcessor
Returns a new instance of ProblemsProcessor.
20 21 22 23 24 25 |
# File 'lib/spirit/render/processors/problems_processor.rb', line 20 def initialize(renderer, *args) @renderer = renderer @problems = [] @solutions = [] renderer.problems = self end |
Instance Attribute Details
#problems ⇒ Object (readonly)
Returns the value of attribute problems.
15 16 17 |
# File 'lib/spirit/render/processors/problems_processor.rb', line 15 def problems @problems end |
#solutions ⇒ Object (readonly)
Returns the value of attribute solutions.
15 16 17 |
# File 'lib/spirit/render/processors/problems_processor.rb', line 15 def solutions @solutions end |
Instance Method Details
#filter(document) ⇒ String
Replaces YAML markup in document with <!– %%index%% –>
29 30 31 |
# File 'lib/spirit/render/processors/problems_processor.rb', line 29 def filter(document) document.gsub(REGEX) { problem $1 } end |
#replace(html) ⇒ Object
33 34 35 36 37 |
# File 'lib/spirit/render/processors/problems_processor.rb', line 33 def replace(html) return html unless is_marker? html replace_nesting html, renderer.nesting '' end |