Skip to content

Commit aad1229

Browse files
Added ability to split responses over multiple lines
1 parent f2aed1e commit aad1229

14 files changed

Lines changed: 35 additions & 23 deletions

source/javascripts/try_ruby.js.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def initialize(key, values)
2020
@chapter = values["chapter"]
2121
answer = decode_uri(values["answer"])
2222
@answer = answer && !answer.empty? ? Regexp.new(answer, 'mi') : nil
23-
@ok = decode_uri(values["ok"])
24-
@error = decode_uri(values["error"])
23+
@ok = decode_uri(values["ok"]).split('<br/>')
24+
@error = decode_uri(values["error"]).split('<br/>')
2525
@text = decode_uri(values["text"])
2626
load_code = values["load_code"]
2727
@load_code = load_code && !load_code.empty? ? decode_uri(load_code) : nil
@@ -57,12 +57,12 @@ def focus
5757
`#@native.focus()`
5858
end
5959

60-
def mark_ok(line_index)
61-
`#@native.markText({line: line_index, ch: 0}, {line: line_index, ch: 99}, {className: "tryruby-output-green"})`
60+
def mark_ok(line_from, line_to)
61+
`#@native.markText({line: line_from, ch: 0}, {line: line_to, ch: 99}, {className: "tryruby-output-green"})`
6262
end
6363

64-
def mark_error(line_index)
65-
`#@native.markText({line: line_index, ch: 0}, {line: line_index, ch: 99}, {className: "tryruby-output-red"})`
64+
def mark_error(line_from, line_to)
65+
`#@native.markText({line: line_from, ch: 0}, {line: line_to, ch: 99}, {className: "tryruby-output-red"})`
6666
end
6767
end
6868

@@ -332,12 +332,19 @@ def eval_code(js_code)
332332

333333
# Check if output matches the defined answer regexp
334334
# and print status message
335+
print_to_output("\n")
336+
from = count_lines
337+
335338
if !value_to_check.empty? && value_to_check.chomp.match(@current_item.answer)
336-
print_to_output("\n#{@current_item.ok}")
337-
@output.mark_ok(count_lines)
339+
@current_item.ok.each do |line|
340+
print_to_output(line)
341+
end
342+
@output.mark_ok(from, count_lines)
338343
else
339-
print_to_output("\n#{@current_item.error}")
340-
@output.mark_error(count_lines)
344+
@current_item.error.each do |line|
345+
print_to_output(line)
346+
end
347+
@output.mark_error(from, count_lines)
341348
end
342349
end
343350

translations/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ translate the Blurb content.
3333

3434
## Reference
3535
For future reference the original content of TryRuby (version 2)
36-
is included. See `ruby-guide-en.html_` and `ruby-guide-es.html_`.
36+
is included. See `ruby-guide-en.html_` and `ruby-guide-es.html_`.
37+
38+
## Tips
39+
40+
- You can use `<br/>` in the _ok_ and _error_ responses to split
41+
the response over multiple lines.
42+
Please limit line length to 80 characters

translations/en/try_ruby_220.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ lang: EN
33
title: Ringlets of Chained Methods
44
answer: ^More still did (.+)
55
load: prev
6-
ok: Good show, my friend! The join method took that array of lines and put them together into a string.
6+
ok: Good show, my friend!<br/>The join method took that array of lines and put them together into a string.
77
error:
88
---
99

translations/en/try_ruby_240.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: A Wee Blank Book
44
answer: ^(splendid|quite_good|mediocre|quite_not_good|abysmal)$
55
load: books = {}
66
ok: Yes that's a new review
7-
error: Use one of splendid, quite_good, mediocre, quite_not_good, abysmal. Don't forget the colon
7+
error: Use one of splendid, quite_good, mediocre, quite_not_good, abysmal.<br/>Don't forget the colon
88
---
99

1010
You've made an empty __hash__. A hash is like an array, only every one of its elements has a name.

translations/es/try_ruby_220.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ lang: ES
33
title: Tirabuzón de Métodos en Cadena
44
answer: ^More still did (.+)
55
load: prev
6-
ok: Bien hecho, amigo mío. El método join cogió el array de líneas y las puso juntas en un string.
6+
ok: Bien hecho, amigo mío.<br/>El método join cogió el array de líneas y las puso juntas en un string.
77
error:
88
---
99

translations/es/try_ruby_240.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Un Diminuto Libro En Blanco
44
answer: ^(esplendido|muy_bueno|mediocre|malo|abismal)$
55
load: libros = {}
66
ok: Sí, eso es una nueva reseña
7-
error: Usa uno de :esplendido, :muy_bueno, :mediocre, :malo, :abismal. No te olvides los dos puntos.
7+
error: Usa uno de :esplendido, :muy_bueno, :mediocre, :malo, :abismal.<br/>No te olvides los dos puntos.
88
---
99

1010
Has creado un __hash__ vacío. Un hash es como un array, salvo que cada uno de sus elementos tiene un nombre.

translations/ja/try_ruby_220.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ lang: JA
33
title: メソッドをつなげる
44
answer: ^More still did (.+)
55
load: prev
6-
ok: Good show, my friend! The join method took that array of lines and put them together into a string.
76
ok: いい感じですね!joinメソッドは、配列の各要素をつなげて、一つの文字列にしました。
87
error:
98
---

translations/ja/try_ruby_240.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: ちっちゃな空っぽの本
44
answer: ^(splendid|quite_good|mediocre|quite_not_good|abysmal)$
55
load: books = {}
66
ok: 新しい書評です
7-
error: splendid、quite_good、mediocre、quite_not_good、abysmalのいずれかを使ってください。また、コロンを忘れないでください
7+
error: splendid、quite_good、mediocre、quite_not_good、abysmal<br/>のいずれかを使ってください。また、コロンを忘れないでください
88
---
99

1010
今作成したのは空の__ハッシュ__です。ハッシュは配列みたいなもので、各要素が名前を持つという点が異なります。

translations/nl/try_ruby_220.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ lang: NL
33
title: De schakels van de ketting
44
answer: ^More still did (.+)
55
load: prev
6-
ok: Goed gedaan hoor! De join methode heeft dat array weer aan elkaar geplakt.
6+
ok: Goed gedaan hoor!<br/>De join methode heeft dat array weer aan elkaar geplakt.
77
error:
88
---
99

translations/nl/try_ruby_240.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Een boekenlijst
44
answer: ^(uitstekend|best_goed|matig|best_wel_slecht|vreselijk)$
55
load: boeken = {}
66
ok: Dank je voor je boekverslag
7-
error: Gebruik: uitstekend, best_goed, matig, best_wel_slecht of vreselijk. Vergeet de dubbele punt niet
7+
error: Gebruik: uitstekend, best_goed, matig, best_wel_slecht of vreselijk.<br/>Vergeet de dubbele punt niet
88
---
99

1010
Je hebt net een lege haspel gemaakt. Een wat ?

0 commit comments

Comments
 (0)