troy 0.0.41 → 0.0.42
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.
- checksums.yaml +4 -4
- data/lib/troy/extension_matcher.rb +1 -1
- data/lib/troy/markdown.rb +34 -2
- data/lib/troy/page.rb +6 -5
- data/lib/troy/server.rb +2 -0
- data/lib/troy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aea1ae6e2d9d8bbbd7c0c631649ac05801b822d4c0b08aade0ff88699233d769
|
4
|
+
data.tar.gz: bff4d30c2137c56cc01f197d716884e861ff699a81f697e28a28deacba8c69d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79b936d7f8350bcd98933b286395d40fbb12a278c6b45758d1fc45ac67f3ec2cff4f2a532bf7d9430c4c6973c4eff2eba138868e4f477f4d1a28d22cf0f51ed7
|
7
|
+
data.tar.gz: 8339a8bf138547add8b4871c745e32b2c3ada40dfce7be721b00f114fd75a91711e6288fe546ae7dad6258447ef658fe12fdea093c3a75fdcb4f779fb9cc4a68
|
data/lib/troy/markdown.rb
CHANGED
@@ -21,6 +21,39 @@ module Troy
|
|
21
21
|
module Rouge
|
22
22
|
include ::Rouge::Plugins::Redcarpet
|
23
23
|
|
24
|
+
# Be more flexible than github and support any arbitrary name.
|
25
|
+
ALERT_MARK = /^\[!(?<type>[A-Z]+)\](?<title>.*?)?$/
|
26
|
+
|
27
|
+
# Support alert boxes just like github.
|
28
|
+
# https://github.com/orgs/community/discussions/16925
|
29
|
+
def block_quote(quote)
|
30
|
+
html = Nokogiri::HTML.fragment(quote)
|
31
|
+
element = html.children.first
|
32
|
+
matches = element.text.to_s.match(ALERT_MARK) if element
|
33
|
+
return "<blockquote>#{quote}</blockquote>" unless matches
|
34
|
+
|
35
|
+
element.remove
|
36
|
+
|
37
|
+
type = matches[:type].downcase
|
38
|
+
title = matches[:title].to_s.strip
|
39
|
+
title = I18n.t(type, scope: :alerts, default: title)
|
40
|
+
|
41
|
+
html = Nokogiri::HTML.fragment <<~HTML
|
42
|
+
<div class="alert-message #{type}">
|
43
|
+
<p class="alert-message--title"></p>
|
44
|
+
#{html}
|
45
|
+
</div>
|
46
|
+
HTML
|
47
|
+
|
48
|
+
if title.empty?
|
49
|
+
html.css(".alert-message--title").first.remove
|
50
|
+
else
|
51
|
+
html.css(".alert-message--title").first.content = title
|
52
|
+
end
|
53
|
+
|
54
|
+
html.to_s
|
55
|
+
end
|
56
|
+
|
24
57
|
def header(text, level)
|
25
58
|
matches = text.strip.match(HEADING_ID)
|
26
59
|
title = matches[:text].strip
|
@@ -52,7 +85,7 @@ module Troy
|
|
52
85
|
end
|
53
86
|
|
54
87
|
def heading_counter
|
55
|
-
@heading_counter ||= Hash.new {|h, k| h[k] = 0}
|
88
|
+
@heading_counter ||= Hash.new {|h, k| h[k] = 0 }
|
56
89
|
end
|
57
90
|
end
|
58
91
|
|
@@ -77,7 +110,6 @@ module Troy
|
|
77
110
|
fenced_code_blocks: true,
|
78
111
|
footnotes: true,
|
79
112
|
tables: true,
|
80
|
-
underline: true,
|
81
113
|
strikethrough: true,
|
82
114
|
highlight: true)
|
83
115
|
end
|
data/lib/troy/page.rb
CHANGED
@@ -44,6 +44,7 @@ module Troy
|
|
44
44
|
.new(path)
|
45
45
|
.default { meta.content }
|
46
46
|
.on("builder") { XML.new(meta.content, to_context).to_xml }
|
47
|
+
.on("md.erb") { Markdown.new(EmbeddedRuby.new(meta.content, to_context).render).to_html } # rubocop:disable Layout/LineLength
|
47
48
|
.on("erb") { EmbeddedRuby.new(meta.content, to_context).render }
|
48
49
|
.on("md") { Markdown.new(meta.content).to_html }
|
49
50
|
.on("txt") { EmbeddedRuby.new(meta.content, to_context).render }
|
@@ -66,11 +67,11 @@ module Troy
|
|
66
67
|
#
|
67
68
|
def render
|
68
69
|
ExtensionMatcher.new(path)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
.default { content }
|
71
|
+
.on("html") { compress render_erb }
|
72
|
+
.on("md") { compress render_erb }
|
73
|
+
.on("erb") { compress render_erb }
|
74
|
+
.match
|
74
75
|
end
|
75
76
|
|
76
77
|
def permalink
|
data/lib/troy/server.rb
CHANGED
@@ -48,6 +48,8 @@ module Troy
|
|
48
48
|
redirect normalized_path
|
49
49
|
elsif (file_path = Pathname.new("#{path}.html")).file?
|
50
50
|
render(200, "text/html; charset=utf-8", file_path)
|
51
|
+
elsif (file_path = Pathname.new("#{path}/index.html")).file?
|
52
|
+
render(200, "text/html; charset=utf-8", file_path)
|
51
53
|
elsif (file_path = Pathname.new("#{path}.xml")).file?
|
52
54
|
render(200, "text/xml; charset=utf-8", file_path)
|
53
55
|
elsif path.file?
|
data/lib/troy/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: troy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.42
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-20 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: builder
|