nanoc-live 1.0.0a1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d1362b4ea80415583b3399354722ae766ed61b0199516864b0fe219c7b1af308
4
+ data.tar.gz: 1dcd6212ba0b6d60f3e467908b3ae93000c5fe5fc0a1e4dc920f69e11c5ecf6f
5
+ SHA512:
6
+ metadata.gz: 7fad4117f790e729f908f35617a4d924ca3ee00a14d39be26f1f309a40faf10c40ce22fe38f1a6b29e0c6a9195ba8b2d0f8160ee52fed16c6bfc54a3d22e0927
7
+ data.tar.gz: 1bc4a7ce7f0bf6b69de1ef2c1e2f7760b0a1586407dbbc2373149b4abab6831b18a2d4c49e3ad77d0708877ca92b684b6c1fc34f595439a8c8b1c05f458d24a5
data/NEWS.md ADDED
@@ -0,0 +1,5 @@
1
+ # Release notes for nanoc-live
2
+
3
+ ## 1.0.0a1 (2017-12-03)
4
+
5
+ Initial release.
@@ -0,0 +1,5 @@
1
+ # Nanoc::Live
2
+
3
+ ⚠️ **Caution:** This project is currently experimental.
4
+
5
+ The _nanoc-live_ gem provides a new `nanoc live` command, and is required to make the `nanoc compile --watch` option work.
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'adsf/live'
4
+
5
+ module Nanoc
6
+ module Live
7
+ end
8
+ end
9
+
10
+ require_relative 'live/version'
11
+ require_relative 'live/live_recompiler'
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc::Live
4
+ class LiveRecompiler
5
+ def initialize(command_runner:)
6
+ @command_runner = command_runner
7
+ end
8
+
9
+ def run
10
+ run_parent do |site|
11
+ handle_changes(site, @command_runner)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def gen_changes_for_child(site)
18
+ changes = [
19
+ site.data_source.item_changes,
20
+ site.data_source.layout_changes,
21
+ gen_config_and_rules_changes,
22
+ ]
23
+
24
+ SlowEnumeratorTools.batch(SlowEnumeratorTools.merge(changes))
25
+ end
26
+
27
+ def run_child(pipe_write, pipe_read)
28
+ pipe_write.close
29
+
30
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
31
+ changes_enum = gen_changes_for_child(site)
32
+ yield(site)
33
+
34
+ quit = Object.new
35
+ parent_enum = Enumerator.new do |y|
36
+ pipe_read.read
37
+ y << quit
38
+ end
39
+
40
+ SlowEnumeratorTools.merge([parent_enum, changes_enum]).each do |e|
41
+ break if quit.equal?(e)
42
+
43
+ $stderr.print 'Reloading site… '
44
+ $stderr.flush
45
+ site_loader = Nanoc::Int::SiteLoader.new
46
+ site = Nanoc::Int::Site.new(
47
+ config: Nanoc::Int::ConfigLoader.new.new_from_cwd,
48
+ data_source: site_loader.gen_data_source_for_config(site.config),
49
+ code_snippets: site.code_snippets,
50
+ )
51
+ $stderr.puts 'done'
52
+
53
+ yield(site)
54
+ end
55
+
56
+ exit 0
57
+ rescue Interrupt
58
+ exit 0
59
+ end
60
+
61
+ def run_parent
62
+ # create initial child
63
+ pipe_read, pipe_write = IO.pipe
64
+ fork { run_child(pipe_write, pipe_read) { |s| yield(s) } }
65
+ pipe_read.close
66
+
67
+ gen_lib_changes.each do |_e|
68
+ # stop child
69
+ pipe_write.write('q')
70
+ pipe_write.close
71
+ Process.wait
72
+
73
+ # create new child
74
+ pipe_read, pipe_write = IO.pipe
75
+ fork { run_child(pipe_write, pipe_read) { |s| yield(s) } }
76
+ pipe_read.close
77
+ end
78
+ rescue Interrupt
79
+ end
80
+
81
+ def handle_changes(site, command_runner)
82
+ time_before = Time.now
83
+
84
+ puts 'Compiling site…'
85
+ compiler = Nanoc::Int::Compiler.new_for(site)
86
+ listener = Nanoc::CLI::Commands::CompileListeners::Aggregate.new(
87
+ command_runner: command_runner,
88
+ site: site,
89
+ compiler: compiler,
90
+ )
91
+ listener.run_while do
92
+ compiler.run_until_end
93
+ end
94
+
95
+ time_after = Time.now
96
+ puts "Site compiled in #{format('%.2f', time_after - time_before)}s."
97
+ puts
98
+ end
99
+
100
+ def gen_lib_changes
101
+ require 'listen'
102
+
103
+ Nanoc::ChangesStream.new do |cl|
104
+ opts = {
105
+ latency: 0.0,
106
+ wait_for_delay: 0.0,
107
+ }
108
+
109
+ listener = Listen.to('lib', opts) { |*| cl.lib }
110
+ listener.start
111
+ sleep
112
+ end
113
+ end
114
+
115
+ def gen_config_and_rules_changes
116
+ require 'listen'
117
+
118
+ Nanoc::ChangesStream.new do |cl|
119
+ opts = {
120
+ only: /(\/|\A)(nanoc\.yaml|config\.yaml|rules|Rules|rules\.rb|Rules\.rb)\z/,
121
+ latency: 0.0,
122
+ wait_for_delay: 0.0,
123
+ }
124
+
125
+ listener = Listen.to('.', opts) { |*| cl.unknown }
126
+ listener.start
127
+ sleep
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Live
5
+ VERSION = '1.0.0a1'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-live
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0a1
5
+ platform: ruby
6
+ authors:
7
+ - Denis Defreyne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: listen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nanoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.8'
41
+ description: Provides support for auto-recompiling Nanoc sites.
42
+ email: denis+rubygems@denis.ws
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - NEWS.md
48
+ - README.md
49
+ - lib/nanoc/live.rb
50
+ - lib/nanoc/live/live_recompiler.rb
51
+ - lib/nanoc/live/version.rb
52
+ homepage: http://nanoc.ws/
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '2.3'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.1
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.7.3
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Live recompilation support for Nanoc
76
+ test_files: []