troy 0.0.34 → 0.0.35
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/cli.rb +22 -10
- data/lib/troy/helpers.rb +1 -1
- data/lib/troy/site.rb +36 -17
- 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: 1de66b8776191039502385cfc1ca3453f4b9bc30ae81b0eefbc4a7257124ad30
|
4
|
+
data.tar.gz: 51fd07dbf2caac206263ed83fd0830d31f2326e30c3cec82796dcc578470d116
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c79d4c7ffc7976d1e7624e8432bcc450b178f45ae46ee06e896a5a501f60e0ca0eec0273853fe304e83e6ef245733e9856a3588453e46571130099c1cb07bda
|
7
|
+
data.tar.gz: 0d87cd79c7ef8e7be0383e5f6ff67788e06a9d3074c2d82e5e66a4ae20e2c26c259e268cbcd9c1fd0c9af740aa4fdb4be507d889f4b90a6652fc9eee97cc9010
|
data/lib/troy/cli.rb
CHANGED
@@ -15,21 +15,33 @@ module Troy
|
|
15
15
|
end
|
16
16
|
|
17
17
|
options assets: :boolean, file: :array
|
18
|
+
option :concurrency, type: :numeric, default: 10
|
19
|
+
option :benchmark, type: :boolean, default: false
|
18
20
|
desc "export", "Export files"
|
19
21
|
def export
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
runner = lambda do
|
23
|
+
if options[:assets]
|
24
|
+
site.export_assets
|
25
|
+
site.export_files
|
26
|
+
end
|
27
|
+
|
28
|
+
if options[:file]
|
29
|
+
options[:file].each do |file|
|
30
|
+
site.export_pages(file)
|
31
|
+
end
|
32
|
+
end
|
24
33
|
|
25
|
-
|
26
|
-
|
27
|
-
site.export_pages(file)
|
34
|
+
if !options[:assets] && !options[:file]
|
35
|
+
site.export
|
28
36
|
end
|
29
37
|
end
|
30
38
|
|
31
|
-
if
|
32
|
-
|
39
|
+
if options[:benchmark]
|
40
|
+
require "benchmark"
|
41
|
+
elapsed = Benchmark.realtime(&runner)
|
42
|
+
puts "=> Finished in #{elapsed.round(2)}s"
|
43
|
+
else
|
44
|
+
runner.call
|
33
45
|
end
|
34
46
|
end
|
35
47
|
|
@@ -62,7 +74,7 @@ module Troy
|
|
62
74
|
|
63
75
|
private
|
64
76
|
def site
|
65
|
-
@site ||= Troy::Site.new(Dir.pwd)
|
77
|
+
@site ||= Troy::Site.new(Dir.pwd, options)
|
66
78
|
end
|
67
79
|
end
|
68
80
|
end
|
data/lib/troy/helpers.rb
CHANGED
data/lib/troy/site.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Troy
|
2
2
|
class Site
|
3
|
-
attr_accessor :root
|
3
|
+
attr_accessor :root, :options
|
4
4
|
|
5
|
-
def initialize(root)
|
5
|
+
def initialize(root, options)
|
6
6
|
@root = Pathname.new(root).realpath
|
7
|
+
@options = options
|
7
8
|
|
8
9
|
load_configuration
|
9
10
|
load_extensions
|
@@ -46,14 +47,20 @@ module Troy
|
|
46
47
|
def export_files
|
47
48
|
assets = root.join("assets")
|
48
49
|
|
49
|
-
assets.entries.
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
FileUtils.cp_r assets.join(entry), root.join("public/#{basename}")
|
50
|
+
assets.entries.each_slice(options[:concurrency]) do |slice|
|
51
|
+
slice.map do |entry|
|
52
|
+
Thread.new { export_file(assets, entry) }
|
53
|
+
end.each(&:join)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
def export_file(assets, entry)
|
58
|
+
basename = entry.to_s
|
59
|
+
return if [".", "..", "javascripts", "stylesheets"].include?(basename)
|
60
|
+
FileUtils.rm_rf root.join("public/#{basename}")
|
61
|
+
FileUtils.cp_r assets.join(entry), root.join("public/#{basename}")
|
62
|
+
end
|
63
|
+
|
57
64
|
#
|
58
65
|
#
|
59
66
|
def remove_public_dir
|
@@ -67,7 +74,13 @@ module Troy
|
|
67
74
|
|
68
75
|
pages
|
69
76
|
.select {|page| file.nil? || page.path == file }
|
70
|
-
.
|
77
|
+
.each_slice(options[:concurrency]) do |slice|
|
78
|
+
threads = slice.map do |page|
|
79
|
+
Thread.new { page.save }
|
80
|
+
end
|
81
|
+
|
82
|
+
threads.each(&:join)
|
83
|
+
end
|
71
84
|
end
|
72
85
|
|
73
86
|
#
|
@@ -79,18 +92,24 @@ module Troy
|
|
79
92
|
sprockets.css_compressor = Sprockets::SassCompressor if config.assets.compress_css
|
80
93
|
sprockets.js_compressor = Uglifier.new(uglifier_options) if config.assets.compress_js
|
81
94
|
|
82
|
-
config.assets.precompile.
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
.gsub(%r[^/], "")
|
87
|
-
.gsub(/\.scss$/, ".css")
|
88
|
-
.gsub(/\.coffee$/, ".js")
|
89
|
-
|
90
|
-
asset.write_to root.join("public/#{output_file}")
|
95
|
+
config.assets.precompile.each_slice(options[:concurrency]) do |slice|
|
96
|
+
slice.map do |asset_name|
|
97
|
+
Thread.new { export_asset(sprockets, asset_name) }
|
98
|
+
end.each(&:join)
|
91
99
|
end
|
92
100
|
end
|
93
101
|
|
102
|
+
def export_asset(sprockets, asset_name)
|
103
|
+
asset = sprockets[asset_name]
|
104
|
+
output_file = asset.pathname.to_s
|
105
|
+
.gsub(root.join("assets").to_s, "")
|
106
|
+
.gsub(%r[^/], "")
|
107
|
+
.gsub(/\.scss$/, ".css")
|
108
|
+
.gsub(/\.coffee$/, ".js")
|
109
|
+
|
110
|
+
asset.write_to root.join("public/#{output_file}")
|
111
|
+
end
|
112
|
+
|
94
113
|
#
|
95
114
|
#
|
96
115
|
#
|
data/lib/troy/version.rb
CHANGED
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.35
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -269,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
269
|
version: '0'
|
270
270
|
requirements: []
|
271
271
|
rubyforge_project:
|
272
|
-
rubygems_version: 2.7.
|
272
|
+
rubygems_version: 2.7.6
|
273
273
|
signing_key:
|
274
274
|
specification_version: 4
|
275
275
|
summary: A static site generator
|