mirror of
https://github.com/Oreolek/raconteur.git
synced 2024-06-26 03:30:47 +03:00
Add sections feature
This commit is contained in:
parent
5ee0231d1c
commit
87f1fd6741
|
@ -173,6 +173,28 @@ situation('progress-bar', {
|
||||||
choices: ['return']
|
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
|
Custom quality definition. We make a constructor for an object that supplies
|
||||||
the QualityDefinition interface Undum expects, and then pass that to
|
the QualityDefinition interface Undum expects, and then pass that to
|
||||||
|
|
|
@ -160,9 +160,17 @@ RaconteurSituation.prototype.enter = function (character, system, f) {
|
||||||
if (this.before) this.before(character, system, f);
|
if (this.before) this.before(character, system, f);
|
||||||
|
|
||||||
if (this.content) {
|
if (this.content) {
|
||||||
system.write(
|
let classes = this.classes ? ' ' + this.classes.join(' ') : '';
|
||||||
markdown.render(
|
let renderedContent = markdown.render(
|
||||||
this.content.fcall(this, character, system, f).normaliseTabs()));
|
this.content.fcall(this, character, system, f).normaliseTabs());
|
||||||
|
if (this.extendSection) {
|
||||||
|
system.writeInto(renderedContent, '#current-situation');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('#current-situation').removeAttr('id');
|
||||||
|
let output = `<section id="current-situation" class="situation-${this.name}${classes}">\n${renderedContent}</section>`;
|
||||||
|
system.write(output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.after) this.after(character, system, f);
|
if (this.after) this.after(character, system, f);
|
||||||
|
@ -193,12 +201,7 @@ RaconteurSituation.prototype.act = function (character, system, action) {
|
||||||
writer: function (ref) {
|
writer: function (ref) {
|
||||||
let content = that.writers[ref].fcall(that, character, system, action);
|
let content = that.writers[ref].fcall(that, character, system, action);
|
||||||
let output = markdown.render(content).fade();
|
let output = markdown.render(content).fade();
|
||||||
if ($('.options').length) {
|
system.writeInto(output, '#current-situation');
|
||||||
// Write before the options list if one is currently shown.
|
|
||||||
system.writeBefore(output, '.options');
|
|
||||||
} else {
|
|
||||||
system.write(output);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
replacer: function (ref) {
|
replacer: function (ref) {
|
||||||
let content = that.writers[ref].fcall(that, character, system, action);
|
let content = that.writers[ref].fcall(that, character, system, action);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
var elements = require('raconteur/elements.js');
|
var elements = require('raconteur/elements.js');
|
||||||
|
|
||||||
var a = elements.a, span = elements.span;
|
var a = elements.a, span = elements.span;
|
||||||
|
|
|
@ -3,7 +3,10 @@ var situation = require('raconteur/situation.js');
|
||||||
describe ('situation', function () {
|
describe ('situation', function () {
|
||||||
var test_situation = situation('test-situation', {
|
var test_situation = situation('test-situation', {
|
||||||
content: "This is the content of the *testing* situation.",
|
content: "This is the content of the *testing* situation.",
|
||||||
choices: ['#foo']
|
choices: ['#foo'],
|
||||||
|
writers: {
|
||||||
|
testwriter: "*Foo*"
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var system_spy;
|
var system_spy;
|
||||||
|
@ -11,11 +14,13 @@ describe ('situation', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
system_spy = {
|
system_spy = {
|
||||||
write: function () {return;},
|
write: function () {return;},
|
||||||
|
writeInto: function () {return;},
|
||||||
getSituationIdChoices: function () {return;},
|
getSituationIdChoices: function () {return;},
|
||||||
writeChoices: function () {return;}
|
writeChoices: function () {return;}
|
||||||
};
|
};
|
||||||
|
|
||||||
spyOn(system_spy, 'write');
|
spyOn(system_spy, 'write');
|
||||||
|
spyOn(system_spy, 'writeInto');
|
||||||
spyOn(system_spy, 'getSituationIdChoices').and.returnValue(['foo', 'foo-bar']);
|
spyOn(system_spy, 'getSituationIdChoices').and.returnValue(['foo', 'foo-bar']);
|
||||||
spyOn(system_spy, 'writeChoices');
|
spyOn(system_spy, 'writeChoices');
|
||||||
});
|
});
|
||||||
|
@ -24,11 +29,11 @@ describe ('situation', function () {
|
||||||
expect(test_situation.name).toBe('test-situation');
|
expect(test_situation.name).toBe('test-situation');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('parses its content as markdown', function () {
|
it('parses its content as markdown inside a <section>', function () {
|
||||||
test_situation.enter({}, system_spy, '');
|
test_situation.enter({}, system_spy, '');
|
||||||
|
|
||||||
expect(system_spy.write)
|
expect(system_spy.write)
|
||||||
.toHaveBeenCalledWith("<p>This is the content of the <em>testing</em> situation.</p>\n");
|
.toHaveBeenCalledWith('<section id="current-situation" class="situation-test-situation">\n<p>This is the content of the <em>testing</em> situation.</p>\n</section>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is agnostic about whether content is a string or a function', function () {
|
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, '');
|
test_situation.enter({}, system_spy, '');
|
||||||
|
|
||||||
expect(system_spy.write)
|
expect(system_spy.write)
|
||||||
.toHaveBeenCalledWith("<p>Foo and bar.</p>\n");
|
.toHaveBeenCalledWith('<section id="current-situation" class="situation-test-situation">\n<p>Foo and bar.</p>\n</section>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds classes to a <section> if the classList attribute is specified', function () {
|
||||||
|
test_situation.classes = ['foo', 'bar'];
|
||||||
|
test_situation.enter({}, system_spy, '');
|
||||||
|
|
||||||
|
expect(system_spy.write)
|
||||||
|
.toHaveBeenCalledWith('<section id="current-situation" class="situation-test-situation foo bar">\n<p>Foo and bar.</p>\n</section>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generates a list of choices', function () {
|
it('generates a list of choices', function () {
|
||||||
|
@ -47,4 +60,10 @@ describe ('situation', function () {
|
||||||
expect(system_spy.writeChoices).toHaveBeenCalledWith(['foo', 'foo-bar']);
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in a new issue