madness 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/app/views/_mobile_search.slim +1 -1
- data/app/views/_nav.slim +2 -2
- data/app/views/layout.slim +5 -5
- data/app/views/search.slim +1 -1
- data/lib/madness/breadcrumbs.rb +6 -2
- data/lib/madness/item.rb +4 -1
- data/lib/madness/server.rb +16 -3
- data/lib/madness/server_base.rb +13 -20
- data/lib/madness/server_helper.rb +25 -0
- data/lib/madness/settings.rb +1 -0
- data/lib/madness/templates/madness.yml +4 -0
- data/lib/madness/version.rb +1 -1
- data/lib/madness.rb +1 -0
- metadata +2 -3
- data/lib/madness/static.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cced29facd3dba093bbc3b25729fce834ade95ebaeb4086fdb8ad0ee179165d5
|
4
|
+
data.tar.gz: 615502287bd4ec1da6b75beddf1d57e2fcd76d71a23b728dc6921d577de7b71d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2d0b4dbf8bae41e71ec0ff9181dac4a0d4254a0219561d50161cb21b93f6abcf0acb6098d430f60c4d2874b05648c91865cf822d251b3bdbeb9894714f48c16
|
7
|
+
data.tar.gz: 78462e7922c4ea8164cab394fe9bb1e0fbb14700947c716f40ab7a7c797094cbb9c7317599c33bf1fb786a45f2a4e8c7a88614d4396a1a9aea067ee5f42eea1d
|
data/README.md
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
a#mobile-search href="/_search"
|
1
|
+
a#mobile-search href="#{config.base_uri}/_search"
|
2
2
|
i.icon-search
|
data/app/views/_nav.slim
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
nav
|
2
2
|
.icon-bar
|
3
|
-
a.icon href="/" accesskey='h' class=('wide' unless nav.with_search?)
|
3
|
+
a.icon href="#{config.base_uri}/" accesskey='h' class=('wide' unless nav.with_search?)
|
4
4
|
i.icon-home
|
5
5
|
|
6
6
|
- if nav.with_search?
|
7
|
-
a.icon href="/_search" accesskey='s' style='text-align:right'
|
7
|
+
a.icon href="#{config.base_uri}/_search" accesskey='s' style='text-align:right'
|
8
8
|
i.icon-search
|
9
9
|
|
10
10
|
- if nav.caption
|
data/app/views/layout.slim
CHANGED
@@ -8,14 +8,14 @@ html
|
|
8
8
|
title = locals[:title]
|
9
9
|
meta name="HandheldFriendly" content="true"
|
10
10
|
meta name="viewport" content="width=device-width, initial-scale=1"
|
11
|
-
link href='/css/main.css' rel='stylesheet' type='text/css'
|
11
|
+
link href='#{config.base_uri}/css/main.css' rel='stylesheet' type='text/css'
|
12
12
|
- custom_css.each do |file|
|
13
|
-
link href="/#{file}" rel='stylesheet' type='text/css'
|
13
|
+
link href="#{config.base_uri}/#{file}" rel='stylesheet' type='text/css'
|
14
14
|
|
15
15
|
- if config.copy_code
|
16
|
-
script src="/js/vendor/jquery.min.js"
|
17
|
-
script src="/js/vendor/clipboard.min.js"
|
18
|
-
script src="/js/clipboard.js"
|
16
|
+
script src="#{config.base_uri}/js/vendor/jquery.min.js"
|
17
|
+
script src="#{config.base_uri}/js/vendor/clipboard.min.js"
|
18
|
+
script src="#{config.base_uri}/js/clipboard.js"
|
19
19
|
|
20
20
|
body
|
21
21
|
== yield
|
data/app/views/search.slim
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
== slim :_nav, locals: { nav: nav } if config.sidebar
|
2
2
|
|
3
3
|
.main class=(config.sidebar ? 'with-sidebar' : 'without-sidebar')
|
4
|
-
form.search-form action="/_search" method="get"
|
4
|
+
form.search-form action="#{config.base_uri}/_search" method="get"
|
5
5
|
input.search-field type="text" name="q" value="#{params[:q]}" placeholder="Search (use quotes for exact match)" autofocus=true
|
6
6
|
input type="submit" value="Search" style='display:none'
|
7
7
|
|
data/lib/madness/breadcrumbs.rb
CHANGED
@@ -17,7 +17,7 @@ module Madness
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def breadcrumbs
|
20
|
-
home = OpenStruct.new({ label: 'Home', href:
|
20
|
+
home = OpenStruct.new({ label: 'Home', href: "#{config.base_uri}/" })
|
21
21
|
result = breadcrumbs_maker(path).reverse.unshift home
|
22
22
|
result.last.last = true
|
23
23
|
result
|
@@ -28,12 +28,16 @@ module Madness
|
|
28
28
|
item = OpenStruct.new(
|
29
29
|
{
|
30
30
|
label: basename.to_label,
|
31
|
-
href: "/#{partial_path}",
|
31
|
+
href: "#{config.base_uri}/#{partial_path}",
|
32
32
|
}
|
33
33
|
)
|
34
34
|
result = [item]
|
35
35
|
result += breadcrumbs_maker parent unless parent == '.'
|
36
36
|
result
|
37
37
|
end
|
38
|
+
|
39
|
+
def config
|
40
|
+
Settings.instance
|
41
|
+
end
|
38
42
|
end
|
39
43
|
end
|
data/lib/madness/item.rb
CHANGED
data/lib/madness/server.rb
CHANGED
@@ -5,7 +5,17 @@ module Madness
|
|
5
5
|
class Server < ServerBase
|
6
6
|
using StringRefinements
|
7
7
|
|
8
|
-
|
8
|
+
if config.base_uri
|
9
|
+
not_found do
|
10
|
+
redirect "#{config.base_uri}/"
|
11
|
+
end
|
12
|
+
|
13
|
+
get config.base_uri do
|
14
|
+
redirect "#{config.base_uri}/"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
get "#{config.base_uri}/_search" do
|
9
19
|
query = params[:q]
|
10
20
|
results = query ? Search.new.search(query) : false
|
11
21
|
nav = Navigation.new docroot
|
@@ -15,15 +25,18 @@ module Madness
|
|
15
25
|
}
|
16
26
|
end
|
17
27
|
|
18
|
-
get
|
28
|
+
get "#{config.base_uri}/*" do
|
19
29
|
path = params[:splat].first
|
30
|
+
static_file = find_static_file path
|
31
|
+
|
32
|
+
next send_file static_file if static_file
|
20
33
|
|
21
34
|
doc = Document.new path
|
22
35
|
dir = doc.dir
|
23
36
|
content = doc.content
|
24
37
|
|
25
38
|
if (doc.type == :readme) && !path.empty? && (path[-1] != '/')
|
26
|
-
redirect "#{
|
39
|
+
redirect "#{request.path_info}/"
|
27
40
|
end
|
28
41
|
|
29
42
|
nav = Navigation.new dir
|
data/lib/madness/server_base.rb
CHANGED
@@ -13,36 +13,29 @@ module Madness
|
|
13
13
|
set :root, File.expand_path('../../', __dir__)
|
14
14
|
set :environment, ENV['MADNESS_ENV'] || :production
|
15
15
|
set :server, :puma
|
16
|
+
set :static, false
|
16
17
|
|
17
18
|
# Since we cannot use any config values in the main body of the class,
|
18
19
|
# since they will be updated later, we need to set anything that relys
|
19
20
|
# on the config values just before running the server.
|
20
21
|
# The CommandLine class and the test suite should both call
|
21
22
|
# `Server.prepare` before calling Server.run!
|
22
|
-
|
23
|
-
|
24
|
-
set :bind, config.bind
|
25
|
-
set :port, config.port
|
23
|
+
class << self
|
24
|
+
include ServerHelper
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def self.set_tempalate_locations
|
32
|
-
theme = Theme.new config.theme
|
33
|
-
|
34
|
-
set :views, theme.views_path
|
35
|
-
set :public_folder, theme.public_path
|
36
|
-
end
|
26
|
+
def prepare
|
27
|
+
set :bind, config.bind
|
28
|
+
set :port, config.port
|
29
|
+
set :views, theme.views_path
|
37
30
|
|
38
|
-
|
39
|
-
use Rack::Auth::Basic, config.auth_zone do |username, password|
|
40
|
-
config.auth.split(':') == [username, password]
|
31
|
+
set_basic_auth if config.auth
|
41
32
|
end
|
42
|
-
end
|
43
33
|
|
44
|
-
|
45
|
-
|
34
|
+
def set_basic_auth
|
35
|
+
use Rack::Auth::Basic, config.auth_zone do |username, password|
|
36
|
+
config.auth.split(':') == [username, password]
|
37
|
+
end
|
38
|
+
end
|
46
39
|
end
|
47
40
|
end
|
48
41
|
end
|
@@ -10,6 +10,10 @@ module Madness
|
|
10
10
|
@docroot ||= File.expand_path(config.path, Dir.pwd)
|
11
11
|
end
|
12
12
|
|
13
|
+
def theme
|
14
|
+
@theme ||= Theme.new config.theme
|
15
|
+
end
|
16
|
+
|
13
17
|
def log(obj)
|
14
18
|
# :nocov:
|
15
19
|
open('madness.log', 'a') do |f|
|
@@ -17,5 +21,26 @@ module Madness
|
|
17
21
|
end
|
18
22
|
# :nocov:
|
19
23
|
end
|
24
|
+
|
25
|
+
# Search for static file, first in the users docroot, then in the template
|
26
|
+
# directory.
|
27
|
+
def find_static_file(path)
|
28
|
+
return nil if disallowed_static?(path)
|
29
|
+
|
30
|
+
candidates = [
|
31
|
+
"#{config.path}/#{path}",
|
32
|
+
"#{theme.public_path}/#{path}",
|
33
|
+
]
|
34
|
+
|
35
|
+
candidates.each do |candidate|
|
36
|
+
return candidate if File.file? candidate
|
37
|
+
end
|
38
|
+
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def disallowed_static?(path)
|
43
|
+
path.end_with?('.md') || path.empty? || File.basename(path).start_with?('.')
|
44
|
+
end
|
20
45
|
end
|
21
46
|
end
|
data/lib/madness/settings.rb
CHANGED
data/lib/madness/version.rb
CHANGED
data/lib/madness.rb
CHANGED
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: 1.
|
4
|
+
version: 1.1.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: 2023-02-
|
11
|
+
date: 2023-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -266,7 +266,6 @@ files:
|
|
266
266
|
- lib/madness/server_base.rb
|
267
267
|
- lib/madness/server_helper.rb
|
268
268
|
- lib/madness/settings.rb
|
269
|
-
- lib/madness/static.rb
|
270
269
|
- lib/madness/table_of_contents.rb
|
271
270
|
- lib/madness/templates/madness.yml
|
272
271
|
- lib/madness/theme.rb
|
data/lib/madness/static.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Madness
|
2
|
-
# The Madness::Static middleware delegates requests to
|
3
|
-
# Rack::Static middleware unless the request URI ends with .md
|
4
|
-
class Static
|
5
|
-
def initialize(app, options)
|
6
|
-
@app = app
|
7
|
-
@static = Rack::Static.new app, options
|
8
|
-
end
|
9
|
-
|
10
|
-
def call(env)
|
11
|
-
if env['PATH_INFO'].end_with? '.md'
|
12
|
-
@app.call env
|
13
|
-
else
|
14
|
-
@static.call env
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|