jekyll-spoiler 1.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/lib/jekyll-spoiler.rb +59 -0
  4. metadata +82 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c6a1362729edcc882330517e0c7b63ee4d627740e8e712bddcba01079bf3fa6a
4
+ data.tar.gz: af293743e255d9406183cbe24bbd9259bab6be58a0fe1deb69755fde129a4fb4
5
+ SHA512:
6
+ metadata.gz: 6d54668822ea623643396e01a6689fd47d65894f6c3e439352d464642f6b1854d070531973814553265e28ed3557a69075321858c7e4e9596967c61d4642fa85
7
+ data.tar.gz: f184b77ae427a416d5498edfa9b4bcc0ade33bfec60af199cddbdf42a595d74e68635f9a3efb995ab16fe22b4b07657456e36ddde92f6a21a55ca89a80a37d34
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Strappazzon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,59 @@
1
+ require 'jekyll'
2
+ require 'kramdown'
3
+ require 'liquid'
4
+
5
+ module Jekyll
6
+ module Spoiler
7
+ class Block < Liquid::Block
8
+ def initialize(tag_name, arguments, _tokens)
9
+ super
10
+
11
+ @args = parse_args(arguments)
12
+ @title = @args['title'].nil? || @args['title'].empty? ? 'Spoiler' : @args['title']
13
+ end
14
+
15
+ def render(context)
16
+ content = Kramdown::Document.new(super).to_html
17
+
18
+ # rubocop:disable Layout/ArrayAlignment
19
+ return %W[
20
+ <details class="spoiler">
21
+ <summary class="spoiler-title">#{@title}</summary>
22
+ #{content.strip}
23
+ </details>
24
+ ].join(' ')
25
+ # rubocop:enable Layout/ArrayAlignment
26
+ end
27
+
28
+ private
29
+
30
+ def parse_args(arguments)
31
+ args = {}
32
+
33
+ # key="value"
34
+ arguments.scan(/(\w+)\s*=\s*"([^"]*)"/i) { |k, v| args[k] = v }
35
+
36
+ raise ArgumentError, "Invalid number of arguments for {% spoiler %} block. Expected 0 or 1, got #{args.length}." unless [0, 1].include? args.length
37
+
38
+ return args
39
+ end
40
+ end
41
+
42
+ module Filter
43
+ def spoiler(input)
44
+ return if input.empty?
45
+
46
+ # rubocop:disable Layout/ArrayAlignment
47
+ return %W[
48
+ <span class="spoiler-inline">
49
+ <span>#{input}</span>
50
+ </span>
51
+ ].join(' ')
52
+ # rubocop:enable Layout/ArrayAlignment
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ Liquid::Template.register_tag('spoiler', Jekyll::Spoiler::Block)
59
+ Liquid::Template.register_filter(Jekyll::Spoiler::Filter)
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-spoiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alberto Strappazzon
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-05-05 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: jekyll
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '4.4'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '4.4'
26
+ - !ruby/object:Gem::Dependency
27
+ name: kramdown
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.5'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.5'
40
+ - !ruby/object:Gem::Dependency
41
+ name: liquid
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '4.0'
54
+ description: This plugin provides spoiler text support for Jekyll.
55
+ executables: []
56
+ extensions: []
57
+ extra_rdoc_files: []
58
+ files:
59
+ - LICENSE.txt
60
+ - lib/jekyll-spoiler.rb
61
+ homepage: https://github.com/Strappzzzon/jekyll-spoiler
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.4.2
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.6.2
80
+ specification_version: 4
81
+ summary: Jekyll support for spoilers.
82
+ test_files: []