jekyll_outline 1.1.1 → 1.2.0

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: 464b66396b0abd3369669875ca6b2be97b51e7823e31d5fa163b4248afc0dc50
4
- data.tar.gz: 1253ef8b8218d0c4f76cb66d5f79ef0bc4fef48cec8d057ef33b0af0411e352f
3
+ metadata.gz: f19cd3e8a114d272e1a25858375c4f9cae27be24c8c7df0794340efc43311cf4
4
+ data.tar.gz: 2c9502f7e10ed8bcdf992b4f7761a597c16d154c4f7889b130ee72d4197ee9ab
5
5
  SHA512:
6
- metadata.gz: 96bf42bd9e24050bf05fc9c5d1a2094383f2dd3853c301da97ce5e8276969de31ddc98cc5102f3288e46cb84ae9032a2e8c40813993445d837a5a60ffd4b0559
7
- data.tar.gz: 56facfe2c9305b0945ad1d315018b078f1a0402b1c91655ea01a2741f9f39d2975bce5de31eb84490126f4b19700e98a617a84d61a17fbc27a225cc750b941ba
6
+ metadata.gz: cd40905342095e621420f8255ab6b59e935559d2b7c744ac6c474dd47c993eaf3a4cd79ac3c0a2983977690485b5feb108aff6b2f222ac6a9ad26523cde88790
7
+ data.tar.gz: 4dde939dffacc17793cb972adec4bf4efaf17fff24251592e517efcb6f8f68823322ade76df90dd55aa29e50d15fa673afc9e13e623a2adf088181d6d263c32b
data/.rubocop.yml CHANGED
@@ -25,14 +25,23 @@ Layout/HashAlignment:
25
25
  Layout/LineLength:
26
26
  Max: 150
27
27
 
28
+ Metrics/AbcSize:
29
+ Max: 30
30
+
28
31
  Metrics/BlockLength:
29
32
  Exclude:
30
33
  - jekyll_outline.gemspec
31
34
  Max: 40
32
35
 
36
+ Metrics/CyclomaticComplexity:
37
+ Max: 20
38
+
33
39
  Metrics/MethodLength:
34
40
  Max: 30
35
41
 
42
+ Metrics/PerceivedComplexity:
43
+ Max: 20
44
+
36
45
  Naming/FileName:
37
46
  Exclude:
38
47
  - Rakefile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.2.0 / 2023-04-23
2
+ - Added optional `field` parameter.
3
+
1
4
  ## 1.1.1 / 2023-04-02
2
5
  * Added [`attribution` support](https://github.com/mslinn/jekyll_plugin_support#subclass-attribution).
3
6
 
data/README.md CHANGED
@@ -16,21 +16,52 @@ end
16
16
 
17
17
  And then execute:
18
18
 
19
- $ bundle install
19
+ $ bundle
20
+
21
+
22
+ ## Fields
23
+ By default, each displayed entry consists of a document title,
24
+ wrapped within an <a href> HTML tag that links to the page for that entry,
25
+ followed by an indication of whether the document is visible (a draft) or not.
26
+
27
+ Entry can also include following fields:
28
+ `draft`, `categories`, `description`, `date`, `last_modified` or `last_modified_at`, `layout`, `order`, `title`, `slug`, `ext`, `tags`, and `excerpt`.
29
+
30
+ Specify the fields like this:
31
+
32
+ ```
33
+ {% outline fields="title &ndash; <i> description </i>" %}
34
+ 000: Topic 0..19
35
+ 020: Topic 20..39
36
+ 040: Topic 40..
37
+ {% endoutline %}
38
+ ```
39
+
40
+ Words that are not a known field are transcribed into the output.
41
+
42
+ In the above example, notice that the HTML is space delimited from the field names.
43
+ The parser is simple and stupid: each token is matched against the known keywords.
44
+ Tokens are separated by white space.
20
45
 
21
46
 
22
47
  ### CSS
23
48
  The CSS used for the demo website should be copied to your project.
24
- See the section of `demo/assets/css/styles.css` as shown:
49
+ See the sections of [`demo/assets/css/styles.css`](/mslinn/jekyll_outline/blob/master/demo/assets/css/style.css#L252-L315) as shown:
25
50
 
26
51
  ```css
52
+ /* Start of jekyll_plugin_support css */
53
+ ... copy this portion ...
54
+ /* End of jekyll_plugin_support css */
55
+
27
56
  /* Start of jekyll_outline css */
28
57
  ... copy this portion ...
29
58
  /* End of jekyll_outline css */
30
59
  ```
31
60
 
32
61
  ### JavaScript
33
- This project's `outline_js` tag returns the Javascript necessary to position images relating to the outline. If used without parameters it just returns the JavaScript:
62
+ This project's `outline_js` tag returns the Javascript necessary to position images relating to the outline.
63
+ If used without parameters it just returns the JavaScript.
64
+ Use the tag this way:
34
65
 
35
66
  ```html
36
67
  <script>
@@ -38,7 +69,8 @@ This project's `outline_js` tag returns the Javascript necessary to position ima
38
69
  </script>
39
70
  ```
40
71
 
41
- If passed the `wrap_in_script_tag` parameter, it wraps the JavaScript in `<script></script>`:
72
+ If passed the `wrap_in_script_tag` parameter, it wraps the JavaScript in `<script></script>`.
73
+ Use the tag this way:
42
74
 
43
75
  ```html
44
76
  {% outline_js wrap_in_script_tag %}
@@ -57,9 +89,9 @@ Given an outline that looks like this:
57
89
 
58
90
  ...and given pages in the `stuff` collection with the following names:
59
91
 
60
- - 010-published.html has title **Published Stuff Post 010**
61
- - 020-unpublished.html has title **Unpublished Post 020**
62
- - 030-unpublished.html has title **Unpublished Post 030**
92
+ - `010-published.html` has title **Published Stuff Post 010**
93
+ - `020-unpublished.html` has title **Unpublished Post 020**
94
+ - `030-unpublished.html` has title **Unpublished Post 030**
63
95
 
64
96
  Then links to the pages in the `stuff` collection's pages are interleaved into the generated outline like this:
65
97
  ```html
@@ -80,13 +112,15 @@ Then links to the pages in the `stuff` collection's pages are interleaved into t
80
112
  </div>
81
113
  ```
82
114
 
83
- The JavaScript searches for images in the current page that were created by the [`img`](https://github.com/mslinn/jekyll_img) tag plugin,
115
+ The JavaScript searches for images in the current page that were created by the
116
+ [`img`](https://github.com/mslinn/jekyll_img) tag plugin,
84
117
  and have `id`s that correspond to outline sections.
85
118
 
86
- Each of following image's `id`s have a `outline_` prefix, followed by a number, which corresponds to one of the sections.
119
+ Each of following image's `id`s have an `outline_` prefix, followed by a number, which corresponds to one of the sections.
87
120
  Note that leading zeros in the first column above are not present in the `id`s below.
88
121
 
89
- The images are wrapped within an invisible `div` so the web page does not jump around as the images are loaded.
122
+ If you want to provide images to embed at appropriate locations within the outline,
123
+ wrap them within an invisible `div` so the web page does not jump around as the images are loaded.
90
124
  ```html
91
125
  <div style="display: none;">
92
126
  {% img align="right"
@@ -118,6 +152,8 @@ The images can be located anywhere on the page; they will be relocated appropria
118
152
  If an image does not correspond to a heading, it is deleted.
119
153
 
120
154
 
155
+
156
+
121
157
  ## Attribution
122
158
  See [`jekyll_plugin_support` for `attribution`](https://github.com/mslinn/jekyll_plugin_support#subclass-attribution)
123
159
 
@@ -129,8 +165,10 @@ More information is available on
129
165
 
130
166
  ## Development
131
167
  After checking out the repo, run `bin/setup` to install development dependencies.
132
- Then you can run `bin/console` for an interactive prompt that will allow you to experiment with `irb`.
133
168
 
169
+ Then you can run `bin/console` for an interactive prompt that will allow you to experiment using `irb`.
170
+
171
+ ### Build and Install Locally
134
172
  To build and install this gem onto your local machine, run:
135
173
  ```shell
136
174
  $ bundle exec rake install
@@ -194,6 +232,11 @@ To release a new version,
194
232
  ## Contributing
195
233
  Bug reports and pull requests are welcome on GitHub at https://github.com/mslinn/jekyll_outline.
196
234
 
235
+ 1. Fork the project
236
+ 2. Create a descriptively named feature branch
237
+ 3. Add your feature
238
+ 4. Submit a pull request
239
+
197
240
 
198
241
  ## License
199
242
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  '.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md',
14
14
  'demo/assets/js/jekyll_outline.js'
15
15
  ]
16
- spec.homepage = 'https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline'
16
+ spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_outline.html'
17
17
  spec.license = 'MIT'
18
18
  spec.metadata = {
19
19
  'allowed_push_host' => 'https://rubygems.org',
@@ -1,3 +1,3 @@
1
1
  module JekyllOutlineVersion
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
data/lib/outline_tag.rb CHANGED
@@ -24,7 +24,7 @@ module OutlineTag
24
24
  end
25
25
  end
26
26
 
27
- class OutlineTag < JekyllSupport::JekyllBlock
27
+ class OutlineTag < JekyllSupport::JekyllBlock # rubocop:disable Metrics/ClassLength
28
28
  include JekyllOutlineVersion
29
29
 
30
30
  FIXNUM_MAX = (2**((0.size * 8) - 2)) - 1
@@ -33,13 +33,17 @@ module OutlineTag
33
33
  headers = make_headers(super) # Process the block content.
34
34
 
35
35
  @helper.gem_file __FILE__
36
+ @fields = @helper.parameter_specified?('fields')&.split(' ') || ['title']
37
+ @logger.info { "@fields are: #{@fields}" }
36
38
  @collection_name = @helper.remaining_markup
37
39
  abort 'OutlineTag: collection_name was not specified' unless @collection_name
38
40
 
39
- collection = headers + obtain_docs(@collection_name)
41
+ @docs = obtain_docs(@collection_name)
42
+ collection = headers + @docs
43
+
40
44
  <<~HEREDOC
41
45
  <div class="outer_posts">
42
- #{make_entries(collection)&.join("\n")}
46
+ #{make_entries collection}
43
47
  </div>
44
48
  #{@helper.attribute if @helper.attribution}
45
49
  HEREDOC
@@ -59,35 +63,67 @@ module OutlineTag
59
63
  # @section_state can have values: :head, :in_body
60
64
  # @param collection Array of Jekyll::Document and Outline::Header
61
65
  # @return Array of String
62
- def make_entries(collection) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
66
+ def make_entries(collection)
63
67
  sorted = collection.sort_by(&obtain_order)
64
- pruned = remove_empty_headers(sorted)
68
+ pruned = remove_empty_headers sorted
65
69
  @section_state = :head
66
70
  @section_id = 0
67
71
  result = pruned.map do |entry|
68
- if entry.instance_of? Header
69
- @header_order = entry.order
70
- section_end = " </div>\n" if @section_state == :in_body
71
- @section_state = :head
72
- entry = section_end + entry.to_s if section_end
73
- entry
74
- else
75
- if @section_state == :head
76
- section_start = "<div id='posts_wrapper_#{@header_order}' class='clearfix'>\n " \
77
- "<div id='posts_#{@header_order}' class='posts'>\n"
72
+ handle entry
73
+ end
74
+ result << " </div>\n </div>" if @section_state == :in_body
75
+ result&.join("\n")
76
+ end
77
+
78
+ KNOWN_FIELDS = %w[draft categories description date last_modified_at layout order title slug ext tags excerpt].freeze
79
+
80
+ def handle(entry)
81
+ if entry.instance_of? Header
82
+ @header_order = entry.order
83
+ section_end = " </div>\n" if @section_state == :in_body
84
+ @section_state = :head
85
+ entry = section_end + entry.to_s if section_end
86
+ entry
87
+ else
88
+ if @section_state == :head
89
+ section_start = "<div id='posts_wrapper_#{@header_order}' class='clearfix'>\n " \
90
+ "<div id='posts_#{@header_order}' class='posts'>\n"
91
+ end
92
+ @section_state = :in_body
93
+ date = entry.data['last_modified_at'] # "%Y-%m-%d"
94
+ draft = Jekyll::Draft.draft_html(entry)
95
+ visible_line = handle_entry entry
96
+ result = " <span>#{date}</span> <span><a href='#{entry.url}'>#{visible_line.strip}</a>#{draft}</span>"
97
+ result = section_start + result if section_start
98
+ result
99
+ end
100
+ end
101
+
102
+ def handle_entry(entry)
103
+ result = ''
104
+ @fields.each do |field|
105
+ if KNOWN_FIELDS.include? field
106
+ if entry.data.key? field
107
+ result += "#{entry.data[field]} "
108
+ else
109
+ @logger.warn { "#{field} is a known field, but it was not present in entry #{entry}" }
78
110
  end
79
- @section_state = :in_body
80
- date = entry.data['last_modified_at'] # "%Y-%m-%d"
81
- draft = Jekyll::Draft.draft_html(entry)
82
- result = " <span>#{date}</span> <span><a href='#{entry.url}'>#{entry.data['title']}</a>#{draft}</span>"
83
- result = section_start + result if section_start
84
- result
111
+ else
112
+ result += "#{field} "
85
113
  end
86
114
  end
87
- result << " </div>\n </div>" if @section_state == :in_body
88
115
  result
89
116
  end
90
117
 
118
+ # Find the given document
119
+ def obtain_doc(doc_name)
120
+ abort "#{@collection_name} is not a valid collection." unless @site.collections.key? @collection_name
121
+ @site
122
+ .collections[@collection_name]
123
+ .docs
124
+ .find { |doc| doc.path.end_with? "#{doc_name}.html" }
125
+ end
126
+
91
127
  # Ignores files called index.html
92
128
  def obtain_docs(collection_name)
93
129
  abort "#{@collection_name} is not a valid collection." unless @site.collections.key? @collection_name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_outline
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-06 00:00:00.000000000 Z
11
+ date: 2023-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -75,14 +75,14 @@ files:
75
75
  - spec/outline_spec.rb
76
76
  - spec/spec_helper.rb
77
77
  - spec/status_persistence.txt
78
- homepage: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline
78
+ homepage: https://www.mslinn.com/jekyll_plugins/jekyll_outline.html
79
79
  licenses:
80
80
  - MIT
81
81
  metadata:
82
82
  allowed_push_host: https://rubygems.org
83
83
  bug_tracker_uri: https://github.com/mslinn/jekyll_outline/issues
84
84
  changelog_uri: https://github.com/mslinn/jekyll_outline/CHANGELOG.md
85
- homepage_uri: https://www.mslinn.com/jekyll/3000-jekyll-plugins.html#outline
85
+ homepage_uri: https://www.mslinn.com/jekyll_plugins/jekyll_outline.html
86
86
  source_code_uri: https://github.com/mslinn/jekyll_outline
87
87
  post_install_message: |2+
88
88