hx 0.11.0 → 0.12.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/LICENSE +1 -1
- data/VERSION +1 -1
- data/lib/hx/backend/hobix.rb +9 -3
- data/lib/hx.rb +5 -7
- data/spec/site_spec.rb +0 -6
- metadata +10 -12
- data/.gitignore +0 -22
- data/lib/hx/backend/couchdb.rb +0 -134
data/LICENSE
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.12.0
|
data/lib/hx/backend/hobix.rb
CHANGED
@@ -28,12 +28,11 @@ require 'hx/backend/rawfiles'
|
|
28
28
|
module Hx
|
29
29
|
module Backend
|
30
30
|
|
31
|
-
class
|
31
|
+
class HobixFilter
|
32
32
|
include Hx::Filter
|
33
33
|
|
34
34
|
def initialize(input, options)
|
35
|
-
|
36
|
-
@source = Hx::StripPath.new(files, :suffix => ".yaml")
|
35
|
+
@source = Hx::StripPath.new(input, :suffix => ".yaml")
|
37
36
|
end
|
38
37
|
|
39
38
|
def yaml_repr(value)
|
@@ -86,5 +85,12 @@ class Hobix
|
|
86
85
|
end
|
87
86
|
end
|
88
87
|
|
88
|
+
class Hobix < HobixFilter
|
89
|
+
def initialize(input, options)
|
90
|
+
files = Hx::Backend::RawFiles.new(input, options)
|
91
|
+
super(files, options)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
89
95
|
end
|
90
96
|
end
|
data/lib/hx.rb
CHANGED
@@ -448,7 +448,6 @@ class Site
|
|
448
448
|
|
449
449
|
attr_reader :options
|
450
450
|
attr_reader :sources
|
451
|
-
attr_reader :outputs
|
452
451
|
|
453
452
|
class << self
|
454
453
|
private :new
|
@@ -516,7 +515,7 @@ class Site
|
|
516
515
|
end
|
517
516
|
|
518
517
|
outputs = []
|
519
|
-
for raw_output in raw_config.fetch('
|
518
|
+
for raw_output in raw_config.fetch('output', [])
|
520
519
|
outputs << Hx.build_source(options, NULL_INPUT, sources, raw_output)
|
521
520
|
end
|
522
521
|
|
@@ -527,22 +526,21 @@ class Site
|
|
527
526
|
def initialize(options, sources, outputs)
|
528
527
|
@options = options
|
529
528
|
@sources = sources
|
530
|
-
@
|
531
|
-
@combined_output = Overlay.new(*@outputs)
|
529
|
+
@output = Overlay.new(*outputs)
|
532
530
|
end
|
533
531
|
|
534
532
|
def edit_entry(path, prototype=nil)
|
535
|
-
@
|
533
|
+
@output.edit_entry(path, prototype) { |text| yield text }
|
536
534
|
self
|
537
535
|
end
|
538
536
|
|
539
537
|
def each_entry_path(selector)
|
540
|
-
@
|
538
|
+
@output.each_entry_path(selector) { |path| yield path }
|
541
539
|
self
|
542
540
|
end
|
543
541
|
|
544
542
|
def get_entry(path)
|
545
|
-
@
|
543
|
+
@output.get_entry(path)
|
546
544
|
end
|
547
545
|
end
|
548
546
|
|
data/spec/site_spec.rb
CHANGED
@@ -45,12 +45,6 @@ describe "Hx::Site.load" do
|
|
45
45
|
site.sources.should include('foo')
|
46
46
|
site.sources.should include('bar')
|
47
47
|
end
|
48
|
-
|
49
|
-
it "creates an output for every entry in outputs" do
|
50
|
-
yaml_config = YAML.dump({'outputs' => [{}, {}]})
|
51
|
-
site = Hx::Site.load(yaml_config, __FILE__)
|
52
|
-
site.outputs.size.should == 2
|
53
|
-
end
|
54
48
|
end
|
55
49
|
|
56
50
|
describe Hx::Site do
|
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: 47
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 12
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.12.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- MenTaLguY
|
@@ -50,14 +50,12 @@ extra_rdoc_files:
|
|
50
50
|
- README.rdoc
|
51
51
|
files:
|
52
52
|
- .document
|
53
|
-
- .gitignore
|
54
53
|
- LICENSE
|
55
54
|
- README.rdoc
|
56
55
|
- Rakefile
|
57
56
|
- VERSION
|
58
57
|
- bin/hx
|
59
58
|
- lib/hx.rb
|
60
|
-
- lib/hx/backend/couchdb.rb
|
61
59
|
- lib/hx/backend/hobix.rb
|
62
60
|
- lib/hx/backend/rawfiles.rb
|
63
61
|
- lib/hx/cli.rb
|
@@ -86,8 +84,8 @@ homepage: http://github.com/mental/hx
|
|
86
84
|
licenses: []
|
87
85
|
|
88
86
|
post_install_message:
|
89
|
-
rdoc_options:
|
90
|
-
|
87
|
+
rdoc_options: []
|
88
|
+
|
91
89
|
require_paths:
|
92
90
|
- lib
|
93
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -116,14 +114,14 @@ signing_key:
|
|
116
114
|
specification_version: 3
|
117
115
|
summary: A miniature static site generator.
|
118
116
|
test_files:
|
119
|
-
- spec/spec_helper.rb
|
120
|
-
- spec/rawfiles_spec.rb
|
121
117
|
- spec/cache_spec.rb
|
122
118
|
- spec/hx_dummy.rb
|
123
|
-
- spec/nullinput_spec.rb
|
124
|
-
- spec/site_spec.rb
|
125
119
|
- spec/hx_dummy2.rb
|
126
|
-
- spec/
|
120
|
+
- spec/nullinput_spec.rb
|
127
121
|
- spec/overlay_spec.rb
|
128
122
|
- spec/pathops_spec.rb
|
123
|
+
- spec/rack_spec.rb
|
124
|
+
- spec/rawfiles_spec.rb
|
129
125
|
- spec/selector_spec.rb
|
126
|
+
- spec/site_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
data/.gitignore
DELETED
data/lib/hx/backend/couchdb.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
# hx/backend/couchdb - CouchDB backend for Hx
|
2
|
-
#
|
3
|
-
# Copyright (c) 2009-2010 MenTaLguY <mental@rydia.net>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
# a copy of this software and associated documentation files (the
|
7
|
-
# "Software"), to deal in the Software without restriction, including
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be
|
14
|
-
# included in all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
|
24
|
-
require 'cgi'
|
25
|
-
require 'net/http'
|
26
|
-
require 'uri'
|
27
|
-
require 'json'
|
28
|
-
require 'time'
|
29
|
-
require 'hx'
|
30
|
-
|
31
|
-
module Hx
|
32
|
-
module Backend
|
33
|
-
|
34
|
-
class CouchDB
|
35
|
-
include Hx::Filter
|
36
|
-
|
37
|
-
class HTTPError < RuntimeError
|
38
|
-
attr_reader :path
|
39
|
-
attr_reader :code
|
40
|
-
attr_reader :response
|
41
|
-
|
42
|
-
def initialize(path, code, response)
|
43
|
-
@path = path
|
44
|
-
@code = code
|
45
|
-
@response = response
|
46
|
-
end
|
47
|
-
|
48
|
-
def to_s
|
49
|
-
"HTTP Error #{@code} for #{path}"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def initialize(input, options)
|
54
|
-
couchdb_server = options.fetch(:couchdb_server, "http://localhost:5984/")
|
55
|
-
couchdb_database = options.fetch(:couchdb_database, "entries")
|
56
|
-
uri = URI.parse(couchdb_server)
|
57
|
-
if uri.scheme != "http"
|
58
|
-
raise RuntimeError, "Unsupported protocol #{uri.proto}"
|
59
|
-
end
|
60
|
-
@host = uri.host || "localhost"
|
61
|
-
@port = uri.port || 80
|
62
|
-
prefix = uri.path || "/"
|
63
|
-
prefix = "#{prefix}/" unless prefix =~ %r(/$)
|
64
|
-
@prefix = "#{prefix}#{couchdb_database}/"
|
65
|
-
end
|
66
|
-
|
67
|
-
def edit_entry(path, prototype=nil)
|
68
|
-
begin
|
69
|
-
text = get_document(path)
|
70
|
-
rescue HTTPError => e
|
71
|
-
raise e unless e.code == 404
|
72
|
-
raise Hx::NoSuchEntryError, "No such entry #{path}" unless prototype
|
73
|
-
text = prototype.to_json
|
74
|
-
end
|
75
|
-
text = yield text
|
76
|
-
entry = JSON.parse(text)
|
77
|
-
entry['updated'] = Time.now.xmlschema
|
78
|
-
entry['created'] ||= entry['updated']
|
79
|
-
put_document(path, entry.to_json)
|
80
|
-
self
|
81
|
-
end
|
82
|
-
|
83
|
-
def each_entry_path(selector)
|
84
|
-
listing = JSON.parse(get_document('_all_docs'))
|
85
|
-
listing['rows'].each do |row|
|
86
|
-
path = row['id']
|
87
|
-
yield path if selector.accept_path? path
|
88
|
-
end
|
89
|
-
self
|
90
|
-
end
|
91
|
-
|
92
|
-
def get_entry(path)
|
93
|
-
begin
|
94
|
-
entry = JSON.parse(get_document(path))
|
95
|
-
rescue HTTPError => e
|
96
|
-
raise e unless e.code == 404
|
97
|
-
raise Hx::NoSuchEntryError, path
|
98
|
-
end
|
99
|
-
for field in %(created updated)
|
100
|
-
entry[field] = Time.parse(entry[field] || "")
|
101
|
-
end
|
102
|
-
entry
|
103
|
-
end
|
104
|
-
|
105
|
-
private
|
106
|
-
def request_path_for(id)
|
107
|
-
"#{@prefix}#{CGI.escape(id)}"
|
108
|
-
end
|
109
|
-
|
110
|
-
def get_document(id)
|
111
|
-
request = Net::HTTP::Get.new(request_path_for(id))
|
112
|
-
http_request(request)
|
113
|
-
end
|
114
|
-
|
115
|
-
def put_document(id, body)
|
116
|
-
request = Net::HTTP::Put.new(request_path_for(id),
|
117
|
-
'Content-Type' => 'application/json')
|
118
|
-
request.body = body
|
119
|
-
http_request(request)
|
120
|
-
end
|
121
|
-
|
122
|
-
def http_request(request)
|
123
|
-
response = Net::HTTP.start(@host, @port) { |http| http.request(request) }
|
124
|
-
case response
|
125
|
-
when Net::HTTPSuccess
|
126
|
-
response.body
|
127
|
-
else
|
128
|
-
raise HTTPError.new(request.path, response.code.to_i, response)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
end
|