daigaku 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8b67152f8cdc2685c5b2edfa2cf611f1f81eb61
4
- data.tar.gz: e969647bd2749977c6f6a4967afbf826b46c291e
3
+ metadata.gz: 3ce9d43dc806807d9613ddac880f1aaafedc6f2f
4
+ data.tar.gz: f1abac8e7d72762851395bfdd5dc397f6b1d7833
5
5
  SHA512:
6
- metadata.gz: 431903dc0fb3e12805b76b94950d47a794180617dd21b25c6dc7c486734f750fadb27cfc4059d6f6a507a72a7995f15e5b2e0e0f356f266f25955624d05986a2
7
- data.tar.gz: fb34667ddd6b7c30af0a22aa86d1bc5a2b6090fc2f0e22d9726fd5b2beb8b1b77592edb5e1241204a4d3a80f955d5050876f4f8633bed70864e3bfdd8d74cc9d
6
+ metadata.gz: 385ee9c126906aa38936e02a74217f22f25b527d879ee882446b6cfbd890b6bf5433d6a4d5d34395b13d0d3c96fc317201c509aaad3247ab31dcca22e70aa3b1
7
+ data.tar.gz: f4bfe1ebffd9570f41ef05082addd694666c2400ec21cdfd362d54ed73cd8fe80c2bfd4e67f101eb5cc3f4fe003f61515e17d9ff2f3aafec9b955e9ff9eadb24
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ![Daigaku](http://res.cloudinary.com/daigaku-ruby/image/upload/c_scale,h_100/v1426946323/rect5481_si3rjr.png)
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/daigaku.svg)](http://badge.fury.io/rb/daigaku)
4
+
3
5
  Daigaku (大学) is the Japanese word for **university**.
4
6
 
5
7
  With Daigaku you can master your way of learning the Ruby programming
@@ -8,7 +8,11 @@ module Daigaku
8
8
  TEST_PASSED_MESSAGE = "Your code passed all tests. Congratulations!"
9
9
 
10
10
  def initialize(result_json)
11
- @result = JSON.parse(result_json, symbolize_names: true)
11
+ @result = begin
12
+ JSON.parse(result_json, symbolize_names: true)
13
+ rescue
14
+ syntax_error_json
15
+ end
12
16
 
13
17
  @example_count = @result[:summary][:example_count]
14
18
  @failure_count = @result[:summary][:failure_count]
@@ -47,6 +51,17 @@ module Daigaku
47
51
  summary = message.map(&:strip).join("\n" * 3)
48
52
  end
49
53
 
54
+ def syntax_error_json
55
+ {
56
+ summary: {},
57
+ examples: [
58
+ {
59
+ status: 'failed',
60
+ exception: { message: ":( You got a syntax error in your code!" }
61
+ }
62
+ ]
63
+ }
64
+ end
50
65
  end
51
66
 
52
67
  class TestExample
@@ -1,3 +1,3 @@
1
1
  module Daigaku
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -102,7 +102,7 @@ module Daigaku
102
102
  if @unit.mastered?
103
103
  window.green(line, A_STANDOUT, full_line: true)
104
104
  else
105
- example_index = ((index + 1) / 4.0).ceil - 1
105
+ example_index = example_index(@example_heights, index)
106
106
 
107
107
  if @examples[example_index].passed?
108
108
  window.green(line, A_STANDOUT, full_line: true)
@@ -186,7 +186,15 @@ module Daigaku
186
186
  @lines = [''] + @test_result_lines + ['', ''] + @unit.task.markdown.lines
187
187
  @examples = result.examples
188
188
 
189
- initialize_window(@lines.count + @top_bar_height + @head_height)
189
+ @example_heights = @examples.reduce({}) do |hash, example|
190
+ start = hash.values.reduce(0) { |sum, r| sum += r.count }
191
+ range = (start..(start + example.message.split("\n").count) + 2)
192
+ hash[hash.keys.count] = range
193
+ hash
194
+ end
195
+
196
+ height = [@lines.count + @top_bar_height + @head_height, Curses.lines].max
197
+ initialize_window(height)
190
198
  end
191
199
 
192
200
  def reset_screen(window)
@@ -200,6 +208,10 @@ module Daigaku
200
208
  @window = default_window(height)
201
209
  main_panel(@window) { |window| show sub_window_below_top_bar(window) }
202
210
  end
211
+
212
+ def example_index(heights, index)
213
+ heights.values.index { |range| range.include?(index) }
214
+ end
203
215
  end
204
216
 
205
217
  end
@@ -115,7 +115,7 @@ module Daigaku
115
115
  when h2
116
116
  text_decoration = Curses::A_UNDERLINE | Curses::A_NORMAL
117
117
  emphasize(text.gsub(/^##\s?/, ''), text_decoration)
118
- when bold || code
118
+ when (code || bold)
119
119
  emphasized = false
120
120
  highlighted = false
121
121
 
@@ -130,14 +130,23 @@ module Daigaku
130
130
  next
131
131
  end
132
132
 
133
- if emphasized
134
- emphasize(char)
135
- elsif highlighted
133
+ if highlighted
136
134
  red(char)
135
+ elsif emphasized
136
+ emphasize(char)
137
137
  else
138
138
  write(char)
139
139
  end
140
140
  end
141
+ when bold
142
+ text.chars.each do |char|
143
+ if char == '*'
144
+ emphasized = !emphasized
145
+ next
146
+ end
147
+
148
+ emphasized ? emphasize(char) : write(char)
149
+ end
141
150
  when line
142
151
  write('-' * (Curses.cols - 2))
143
152
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daigaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Götze
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-22 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses