troy 0.0.34 → 0.0.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +83 -0
- data/lib/troy/cli.rb +26 -15
- data/lib/troy/configuration.rb +5 -3
- data/lib/troy/context.rb +2 -0
- data/lib/troy/embedded_ruby.rb +2 -0
- data/lib/troy/extension_matcher.rb +3 -7
- data/lib/troy/generator.rb +3 -1
- data/lib/troy/hacks.rb +8 -4
- data/lib/troy/helpers.rb +6 -4
- data/lib/troy/markdown.rb +7 -6
- data/lib/troy/meta.rb +7 -4
- data/lib/troy/page.rb +23 -44
- data/lib/troy/server.rb +7 -3
- data/lib/troy/site.rb +50 -41
- data/lib/troy/version.rb +3 -1
- data/lib/troy/xml.rb +2 -0
- data/lib/troy.rb +4 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 232d28c2479e9de14fdd26394f68799351a432c9bb8d0d083e2440023146d218
|
4
|
+
data.tar.gz: f79a7f77e133f99e45fe1c3d72c2a2713687545b18ac3e74814228d28eeee040
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f88b7abf0b3e02e7df2bd6c4dc644b24845c71823245cd3f74b07899f220d8b6f720088f2a505d07096d7aa778ab89bd4baf1f56aee4226034f3129d6bb5e2a8
|
7
|
+
data.tar.gz: 0d200cea534be0da48533ab1208d8ba5c09d18d2d2fd20afc774ad2c94d8eb919513e6154de765ad4514e45636bcb2ab9637c68d482f156480a8531da45726dc
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
|
4
|
+
Style/Documentation:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Rails/Delegate:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/StringLiterals:
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Layout/SpaceInsideBlockBraces:
|
14
|
+
EnforcedStyle: space
|
15
|
+
EnforcedStyleForEmptyBraces: space
|
16
|
+
SpaceBeforeBlockParameters: false
|
17
|
+
|
18
|
+
Layout/SpaceInsideHashLiteralBraces:
|
19
|
+
EnforcedStyle: no_space
|
20
|
+
EnforcedStyleForEmptyBraces: no_space
|
21
|
+
|
22
|
+
Layout/FirstArrayElementLineBreak:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
Layout/FirstHashElementLineBreak:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Style/SymbolArray:
|
29
|
+
Enabled: true
|
30
|
+
|
31
|
+
Style/PercentLiteralDelimiters:
|
32
|
+
PreferredDelimiters:
|
33
|
+
"%": "[]"
|
34
|
+
"%i": "[]"
|
35
|
+
"%q": "[]"
|
36
|
+
"%Q": "[]"
|
37
|
+
"%r": "{}"
|
38
|
+
"%s": "[]"
|
39
|
+
"%w": "[]"
|
40
|
+
"%W": "[]"
|
41
|
+
"%x": "[]"
|
42
|
+
|
43
|
+
Metrics/LineLength:
|
44
|
+
Enabled: true
|
45
|
+
|
46
|
+
Metrics/MethodLength:
|
47
|
+
Exclude:
|
48
|
+
- db/migrate/**.rb
|
49
|
+
- config/config.rb
|
50
|
+
- test/support/**/*.rb
|
51
|
+
|
52
|
+
Metrics/BlockLength:
|
53
|
+
Exclude:
|
54
|
+
- config/config.rb
|
55
|
+
- test/support/**/*.rb
|
56
|
+
|
57
|
+
Style/EmptyMethod:
|
58
|
+
EnforcedStyle: expanded
|
59
|
+
|
60
|
+
Layout/IndentFirstArrayElement:
|
61
|
+
EnforcedStyle: consistent
|
62
|
+
|
63
|
+
Style/AccessModifierDeclarations:
|
64
|
+
EnforcedStyle: inline
|
65
|
+
|
66
|
+
Naming/UncommunicativeMethodParamName:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
Lint/Debugger:
|
70
|
+
Exclude:
|
71
|
+
- test/**/*
|
72
|
+
|
73
|
+
Style/TrailingUnderscoreVariable:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
Naming/RescuedExceptionsVariableName:
|
77
|
+
PreferredName: error
|
78
|
+
|
79
|
+
Metrics/AbcSize:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
Metrics/MethodLength:
|
83
|
+
Enabled: false
|
data/lib/troy/cli.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
class Cli < Thor
|
3
5
|
check_unknown_options!
|
@@ -15,21 +17,29 @@ module Troy
|
|
15
17
|
end
|
16
18
|
|
17
19
|
options assets: :boolean, file: :array
|
20
|
+
option :concurrency, type: :numeric, default: 10
|
21
|
+
option :benchmark, type: :boolean, default: false
|
18
22
|
desc "export", "Export files"
|
19
23
|
def export
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
runner = lambda do
|
25
|
+
if options[:assets]
|
26
|
+
site.export_assets
|
27
|
+
site.export_files
|
28
|
+
end
|
24
29
|
|
25
|
-
|
26
|
-
options[:file].each do |file|
|
30
|
+
options[:file]&.each do |file|
|
27
31
|
site.export_pages(file)
|
28
32
|
end
|
33
|
+
|
34
|
+
site.export if !options[:assets] && !options[:file]
|
29
35
|
end
|
30
36
|
|
31
|
-
if
|
32
|
-
|
37
|
+
if options[:benchmark]
|
38
|
+
require "benchmark"
|
39
|
+
elapsed = Benchmark.realtime(&runner)
|
40
|
+
puts "=> Finished in #{elapsed.round(2)}s"
|
41
|
+
else
|
42
|
+
runner.call
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
@@ -41,14 +51,14 @@ module Troy
|
|
41
51
|
end
|
42
52
|
|
43
53
|
desc "version", "Display Troy version"
|
44
|
-
map %w
|
54
|
+
map %w[-v --version] => :version
|
45
55
|
def version
|
46
56
|
say "Troy #{Troy::VERSION}"
|
47
57
|
end
|
48
58
|
|
49
59
|
desc "server", "Start a server"
|
50
|
-
option :port, :
|
51
|
-
option :host, :
|
60
|
+
option :port, type: :numeric, default: 9292, aliases: "-p"
|
61
|
+
option :host, type: :string, default: "0.0.0.0", aliases: "-b"
|
52
62
|
def server
|
53
63
|
begin
|
54
64
|
handler = Rack::Handler::Thin
|
@@ -57,12 +67,13 @@ module Troy
|
|
57
67
|
handler = Rack::Handler::WEBrick
|
58
68
|
end
|
59
69
|
|
60
|
-
handler.run Troy::Server.new(File.join(Dir.pwd, "public")), :
|
70
|
+
handler.run Troy::Server.new(File.join(Dir.pwd, "public")), Port: options[:port], Host: options[:host]
|
61
71
|
end
|
62
72
|
|
63
|
-
|
64
|
-
|
65
|
-
|
73
|
+
no_commands do
|
74
|
+
def site
|
75
|
+
@site ||= Troy::Site.new(Dir.pwd, options)
|
76
|
+
end
|
66
77
|
end
|
67
78
|
end
|
68
79
|
end
|
data/lib/troy/configuration.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
::I18n.enforce_available_locales = false
|
3
5
|
|
@@ -5,18 +7,18 @@ module Troy
|
|
5
7
|
@configuration ||= Configuration.new
|
6
8
|
end
|
7
9
|
|
8
|
-
def self.configure
|
10
|
+
def self.configure
|
9
11
|
yield configuration
|
10
12
|
end
|
11
13
|
|
12
14
|
class Configuration < OpenStruct
|
13
15
|
def assets
|
14
|
-
@assets ||= Configuration.new(
|
16
|
+
@assets ||= Configuration.new(
|
15
17
|
compress_html: true,
|
16
18
|
compress_css: true,
|
17
19
|
compress_js: true,
|
18
20
|
precompile: []
|
19
|
-
|
21
|
+
)
|
20
22
|
end
|
21
23
|
|
22
24
|
def i18n
|
data/lib/troy/context.rb
CHANGED
data/lib/troy/embedded_ruby.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
class ExtensionMatcher
|
3
|
-
#
|
4
|
-
#
|
5
5
|
attr_reader :path
|
6
6
|
|
7
|
-
#
|
8
|
-
#
|
9
7
|
attr_reader :performed
|
10
8
|
|
11
|
-
#
|
12
|
-
#
|
13
9
|
attr_reader :matchers
|
14
10
|
|
15
11
|
def initialize(path)
|
@@ -32,7 +28,7 @@ module Troy
|
|
32
28
|
return handler.call if File.extname(path) == ext
|
33
29
|
end
|
34
30
|
|
35
|
-
matchers["default"]
|
31
|
+
matchers["default"]&.call
|
36
32
|
end
|
37
33
|
end
|
38
34
|
end
|
data/lib/troy/generator.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
# The Troy::Generator class will create a new book structure.
|
3
5
|
#
|
@@ -11,7 +13,7 @@ module Troy
|
|
11
13
|
desc "Generate a new site structure"
|
12
14
|
|
13
15
|
def self.source_root
|
14
|
-
File.expand_path("
|
16
|
+
File.expand_path("../../templates", __dir__)
|
15
17
|
end
|
16
18
|
|
17
19
|
def create_directories
|
data/lib/troy/hacks.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "digest/sha1"
|
2
4
|
|
3
5
|
module HtmlPress
|
4
|
-
|
6
|
+
def self.content_cache
|
7
|
+
@content_cache ||= {}
|
8
|
+
end
|
5
9
|
|
6
|
-
def self.js_compressor
|
10
|
+
def self.js_compressor(text, options = nil)
|
7
11
|
options ||= {}
|
8
12
|
options[:output] ||= {inline_script: true}
|
9
13
|
|
10
14
|
hash = Digest::SHA1.hexdigest(text)
|
11
|
-
|
12
|
-
|
15
|
+
content_cache[hash] ||= MultiJs.compile(text, options).gsub(/;$/, "")
|
16
|
+
content_cache[hash]
|
13
17
|
end
|
14
18
|
end
|
data/lib/troy/helpers.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
module Helpers
|
3
5
|
def h(content)
|
4
6
|
CGI.escapeHTML(content)
|
5
7
|
end
|
6
8
|
|
7
|
-
def t(*args)
|
8
|
-
I18n.t(*args)
|
9
|
+
def t(*args, **kwargs)
|
10
|
+
I18n.t(*args, **kwargs)
|
9
11
|
end
|
10
12
|
|
11
13
|
def partial(name, locals = {})
|
14
|
+
name = name.to_s
|
12
15
|
basename = File.basename(name)
|
13
16
|
dirname = File.dirname(name)
|
14
|
-
|
15
17
|
partial = []
|
16
18
|
partial << dirname unless dirname.start_with?(".")
|
17
19
|
partial << "_#{basename}.erb"
|
@@ -20,7 +22,7 @@ module Troy
|
|
20
22
|
path = site.root.join("partials/#{partial}")
|
21
23
|
locals = locals.merge(site: site, page: page)
|
22
24
|
EmbeddedRuby.new(path.read, locals).render
|
23
|
-
rescue Exception
|
25
|
+
rescue Exception => error
|
24
26
|
raise "Unable to render #{path}; #{error.message}"
|
25
27
|
end
|
26
28
|
|
data/lib/troy/markdown.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
class Markdown
|
3
5
|
# Create a new Redcarpet renderer, that prepares the code block
|
@@ -31,12 +33,11 @@ module Troy
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def renderer
|
34
|
-
@renderer ||= Redcarpet::Markdown.new(Renderer,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
})
|
36
|
+
@renderer ||= Redcarpet::Markdown.new(Renderer,
|
37
|
+
autolink: true,
|
38
|
+
space_after_headers: true,
|
39
|
+
fenced_code_blocks: true,
|
40
|
+
footnotes: true)
|
40
41
|
end
|
41
42
|
|
42
43
|
def to_html
|
data/lib/troy/meta.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
class Meta
|
3
5
|
extend Forwardable
|
4
6
|
def_delegators :data, :[], :fetch, :key?
|
5
7
|
|
6
|
-
REGEX = /^---\n(.*?)\n---\n+/m
|
8
|
+
REGEX = /^---\n(.*?)\n---\n+/m.freeze
|
7
9
|
|
8
10
|
attr_reader :file
|
9
11
|
|
@@ -16,14 +18,15 @@ module Troy
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def data
|
19
|
-
@data ||=
|
21
|
+
@data ||=
|
22
|
+
raw =~ REGEX ? YAML.unsafe_load(raw[REGEX, 1]) : {}
|
20
23
|
end
|
21
24
|
|
22
|
-
def method_missing(name, *
|
25
|
+
def method_missing(name, *_args)
|
23
26
|
data[name.to_s]
|
24
27
|
end
|
25
28
|
|
26
|
-
def respond_to_missing?(
|
29
|
+
def respond_to_missing?(_method, _include_private = false)
|
27
30
|
true
|
28
31
|
end
|
29
32
|
|
data/lib/troy/page.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
class Page
|
3
5
|
extend Forwardable
|
@@ -27,33 +29,26 @@ module Troy
|
|
27
29
|
@meta = meta || Meta.new(path)
|
28
30
|
end
|
29
31
|
|
30
|
-
#
|
31
|
-
#
|
32
32
|
def method_missing(name, *args, &block)
|
33
33
|
return meta[name.to_s] if meta.key?(name.to_s)
|
34
|
+
|
34
35
|
super
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
-
#
|
39
|
-
def respond_to_missing?(name, include_private = false)
|
38
|
+
def respond_to_missing?(name, _include_private = false)
|
40
39
|
meta.key?(name.to_s)
|
41
40
|
end
|
42
41
|
|
43
|
-
#
|
44
|
-
#
|
45
42
|
def content
|
46
43
|
ExtensionMatcher.new(path)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
.default { meta.content }
|
45
|
+
.on("builder") { XML.new(meta.content, to_context).to_xml }
|
46
|
+
.on("erb") { EmbeddedRuby.new(meta.content, to_context).render }
|
47
|
+
.on("md") { Markdown.new(meta.content).to_html }
|
48
|
+
.on("txt") { EmbeddedRuby.new(meta.content, to_context).render }
|
49
|
+
.match
|
53
50
|
end
|
54
51
|
|
55
|
-
#
|
56
|
-
#
|
57
52
|
def to_context
|
58
53
|
{
|
59
54
|
page: self,
|
@@ -61,8 +56,6 @@ module Troy
|
|
61
56
|
}
|
62
57
|
end
|
63
58
|
|
64
|
-
#
|
65
|
-
#
|
66
59
|
def compress(content)
|
67
60
|
content = HtmlPress.press(content) if config.assets.compress_html
|
68
61
|
content
|
@@ -72,38 +65,30 @@ module Troy
|
|
72
65
|
#
|
73
66
|
def render
|
74
67
|
ExtensionMatcher.new(path)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
68
|
+
.default { content }
|
69
|
+
.on("html") { compress render_erb }
|
70
|
+
.on("md") { compress render_erb }
|
71
|
+
.on("erb") { compress render_erb }
|
72
|
+
.match
|
80
73
|
end
|
81
74
|
|
82
|
-
#
|
83
|
-
#
|
84
75
|
def permalink
|
85
76
|
meta.fetch("permalink", File.basename(path).gsub(/\..*?$/, ""))
|
86
77
|
end
|
87
78
|
|
88
|
-
#
|
89
|
-
#
|
90
79
|
def filename
|
91
80
|
ExtensionMatcher.new(path)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
81
|
+
.default { "#{permalink}.html" }
|
82
|
+
.on("builder") { "#{permalink}.xml" }
|
83
|
+
.on("xml") { "#{permalink}.xml" }
|
84
|
+
.on("txt") { "#{permalink}.txt" }
|
85
|
+
.match
|
97
86
|
end
|
98
87
|
|
99
|
-
#
|
100
|
-
#
|
101
88
|
def layout
|
102
|
-
site.root.join("layouts/#{meta.fetch(
|
89
|
+
site.root.join("layouts/#{meta.fetch('layout', 'default')}.erb")
|
103
90
|
end
|
104
91
|
|
105
|
-
#
|
106
|
-
#
|
107
92
|
def render_erb
|
108
93
|
if layout.exist?
|
109
94
|
EmbeddedRuby.new(
|
@@ -125,25 +110,19 @@ module Troy
|
|
125
110
|
end
|
126
111
|
end
|
127
112
|
|
128
|
-
#
|
129
|
-
#
|
130
113
|
def output_file
|
131
114
|
base = File.dirname(path)
|
132
|
-
|
133
|
-
|
115
|
+
.gsub(site.root.join("source").to_s, "")
|
116
|
+
.gsub(%r{^/}, "")
|
134
117
|
|
135
118
|
site.root.join("public", base, filename)
|
136
119
|
end
|
137
120
|
|
138
|
-
#
|
139
|
-
#
|
140
121
|
def save
|
141
122
|
FileUtils.mkdir_p(File.dirname(output_file))
|
142
123
|
save_to(output_file)
|
143
124
|
end
|
144
125
|
|
145
|
-
#
|
146
|
-
#
|
147
126
|
def config
|
148
127
|
Troy.configuration
|
149
128
|
end
|
data/lib/troy/server.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
class Server
|
3
5
|
attr_reader :root, :request
|
@@ -13,7 +15,9 @@ module Troy
|
|
13
15
|
|
14
16
|
def render(status, content_type, path)
|
15
17
|
last_modified = path.mtime.httpdate
|
16
|
-
|
18
|
+
if request.env["HTTP_IF_MODIFIED_SINCE"] == last_modified
|
19
|
+
return [304, {}, []]
|
20
|
+
end
|
17
21
|
|
18
22
|
headers = {
|
19
23
|
"Content-Type" => content_type,
|
@@ -26,7 +30,7 @@ module Troy
|
|
26
30
|
end
|
27
31
|
|
28
32
|
def normalized_path
|
29
|
-
path = request.path.gsub(%r
|
33
|
+
path = request.path.gsub(%r{/$}, "")
|
30
34
|
path << "?#{request.query_string}" unless request.query_string.empty?
|
31
35
|
path
|
32
36
|
end
|
@@ -36,7 +40,7 @@ module Troy
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def process
|
39
|
-
path = request.path[%r
|
43
|
+
path = request.path[%r{^/(.*?)/?$}, 1]
|
40
44
|
path = "index" if path == ""
|
41
45
|
path = root.join(path)
|
42
46
|
|
data/lib/troy/site.rb
CHANGED
@@ -1,39 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Troy
|
2
4
|
class Site
|
3
|
-
attr_accessor :root
|
5
|
+
attr_accessor :root, :options
|
4
6
|
|
5
|
-
def initialize(root)
|
7
|
+
def initialize(root, options)
|
6
8
|
@root = Pathname.new(root).realpath
|
9
|
+
@options = options
|
7
10
|
|
8
11
|
load_configuration
|
9
12
|
load_extensions
|
10
13
|
set_locale
|
11
14
|
end
|
12
15
|
|
13
|
-
#
|
14
|
-
#
|
15
16
|
def load_extensions
|
16
17
|
Dir[root.join("config/**/*helpers.rb")].each do |file|
|
17
18
|
require file
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
#
|
22
|
-
#
|
23
22
|
def set_locale
|
24
23
|
I18n.load_path += config.i18n.load_path
|
25
24
|
I18n.default_locale = config.i18n.locale
|
26
25
|
I18n.locale = config.i18n.locale
|
27
26
|
end
|
28
27
|
|
29
|
-
#
|
30
|
-
#
|
31
28
|
def load_configuration
|
32
29
|
load root.join("config/troy.rb")
|
33
30
|
end
|
34
31
|
|
35
|
-
#
|
36
|
-
#
|
37
32
|
def export
|
38
33
|
remove_public_dir
|
39
34
|
export_assets
|
@@ -41,67 +36,81 @@ module Troy
|
|
41
36
|
export_pages
|
42
37
|
end
|
43
38
|
|
44
|
-
#
|
45
|
-
#
|
46
39
|
def export_files
|
47
40
|
assets = root.join("assets")
|
48
41
|
|
49
|
-
assets.entries.
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
FileUtils.cp_r assets.join(entry), root.join("public/#{basename}")
|
42
|
+
assets.entries.each_slice(options[:concurrency]) do |slice|
|
43
|
+
slice.map do |entry|
|
44
|
+
Thread.new { export_file(assets, entry) }
|
45
|
+
end.each(&:join)
|
54
46
|
end
|
55
47
|
end
|
56
48
|
|
57
|
-
|
58
|
-
|
49
|
+
def export_file(assets, entry)
|
50
|
+
basename = entry.to_s
|
51
|
+
return if [".", "..", "javascripts", "stylesheets"].include?(basename)
|
52
|
+
|
53
|
+
FileUtils.rm_rf root.join("public/#{basename}")
|
54
|
+
FileUtils.cp_r assets.join(entry), root.join("public/#{basename}")
|
55
|
+
end
|
56
|
+
|
59
57
|
def remove_public_dir
|
60
58
|
FileUtils.rm_rf root.join("public")
|
61
59
|
end
|
62
60
|
|
63
|
-
#
|
64
|
-
#
|
65
61
|
def export_pages(file = nil)
|
66
62
|
file = File.expand_path(file) if file
|
67
63
|
|
68
64
|
pages
|
69
65
|
.select {|page| file.nil? || page.path == file }
|
70
|
-
.
|
66
|
+
.each_slice(options[:concurrency]) do |slice|
|
67
|
+
threads = slice.map do |page|
|
68
|
+
Thread.new do
|
69
|
+
page.save
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
threads.each(&:join)
|
74
|
+
end
|
71
75
|
end
|
72
76
|
|
73
|
-
#
|
74
|
-
#
|
75
77
|
def export_assets
|
76
78
|
sprockets = Sprockets::Environment.new
|
77
79
|
sprockets.append_path root.join("assets/javascripts")
|
78
80
|
sprockets.append_path root.join("assets/stylesheets")
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
81
|
+
|
82
|
+
if config.assets.compress_css
|
83
|
+
sprockets.css_compressor = Sprockets::SassCompressor
|
84
|
+
end
|
85
|
+
|
86
|
+
if config.assets.compress_js
|
87
|
+
sprockets.js_compressor = Uglifier.new(uglifier_options)
|
88
|
+
end
|
89
|
+
|
90
|
+
config.assets.precompile.each_slice(options[:concurrency]) do |slice|
|
91
|
+
slice.map do |asset_name|
|
92
|
+
Thread.new { export_asset(sprockets, asset_name) }
|
93
|
+
end.each(&:join)
|
91
94
|
end
|
92
95
|
end
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
+
def export_asset(sprockets, asset_name)
|
98
|
+
asset = sprockets[asset_name]
|
99
|
+
output_file = asset.filename.to_s
|
100
|
+
.gsub(root.join("assets").to_s, "")
|
101
|
+
.gsub(%r{^/}, "")
|
102
|
+
.gsub(/\.scss$/, ".css")
|
103
|
+
.gsub(/\.coffee$/, ".js")
|
104
|
+
|
105
|
+
asset.write_to root.join("public/#{output_file}")
|
106
|
+
end
|
107
|
+
|
97
108
|
def uglifier_options
|
98
109
|
options = Uglifier::DEFAULTS.dup
|
99
110
|
options[:output][:comments] = :none
|
100
111
|
options
|
101
112
|
end
|
102
113
|
|
103
|
-
#
|
104
|
-
#
|
105
114
|
def source
|
106
115
|
Dir[root.join("source/**/*.{html,erb,md,builder,xml,txt}").to_s]
|
107
116
|
end
|
data/lib/troy/version.rb
CHANGED
data/lib/troy/xml.rb
CHANGED
data/lib/troy.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Encoding.default_external = "UTF-8"
|
2
4
|
Encoding.default_internal = "UTF-8"
|
3
5
|
|
@@ -14,7 +16,8 @@ require "rack"
|
|
14
16
|
require "uglifier"
|
15
17
|
require "html_press"
|
16
18
|
|
17
|
-
level
|
19
|
+
level = $VERBOSE
|
20
|
+
$VERBOSE = nil
|
18
21
|
require "rouge"
|
19
22
|
require "rouge/plugins/redcarpet"
|
20
23
|
$VERBOSE = level
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -215,6 +215,7 @@ extensions: []
|
|
215
215
|
extra_rdoc_files: []
|
216
216
|
files:
|
217
217
|
- ".gitignore"
|
218
|
+
- ".rubocop.yml"
|
218
219
|
- Gemfile
|
219
220
|
- LICENSE.txt
|
220
221
|
- README.md
|
@@ -253,7 +254,7 @@ homepage: http://github.com/fnando/troy
|
|
253
254
|
licenses:
|
254
255
|
- MIT
|
255
256
|
metadata: {}
|
256
|
-
post_install_message:
|
257
|
+
post_install_message:
|
257
258
|
rdoc_options: []
|
258
259
|
require_paths:
|
259
260
|
- lib
|
@@ -268,9 +269,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
268
269
|
- !ruby/object:Gem::Version
|
269
270
|
version: '0'
|
270
271
|
requirements: []
|
271
|
-
|
272
|
-
|
273
|
-
signing_key:
|
272
|
+
rubygems_version: 3.3.3
|
273
|
+
signing_key:
|
274
274
|
specification_version: 4
|
275
275
|
summary: A static site generator
|
276
276
|
test_files: []
|