daigaku 0.1.1 → 0.2.0
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 +4 -4
- data/README.md +3 -0
- data/daigaku.gemspec +7 -6
- data/lib/daigaku/coloring.rb +37 -0
- data/lib/daigaku/markdown.rb +1 -0
- data/lib/daigaku/markdown/ruby_doc.rb +104 -0
- data/lib/daigaku/terminal/courses.rb +2 -2
- data/lib/daigaku/version.rb +1 -1
- data/lib/daigaku/views/task_view.rb +1 -1
- data/lib/daigaku/window.rb +50 -112
- data/spec/daigaku/coloring_spec.rb +36 -0
- data/spec/daigaku/markdown/ruby_doc_spec.rb +110 -0
- metadata +36 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c6f1f336e0af615495359124f476852ef7dfa36
|
4
|
+
data.tar.gz: 2baf4a0586e8b933fb30cd9af7bbe2be9a3fe983
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 537a9fa9742cda1129165bf8f0a163213d415fd3d6f221e93c54244f6a0eb379451146ba9e4e7f094c705416e9aef9f6ed350e9b849030fa6cba0278ac33eb19
|
7
|
+
data.tar.gz: c4a943a667fd22f0d420838ee6f83cac333613b4740ba889d3a24b8b32e989ca63813ab80206bd2aa8afb1429cc739a3f9717c07d9dc2ba3a9818b93794b1198
|
data/README.md
CHANGED
@@ -16,6 +16,7 @@ language-explaining programming tasks.
|
|
16
16
|
## Installation
|
17
17
|
|
18
18
|
First of all make sure Ruby is installed on your computer.
|
19
|
+
Daigaku works with [MRI Ruby](https://www.ruby-lang.org/en/documentation/installation/) v2.x and [Rubinius](http://rubini.us/doc/en/getting-started/) v2.x.
|
19
20
|
|
20
21
|
Then open a terminal and install Daigaku by running:
|
21
22
|
|
@@ -51,6 +52,8 @@ Please visit the [Diagaku Wiki](https://github.com/daigaku-ruby/daigaku/wiki/How
|
|
51
52
|
|
52
53
|
We encourage you to contribute to Daigaku development and course creation.
|
53
54
|
|
55
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant code of conduct](http://contributor-covenant.org/version/1/2/0).
|
56
|
+
|
54
57
|
### Creating Daigaku courses
|
55
58
|
|
56
59
|
Daigaku is a great tool, but it's nothing without courses to learn from.
|
data/daigaku.gemspec
CHANGED
@@ -19,17 +19,18 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
if RUBY_VERSION >= '2.1'
|
22
|
-
spec.add_runtime_dependency "curses", "
|
22
|
+
spec.add_runtime_dependency "curses", "~> 1.0"
|
23
23
|
end
|
24
24
|
|
25
|
-
spec.add_runtime_dependency "activesupport", "
|
26
|
-
spec.add_runtime_dependency "rspec", "
|
25
|
+
spec.add_runtime_dependency "activesupport", "~> 4.0"
|
26
|
+
spec.add_runtime_dependency "rspec", "~> 3.0"
|
27
27
|
spec.add_runtime_dependency "thor", "~> 0.19.1"
|
28
28
|
spec.add_runtime_dependency "os", "~> 0.9.6"
|
29
29
|
spec.add_runtime_dependency "colorize", "~> 0.7.5"
|
30
|
-
spec.add_runtime_dependency "rubyzip", "
|
31
|
-
spec.add_runtime_dependency "wisper", "
|
32
|
-
spec.add_runtime_dependency "quick_store", "~> 0.1
|
30
|
+
spec.add_runtime_dependency "rubyzip", "~> 1.0"
|
31
|
+
spec.add_runtime_dependency "wisper", "~> 2.0.0.rc1"
|
32
|
+
spec.add_runtime_dependency "quick_store", "~> 0.1"
|
33
|
+
spec.add_runtime_dependency "code_breaker", "~> 0.1"
|
33
34
|
|
34
35
|
spec.add_development_dependency "bundler", "~> 1.7"
|
35
36
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'curses'
|
2
|
+
require 'active_support/concern'
|
3
|
+
|
4
|
+
module Daigaku
|
5
|
+
module Coloring
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
COLOR_TEXT = Curses::COLOR_YELLOW unless defined? COLOR_TEXT
|
10
|
+
COLOR_TEXT_EMPHASIZE = Curses::COLOR_CYAN unless defined? COLOR_TEXT_EMPHASIZE
|
11
|
+
COLOR_HEADING = Curses::COLOR_WHITE unless defined? COLOR_HEADING
|
12
|
+
COLOR_RED = Curses::COLOR_BLUE unless defined? COLOR_RED
|
13
|
+
COLOR_GREEN = Curses::COLOR_MAGENTA unless defined? COLOR_GREEN
|
14
|
+
COLOR_YELLOW = Curses::COLOR_RED unless defined? COLOR_YELLOW
|
15
|
+
|
16
|
+
BACKGROUND = Curses::COLOR_WHITE unless defined? BACKGROUND
|
17
|
+
FONT = Curses::COLOR_BLACK unless defined? FONT
|
18
|
+
FONT_HEADING = Curses::COLOR_MAGENTA unless defined? FONT_HEADING
|
19
|
+
FONT_EMPHASIZE = Curses::COLOR_BLUE unless defined? FONT_EMPHASIZE
|
20
|
+
RED = Curses::COLOR_RED unless defined? RED
|
21
|
+
GREEN = Curses::COLOR_GREEN unless defined? GREEN
|
22
|
+
YELLOW = Curses::COLOR_YELLOW unless defined? YELLOW
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def init_colors
|
27
|
+
Curses.start_color
|
28
|
+
Curses.init_pair(COLOR_TEXT, FONT, BACKGROUND)
|
29
|
+
Curses.init_pair(COLOR_TEXT_EMPHASIZE, FONT_EMPHASIZE, BACKGROUND)
|
30
|
+
Curses.init_pair(COLOR_HEADING, FONT_HEADING, BACKGROUND)
|
31
|
+
Curses.init_pair(COLOR_RED, RED, BACKGROUND)
|
32
|
+
Curses.init_pair(COLOR_GREEN, GREEN, BACKGROUND)
|
33
|
+
Curses.init_pair(COLOR_YELLOW, YELLOW, BACKGROUND)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'daigaku/markdown/ruby_doc'
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module Daigaku
|
4
|
+
class Markdown
|
5
|
+
class RubyDoc
|
6
|
+
|
7
|
+
RUBY_DOC_URL = "http://ruby-doc.org".freeze
|
8
|
+
CORE_BASE_URL = "#{RUBY_DOC_URL}/core-#{RUBY_VERSION}".freeze
|
9
|
+
STDLIB_BASE_URL = "#{RUBY_DOC_URL}/stdlib-#{RUBY_VERSION}".freeze
|
10
|
+
|
11
|
+
CORE_REGEX = /\(ruby-doc core:\s?(.*)\)/.freeze
|
12
|
+
STDLIB_REGEX = /\(ruby-doc stdlib:\s?(.*)\)/.freeze
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def parse(text)
|
16
|
+
new.parse(text)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse(text)
|
21
|
+
parsed_text = sub_stdlib_links(text)
|
22
|
+
sub_core_links(parsed_text)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def sub_core_links(text)
|
28
|
+
match = text.match(CORE_REGEX)
|
29
|
+
return text if match.nil?
|
30
|
+
|
31
|
+
match.captures.reduce(text) do |result, capture|
|
32
|
+
result.sub!(doc_regex(:core, capture), core_link(capture))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def sub_stdlib_links(text)
|
37
|
+
match = text.match(STDLIB_REGEX)
|
38
|
+
return text if match.nil?
|
39
|
+
|
40
|
+
match.captures.reduce(text) do |result, capture|
|
41
|
+
result.sub!(doc_regex(:stdlib, capture), stdlib_link(capture))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def doc_regex(type, capture)
|
46
|
+
/\(ruby-doc #{type}: #{capture}\)/
|
47
|
+
end
|
48
|
+
|
49
|
+
def core_link(text)
|
50
|
+
constants = ruby_constants(text).join('/')
|
51
|
+
method = ruby_method(text)
|
52
|
+
|
53
|
+
"#{CORE_BASE_URL}/#{constants}.html#{method}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def stdlib_link(text)
|
57
|
+
constants = ruby_constants(text).join('/')
|
58
|
+
method = ruby_method(text)
|
59
|
+
libdoc_part = "libdoc/#{ruby_stdlib(text)}/rdoc"
|
60
|
+
|
61
|
+
"#{STDLIB_BASE_URL}/#{libdoc_part}/#{constants}.html#{method}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns the stdlib part of the url.
|
65
|
+
# If an explicit stdlib name is defined in markdown, e.g.
|
66
|
+
# (ruby-doc stdlib: net/http Net::HTTP) => 'net/http'
|
67
|
+
# then this lib name is used.
|
68
|
+
# Else the lib is created from the constants, e.g.
|
69
|
+
# (ruby-doc stdlib: Time) => 'time'
|
70
|
+
def ruby_stdlib(text)
|
71
|
+
parts = text.split(' ')
|
72
|
+
|
73
|
+
if parts.length > 1
|
74
|
+
parts.first.strip.downcase
|
75
|
+
else
|
76
|
+
ruby_constants(text).join('/').downcase
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def ruby_constants(text)
|
81
|
+
parts = text.split(' ').last.split(/::|#/)
|
82
|
+
select_capitalized(parts)
|
83
|
+
end
|
84
|
+
|
85
|
+
def ruby_method(text)
|
86
|
+
method = text.split(/::|#/).last
|
87
|
+
return '' unless downcased?(method)
|
88
|
+
|
89
|
+
method_type = text.match(/#/) ? 'i' : 'c'
|
90
|
+
method_name = CGI.escape(method.strip).gsub('%', '-').gsub(/\A-/, '')
|
91
|
+
"#method-#{method_type}-#{method_name}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def select_capitalized(parts)
|
95
|
+
parts.select { |part| part[0] == part[0].upcase }
|
96
|
+
end
|
97
|
+
|
98
|
+
def downcased?(text)
|
99
|
+
text == text.downcase
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -57,7 +57,7 @@ module Daigaku
|
|
57
57
|
end
|
58
58
|
|
59
59
|
method_option :all, type: :boolean, aliases: '-a', desc: 'Update all courses'
|
60
|
-
desc 'update [COURSE_NAME] [OPTIONS]', 'Update
|
60
|
+
desc 'update [COURSE_NAME] [OPTIONS]', 'Update Daigaku courses.'
|
61
61
|
def update(course_name = nil)
|
62
62
|
if options[:all]
|
63
63
|
courses = Loading::Courses.load(Daigaku.config.courses_path)
|
@@ -98,7 +98,7 @@ module Daigaku
|
|
98
98
|
return
|
99
99
|
end
|
100
100
|
|
101
|
-
get_confirm("Are you
|
101
|
+
get_confirm("Are you sure you want to delete the course \"#{course_name}\"?") do
|
102
102
|
FileUtils.remove_dir(path)
|
103
103
|
QuickStore.store.delete(Storeable.key(course_name, prefix: 'courses'))
|
104
104
|
say_info "The course \"#{course_name}\" was successfully deleted."
|
data/lib/daigaku/version.rb
CHANGED
data/lib/daigaku/window.rb
CHANGED
@@ -1,23 +1,10 @@
|
|
1
1
|
require 'curses'
|
2
|
-
require '
|
2
|
+
require 'daigaku/coloring'
|
3
|
+
require 'daigaku/markdown'
|
3
4
|
|
4
5
|
module Daigaku
|
5
6
|
class Window < Curses::Window
|
6
|
-
|
7
|
-
COLOR_TEXT = Curses::COLOR_YELLOW unless defined? COLOR_TEXT
|
8
|
-
COLOR_TEXT_EMPHASIZE = Curses::COLOR_CYAN unless defined? COLOR_TEXT_EMPHASIZE
|
9
|
-
COLOR_HEADING = Curses::COLOR_WHITE unless defined? COLOR_HEADING
|
10
|
-
COLOR_RED = Curses::COLOR_BLUE unless defined? COLOR_RED
|
11
|
-
COLOR_GREEN = Curses::COLOR_MAGENTA unless defined? COLOR_GREEN
|
12
|
-
COLOR_YELLOW = Curses::COLOR_RED unless defined? COLOR_YELLOW
|
13
|
-
|
14
|
-
BACKGROUND = Curses::COLOR_WHITE unless defined? BACKGROUND
|
15
|
-
FONT = Curses::COLOR_BLACK unless defined? FONT
|
16
|
-
FONT_HEADING = Curses::COLOR_MAGENTA unless defined? FONT_HEADING
|
17
|
-
FONT_EMPHASIZE = Curses::COLOR_BLUE unless defined? FONT_EMPHASIZE
|
18
|
-
RED = Curses::COLOR_RED unless defined? RED
|
19
|
-
GREEN = Curses::COLOR_GREEN unless defined? GREEN
|
20
|
-
YELLOW = Curses::COLOR_YELLOW unless defined? YELLOW
|
7
|
+
include Coloring
|
21
8
|
|
22
9
|
def initialize(height = Curses.lines, width = Curses.cols, top = 0, left = 0)
|
23
10
|
super(height, width, top, left)
|
@@ -29,23 +16,23 @@ module Daigaku
|
|
29
16
|
end
|
30
17
|
|
31
18
|
def emphasize(text, text_decoration = Curses::A_NORMAL)
|
32
|
-
write(text,
|
19
|
+
write(text, COLOR_TEXT_EMPHASIZE, text_decoration)
|
33
20
|
end
|
34
21
|
|
35
22
|
def heading(text, text_decoration = Curses::A_UNDERLINE)
|
36
|
-
write(text,
|
23
|
+
write(text, COLOR_HEADING, text_decoration)
|
37
24
|
end
|
38
25
|
|
39
26
|
def red(text, text_decoration = Curses::A_NORMAL, options = {})
|
40
|
-
colored(text,
|
27
|
+
colored(text, COLOR_RED, text_decoration, options)
|
41
28
|
end
|
42
29
|
|
43
30
|
def yellow(text, text_decoration = Curses::A_NORMAL, options = {})
|
44
|
-
colored(text,
|
31
|
+
colored(text, COLOR_YELLOW, text_decoration, options)
|
45
32
|
end
|
46
33
|
|
47
34
|
def green(text, text_decoration = Curses::A_NORMAL, options = {})
|
48
|
-
colored(text,
|
35
|
+
colored(text, COLOR_GREEN, text_decoration, options)
|
49
36
|
end
|
50
37
|
|
51
38
|
def colored(text, color, text_decoration = Curses::A_NORMAL, options = {})
|
@@ -112,104 +99,55 @@ module Daigaku
|
|
112
99
|
ruby_doc_core = /(\(ruby-doc core:.*\))/ # '(ruby-doc core: Kernel#print)'
|
113
100
|
ruby_doc_stdlib = /(\(ruby-doc stdlib:.*\))/ # '(ruby-doc stdlib: CSV#Row::<<)'
|
114
101
|
|
102
|
+
text = Markdown::RubyDoc.parse(text)
|
103
|
+
|
115
104
|
case text
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
if char == '`'
|
132
|
-
highlighted = !highlighted
|
133
|
-
next
|
134
|
-
end
|
135
|
-
|
136
|
-
character = "#{text[index..(index + 1)]}" == '\\*' ? '' : char
|
137
|
-
|
138
|
-
if highlighted
|
139
|
-
red(character)
|
140
|
-
elsif emphasized
|
141
|
-
emphasize(character)
|
142
|
-
else
|
143
|
-
write(character)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
when bold
|
147
|
-
text.chars.each_with_index do |char, index|
|
148
|
-
if char == '*' && text[index - 1] != '\\'
|
149
|
-
emphasized = !emphasized
|
150
|
-
next
|
151
|
-
end
|
152
|
-
|
153
|
-
character = "#{text[index..(index + 1)]}" == '\\*' ? '' : char
|
154
|
-
emphasized ? emphasize(character) : write(character)
|
105
|
+
when h1
|
106
|
+
heading(text.gsub(/^#\s?/, ''))
|
107
|
+
when h2
|
108
|
+
text_decoration = Curses::A_UNDERLINE | Curses::A_NORMAL
|
109
|
+
emphasize(text.gsub(/^##\s?/, ''), text_decoration)
|
110
|
+
when (code || bold)
|
111
|
+
emphasized = false
|
112
|
+
highlighted = false
|
113
|
+
|
114
|
+
text.chars.each_with_index do |char, index|
|
115
|
+
if char == '*' && text[index - 1] != '\\'
|
116
|
+
emphasized = !emphasized
|
117
|
+
next
|
155
118
|
end
|
156
|
-
when line
|
157
|
-
write('-' * (Curses.cols - 2))
|
158
|
-
when ruby_doc_core
|
159
|
-
capture = text.match(/\(ruby-doc core:\s?(.*)\)/).captures.first
|
160
|
-
write text.gsub(ruby_doc_core, ruby_doc_core_link(capture))
|
161
|
-
when ruby_doc_stdlib
|
162
|
-
capture = text.match(/\(ruby-doc stdlib:\s?(.*)\)/).captures.first
|
163
|
-
write text.gsub(ruby_doc_stdlib, ruby_doc_stdlib_link(capture))
|
164
|
-
else
|
165
|
-
write(text.gsub(/(\\#)/, '#'))
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
protected
|
170
|
-
|
171
|
-
def init_colors
|
172
|
-
Curses.start_color
|
173
|
-
Curses.init_pair(COLOR_TEXT, FONT, BACKGROUND)
|
174
|
-
Curses.init_pair(COLOR_TEXT_EMPHASIZE, FONT_EMPHASIZE, BACKGROUND)
|
175
|
-
Curses.init_pair(COLOR_HEADING, FONT_HEADING, BACKGROUND)
|
176
|
-
Curses.init_pair(COLOR_RED, RED, BACKGROUND)
|
177
|
-
Curses.init_pair(COLOR_GREEN, GREEN, BACKGROUND)
|
178
|
-
Curses.init_pair(COLOR_YELLOW, YELLOW, BACKGROUND)
|
179
|
-
end
|
180
|
-
|
181
|
-
private
|
182
|
-
|
183
|
-
def ruby_doc_core_link(text)
|
184
|
-
base_url = "http://ruby-doc.org/core-#{RUBY_VERSION}"
|
185
|
-
class_part = ruby_doc_class_parts(text).join('/')
|
186
|
-
method = ruby_doc_method(text)
|
187
119
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
base_url = "http://ruby-doc.org/stdlib-#{RUBY_VERSION}"
|
193
|
-
class_parts = ruby_doc_class_parts(text)
|
194
|
-
libdoc_part = "libdoc/#{class_parts.first.downcase}/rdoc"
|
195
|
-
method = ruby_doc_method(text)
|
196
|
-
|
197
|
-
"#{base_url}/#{libdoc_part}/#{class_parts.join('/')}.html#{method}"
|
198
|
-
end
|
120
|
+
if char == '`'
|
121
|
+
highlighted = !highlighted
|
122
|
+
next
|
123
|
+
end
|
199
124
|
|
200
|
-
|
201
|
-
parts = text.split(/::|#/)
|
202
|
-
parts[0..(parts.count > 1 ? -2 : -1)]
|
203
|
-
end
|
125
|
+
character = "#{text[index..(index + 1)]}" == '\\*' ? '' : char
|
204
126
|
|
205
|
-
|
206
|
-
|
127
|
+
if highlighted
|
128
|
+
red(character)
|
129
|
+
elsif emphasized
|
130
|
+
emphasize(character)
|
131
|
+
else
|
132
|
+
write(character)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
when bold
|
136
|
+
text.chars.each_with_index do |char, index|
|
137
|
+
if char == '*' && text[index - 1] != '\\'
|
138
|
+
emphasized = !emphasized
|
139
|
+
next
|
140
|
+
end
|
207
141
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
142
|
+
character = "#{text[index..(index + 1)]}" == '\\*' ? '' : char
|
143
|
+
emphasized ? emphasize(character) : write(character)
|
144
|
+
end
|
145
|
+
when line
|
146
|
+
write('-' * (Curses.cols - 2))
|
147
|
+
else
|
148
|
+
write(text.gsub(/(\\#)/, '#'))
|
212
149
|
end
|
213
150
|
end
|
151
|
+
|
214
152
|
end
|
215
153
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Daigaku::Coloring do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
class Example
|
7
|
+
include Daigaku::Coloring
|
8
|
+
end
|
9
|
+
|
10
|
+
Example.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has the protected method #init_colors' do
|
14
|
+
expect(subject.protected_methods).to include :init_colors
|
15
|
+
end
|
16
|
+
|
17
|
+
[
|
18
|
+
:COLOR_TEXT,
|
19
|
+
:COLOR_TEXT_EMPHASIZE,
|
20
|
+
:COLOR_HEADING,
|
21
|
+
:COLOR_RED,
|
22
|
+
:COLOR_GREEN,
|
23
|
+
:COLOR_YELLOW,
|
24
|
+
:BACKGROUND,
|
25
|
+
:FONT,
|
26
|
+
:FONT_HEADING,
|
27
|
+
:FONT_EMPHASIZE,
|
28
|
+
:RED,
|
29
|
+
:GREEN,
|
30
|
+
:YELLOW
|
31
|
+
].each do |const|
|
32
|
+
it "has the constant #{const}" do
|
33
|
+
expect(Example.const_defined?(const)).to be true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Daigaku::Markdown::RubyDoc do
|
4
|
+
|
5
|
+
[:parse].each do |class_method|
|
6
|
+
it "responds to #{class_method}" do
|
7
|
+
expect(Daigaku::Markdown::RubyDoc).to respond_to class_method
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(text)
|
12
|
+
Daigaku::Markdown::RubyDoc.parse(text)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '::parse' do
|
16
|
+
context 'for a text containing a core doc markup' do
|
17
|
+
let(:base_url) { "http://ruby-doc.org/core-#{RUBY_VERSION}" }
|
18
|
+
|
19
|
+
it 'returns the right link for a single class' do
|
20
|
+
markdown = '(ruby-doc core: String)'
|
21
|
+
expect(parse(markdown)).to eq "#{base_url}/String.html"
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns the right text with link for a single class' do
|
25
|
+
markdown = '*emphasized* (ruby-doc core: String)'
|
26
|
+
expect(parse(markdown)).to eq "*emphasized* #{base_url}/String.html"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns the right link for a single namespaced class' do
|
30
|
+
markdown = '(ruby-doc core: Enumerator::Lazy)'
|
31
|
+
expect(parse(markdown)).to eq "#{base_url}/Enumerator/Lazy.html"
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns the right link for a multi namespaced class' do
|
35
|
+
markdown = '(ruby-doc core: Thread::Backtrace::Location)'
|
36
|
+
expect(parse(markdown)).to eq "#{base_url}/Thread/Backtrace/Location.html"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the right link for a single class's class method" do
|
40
|
+
markdown = '(ruby-doc core: String::new)'
|
41
|
+
expect(parse(markdown)).to eq "#{base_url}/String.html#method-c-new"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the right link for a single class's instance method" do
|
45
|
+
markdown = '(ruby-doc core: String#count)'
|
46
|
+
expect(parse(markdown)).to eq "#{base_url}/String.html#method-i-count"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns the right link for a namespaced class's class method" do
|
50
|
+
markdown = '(ruby-doc core: Enumerator::Lazy::new)'
|
51
|
+
expect(parse(markdown)).to eq "#{base_url}/Enumerator/Lazy.html#method-c-new"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the right link for a namespaced class's instance method" do
|
55
|
+
markdown = '(ruby-doc core: Enumerator::Lazy#flat_map)'
|
56
|
+
expect(parse(markdown)).to eq "#{base_url}/Enumerator/Lazy.html#method-i-flat_map"
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'for a text containing a stdlib doc markup' do
|
62
|
+
let(:base_url) { "http://ruby-doc.org/stdlib-#{RUBY_VERSION}/libdoc" }
|
63
|
+
|
64
|
+
it 'returns the right link for a single class' do
|
65
|
+
markdown = '(ruby-doc stdlib: Time)'
|
66
|
+
expect(parse(markdown)).to eq "#{base_url}/time/rdoc/Time.html"
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns the right text with link for a single class' do
|
70
|
+
markdown = '*emphasized* (ruby-doc stdlib: Time)'
|
71
|
+
expect(parse(markdown)).to eq "*emphasized* #{base_url}/time/rdoc/Time.html"
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns the right link for a single class with an explicit lib' do
|
75
|
+
markdown = '(ruby-doc stdlib: date Time)'
|
76
|
+
expect(parse(markdown)).to eq "#{base_url}/date/rdoc/Time.html"
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'returns the right link for a single namespaced class' do
|
80
|
+
markdown = '(ruby-doc stdlib: Net::HTTP)'
|
81
|
+
expect(parse(markdown)).to eq "#{base_url}/net/http/rdoc/Net/HTTP.html"
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns the right link for a multi namespaced class' do
|
85
|
+
markdown = '(ruby-doc stdlib: json JSON::Ext::Generator::State)'
|
86
|
+
expect(parse(markdown)).to eq "#{base_url}/json/rdoc/JSON/Ext/Generator/State.html"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns the right link for a single class's class method" do
|
90
|
+
markdown = '(ruby-doc stdlib: Time::parse)'
|
91
|
+
expect(parse(markdown)).to eq "#{base_url}/time/rdoc/Time.html#method-c-parse"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns the right link for a single class's instance method" do
|
95
|
+
markdown = '(ruby-doc stdlib: Time#httpdate)'
|
96
|
+
expect(parse(markdown)).to eq "#{base_url}/time/rdoc/Time.html#method-i-httpdate"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns the right link for a namespaced class's class method" do
|
100
|
+
markdown = '(ruby-doc stdlib: Net::HTTP::get)'
|
101
|
+
expect(parse(markdown)).to eq "#{base_url}/net/http/rdoc/Net/HTTP.html#method-c-get"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "returns the right link for a namespaced class's instance method" do
|
105
|
+
markdown = '(ruby-doc stdlib: Net::HTTP#get)'
|
106
|
+
expect(parse(markdown)).to eq "#{base_url}/net/http/rdoc/Net/HTTP.html#method-i-get"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
CHANGED
@@ -1,75 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daigaku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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-05
|
11
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '2.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.0'
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '2.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: activesupport
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- - "
|
31
|
+
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
33
|
version: '4.0'
|
40
|
-
- - "<"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '5.0'
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
46
37
|
requirements:
|
47
|
-
- - "
|
38
|
+
- - "~>"
|
48
39
|
- !ruby/object:Gem::Version
|
49
40
|
version: '4.0'
|
50
|
-
- - "<"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '5.0'
|
53
41
|
- !ruby/object:Gem::Dependency
|
54
42
|
name: rspec
|
55
43
|
requirement: !ruby/object:Gem::Requirement
|
56
44
|
requirements:
|
57
|
-
- - "
|
45
|
+
- - "~>"
|
58
46
|
- !ruby/object:Gem::Version
|
59
47
|
version: '3.0'
|
60
|
-
- - "<"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '4.0'
|
63
48
|
type: :runtime
|
64
49
|
prerelease: false
|
65
50
|
version_requirements: !ruby/object:Gem::Requirement
|
66
51
|
requirements:
|
67
|
-
- - "
|
52
|
+
- - "~>"
|
68
53
|
- !ruby/object:Gem::Version
|
69
54
|
version: '3.0'
|
70
|
-
- - "<"
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: '4.0'
|
73
55
|
- !ruby/object:Gem::Dependency
|
74
56
|
name: thor
|
75
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,56 +98,58 @@ dependencies:
|
|
116
98
|
name: rubyzip
|
117
99
|
requirement: !ruby/object:Gem::Requirement
|
118
100
|
requirements:
|
119
|
-
- - "
|
101
|
+
- - "~>"
|
120
102
|
- !ruby/object:Gem::Version
|
121
103
|
version: '1.0'
|
122
|
-
- - "<"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '2.0'
|
125
104
|
type: :runtime
|
126
105
|
prerelease: false
|
127
106
|
version_requirements: !ruby/object:Gem::Requirement
|
128
107
|
requirements:
|
129
|
-
- - "
|
108
|
+
- - "~>"
|
130
109
|
- !ruby/object:Gem::Version
|
131
110
|
version: '1.0'
|
132
|
-
- - "<"
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
version: '2.0'
|
135
111
|
- !ruby/object:Gem::Dependency
|
136
112
|
name: wisper
|
137
113
|
requirement: !ruby/object:Gem::Requirement
|
138
114
|
requirements:
|
139
|
-
- - "
|
115
|
+
- - "~>"
|
140
116
|
- !ruby/object:Gem::Version
|
141
117
|
version: 2.0.0.rc1
|
142
|
-
- - "<"
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version: '3.0'
|
145
118
|
type: :runtime
|
146
119
|
prerelease: false
|
147
120
|
version_requirements: !ruby/object:Gem::Requirement
|
148
121
|
requirements:
|
149
|
-
- - "
|
122
|
+
- - "~>"
|
150
123
|
- !ruby/object:Gem::Version
|
151
124
|
version: 2.0.0.rc1
|
152
|
-
- - "<"
|
153
|
-
- !ruby/object:Gem::Version
|
154
|
-
version: '3.0'
|
155
125
|
- !ruby/object:Gem::Dependency
|
156
126
|
name: quick_store
|
157
127
|
requirement: !ruby/object:Gem::Requirement
|
158
128
|
requirements:
|
159
129
|
- - "~>"
|
160
130
|
- !ruby/object:Gem::Version
|
161
|
-
version: 0.1
|
131
|
+
version: '0.1'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.1'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: code_breaker
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.1'
|
162
146
|
type: :runtime
|
163
147
|
prerelease: false
|
164
148
|
version_requirements: !ruby/object:Gem::Requirement
|
165
149
|
requirements:
|
166
150
|
- - "~>"
|
167
151
|
- !ruby/object:Gem::Version
|
168
|
-
version: 0.1
|
152
|
+
version: '0.1'
|
169
153
|
- !ruby/object:Gem::Dependency
|
170
154
|
name: bundler
|
171
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -241,6 +225,7 @@ files:
|
|
241
225
|
- daigaku.gemspec
|
242
226
|
- lib/daigaku.rb
|
243
227
|
- lib/daigaku/chapter.rb
|
228
|
+
- lib/daigaku/coloring.rb
|
244
229
|
- lib/daigaku/configuration.rb
|
245
230
|
- lib/daigaku/congratulator.rb
|
246
231
|
- lib/daigaku/course.rb
|
@@ -251,6 +236,8 @@ files:
|
|
251
236
|
- lib/daigaku/loading/chapters.rb
|
252
237
|
- lib/daigaku/loading/courses.rb
|
253
238
|
- lib/daigaku/loading/units.rb
|
239
|
+
- lib/daigaku/markdown.rb
|
240
|
+
- lib/daigaku/markdown/ruby_doc.rb
|
254
241
|
- lib/daigaku/reference_solution.rb
|
255
242
|
- lib/daigaku/solution.rb
|
256
243
|
- lib/daigaku/storeable.rb
|
@@ -282,6 +269,7 @@ files:
|
|
282
269
|
- lib/daigaku/views/units_menu.rb
|
283
270
|
- lib/daigaku/window.rb
|
284
271
|
- spec/daigaku/chapter_spec.rb
|
272
|
+
- spec/daigaku/coloring_spec.rb
|
285
273
|
- spec/daigaku/configuration_spec.rb
|
286
274
|
- spec/daigaku/congratulator_spec.rb
|
287
275
|
- spec/daigaku/course_spec.rb
|
@@ -290,6 +278,7 @@ files:
|
|
290
278
|
- spec/daigaku/loading/chapters_spec.rb
|
291
279
|
- spec/daigaku/loading/courses_spec.rb
|
292
280
|
- spec/daigaku/loading/units_spec.rb
|
281
|
+
- spec/daigaku/markdown/ruby_doc_spec.rb
|
293
282
|
- spec/daigaku/reference_solution_spec.rb
|
294
283
|
- spec/daigaku/solution_spec.rb
|
295
284
|
- spec/daigaku/storeable_spec.rb
|
@@ -340,12 +329,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
340
329
|
version: '0'
|
341
330
|
requirements: []
|
342
331
|
rubyforge_project:
|
343
|
-
rubygems_version: 2.4.
|
332
|
+
rubygems_version: 2.4.6
|
344
333
|
signing_key:
|
345
334
|
specification_version: 4
|
346
335
|
summary: Learning Ruby on the command line.
|
347
336
|
test_files:
|
348
337
|
- spec/daigaku/chapter_spec.rb
|
338
|
+
- spec/daigaku/coloring_spec.rb
|
349
339
|
- spec/daigaku/configuration_spec.rb
|
350
340
|
- spec/daigaku/congratulator_spec.rb
|
351
341
|
- spec/daigaku/course_spec.rb
|
@@ -354,6 +344,7 @@ test_files:
|
|
354
344
|
- spec/daigaku/loading/chapters_spec.rb
|
355
345
|
- spec/daigaku/loading/courses_spec.rb
|
356
346
|
- spec/daigaku/loading/units_spec.rb
|
347
|
+
- spec/daigaku/markdown/ruby_doc_spec.rb
|
357
348
|
- spec/daigaku/reference_solution_spec.rb
|
358
349
|
- spec/daigaku/solution_spec.rb
|
359
350
|
- spec/daigaku/storeable_spec.rb
|