diff --git a/devel/js/main.js b/devel/js/main.js index f08dcd7..73dcfd6 100644 --- a/devel/js/main.js +++ b/devel/js/main.js @@ -173,6 +173,28 @@ situation('progress-bar', { choices: ['return'] }); +situation('continuation', { + content: ` + # Continuation and Sections + + Each situation is output to the screen as its own section. You can + go to [the next situation](continuation-continue) to see a situation + that adds to the existing section, instead of writing a new one. + `, + optionText: 'Continuations and Sections', + tags: ['testing-option'] +}); + +situation ('continuation-continue', { + content: ` + This feature allows situations to be individually styled. The \`classes\` + attribute of a situation controls additional classes to be added to the + section. + `, + continueSection: true, + choices: ['return'] +}); + /* Custom quality definition. We make a constructor for an object that supplies the QualityDefinition interface Undum expects, and then pass that to diff --git a/lib/situation.js b/lib/situation.js index d3e66d9..dd9535e 100644 --- a/lib/situation.js +++ b/lib/situation.js @@ -160,9 +160,17 @@ RaconteurSituation.prototype.enter = function (character, system, f) { if (this.before) this.before(character, system, f); if (this.content) { - system.write( - markdown.render( - this.content.fcall(this, character, system, f).normaliseTabs())); + let classes = this.classes ? ' ' + this.classes.join(' ') : ''; + let renderedContent = markdown.render( + this.content.fcall(this, character, system, f).normaliseTabs()); + if (this.extendSection) { + system.writeInto(renderedContent, '#current-situation'); + } + else { + $('#current-situation').removeAttr('id'); + let output = `
\n${renderedContent}
`; + system.write(output); + } } if (this.after) this.after(character, system, f); @@ -193,12 +201,7 @@ RaconteurSituation.prototype.act = function (character, system, action) { writer: function (ref) { let content = that.writers[ref].fcall(that, character, system, action); let output = markdown.render(content).fade(); - if ($('.options').length) { - // Write before the options list if one is currently shown. - system.writeBefore(output, '.options'); - } else { - system.write(output); - } + system.writeInto(output, '#current-situation'); }, replacer: function (ref) { let content = that.writers[ref].fcall(that, character, system, action); diff --git a/spec/elementsSpec.js b/spec/elementsSpec.js index f5fb497..0dfe164 100644 --- a/spec/elementsSpec.js +++ b/spec/elementsSpec.js @@ -1,3 +1,5 @@ +'use strict' + var elements = require('raconteur/elements.js'); var a = elements.a, span = elements.span; diff --git a/spec/situationSpec.js b/spec/situationSpec.js index c7e05ae..a076584 100644 --- a/spec/situationSpec.js +++ b/spec/situationSpec.js @@ -3,7 +3,10 @@ var situation = require('raconteur/situation.js'); describe ('situation', function () { var test_situation = situation('test-situation', { content: "This is the content of the *testing* situation.", - choices: ['#foo'] + choices: ['#foo'], + writers: { + testwriter: "*Foo*" + } }); var system_spy; @@ -11,11 +14,13 @@ describe ('situation', function () { beforeEach(function () { system_spy = { write: function () {return;}, + writeInto: function () {return;}, getSituationIdChoices: function () {return;}, writeChoices: function () {return;} }; spyOn(system_spy, 'write'); + spyOn(system_spy, 'writeInto'); spyOn(system_spy, 'getSituationIdChoices').and.returnValue(['foo', 'foo-bar']); spyOn(system_spy, 'writeChoices'); }); @@ -24,11 +29,11 @@ describe ('situation', function () { expect(test_situation.name).toBe('test-situation'); }); - it('parses its content as markdown', function () { + it('parses its content as markdown inside a
', function () { test_situation.enter({}, system_spy, ''); expect(system_spy.write) - .toHaveBeenCalledWith("

This is the content of the testing situation.

\n"); + .toHaveBeenCalledWith('
\n

This is the content of the testing situation.

\n
'); }); it('is agnostic about whether content is a string or a function', function () { @@ -36,7 +41,15 @@ describe ('situation', function () { test_situation.enter({}, system_spy, ''); expect(system_spy.write) - .toHaveBeenCalledWith("

Foo and bar.

\n"); + .toHaveBeenCalledWith('
\n

Foo and bar.

\n
'); + }); + + it('adds classes to a
if the classList attribute is specified', function () { + test_situation.classes = ['foo', 'bar']; + test_situation.enter({}, system_spy, ''); + + expect(system_spy.write) + .toHaveBeenCalledWith('
\n

Foo and bar.

\n
'); }); it('generates a list of choices', function () { @@ -47,4 +60,10 @@ describe ('situation', function () { expect(system_spy.writeChoices).toHaveBeenCalledWith(['foo', 'foo-bar']); }); + it('writes into the current situation when a default writer is called', function () { + test_situation.act({}, system_spy, '_writer_testwriter'); + + expect(system_spy.writeInto).toHaveBeenCalled(); + }); + }); \ No newline at end of file