asciidoctor-tabs 1.0.0.alpha.3 → 1.0.0.alpha.5

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: a6224fd054576b98130cb17fff445018029d8c3271cc4747ff00c112e513bb42
4
- data.tar.gz: 1f1f618257e63009b54fc7d3fd11fd41bc490fc96c089fae0de75f6b74bb4239
3
+ metadata.gz: 9a220a5fcabda931f52d5ca7d6fbf4b3c459eb258c6694288cd147b5db58f68b
4
+ data.tar.gz: 20b389528d89b8e450e06dedfc0e9dc4944c9672854a12469b4e15189dfd8868
5
5
  SHA512:
6
- metadata.gz: 96ac2018cfaa5c8d0ee23c87c306cc64d0f67b76100d623816166ea1a09f9a9c1939503111717616dc2f062efe3d13bffe3469d88570011de18ff9a9c7ea6b82
7
- data.tar.gz: 97b9ab0a22a0ffa2eadec746d963c91b5a9c60d274bb088e82ef3224f55116ec5353706601765c1d858c45a364b2e8d5ff3a9d61a51e8034d9b78a80f64b4cb8
6
+ metadata.gz: 641e2de8bba5626ba461fca9b5b212769bf4175724d02f6fc56d2f891395dffdd9072aa65224530fc0ec26e84d35ff21026097aa0f57a37d7e81a957dbf14c6d
7
+ data.tar.gz: 5d723e02e0b9a4255715ee4daae0502900a1598e804dbf08801dd9e7acc91a78e2c3b9451a95a4b1d1d6a1060e41ef2c91d6527c3b3e278940f8b27045f41d0a
data/CHANGELOG.adoc CHANGED
@@ -4,6 +4,48 @@
4
4
  This document provides a curated view of the changes to Asciidoctor Tabs per release.
5
5
  For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.
6
6
 
