troy 0.0.40 → 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/.rubocop.yml +3 -0
- data/lib/troy/cli.rb +8 -3
- data/lib/troy/extension_matcher.rb +1 -1
- data/lib/troy/helpers.rb +1 -1
- data/lib/troy/markdown.rb +76 -2
- data/lib/troy/page.rb +1 -0
- data/lib/troy/server.rb +7 -5
- data/lib/troy/version.rb +1 -1
- metadata +3 -3
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/.rubocop.yml
CHANGED
data/lib/troy/cli.rb
CHANGED
@@ -9,7 +9,11 @@ module Troy
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(args = [], options = {}, config = {})
|
12
|
-
|
12
|
+
has_error =
|
13
|
+
(config[:current_task] || config[:current_command]).name == "new" &&
|
14
|
+
args.empty?
|
15
|
+
|
16
|
+
if has_error
|
13
17
|
raise Error, "The site path is required. For details run: troy help new"
|
14
18
|
end
|
15
19
|
|
@@ -62,9 +66,10 @@ module Troy
|
|
62
66
|
def server
|
63
67
|
begin
|
64
68
|
handler = Rackup::Handler.pick(%i[puma thin webrick])
|
65
|
-
rescue
|
69
|
+
rescue StandardError
|
66
70
|
raise Error,
|
67
|
-
"No Rack handler found. Install a Rack handler
|
71
|
+
"No Rack handler found. Install a Rack handler " \
|
72
|
+
"(e.g. puma, thing, webrick)"
|
68
73
|
end
|
69
74
|
|
70
75
|
handler.run Troy::Server.new(File.join(Dir.pwd, "public")),
|
data/lib/troy/helpers.rb
CHANGED
@@ -22,7 +22,7 @@ module Troy
|
|
22
22
|
path = site.root.join("partials/#{partial}")
|
23
23
|
locals = locals.merge(site: site, page: page)
|
24
24
|
EmbeddedRuby.new(path.read, locals).render
|
25
|
-
rescue
|
25
|
+
rescue StandardError => error
|
26
26
|
raise "Unable to render #{path}; #{error.message}"
|
27
27
|
end
|
28
28
|
|
data/lib/troy/markdown.rb
CHANGED
@@ -2,12 +2,16 @@
|
|
2
2
|
|
3
3
|
module Troy
|
4
4
|
class Markdown
|
5
|
+
# Match the id portion of a header, as in `# Title {#custom-id}`.
|
6
|
+
HEADING_ID = /^(?<text>.*?)(?: {#(?<id>.*?)})?$/
|
7
|
+
|
5
8
|
# Create a new Redcarpet renderer, that prepares the code block
|
6
9
|
# to use Prisme.js syntax.
|
7
10
|
#
|
8
11
|
module PrismJs
|
9
12
|
def block_code(code, language)
|
10
|
-
|
13
|
+
code = CGI.escapeHTML(code)
|
14
|
+
%[<pre class="language-#{language}"><code>#{code}</code></pre>]
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
@@ -16,6 +20,73 @@ module Troy
|
|
16
20
|
#
|
17
21
|
module Rouge
|
18
22
|
include ::Rouge::Plugins::Redcarpet
|
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
|
+
|
57
|
+
def header(text, level)
|
58
|
+
matches = text.strip.match(HEADING_ID)
|
59
|
+
title = matches[:text].strip
|
60
|
+
html = Nokogiri::HTML.fragment("<h#{level}>#{title}</h#{level}>")
|
61
|
+
heading = html.first_element_child
|
62
|
+
title = heading.text
|
63
|
+
|
64
|
+
id = matches[:id]
|
65
|
+
id ||= permalink(title)
|
66
|
+
|
67
|
+
heading_counter[id] += 1
|
68
|
+
id = "#{id}-#{heading_counter[id]}" if heading_counter[id] > 1
|
69
|
+
|
70
|
+
heading.add_child %[<a class="anchor" href="##{id}" aria-hidden="true" tabindex="-1"></a>] # rubocop:disable Style/LineLength
|
71
|
+
heading.set_attribute :tabindex, "-1"
|
72
|
+
heading.set_attribute(:id, id)
|
73
|
+
|
74
|
+
heading.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
def permalink(text)
|
78
|
+
str = text.dup.unicode_normalize(:nfkd)
|
79
|
+
str = str.gsub(/[^\x00-\x7F]/, "").to_s
|
80
|
+
str.gsub!(/[^-\w]+/xim, "-")
|
81
|
+
str.gsub!(/-+/xm, "-")
|
82
|
+
str.gsub!(/^-?(.*?)-?$/, '\1')
|
83
|
+
str.downcase!
|
84
|
+
str
|
85
|
+
end
|
86
|
+
|
87
|
+
def heading_counter
|
88
|
+
@heading_counter ||= Hash.new {|h, k| h[k] = 0 }
|
89
|
+
end
|
19
90
|
end
|
20
91
|
|
21
92
|
class Renderer < Redcarpet::Render::HTML
|
@@ -37,7 +108,10 @@ module Troy
|
|
37
108
|
autolink: true,
|
38
109
|
space_after_headers: true,
|
39
110
|
fenced_code_blocks: true,
|
40
|
-
footnotes: true
|
111
|
+
footnotes: true,
|
112
|
+
tables: true,
|
113
|
+
strikethrough: true,
|
114
|
+
highlight: true)
|
41
115
|
end
|
42
116
|
|
43
117
|
def to_html
|
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 }
|
data/lib/troy/server.rb
CHANGED
@@ -46,16 +46,18 @@ module Troy
|
|
46
46
|
|
47
47
|
if request.path != "/" && request.path.end_with?("/")
|
48
48
|
redirect normalized_path
|
49
|
-
elsif (
|
50
|
-
render(200, "text/html; charset=utf-8",
|
51
|
-
elsif (
|
52
|
-
render(200, "text/
|
49
|
+
elsif (file_path = Pathname.new("#{path}.html")).file?
|
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)
|
53
|
+
elsif (file_path = Pathname.new("#{path}.xml")).file?
|
54
|
+
render(200, "text/xml; charset=utf-8", file_path)
|
53
55
|
elsif path.file?
|
54
56
|
render(200, Rack::Mime.mime_type(path.extname, "text/plain"), path)
|
55
57
|
else
|
56
58
|
render(404, "text/html; charset=utf-8", root.join("404.html"))
|
57
59
|
end
|
58
|
-
rescue
|
60
|
+
rescue StandardError
|
59
61
|
render(500, "text/html; charset=utf-8", root.join("500.html"))
|
60
62
|
end
|
61
63
|
end
|
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
|
@@ -294,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
294
294
|
- !ruby/object:Gem::Version
|
295
295
|
version: '0'
|
296
296
|
requirements: []
|
297
|
-
rubygems_version: 3.6.
|
297
|
+
rubygems_version: 3.6.2
|
298
298
|
specification_version: 4
|
299
299
|
summary: A static site generator
|
300
300
|
test_files: []
|