docrb-html 0.3.1 → 0.3.2

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
  SHA256:
3
- metadata.gz: 5e032e7d421f2811ed73880d0e9b224ebf11b9027446baee4fbf58f8fe28efb5
4
- data.tar.gz: 9ea3088213e3e09e31c12a81041ad3cab9f48d16b859a36597603d159bc8423d
3
+ metadata.gz: 2d537de0bf7498e0737d3e5fa22fdce806a5fc60cd43db277654bf6d29e5f166
4
+ data.tar.gz: 8ad531ba61d72206428b7c51146407e64b67e31d52831e46871f0511c868aab4
5
5
  SHA512:
6
- metadata.gz: 6e4c417666d05eb251dfee6ffc8b1243f1db13e73d34b48e9c7a1645fedb6fbad9eec4679387d18e76f25e78fb0253ac9c44c6f3ff753ed78673884e7d26ab75
7
- data.tar.gz: 6b4e542016f1c14f2f40a6adabddecc97afbde132021c1ac5f830a1b785255b79eb27078570296f287e39a9ef2f348e75612446b360c3a530b47f077748bfad2
6
+ metadata.gz: 64bed70222a7dca33da8f1d63f744da880bd8a1cd5e94f2a32816f77453b9d0d99c4529104a106b900f081591e4fb1ed2b897279b7bbdc53c0f5d0e28a0ecafc
7
+ data.tar.gz: 2f4c229846d54b5447283693eadb795d1e2c460959bafe6ebe8614d248b8b0b92ac8d6a923b159ff6e7d3b87f5e5e842aed788cd30aa402768e1a65e57ae6194
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docrb-html (0.3.1)
4
+ docrb-html (0.3.2)
5
5
  nokogiri (~> 1.14)
6
6
  redcarpet (~> 3.6)
7
7
  rouge (~> 4.1)
data/lib/docrb-html.rb CHANGED
@@ -29,6 +29,8 @@ require_relative "renderer/metadata"
29
29
  require_relative "renderer/entities"
30
30
 
31
31
  class Renderer
32
+ attr_reader :spec
33
+
32
34
  def now = Time.now.strftime("%A, %-d %b %Y %H:%M:%S %Z")
33
35
 
34
36
  def output_path(*args) = File.join(@output, *args.map(&:to_s))
@@ -55,6 +57,11 @@ class Renderer
55
57
  .map { outline(_1) }
56
58
  end
57
59
 
60
+ def make_path(*args)
61
+ root = spec.fetch(:base_path, "/")
62
+ File.join(root, *args.flatten.map(&:to_s))
63
+ end
64
+
58
65
  def outline(object, level = 0)
