madness 0.7.6 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 476c5a098ba603805e53fa355f545eb3daaa7d692fc63a1793abb6f89fea7946
4
- data.tar.gz: 0552adeb738418cc51ae4cd67caa12d3f577238bc95ac9f599945892df1c92ce
3
+ metadata.gz: 17e42d618e170958cf8b556c2271ddb7efeeae6e15144c5e5f4252cdb4708808
4
+ data.tar.gz: b4fc80231d2cdbc2834dab2a428a501371abbb3b7426984f20833b411314df6e
5
5
  SHA512:
6
- metadata.gz: 98410335fb59c3795fe8a009c171a7099c06b7bdda6f54699e31e386bc264a74aa8d30bd8cc7a98902698d271d40bcb2b00a5228b3830d1b0e0ffcad5931e65b
7
- data.tar.gz: 05aec5e799377845efdef6a70e3563ab1f47e1c702b15d177c63af781b0b397705d2526067f6eed7518d9d732bd075dfd360f4ea0aabff06b19b6fd4a5260e88
6
+ metadata.gz: 547e6b50b089cac0e4c01bc4938ea14a0cee3985c7dbdcf6bf01a7aa375a4f18f31d720c368918e595c4d03a2ef5f03b6ece929d260c90b523f90d2886b54af5
7
+ data.tar.gz: 5c72050811de28e4bf8174b1897f847a770f6eeb12844b741c81ca810ba1c345b353e7aac00194f7ca0c01493d5ba664539ae00bdbedb552b81bffec4c07d4f9
@@ -15,7 +15,7 @@ module Madness
15
15
  path == "" ? [] : get_breadcrumbs
16
16
  end
17
17
 
18
- private
18
+ private
19
19
 
20
20
  def get_breadcrumbs
21
21
  home = OpenStruct.new({ label: "Home", href: '/' })
@@ -22,7 +22,7 @@ module Madness
22
22
  end
23
23
  end
24
24
 
25
- private
25
+ private
26
26
 
27
27
  # Separate between the two main modes: Create something, or launch
28
28
  # the server.
@@ -14,7 +14,7 @@ module Madness
14
14
  @list ||= (dirs + files)
15
15
  end
16
16
 
17
- private
17
+ private
18
18
 
19
19
  def files
20
20
  result = Dir["#{dir}/*.md"]
@@ -47,19 +47,20 @@ module Madness
47
47
 
48
48
  # Return the HTML for that document, force re-read.
49
49
  def content!
50
- type == :empty ? "<h1>#{title}</h1>" : markdown_to_html
50
+ [:empty, :missing].include?(type) ? "<h1>#{title}</h1>" : markdown_to_html
51
51
  end
52
52
 
53
- private
53
+ private
54
54
 
55
55
  # Identify file, dir and type.
56
- # :readme - in case the path is a directory, and it contains index.md
57
- # or README.md
58
- # :file - in case the path is a *.md file
59
- # :empty - in any other case, we don't know.
56
+ # :readme - in case the path is a directory, and it contains index.md
57
+ # or README.md
58
+ # :file - in case the path is a *.md file
59
+ # :empty - in case it is a folder without README.md or index.md
60
+ # :missing - in any other case, we don't know (will trigger 404)
60
61
  def set_base_attributes
61
62
  @dir = docroot
62
- @type = :empty
63
+ @type = :missing
63
64
  @file = ''
64
65
  @title = 'Index'
65
66
 
@@ -14,7 +14,7 @@ module Madness
14
14
  end
15
15
 
16
16
  def href
17
- URI.escape(path_without_extension.sub(/^#{docroot}/, ''))
17
+ path_without_extension.sub(/^#{docroot}/, '').to_href
18
18
  end
19
19
 
20
20
  def dir?
@@ -25,7 +25,7 @@ module Madness
25
25
  type == :file
26
26
  end
27
27
 
28
- private
28
+ private
29
29
 
30
30
  def label!
31
31
  File.basename(path_without_extension).to_label
@@ -22,7 +22,7 @@ module Madness
22
22
  @with_search ||= Search.new.has_index?
23
23
  end
24
24
 
25
- private
25
+ private
26
26
 
27
27
  def directory
28
28
  @directory ||= Directory.new(dir)
@@ -5,6 +5,10 @@ module Madness
5
5
  gsub regex, ''
6
6
  end
7
7
 
8
+ def to_href
9
+ URI.escape self
10
+ end
11
+
8
12
  def to_slug
9
13
  downcase.strip.gsub(' ', '-').remove(/[^\w-]/)
10
14
  end
@@ -60,7 +60,7 @@ module Madness
60
60
  "#{@path}/_index"
61
61
  end
62
62
 
63
- private
63
+ private
64
64
 
65
65
  # We are going to avoid indexing of README.md when there is also an
66
66
  # index.md in the same directory, to keep behavior consistent with the
@@ -4,6 +4,8 @@ module Madness
4
4
 
5
5
  # The Sinatra server
6
6
  class Server < ServerBase
7
+ using StringRefinements
8
+
7
9
  get '/_search' do
8
10
  query = params[:q]
9
11
  results = query ? Search.new.search(query) : false
@@ -33,7 +35,7 @@ module Madness
33
35
  content = doc.content
34
36
 
35
37
  if doc.type == :readme and !path.empty? and path[-1] != '/'
36
- redirect "#{path}/"
38
+ redirect "#{path.to_href}/"
37
39
  end
38
40
 
39
41
  nav = Navigation.new dir
@@ -43,6 +45,8 @@ module Madness
43
45
  redirect to(nav.links.first.href)
44
46
  end
45
47
 
48
+ status 404 if doc.type == :missing
49
+
46
50
  slim :document, locals: {
47
51
  content: content,
48
52
  type: doc.type,
@@ -39,7 +39,7 @@ module Madness
39
39
  '.madness.yml'
40
40
  end
41
41
 
42
- private
42
+ private
43
43
 
44
44
  def defaults
45
45
  {
@@ -18,7 +18,7 @@ module Madness
18
18
  @toc ||= toc!.join("\n")
19
19
  end
20
20
 
21
- private
21
+ private
22
22
 
23
23
  def toc!(path=dir, indent=0)
24
24
  list = Directory.new(path).list
@@ -1,3 +1,3 @@
1
1
  module Madness
2
- VERSION = "0.7.6"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-08 00:00:00.000000000 Z
11
+ date: 2019-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coderay