hx 0.24.0 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.24.0
1
+ 0.25.0
data/lib/hx.rb CHANGED
@@ -39,12 +39,27 @@ end
39
39
  class EditingNotSupportedError < RuntimeError
40
40
  end
41
41
 
42
- # minimal complete definition: each_entry_path + get_entry, or each_entry
43
- module Filter
42
+ module View
44
43
  def edit_entry(path, prototype=nil)
45
44
  raise EditingNotSupportedError, "Editing not supported for #{path}"
46
45
  end
47
46
 
47
+ def each_entry(selector)
48
+ raise NotImplementedError, "#{self.class}#each_entry not implemented"
49
+ end
50
+ end
51
+
52
+ def self.get_entry(view, path)
53
+ view.each_entry(Path.literal(path)) do |entry_path, entry|
54
+ return entry
55
+ end
56
+ raise NoSuchEntryError, path
57
+ end
58
+
59
+ # minimal complete definition: each_entry_path + get_entry, or each_entry
60
+ module Filter
61
+ include View
62
+
48
63
  def each_entry_path(selector)
49
64
  each_entry(selector) { |path, entry| yield path }
50
65
  end
@@ -61,10 +76,7 @@ module Filter
61
76
  end
62
77
 
63
78
  def get_entry(path)
64
- each_entry(Path.literal(path)) do |entry_path, entry|
65
- return entry
66
- end
67
- raise NoSuchEntryError, path
79
+ Hx.get_entry(self, path)
68
80
  end
69
81
  end
70
82
 
@@ -332,42 +344,6 @@ class Sort
332
344
  end
333
345
  end
334
346
 
335
- class IncludeFragments
336
- include Hx::Filter
337
-
338
- def initialize(input, options)
339
- @input = input
340
- @fragments = options[:fragments] || {}
341
- @fragment_paths = Set.new(@fragments.values)
342
- end
343
-
344
- def edit_entry(path, prototype)
345
- raise EditingNotSupported, path if @fragment_paths.include? path
346
- @input.edit_entry(path, prototype) { |text| yield text }
347
- self
348
- end
349
-
350
- def each_entry_path(selector)
351
- @input.each_entry_path(selector) do |path|
352
- yield path unless @fragment_paths.include? path
353
- end
354
- self
355
- end
356
-
357
- def get_entry(path)
358
- raise NoSuchEntryError, path if @fragment_paths.include? path
359
- entry = @input.get_entry(path)
360
- entry = entry.dup
361
- for field, fragment_path in @fragments
362
- begin
363
- entry[field] = @input.get_entry(path)
364
- rescue NoSuchEntryError
365
- end
366
- end
367
- entry
368
- end
369
- end
370
-
371
347
  Chain = Object.new
372
348
  def Chain.new(input, options)
373
349
  filters = options[:chain] || []
@@ -473,11 +449,6 @@ def self.build_source(options, default_input, sources, raw_source)
473
449
  source = Overlay.new(*input_sources)
474
450
  end
475
451
 
476
- if raw_source.has_key? 'fragments'
477
- source = IncludeFragments.new(source,
478
- :fragments => raw_source['fragments'])
479
- end
480
-
481
452
  if raw_source.has_key? 'filter'
482
453
  if raw_source.has_key? 'options'
483
454
  filter_options = options.dup
@@ -48,8 +48,8 @@ Usage: hx [--config CONFIG_FILE] [upgen]
48
48
  hx [--config CONFIG_FILE] regen
49
49
  hx [--config CONFIG_FILE] post[up] SOURCE:PATH
50
50
  hx [--config CONFIG_FILE] edit[up] SOURCE:PATH
51
- hx [--config CONFIG_FILE] list SOURCE:PATTERN
52
- hx [--config CONFIG_FILE] dump SOURCE:PATTERN
51
+ hx [--config CONFIG_FILE] list SOURCE[:PATTERN]
52
+ hx [--config CONFIG_FILE] dump SOURCE[:PATTERN]
53
53
  hx [--config CONFIG_FILE] serve [PORT]
54
54
 
55
55
  EOS
@@ -102,6 +102,7 @@ EOS
102
102
  end
103
103
 
104
104
  def self.cmd_serve(site, port=nil)
105
+ Socket.do_not_reverse_lookup = true
105
106
  server = WEBrick::HTTPServer.new({:Port => port || 0})
106
107
  real_port = server.config[:Port]
107
108
 
@@ -29,6 +29,10 @@ module Selector
29
29
  raise NotImplementedError, "#{self.class}#accept_path? not implemented"
30
30
  end
31
31
 
32
+ def literal?
33
+ false
34
+ end
35
+
32
36
  def |(other)
33
37
  Disjunction.build(self, other)
34
38
  end
@@ -61,6 +65,7 @@ class Pattern
61
65
  include Selector
62
66
 
63
67
  def initialize(tokens)
68
+ @is_literal = tokens.size == 1 and String === tokens.first
64
69
  @regexp = Regexp.new("^#{tokens.map { |token|
65
70
  case token
66
71
  when :doublestar; '.*'
@@ -70,6 +75,10 @@ class Pattern
70
75
  }}$")
71
76
  end
72
77
 
78
+ def literal?
79
+ @is_literal
80
+ end
81
+
73
82
  def accept_path?(path) ; !!(path =~ @regexp) ; end
74
83
  end
75
84
 
@@ -7,6 +7,16 @@ describe Hx::Path::Pattern do
7
7
  Hx::Path::Pattern.should < Hx::Path::Selector
8
8
  end
9
9
 
10
+ it "should indicate literal paths as singletons" do
11
+ pattern = Hx::Path.literal("foo/bar")
12
+ pattern.literal?.should be_true
13
+ end
14
+
15
+ it "should not indicate patterns as singletons" do
16
+ pattern = Hx::Path.parse_pattern('foo/*')
17
+ pattern.literal?.should be_false
18
+ end
19
+
10
20
  it "should accept or reject literal paths" do
11
21
  pattern = Hx::Path.literal("foo/bar")
12
22
  pattern.should accept_path("foo/bar")
@@ -84,7 +94,13 @@ describe "Hx::Path::Selector conjunctions" do
84
94
  end
85
95
  end
86
96
 
87
- describe "Hx::Path::Selector" do
97
+ describe Hx::Path::Selector do
98
+ it "should define a default literal? method which returns false" do
99
+ o = Object.new
100
+ o.extend Hx::Path::Selector
101
+ o.literal?.should be_false
102
+ end
103
+
88
104
  it "should be able to elide specific circumfixes" do
89
105
  filter = Hx::Path.parse_pattern("foo").elide_circumfix("XXX", "YYY")
90
106
  filter.should accept_path("XXXfooYYY")
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: 127
5
- prerelease: false
4
+ hash: 123
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 24
8
+ - 25
9
9
  - 0
10
- version: 0.24.0
10
+ version: 0.25.0
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-03-25 00:00:00 -07:00
18
+ date: 2011-04-29 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  requirements: []
161
161
 
162
162
  rubyforge_project:
163
- rubygems_version: 1.3.7
163
+ rubygems_version: 1.6.2
164
164
  signing_key:
165
165
  specification_version: 3
166
166
  summary: A miniature static site generator.