59
66
  {
60
67
  level:,
@@ -86,8 +93,8 @@ class Renderer
86
93
  Component::TabBar.new(
87
94
  selected_index: 0,
88
95
  items: [
89
- { name: "Readme", href: "/" },
90
- { name: "Components", href: "/components.html" }
96
+ { name: "Readme", href: make_path("/") },
97
+ { name: "Components", href: make_path("/components.html") }
91
98
  ]
92
99
  ),
93
100
  readme,
@@ -101,8 +108,8 @@ class Renderer
101
108
  Component::TabBar.new(
102
109
  selected_index: 1,
103
110
  items: [
104
- { name: "Readme", href: "/" },
105
- { name: "Components", href: "/components.html" }
111
+ { name: "Readme", href: make_path("/") },
112
+ { name: "Components", href: make_path("/components.html") }
106
113
  ]
107
114
  ),
108
115
  Component::ComponentList.new(list: make_outline),
@@ -9,7 +9,7 @@ class Renderer
9
9
  case @object
10
10
  when Docrb::Parser::Reference
11
11
  @unresolved = !@object.fulfilled?
12
- @path = [@object.path.last]
12
+ @path = @object.path
13
13
  return if @unresolved
14
14
 
15
15
  @object = @object.dereference!
@@ -96,13 +96,14 @@ class Renderer
96
96
  end
97
97
  end
98
98
 
99
+ def make_path(*) = self.class.current_renderer.make_path(*)
100
+
99
101
  def path_of(object, root: true)
100
102
  return [] if object.nil? && !root
101
103
  return [object.name] + path_of(object.parent, root: false) unless root
102
104
 
103
105
  path = ["#{object.name}.html"] + path_of(object.parent, root: false)
104
- path << ""
105
- path.reverse.join("/")
106
+ make_path(*path.reverse)
106
107
  end
107
108
 
108
109
  def link_for(object)
data/lib/renderer/page.rb CHANGED
@@ -8,9 +8,17 @@ class Renderer
8
8
  @title = "#{title} - Docrb"
9
9
  @body = body || -> { "" }
10
10
  @level = level
11
+ @make_path = -> (path) { Helpers.current_renderer.make_path(path) }
11
12
  end
12
13
 
13
- def render = PAGE_BASE.render(Object.new, title: @title, level: @level, body: @body.call)
14
+ def render
15
+ PAGE_BASE.render(Object.new,
16
+ make_path: @make_path,
17
+ title: @title,
18
+ level: @level,
19
+ body: @body.call
20
+ )
21
+ end
14
22
 
15
23
  def render_to(path) = File.write(path, render)
16
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Renderer
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
data/templates/base.erb CHANGED
@@ -7,12 +7,9 @@
7
7
  <link rel="preconnect" href="https://fonts.googleapis.com" />
8
8
  <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="true" />
9
9
  <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500&family=Inter:wght@300;400;500&display=swap" rel="stylesheet" />
10
- <% unless level.zero? %>
11
- <base href="<%= ([".."] * level).join("/") %>" />
12
- <% end %>
13
- <link rel="stylesheet" type="text/css" href="style.css" />
14
- <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
15
- <link rel="icon" href="favicon.ico" type="image/x-icon"/>
10
+ <link rel="stylesheet" type="text/css" href="<%= make_path.call("style.css") %>" />
11
+ <link rel="shortcut icon" href="<%= make_path.call("favicon.ico") %>" type="image/x-icon"/>
12
+ <link rel="icon" href="<%= make_path.call("favicon.ico") %>" type="image/x-icon"/>
16
13
  </head>
17
14
  <body>
18
15
  <% if body.is_a? Array %>
@@ -20,6 +17,6 @@
20
17
  <% else %>
21
18
  <%= body %>
22
19
  <% end %>
23
- <script type="text/javascript" src="filtering.js"></script>
20
+ <script type="text/javascript" src="<%= make_path.call("filtering.js") %>"></script>
24
21
  </body>
25
22
  </html>
@@ -1,6 +1,6 @@
1
1
  <% div("breadcrumb-base", id:) do %>
2
2
  <div class="link">
3
- <a href="/">
3
+ <a href="<%= make_path %>">
4
4
  <%= svg("home") %>
5
5
  <span class="padded">
6
6
  <%= project_name %>
@@ -11,13 +11,13 @@
11
11
  <%= svg("breadcrumb_separator") %>
12
12
  <div class="link">
13
13
  <% if i[:parents].empty? && idx == 0 %>
14
- <a href="components.html">
14
+ <a href="<%= make_path("/components.html") %>">
15
15
  <span class="padded">
16
16
  <%= i[:name] %>
17
17
  </span>
18
18
  </a>
19
19
  <% else %>
20
- <a href="<%= (i[:parents] + [idx == 0 ? nil : i[:name]]).flatten.compact.join("/") %>.html">
20
+ <a href="<%= make_path((i[:parents] + [idx == 0 ? nil : i[:name]]).flatten.compact) %>.html">
21
21
  <span class="padded">
22
22
  <%= i[:name] %>
23
23
  </span>
@@ -1,6 +1,6 @@
1
1
  <% div("reference-base", id:) do %>
2
2
  <% if unresolved %>
3
- <span class="broken"><%= value || path.last %></span>
3
+ <span class="broken"><%= value || path.join("::") %></span>
4
4
  <% elsif ref_type == :pure %>
5
5
  <a href="<%= link_for(object) %>">
6
6
  <span class="resolved <%= ref_type %>">
@@ -8,7 +8,7 @@
8
8
  </span>
9
9
  </a>
10
10
  <% else %>
11
- <a href="<%= path.join('/') %>.html">
11
+ <a href="<%= make_path(*path) %>.html">
12
12
  <span class="resolved <%= ref_type %>">
13
13
  <span><%= value || path.last %></span>
14
14
  </span>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docrb-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Gama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-28 00:00:00.000000000 Z
11
+ date: 2023-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri