hx 0.15.0 → 0.16.0
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.
- data/VERSION +1 -1
- data/lib/hx.rb +46 -24
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.16.0
|
data/lib/hx.rb
CHANGED
@@ -27,6 +27,7 @@ require 'pathname'
|
|
27
27
|
require 'tempfile'
|
28
28
|
require 'yaml'
|
29
29
|
require 'hx/path'
|
30
|
+
require 'set'
|
30
31
|
|
31
32
|
module Hx
|
32
33
|
|
@@ -337,6 +338,7 @@ def Chain.new(input, options)
|
|
337
338
|
options = options.dup
|
338
339
|
options.delete(:chain) # prevent inheritance
|
339
340
|
for raw_filter in filters
|
341
|
+
raw_filter = Hx.expand_chain(raw_filter)
|
340
342
|
input = Hx.build_source(options, input, {}, raw_filter)
|
341
343
|
end
|
342
344
|
input
|
@@ -409,18 +411,30 @@ def self.expand_chain(raw_input)
|
|
409
411
|
raw_input
|
410
412
|
end
|
411
413
|
|
412
|
-
def self.
|
413
|
-
raw_source = expand_chain(raw_source)
|
414
|
-
|
414
|
+
def self.get_input_names(raw_source)
|
415
415
|
if raw_source.has_key? 'input'
|
416
|
-
|
416
|
+
return Array(raw_source['input'])
|
417
|
+
else
|
418
|
+
[]
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
def self.build_source(options, default_input, sources, raw_source)
|
423
|
+
input_names = get_input_names(raw_source)
|
424
|
+
input_sources = input_names.map do |input_name|
|
417
425
|
begin
|
418
|
-
|
426
|
+
sources.fetch(input_name)
|
419
427
|
rescue IndexError
|
420
428
|
raise NameError, "No source named #{input_name} in scope"
|
421
429
|
end
|
422
|
-
|
430
|
+
end
|
431
|
+
case input_sources.length
|
432
|
+
when 0
|
423
433
|
source = default_input
|
434
|
+
when 1
|
435
|
+
source = input_sources.first
|
436
|
+
else
|
437
|
+
source = Overlay.new(*input_sources)
|
424
438
|
end
|
425
439
|
|
426
440
|
if raw_source.has_key? 'filter'
|
@@ -500,40 +514,48 @@ class Site
|
|
500
514
|
|
501
515
|
raw_sources_by_name = raw_config.fetch('sources', {})
|
502
516
|
raw_outputs = raw_config.fetch('output', [])
|
503
|
-
|
517
|
+
for name, raw_source in raw_sources_by_name
|
518
|
+
raw_sources_by_name[name] = Hx.expand_chain(raw_source)
|
519
|
+
end
|
520
|
+
raw_outputs = raw_outputs.map! do |raw_output|
|
521
|
+
Hx.expand_chain(raw_output)
|
522
|
+
end
|
504
523
|
|
505
524
|
# build input dependency graph
|
506
|
-
source_dependencies = {}
|
525
|
+
source_dependencies = Hash.new { |h,k| h[k] = Set.new }
|
507
526
|
source_count_by_dependency = Hash.new(0)
|
508
527
|
for name, raw_source in raw_sources_by_name
|
509
|
-
|
510
|
-
|
511
|
-
input_name = raw_source['input']
|
512
|
-
source_dependencies[name] = input_name
|
528
|
+
for input_name in Hx.get_input_names(raw_source)
|
529
|
+
source_dependencies[name].add input_name
|
513
530
|
source_count_by_dependency[input_name] += 1
|
514
531
|
end
|
515
532
|
end
|
516
533
|
for raw_output in raw_outputs
|
517
|
-
|
518
|
-
if raw_output.has_key? 'input'
|
519
|
-
input_name = raw_source['input']
|
534
|
+
for input_name in Hx.get_input_names(raw_source)
|
520
535
|
source_count_by_dependency[input_name] += 1
|
521
536
|
end
|
522
537
|
end
|
523
538
|
|
539
|
+
source_names = raw_sources_by_name.keys
|
540
|
+
|
524
541
|
# calculate depth for each input in the graph
|
525
542
|
source_depths = Hash.new(0)
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
raise RuntimeError, "cycle in source graph at #{name}"
|
531
|
-
end
|
532
|
-
seen.add name
|
543
|
+
to_process = Set.new(source_names)
|
544
|
+
until to_process.empty?
|
545
|
+
need_updating = Set.new
|
546
|
+
for name in to_process
|
533
547
|
depth = source_depths[name] + 1
|
534
|
-
|
535
|
-
|
548
|
+
if depth >= source_names.length
|
549
|
+
raise "cycle in source graph involving #{name}"
|
550
|
+
end
|
551
|
+
for input_name in source_dependencies[name]
|
552
|
+
if depth > source_depths[input_name]
|
553
|
+
source_depths[input_name] = depth
|
554
|
+
need_updating.add input_name
|
555
|
+
end
|
556
|
+
end
|
536
557
|
end
|
558
|
+
to_process = need_updating
|
537
559
|
end
|
538
560
|
|
539
561
|
# depth-first topological sort
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 95
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 16
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.16.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- MenTaLguY
|