7
+ == 1.0.0-alpha.5 (2022-10-23) - @mojavelinux
8
+
9
+ === Added
10
+
11
+ * Link to stylesheet (style) and script (behavior) if `linkcss` attribute is set on document (#7)
12
+ * Honor safe mode settings (don't read files if safe mode is secure) (#7)
13
+
14
+ === Changed
15
+
16
+ * Rename Docinfo::Styles class to Docinfo::Style (#22)
17
+ * Add smoke test for npm package (#19)
18
+
19
+ === Fixed
20
+
21
+ * Prevent dlist ref from being registered again to avoid warning when filetype is not html (#21)
22
+ * Restore missing default style and behavior in JavaScript version by mapping data dir to dist folder in npm package (#18)
23
+
24
+ === Details
25
+
26
+ {url-repo}/releases/tag/v1.0.0-alpha.5[git tag] | {url-repo}/compare/v1.0.0-alpha.4\...v1.0.0-alpha.5[full diff]
27
+
28
+ == 1.0.0-alpha.4 (2022-10-08) - @mojavelinux
29
+
30
+ === Added
31
+
32
+ * Define exports for behavior (tabs.js) and style (tabs.css) in npm package
33
+
34
+ === Changed
35
+
36
+ * Use value of `idseparator` attribute in front of tabset number in auto-generated ID (#16)
37
+ * Add aliases for `Block` and `Docinfo` classes to `Extensions` class; remove workaround in js module
38
+ * Move `margin-bottom` style to tabset element
39
+ * Move behavior (tabs.js) and style (tabs.css) to dist folder in npm package
40
+
41
+ === Fixed
42
+
43
+ * Increase specificity of sibling selector for tab to work with Antora default UI
44
+
45
+ === Details
46
+
47
+ {url-repo}/releases/tag/v1.0.0-alpha.4[git tag] | {url-repo}/compare/v1.0.0-alpha.3\...v1.0.0-alpha.4[full diff]
48
+
7
49
  == 1.0.0-alpha.3 (2022-10-05) - @mojavelinux
8
50
 
9
51
  === Added
@@ -18,6 +60,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
18
60
 
19
61
  === Fixed
20
62
 
63
+ * Preserve text of dlist item for tab if item has both text and blocks (#13)
21
64
  * Create empty pane instead of crashing if dlist item has term only / no description
22
65
 
23
66
  === Details
@@ -40,7 +83,6 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
40
83
 
41
84
  === Fixed
42
85
 
43
- * Preserve text of dlist item for tab if item has both text and blocks (#13)
44
86
  * Honor explicit ID on tabs block and use it as ID prefix for tabs
45
87
  * Register reference for tabset in document catalog
46
88
  * Autogenerate IDs for tabsets and tabs in a manner consistent with section ID generation (#2)
data/README.adoc CHANGED
@@ -1,18 +1,28 @@
1
1
  = Asciidoctor Tabs
2
2
  Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
3
- v1.0.0-alpha.3, 2022-10-05
3
+ v1.0.0-alpha.5, 2022-10-23
4
4
  :idprefix:
5
5
  :idseparator: -
6
6
  ifndef::env-github[:icons: font]
7
7
  ifdef::env-github[]
8
8
  :note-caption: :paperclip:
9
+ :tip-caption: :bulb:
9
10
  endif::[]
10
11
 
11
12
  An Asciidoctor extension that adds a tabs block to the AsciiDoc syntax.
12
- Each set of tabs (a "tabset") is constructed from a dlist enclosed in an example block marked with the tabs style.
13
13
 
14
- NOTE: This extension is intended to be used with HTML backends (e.g., `html`).
15
- For other backends (i.e., filetype is not html), the example block enclosure will be taken away and the dlist will be converted normally.
14
+ NOTE: This extension is intended to be used with HTML backends (e.g., `html5`).
15
+ For all other backends (i.e., the filetype is not html), the custom block enclosure is taken away and its contents (a dlist) is converted normally.
16
+
17
+ TIP: This extension is also published as an npm package named `@asciidoctor/tabs` for use with Asciidoctor.js (and thus Antora).
18
+
19
+ == Overview
20
+
21
+ Each set of tabs (a "`tabset`") is constructed from a description list (dlist) enclosed in an example block marked with the tabs style (i.e., `[tab]`).
22
+ The tabbed interface that this block produces can help to organize information by code language, operating system, or product variant.
23
+
24
+ The benefit of organizing information in this way is that it condenses the use of vertical space by only showing what's relevant to the reader (and thus hiding information that's irrelevant or redundant).
25
+ The result is that readers enjoy a better user experience when reading your documentation.
16
26
 
17
27
  == Install
18
28
 
@@ -32,10 +42,10 @@ source 'https://rubygems.org'
32
42
  gem 'asciidoctor-tabs'
33
43
 
34
44
  # or use the code directlly from GitHub
35
- # gem 'asciidoctor-tabs', github: 'asciidoctor/asciidoctor-pdf'
45
+ # gem 'asciidoctor-tabs', github: 'asciidoctor/asciidoctor-tabs'
36
46
  ----
37
47
 
38
- Then configure Bundler to install gems locally (optional):
48
+ Then optionally configure Bundler to install gems locally:
39
49
 
40
50
  $ bundle config --local path .bundle/gems
41
51
 
@@ -45,12 +55,7 @@ Then use Bundler to install the gem:
45
55
 
46
56
  == Syntax
47
57
 
48
- A tabset is defined using a dlist enclosed in an example block marked with the tabs style.
49
- Each item in the dlist becomes a separate tab.
50
- The term in the dlist item is used as the tab's label.
51
- The description in the dlist item is used for the contents of the tab.
52
- The contents can be defined as primary text, attached blocks, or blocks enclosed in an attached open block.
53
- If the blocks are enclosed in an attached open block, the open block enclosure itself will be discarded.
58
+ A tabset is defined using a description list (dlist) enclosed in an example block marked with the tabs style.
54
59
 
55
60
  .document-with-tabs.adoc
56
61
  [,asciidoc]
@@ -73,6 +78,28 @@ Contains more than one block.
73
78
  ====
74
79
  ----
75
80
 
81
+ The tabbed content is modeled as a dlist.
82
+ Each item in the dlist becomes a separate tab.
83
+ The term is used as the tab's label and the description is used as the tab's contents.
84
+ The contents can be defined as primary text, attached blocks, or both.
85
+ If the attached blocks are themselves enclosed in a single open block, the open block enclosure itself is discarded upon conversion.
86
+
87
+ You may decide to extend the block delimiter length instead of using the typical 4 characters to avoid conflicts with any example blocks inside the tab block (or just as a manner of style).
88
+
89
+ [,asciidoc]
90
+ ----
91
+ [tabs]
92
+ ======
93
+ Tab A::
94
+ +
95
+ ====
96
+ Example block in Tab A.
97
+ ====
98
+
99
+ Tab B:: Just text.
100
+ ======
101
+ ----
102
+
76
103
  == Usage
77
104
 
78
105
  === CLI
@@ -80,11 +107,12 @@ Contains more than one block.
80
107
  $ asciidoctor -r asciidoctor-tabs document-with-tabs.adoc
81
108
 
82
109
  You can specify an alternate stylesheet for tabs using the `tabs-stylesheet` document attribute.
83
- The value of this attribute is handled in the same way as the built-in `stylesheet` document attribute.
84
- A relative path is resolved starting from the value of the `stylesdir` document attribute, which defaults to the directory of the document.
85
110
 
86
111
  $ asciidoctor -r asciidoctor-tabs -a tabs-stylesheet=my-tabs.css document-with-tabs.adoc
87
112
 
113
+ The value of the `tabs-stylesheet` attribute is handled in the same way as the built-in `stylesheet` document attribute.
114
+ A relative path is resolved starting from the value of the `stylesdir` document attribute, which defaults to the directory of the document.
115
+
88
116
  === API
89
117
 
90
118
  There are two ways to use the extension with the Asciidoctor API.
@@ -113,13 +141,35 @@ Asciidoctor::Tabs::Extensions.register registry
113
141
  Asciidoctor.convert_file 'document-with-tabs.adoc', extension_registry: registry, safe: :safe
114
142
  ----
115
143
 
116
- If you're not using other scoped extensions, you can pass in the extensions group without creating a registry instance:
144
+ If you're not using other scoped extensions, you can pass in the extensions group without first creating a registry instance:
117
145
 
118
146
  [,js]
119
147
  ----
120
148
  Asciidoctor.convert_file 'document-with-tabs.adoc', extensions: Asciidoctor::Tabs::Extensions.group, safe: :safe
121
149
  ----
122
150
 
151
+ == How it Works
152
+
153
+ This extension works by transforming the dlist inside the example block into a tabbed interface.
154
+ The example block enclosure is discarded.
155
+ The tabbed interface is supported by a stylesheet (style) and script (behavior) that are added to the HTML document by this extension.
156
+ (These assets can be found in the [.path]_data_ folder of the gem).
157
+
158
+ NOTE: The stylesheet and script are only added when producing a standalone document.
159
+ The stylesheet is added to the end of the `<head>` tag and the script added to the end of the `<body>` tag.
160
+ If the `linkcss` attribute is set by the API, the CLI, the document, or the safe mode, the HTML links to these assets.
161
+ Otherwise, the contents of these assets are embedded into the HTML.
162
+
163
+ The tabbed interface consists of two output elements.
164
+ The first element contains an unordered list of all the tab labels in document order.
165
+ The second element contains all the tab panes.
166
+ The labels and panes are correlated through the use of a unique ID.
167
+ Each tab is assigned an `id` attribute and each pane is assigned an `aria-labelledby` attribute that references the corresponding ID.
168
+ The added stylesheet sets up the appearance of the tabbed interface and the added script supports the interaction (i.e., tab selection).
169
+
170
+ A tab can be selected when the page loads using a URL fragment (e.g., `#id-of-tab-here`).
171
+ Otherwise, the first tab is selected when the page loads.
172
+
123
173
  == Authors
124
174
 
125
175
  Asciidoctor Tabs was written by Dan Allen of OpenDevise Inc. and contributed to the Asciidoctor project.
data/data/css/tabs.css CHANGED
@@ -1,4 +1,4 @@
1
- /*! Asciidoctor Tabs stylesheet | Copyright (c) 2018-present Dan Allen | MIT License */
1
+ /*! Asciidoctor Tabs | Copyright (c) 2018-present Dan Allen | MIT License */
2
2
  .tabs > ul {
3
3
  display: flex;
4
4
  flex-wrap: wrap;
@@ -25,10 +25,14 @@
25
25
  margin-bottom: 0;
26
26
  }
27
27
 
28
- .tabs > ul li + li {
28
+ .tabs > ul li + li[id] {
29
29
  margin-top: 0;
30
30
  }
31
31
 
32
+ .tabset {
33
+ margin-bottom: 1.25em;
34
+ }
35
+
32
36
  .tabset.is-loading .tabs li:not(:first-child),
33
37
  .tabset:not(.is-loading) .tabs li:not(.is-active) {
34
38
  background-color: black;
@@ -50,7 +54,6 @@
50
54
  .tabset > .content {
51
55
  border: 1px solid gray;
52
56
  padding: 1.25em;
53
- margin-bottom: 1.25em;
54
57
  }
55
58
 
56
59
  .tabset.is-loading .tab-pane:not(:first-child),
data/data/js/tabs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Asciidoctor Tabs behavior | Copyright (c) 2018-present Dan Allen | MIT License */
1
+ /*! Asciidoctor Tabs | Copyright (c) 2018-present Dan Allen | MIT License */
2
2
  ;(function () {
3
3
  'use strict'
4
4
 
@@ -11,35 +11,34 @@ module Asciidoctor
11
11
  children = (parse_content block, reader).blocks
12
12
  return block unless children.size == 1 && (source_tabs = children[0]).context == :dlist && source_tabs.items?
13
13
  unless (doc = parent.document).attr? 'filetype', 'html'
14
- source_tabs.id ||= attrs['id']
15
- (reftext = attrs['reftext']) && (source_tabs.set_attr 'reftext', reftext) unless source_tabs.attr? 'reftext'
16
- return source_tabs
14
+ (id = attrs['id']) && (doc.register :refs, [(source_tabs.id = id), source_tabs]) unless source_tabs.id
15
+ (reftext = attrs['reftext']) && (source_tabs.set_attr 'reftext', reftext) unless source_tabs.reftext?
16
+ parent << source_tabs
17
+ return
17
18
  end
18
19
  tabset_number = doc.counter 'tabset-number'
19
- id = attrs['id'] || %(#{doc.attributes['idprefix'] || '_'}tabset#{tabset_number})
20
- parent << (create_html_fragment parent, %(<div id="#{id}" class="tabset is-loading">))
20
+ tabs_id = attrs['id'] || (generate_id %(tabset #{tabset_number}), doc)
21
+ parent << (create_html_fragment parent, %(<div id="#{tabs_id}" class="tabset is-loading">))
21
22
  (tabs = create_list parent, :ulist).add_role 'tabs'
22
23
  panes = {}
23
24
  set_id_on_tab = (doc.backend == 'html5') || (list_item_supports_id? doc)
24
25
  source_tabs.items.each do |labels, content|
25
26
  tab_ids = labels.map do |tab|
26
27
  tabs << tab
27
- tab_id = generate_id tab.text, id, doc
28
+ tab_id = generate_id tab.text, doc, tabs_id
28
29
  set_id_on_tab ? (tab.id = tab_id) : (tab.text = %([[#{tab_id}]]#{tab.instance_variable_get :@text}))
29
30
  tab_id
30
31
  end
31
32
  if content
32
- text = create_paragraph parent, (content.instance_variable_get :@text), nil if content.text?
33
+ tab_blocks = content.text? ? [(create_paragraph parent, (content.instance_variable_get :@text), nil)] : []
33
34
  if content.blocks?
34
35
  if (block0 = (blocks = content.blocks)[0]).context == :open && blocks.size == 1 && block0.blocks?
35
36
  blocks = block0.blocks
36
37
  end
37
- blocks.unshift text if text
38
- elsif text
39
- blocks = [text]
38
+ tab_blocks.push(*blocks)
40
39
  end
41
40
  end
42
- panes[tab_ids] = blocks || []
41
+ panes[tab_ids] = tab_blocks || []
43
42
  end
44
43
  parent << tabs
45
44
  parent << (create_html_fragment parent, '<div class="content">')
@@ -49,7 +48,7 @@ module Asciidoctor
49
48
  parent << (create_html_fragment parent, '</div>')
50
49
  end
51
50
  parent << (create_html_fragment parent, '</div>')
52
- create_html_fragment parent, '</div>', 'id' => id
51
+ create_html_fragment parent, '</div>', 'id' => tabs_id
53
52
  end
54
53
 
55
54
  private
@@ -58,12 +57,14 @@ module Asciidoctor
58
57
  create_block parent, :pass, html, attributes
59
58
  end
60
59
 
61
- def generate_id str, base_id, doc
62
- restore_idprefix = (attrs = doc.attributes)['idprefix']
63
- attrs['idprefix'] = %(#{base_id}#{attrs['idseparator'] || '_'})
60
+ def generate_id str, doc, base_id = nil
61
+ if base_id
62
+ restore_idprefix = (attrs = doc.attributes)['idprefix']
63
+ attrs['idprefix'] = %(#{base_id}#{attrs['idseparator'] || '_'})
64
+ end
64
65
  ::Asciidoctor::Section.generate_id str, doc
65
66
  ensure
66
- restore_idprefix ? (attrs['idprefix'] = restore_idprefix) : (attrs.delete 'idprefix')
67
+ restore_idprefix ? (attrs['idprefix'] = restore_idprefix) : (attrs.delete 'idprefix') if base_id
67
68
  end
68
69
 
69
70
  def list_item_supports_id? doc
@@ -4,14 +4,12 @@ module Asciidoctor
4
4
  module Tabs
5
5
  module Docinfo
6
6
  if RUBY_ENGINE == 'opal'
7
- DATA_DIR = ::File.absolute_path '../data', %x(__dirname)
8
- FILE_READ_MODE = 'r'
7
+ DATA_DIR = ::File.absolute_path '../dist', %x(__dirname)
9
8
  else
10
9
  DATA_DIR = ::File.join (::File.absolute_path '../../..', __dir__), 'data'
11
- FILE_READ_MODE = 'rb:utf-8:utf-8'
12
10
  end
13
11
 
14
- class Styles < ::Asciidoctor::Extensions::DocinfoProcessor
12
+ class Style < ::Asciidoctor::Extensions::DocinfoProcessor
15
13
  use_dsl
16
14
  at_location :head
17
15
 
@@ -19,11 +17,14 @@ module Asciidoctor
19
17
 
20
18
  def process doc
21
19
  return unless (path = doc.attr 'tabs-stylesheet')
22
- styles = path.empty? ?
23
- (::File.read DEFAULT_STYLESHEET_FILE, mode: FILE_READ_MODE) :
24
- (doc.read_contents path, start: (doc.attr 'stylesdir'), warn_on_failure: true, label: 'tabs stylesheet')
25
- return unless styles
26
- %(<style>\n#{styles.chomp}\n</style>)
20
+ if doc.attr? 'linkcss'
21
+ href = doc.normalize_web_path (path.empty? ? 'asciidoctor-tabs.css' : path), (doc.attr 'stylesdir')
22
+ %(<link rel="stylesheet" href="#{href}"#{(doc.attr? 'htmlsyntax', 'xml') ? '/' : ''}>) # rubocop:disable Style/TernaryParentheses
23
+ elsif (styles = path.empty? ?
24
+ (doc.read_asset DEFAULT_STYLESHEET_FILE) :
25
+ (doc.read_contents path, start: (doc.attr 'stylesdir'), warn_on_failure: true, label: 'tabs stylesheet'))
26
+ %(<style>\n#{styles.chomp}\n</style>)
27
+ end
27
28
  end
28
29
  end
29
30
 
@@ -33,8 +34,13 @@ module Asciidoctor
33
34
 
34
35
  JAVASCRIPT_FILE = ::File.join DATA_DIR, 'js/tabs.js'
35
36
 
36
- def process _doc
37
- %(<script>\n#{(::File.read JAVASCRIPT_FILE, mode: FILE_READ_MODE).chomp}\n</script>)
37
+ def process doc
38
+ if doc.attr? 'linkcss'
39
+ src = doc.normalize_web_path 'asciidoctor-tabs.js', (doc.attr 'scriptsdir')
40
+ %(<script src="#{src}"></script>)
41
+ elsif (script = doc.read_asset JAVASCRIPT_FILE)
42
+ %(<script>\n#{script.chomp}\n</script>)
43
+ end
38
44
  end
39
45
  end
40
46
  end
@@ -8,6 +8,9 @@ end
8
8
  module Asciidoctor
9
9
  module Tabs
10
10
  module Extensions
11
+ const_set :Block, Block
12
+ const_set :Docinfo, Docinfo
13
+
11
14
  module_function
12
15
 
13
16
  def group
@@ -18,7 +21,7 @@ module Asciidoctor
18
21
  ((doc.options[:attributes] || {}).transform_keys {|it| it.delete '@!' }.key? 'tabs-stylesheet')
19
22
  doc.set_attr 'tabs-stylesheet'
20
23
  end
21
- docinfo_processor Docinfo::Styles
24
+ docinfo_processor Docinfo::Style
22
25
  docinfo_processor Docinfo::Behavior
23
26
  nil
24
27
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Tabs
5
- VERSION = '1.0.0.alpha.3'
5
+ VERSION = '1.0.0.alpha.5'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-tabs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.3
4
+ version: 1.0.0.alpha.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-05 00:00:00.000000000 Z
11
+ date: 2022-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor