troy 0.0.40 → 0.0.41

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75124a7a67018ad7d680458cf50208524f02df66837a923f7d38c78713ad0b96
4
- data.tar.gz: 310a90f7c1d4cc78c593edc168bd69213ebb735ee3ad6795599bc42d4d834acd
3
+ metadata.gz: f57aeee4d50d6479bd8fef1d4396698770c17d7332116c917f061e5fdd098a41
4
+ data.tar.gz: 7b649d9f2f436b1fa6a3539936f4e60fc9f0f426ef13c60dd8cca841b9ddd41b
5
5
  SHA512:
6
- metadata.gz: 9e1f10c4c527cd869169aed1a21c5d0868edb00cddd4bdf909bcc6466733e8eadbbab36d29448071d10edd73945954bfa3f68b7d995c4081f9f9bd2befb88bca
7
- data.tar.gz: 7350351be857a3eecd0da49a54acff32500cf375d1b608e43e9597b21f773e59e92017db334074f82f2c6bf47c78a4a1dee864256021f38562ad4e35d7a4e83d
6
+ metadata.gz: 10e4951c435e30e69e128c073ffc860d9ae2d4c7139424e68f916d4412e8c65c41ce1a44148bb2d6ae152bf419e7e7fcd862b28ebe90698e6e2ebc0313ef280e
7
+ data.tar.gz: 3b90a4c4254a327788766d01f7c3dca039e49a737eb3a69e139eef857d44441013b417332f56804ec16be4d22ecb7fbd4a36cad9da2b8101391204f1cb7e1fc5
data/.rubocop.yml CHANGED
@@ -8,3 +8,6 @@ AllCops:
8
8
  Exclude:
9
9
  - vendor/**/*
10
10
  - gemfiles/**/*
11
+
12
+ Style/OpenStructUse:
13
+ Enabled: false
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
- if (config[:current_task] || config[:current_command]).name == "new" && args.empty?
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 Exception
69
+ rescue StandardError
66
70
  raise Error,
67
- "No Rack handler found. Install a Rack handler (e.g. puma, thing, unicorn, webrick)"
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 Exception => error
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
- %[<pre class="language-#{language}"><code>#{CGI.escapeHTML(code)}</code></pre>]
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,40 @@ module Troy
16
20
  #
17
21
  module Rouge
18
22
  include ::Rouge::Plugins::Redcarpet
23
+
24
+ def header(text, level)
25
+ matches = text.strip.match(HEADING_ID)
26
+ title = matches[:text].strip
27
+ html = Nokogiri::HTML.fragment("<h#{level}>#{title}</h#{level}>")
28
+ heading = html.first_element_child
29
+ title = heading.text
30
+
31
+ id = matches[:id]
32
+ id ||= permalink(title)
33
+
34
+ heading_counter[id] += 1
35
+ id = "#{id}-#{heading_counter[id]}" if heading_counter[id] > 1
36
+
37
+ heading.add_child %[<a class="anchor" href="##{id}" aria-hidden="true" tabindex="-1"></a>] # rubocop:disable Style/LineLength
38
+ heading.set_attribute :tabindex, "-1"
39
+ heading.set_attribute(:id, id)
40
+
41
+ heading.to_s
42
+ end
43
+
44
+ def permalink(text)
45
+ str = text.dup.unicode_normalize(:nfkd)
46
+ str = str.gsub(/[^\x00-\x7F]/, "").to_s
47
+ str.gsub!(/[^-\w]+/xim, "-")
48
+ str.gsub!(/-+/xm, "-")
49
+ str.gsub!(/^-?(.*?)-?$/, '\1')
50
+ str.downcase!
51
+ str
52
+ end
53
+
54
+ def heading_counter
55
+ @heading_counter ||= Hash.new {|h, k| h[k] = 0}
56
+ end
19
57
  end
20
58
 
21
59
  class Renderer < Redcarpet::Render::HTML
@@ -37,7 +75,11 @@ module Troy
37
75
  autolink: true,
38
76
  space_after_headers: true,
39
77
  fenced_code_blocks: true,
40
- footnotes: true)
78
+ footnotes: true,
79
+ tables: true,
80
+ underline: true,
81
+ strikethrough: true,
82
+ highlight: true)
41
83
  end
42
84
 
43
85
  def to_html
data/lib/troy/page.rb CHANGED
@@ -66,11 +66,11 @@ module Troy
66
66
  #
67
67
  def render
68
68
  ExtensionMatcher.new(path)
69
- .default { content }
70
- .on("html") { compress render_erb }
71
- .on("md") { compress render_erb }
72
- .on("erb") { compress render_erb }
73
- .match
69
+ .default { content }
70
+ .on("html") { compress render_erb }
71
+ .on("md") { compress render_erb }
72
+ .on("erb") { compress render_erb }
73
+ .match
74
74
  end
75
75
 
76
76
  def permalink
data/lib/troy/server.rb CHANGED
@@ -46,16 +46,16 @@ module Troy
46
46
 
47
47
  if request.path != "/" && request.path.end_with?("/")
48
48
  redirect normalized_path
49
- elsif (_path = Pathname.new("#{path}.html")).file?
50
- render(200, "text/html; charset=utf-8", _path)
51
- elsif (_path = Pathname.new("#{path}.xml")).file?
52
- render(200, "text/xml; charset=utf-8", _path)
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}.xml")).file?
52
+ render(200, "text/xml; charset=utf-8", file_path)
53
53
  elsif path.file?
54
54
  render(200, Rack::Mime.mime_type(path.extname, "text/plain"), path)
55
55
  else
56
56
  render(404, "text/html; charset=utf-8", root.join("404.html"))
57
57
  end
58
- rescue Exception => error
58
+ rescue StandardError
59
59
  render(500, "text/html; charset=utf-8", root.join("500.html"))
60
60
  end
61
61
  end
data/lib/troy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Troy
4
- VERSION = "0.0.40"
4
+ VERSION = "0.0.41"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: troy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.40
4
+ version: 0.0.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -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.4
297
+ rubygems_version: 3.6.2
298
298
  specification_version: 4
299
299
  summary: A static site generator
300
300
  test_files: []