troy 0.0.34 → 0.0.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc838bf9fc86348d55ed3f93a986c1047924d9a513901e02dafad3f45ddcdcdf
4
- data.tar.gz: 544b493ec0e506a3ffb3289ae4215a0d51a0e4a88e374bd263cd3d5b25979000
3
+ metadata.gz: 1de66b8776191039502385cfc1ca3453f4b9bc30ae81b0eefbc4a7257124ad30
4
+ data.tar.gz: 51fd07dbf2caac206263ed83fd0830d31f2326e30c3cec82796dcc578470d116
5
5
  SHA512:
6
- metadata.gz: 9078b888d8f31cb059f5ce90e29ccdcf19f240ff990adfd40f7e4fb0d61bc3285ae63d5e416f2ca8e949f5a75f91eaa64103587d6c8b66a4f809a7a232b4a46b
7
- data.tar.gz: a092f247955e1864016ce2aeed04cea8628cef875bc23648c8b2d3093b801272d311b8d59a3b1f2889259f68ba76cf172338b51541a3b62e06d1b91fd55022cc
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
- if options[:assets]
21
- site.export_assets
22
- site.export_files
23
- end
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
- if options[:file]
26
- options[:file].each do |file|
27
- site.export_pages(file)
34
+ if !options[:assets] && !options[:file]
35
+ site.export
28
36
  end
29
37
  end
30
38
 
31
- if !options[:assets] && !options[:file]
32
- site.export
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
@@ -9,9 +9,9 @@ module Troy
9
9
  end
10
10
 
11
11
  def partial(name, locals = {})
12
+ name = name.to_s
12
13
  basename = File.basename(name)
13
14
  dirname = File.dirname(name)
14
-
15
15
  partial = []
16
16
  partial << dirname unless dirname.start_with?(".")
17
17
  partial << "_#{basename}.erb"
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.each do |entry|
50
- basename = entry.to_s
51
- next if [".", "..", "javascripts", "stylesheets"].include?(basename)
52
- FileUtils.rm_rf root.join("public/#{basename}")
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
- .each(&:save)
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.each do |asset_name|
83
- asset = sprockets[asset_name]
84
- output_file = asset.pathname.to_s
85
- .gsub(root.join("assets").to_s, "")
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
@@ -1,3 +1,3 @@
1
1
  module Troy
2
- VERSION = "0.0.34"
2
+ VERSION = "0.0.35"
3
3
  end
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.34
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-02-15 00:00:00.000000000 Z
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.3
272
+ rubygems_version: 2.7.6
273
273
  signing_key:
274
274
  specification_version: 4
275
275
  summary: A static site generator