doc_repo 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/doc_repo/github_file.rb +2 -2
- data/lib/doc_repo/page.rb +9 -1
- data/lib/doc_repo/repository.rb +11 -2
- data/lib/doc_repo/version.rb +1 -1
- data/lib/doc_repo.rb +7 -1
- data/spec/doc_repo/page_spec.rb +20 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e1a9e6408d42a187fc5d668426aca25ad3661be
|
4
|
+
data.tar.gz: 0373f7e7efbd2fc35d5afd711e83e7eef7f789a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d5e6709b03df737388ec015522debeff764530d55e863ae9298eef7ed809ea1dc7851fdc50b923bb8ed6186655ded67baa554c7658011e78c42ab68b964afaf
|
7
|
+
data.tar.gz: 47467108c56abf3c402705c757cead63ffd31dcd7c6c36f1af05ad062a8df7cea45be0fc3ff2b969c73a092b7f899a904163bf589cb12d5d6647661b2de7a192
|
data/lib/doc_repo/github_file.rb
CHANGED
@@ -20,8 +20,8 @@ module DocRepo
|
|
20
20
|
|
21
21
|
def read_remote_file
|
22
22
|
open(url(file), headers).read
|
23
|
-
rescue OpenURI::HTTPError =>
|
24
|
-
raise DocRepo::NotFound
|
23
|
+
rescue OpenURI::HTTPError => http_error
|
24
|
+
raise DocRepo::NotFound.new(base: http_error)
|
25
25
|
end
|
26
26
|
|
27
27
|
def headers
|
data/lib/doc_repo/page.rb
CHANGED
@@ -5,7 +5,15 @@ module DocRepo
|
|
5
5
|
attr_accessor :body
|
6
6
|
|
7
7
|
def initialize(file)
|
8
|
-
@body = GithubFile.new(
|
8
|
+
@body = GithubFile.new(default_ext(file)).read_remote_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_ext(file)
|
12
|
+
if File.extname(file).empty?
|
13
|
+
"#{file}.md"
|
14
|
+
else
|
15
|
+
file
|
16
|
+
end
|
9
17
|
end
|
10
18
|
|
11
19
|
def to_html
|
data/lib/doc_repo/repository.rb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
1
|
module DocRepo
|
2
2
|
class Repository
|
3
|
+
REDIRECT_FORMATS = %w[
|
4
|
+
.jpg
|
5
|
+
.png
|
6
|
+
.jpeg
|
7
|
+
.svg
|
8
|
+
.css
|
9
|
+
.txt
|
10
|
+
]
|
11
|
+
|
3
12
|
def respond(slug, &block)
|
4
|
-
if
|
13
|
+
if REDIRECT_FORMATS.include?(File.extname(slug).downcase)
|
5
14
|
yield DocRepo::Response.redirect(get_redirect_url(slug))
|
6
15
|
else
|
7
16
|
yield DocRepo::Response.html(render_page(slug))
|
8
17
|
end
|
9
18
|
end
|
10
19
|
|
11
|
-
|
20
|
+
private
|
12
21
|
|
13
22
|
def render_page(slug)
|
14
23
|
DocRepo::Page.new(slug).to_html
|
data/lib/doc_repo/version.rb
CHANGED
data/lib/doc_repo.rb
CHANGED
@@ -8,7 +8,13 @@ module DocRepo
|
|
8
8
|
autoload :Response, "doc_repo/response"
|
9
9
|
|
10
10
|
BadPageFormat = Class.new(StandardError)
|
11
|
-
NotFound
|
11
|
+
class NotFound < StandardError
|
12
|
+
attr_reader :base
|
13
|
+
def initialize(*args, base: $!)
|
14
|
+
@base = base
|
15
|
+
super(*args)
|
16
|
+
end
|
17
|
+
end
|
12
18
|
|
13
19
|
class << self
|
14
20
|
attr_accessor :configuration
|
data/spec/doc_repo/page_spec.rb
CHANGED
@@ -10,21 +10,35 @@ RSpec.describe DocRepo::Page do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
let(:body){
|
14
|
+
<<-END.strip_heredoc
|
15
15
|
# A heading
|
16
16
|
|
17
17
|
Some content
|
18
18
|
END
|
19
|
+
}
|
19
20
|
|
21
|
+
let(:rendered_html){
|
22
|
+
<<-END.strip_heredoc
|
23
|
+
<h1 id=\"a-heading\">A heading</h1>
|
24
|
+
|
25
|
+
<p>Some content</p>
|
26
|
+
END
|
27
|
+
}
|
28
|
+
|
29
|
+
it "returns the markdown as html when there is no extension" do
|
20
30
|
stub_request(:get, "https://api.github.com/repos/RadiusNetworks/doc_spec/contents/docs/page.md?ref=master")
|
21
31
|
.to_return(body: body)
|
22
32
|
|
23
33
|
page = DocRepo::Page.new("page")
|
24
|
-
expect(page.to_html).to eq
|
25
|
-
|
34
|
+
expect(page.to_html).to eq rendered_html
|
35
|
+
end
|
26
36
|
|
27
|
-
|
28
|
-
|
37
|
+
it "returns the markdown as html when there is a .md extension" do
|
38
|
+
stub_request(:get, "https://api.github.com/repos/RadiusNetworks/doc_spec/contents/docs/page.md?ref=master")
|
39
|
+
.to_return(body: body)
|
40
|
+
|
41
|
+
page = DocRepo::Page.new("page.md")
|
42
|
+
expect(page.to_html).to eq rendered_html
|
29
43
|
end
|
30
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doc_repo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Sexton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rouge
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
147
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.6.11
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: 'Doc Repo: Load in app documentation via an external Github repo'
|