hx 0.26.0 → 0.26.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.26.0
1
+ 0.26.1
data/lib/hx.rb CHANGED
@@ -632,6 +632,10 @@ def self.write_file(pathname, content, executable=false)
632
632
  nil
633
633
  end
634
634
 
635
+ def self.last_update_time(*entries)
636
+ entries.map { |e| e['updated'] || e['created'] }.compact.max
637
+ end
638
+
635
639
  class LazyContent
636
640
  def initialize(&block)
637
641
  raise ArgumentError, "No block given" unless block
@@ -23,6 +23,7 @@
23
23
 
24
24
  require 'pathname'
25
25
  require 'hx'
26
+ require 'find'
26
27
 
27
28
  module Hx
28
29
  module Backend
@@ -41,11 +42,6 @@ class RawFiles
41
42
  def path_to_pathname(path) ; @entry_dir + path ; end
42
43
  private :path_to_pathname
43
44
 
44
- def pathname_to_path(pathname)
45
- pathname.relative_path_from(@entry_dir).to_s
46
- end
47
- private :pathname_to_path
48
-
49
45
  def edit_entry(path, prototype=nil)
50
46
  pathname = path_to_pathname(path)
51
47
  begin
@@ -69,9 +65,9 @@ class RawFiles
69
65
  end
70
66
 
71
67
  def each_entry_path(selector)
72
- Pathname.glob(@entry_dir + '**/*') do |pathname|
73
- next unless pathname.file?
74
- path = pathname_to_path(pathname)
68
+ Find.find @entry_dir.to_s do |fs_path|
69
+ next unless FileTest.file? fs_path
70
+ path = Pathname.new(fs_path).relative_path_from(@entry_dir).to_s
75
71
  yield path if selector.accept_path? path
76
72
  end
77
73
  self
@@ -39,39 +39,33 @@ class RecursiveIndex
39
39
  def initialize(input, options)
40
40
  @input = input
41
41
  @index_name = options[:index_name] || "index"
42
- @index_re = %r!^((?:.*/)?)#{Regexp.quote(@index_name)}$!
43
42
  end
44
43
 
45
- def each_entry_path(selector)
46
- emitted = Set.new
47
- @input.each_entry_path(Path::ALL) do |path|
44
+ def each_entry(selector)
45
+ indices = {}
46
+ @input.each_entry(Path::ALL) do |path, entry|
48
47
  components = path.split("/")
49
48
  until components.empty?
50
49
  components.pop
51
50
  index_path = (components + [@index_name]).join("/")
52
- break if emitted.include? index_path
53
- yield index_path if selector.accept_path? index_path
54
- emitted.add index_path
51
+ next unless selector.accept_path? index_path
52
+ index_entry = indices[index_path]
53
+ unless index_entry
54
+ index_entry = {'items' => []}
55
+ indices[index_path] = index_entry
56
+ end
57
+ if path == index_path
58
+ index_entry = entry.merge(index_entry)
59
+ indices[index_path] = index_entry
60
+ end
61
+ index_entry['items'] << {'path' => path, 'entry' => entry}
62
+ index_entry['updated'] = Hx.last_update_time(index_entry, entry)
55
63
  end
56
64
  end
57
- self
58
- end
59
-
60
- def get_entry(path)
61
- raise NoSuchEntryError, path unless path =~ @index_re
62
- selector = Path.parse_pattern("#{$1}**")
63
- index = {'items' => []}
64
- @input.each_entry(selector) do |child_path, entry|
65
- if child_path == path
66
- index = entry.merge(index)
67
- else
68
- index['items'] << {'path' => child_path, 'entry' => entry}
69
- end
70
- updated = [entry['updated'], index['updated']].compact.max
71
- index['updated'] = updated if updated
65
+ indices.each do |path, entry|
66
+ yield path, entry
72
67
  end
73
- raise NoSuchEntryError, path if index['items'].empty?
74
- index
68
+ self
75
69
  end
76
70
  end
77
71
 
@@ -22,7 +22,7 @@ describe Hx::Backend::RawFiles do
22
22
  end
23
23
 
24
24
  it "should enumerate files" do
25
- entry_names = Set.new %q(foo bar baz)
25
+ entry_names = Set.new %q(foo bar baz .dotfile)
26
26
  for name in entry_names
27
27
  File.open(File.join(@dir, name), 'w') {}
28
28
  end
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: 119
4
+ hash: 117
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 26
9
- - 0
10
- version: 0.26.0
9
+ - 1
10
+ version: 0.26.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - MenTaLguY
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-30 00:00:00 -07:00
18
+ date: 2011-08-22 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -164,15 +164,5 @@ rubygems_version: 1.6.2
164
164
  signing_key:
165
165
  specification_version: 3
166
166
  summary: A miniature static site generator.
167
- test_files:
168
- - spec/cache_spec.rb
169
- - spec/hx_dummy.rb
170
- - spec/hx_dummy2.rb
171
- - spec/nullinput_spec.rb
172
- - spec/overlay_spec.rb
173
- - spec/pathops_spec.rb
174
- - spec/rack_spec.rb
175
- - spec/rawfiles_spec.rb
176
- - spec/selector_spec.rb
177
- - spec/site_spec.rb
178
- - spec/spec_helper.rb
167
+ test_files: []
168
+