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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc7d8c08c2b6224d86b67f6d1a3fbaa7eeba0c9d
4
- data.tar.gz: b6d49db3309f95fe6dc30d97b2ae45dc02522242
3
+ metadata.gz: 7e1a9e6408d42a187fc5d668426aca25ad3661be
4
+ data.tar.gz: 0373f7e7efbd2fc35d5afd711e83e7eef7f789a6
5
5
  SHA512:
6
- metadata.gz: 19488fa0c31b900f1f679c309c9921627fa0a9963a312c2657323c5938ae425328701ebcdda02382c234f69c859a88c44c1c4bf852617247bf4d07141739a35f
7
- data.tar.gz: aec5d27ab0a945616e4d08fd02ffcaca3c75e94da608dd20b0710d6589166125a769208e68301c9672eb39044744a3be27b62df055162371b4dd441e667c6484
6
+ metadata.gz: 1d5e6709b03df737388ec015522debeff764530d55e863ae9298eef7ed809ea1dc7851fdc50b923bb8ed6186655ded67baa554c7658011e78c42ab68b964afaf
7
+ data.tar.gz: 47467108c56abf3c402705c757cead63ffd31dcd7c6c36f1af05ad062a8df7cea45be0fc3ff2b969c73a092b7f899a904163bf589cb12d5d6647661b2de7a192
@@ -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 => _ignore
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("#{file}.md").read_remote_file
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
@@ -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 %w(.jpg .png .jpeg .svg .css .txt).include? File.extname(slug)
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
- private
20
+ private
12
21
 
13
22
  def render_page(slug)
14
23
  DocRepo::Page.new(slug).to_html
@@ -1,3 +1,3 @@
1
1
  module DocRepo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
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 = Class.new(StandardError)
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
@@ -10,21 +10,35 @@ RSpec.describe DocRepo::Page do
10
10
  end
11
11
  end
12
12
 
13
- it "returns the markdown as html" do
14
- body = <<-END.strip_heredoc
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 <<-END.strip_heredoc
25
- <h1 id=\"a-heading\">A heading</h1>
34
+ expect(page.to_html).to eq rendered_html
35
+ end
26
36
 
27
- <p>Some content</p>
28
- END
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.2
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: 2015-04-30 00:00:00.000000000 Z
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.4.5
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'