asciidoctor-html 0.1.3 → 0.1.5

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.
@@ -43,12 +43,15 @@ module Asciidoctor
43
43
 
44
44
  # opts:
45
45
  # - title
46
+ # - short_title
46
47
  # - author
47
48
  # - date
49
+ # - se_id
48
50
  # - chapname
49
51
  def initialize(opts = {})
50
52
  opts = DEFAULT_OPTS.merge opts
51
53
  @title = ERB::Escape.html_escape opts[:title]
54
+ @short_title = ERB::Escape.html_escape opts[:short_title]
52
55
  @author = ERB::Escape.html_escape opts[:author]
53
56
  @date = opts.include?(:date) ? Date.parse(opts[:date]) : Date.today
54
57
  @se_id = opts[:se_id]
@@ -96,6 +99,7 @@ module Asciidoctor
96
99
  content,
97
100
  nav_items,
98
101
  title: @title,
102
+ short_title: @short_title,
99
103
  author: @author,
100
104
  date: @date,
101
105
  chapnum: "",
@@ -210,11 +214,13 @@ module Asciidoctor
210
214
  content,
211
215
  nav_items,
212
216
  title: @title,
217
+ short_title: @short_title,
213
218
  author: @author,
214
219
  date: @date,
215
220
  chapnum: tdata.chapnum,
216
221
  chaptitle: tdata.chaptitle,
217
- langs: langs(doc)
222
+ langs: langs(doc),
223
+ nav: (nav_items.size > 1)
218
224
  )
219
225
  end
220
226
  end
@@ -45,7 +45,8 @@ module Asciidoctor
45
45
  config[prop] = File.expand_path(config[prop] || DEFAULT_DIRS[prop], config_dir)
46
46
  end
47
47
  %w[chapters appendices].each do |prop|
48
- config[prop] &&= config[prop].map do |f|
48
+ config[prop] ||= []
49
+ config[prop] = config[prop].map do |f|
49
50
  File.expand_path(f, config_dir)
50
51
  end
51
52
  end
@@ -84,7 +84,7 @@ module Asciidoctor
84
84
  def bullet(depth)
85
85
  case depth
86
86
  when 1 then "‐"
87
- when 2 then "∗"
87
+ when 2 then "⭑"
88
88
  when 3 then "◦"
89
89
  else "•"
90
90
  end
@@ -48,14 +48,23 @@ module Asciidoctor
48
48
  HTML
49
49
  end
50
50
 
51
- def self.header(title)
51
+ def self.header(title, short_title, nav: true)
52
+ nav_btn = if nav
53
+ <<~HTML
54
+ <button type="button" class="btn menu"
55
+ data-bs-toggle="collapse" data-bs-target="#sidebar"
56
+ aria-expanded="false" aria-controls="sidebar">
57
+ <i class="bi bi-list"></i>
58
+ </button>
59
+ HTML
60
+ else
61
+ ""
62
+ end
52
63
  <<~HTML
53
64
  <header class="header">
54
- <a class="home" href="./">#{title}</a>
55
- <button type="button" class="btn menu" data-bs-toggle="collapse" data-bs-target="#sidebar"
56
- aria-expanded="false" aria-controls="sidebar">
57
- <i class="bi bi-list"></i>
58
- </button>
65
+ <a class="home d-none d-sm-block" href="./">#{title}</a>
66
+ <a class="home d-block d-sm-none" href="./">#{short_title}</a>
67
+ #{nav_btn}
59
68
  </header>
60
69
  HTML
61
70
  end
@@ -91,19 +100,31 @@ module Asciidoctor
91
100
 
92
101
  # opts:
93
102
  # - title: String
103
+ # - short_title: String
94
104
  # - author: String
95
105
  # - date: Date
106
+ # - nav: Boolean
96
107
  # - chapnum: Int
97
108
  # - chaptitle: String
98
109
  # - langs: Array[String]
99
110
  def self.html(content, nav_items, opts = {})
111
+ hash_listener = if opts[:nav]
112
+ <<~JS
113
+ addEventListener('hashchange', function() {
114
+ collapse = bootstrap.Collapse.getInstance('#sidebar');
115
+ if(collapse) collapse.hide();
116
+ });
117
+ JS
118
+ else
119
+ ""
120
+ end
100
121
  <<~HTML
101
122
  <!DOCTYPE html>
102
123
  <html lang="en">
103
124
  #{head opts[:title], opts[:langs]}
104
125
  <body>
105
- #{header opts[:title]}
106
- #{sidebar nav_items}
126
+ #{header opts[:title], opts[:short_title], nav: opts[:nav]}
127
+ #{sidebar(nav_items) if opts[:nav]}
107
128
  #{main content, opts[:chapnum], opts[:chaptitle], opts[:author], opts[:date].year}
108
129
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.bundle.min.js"
109
130
  integrity="sha384-j1CDi7MgGQ12Z7Qab0qlWQ/Qqz24Gc6BM0thvEMVjHnfYGF0rmFCozFSxQBxwHKO"
@@ -112,10 +133,7 @@ module Asciidoctor
112
133
  const touch = matchMedia('(hover: none)').matches;
113
134
  #{Highlightjs::PLUGIN}
114
135
  hljs.highlightAll();
115
- addEventListener('hashchange', function() {
116
- collapse = bootstrap.Collapse.getInstance("#sidebar");
117
- if(collapse) collapse.hide();
118
- });
136
+ #{hash_listener}
119
137
  #{Popovers::POPOVERS}
120
138
  </script>
121
139
  </body>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravi Rajani