flutterby 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flutterby/node.rb +7 -7
- data/lib/flutterby/server.rb +27 -24
- data/lib/flutterby/version.rb +1 -1
- data/lib/flutterby/view.rb +11 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2c1bd44e0401ad1f8046a70b01ca191d8d8661c
|
4
|
+
data.tar.gz: 74e111066e2dcdf84c50db61daab894e069d7376
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0a76a23bd09f814804040af24d20df03e7ddcbfa3f1c88833019b356db31ec8f3c228c85a592e86f237d41a71bfd10a9c21af7bc92ff26ad4f6f5d15fb7f73e
|
7
|
+
data.tar.gz: 7bde567d6c410cab6bee564921f6598b0549ed45b322fb96f0daab9fbb11dfbde57f8abc7a8ca46b316fa99f51e17f0a34fffed592f85d9bc0a476384fc0bf3d
|
data/lib/flutterby/node.rb
CHANGED
@@ -18,7 +18,7 @@ module Flutterby
|
|
18
18
|
#
|
19
19
|
@ext = @filters.last
|
20
20
|
|
21
|
-
# If a filesystem path was given, read the
|
21
|
+
# If a filesystem path was given, read the node from disk
|
22
22
|
if fs_path
|
23
23
|
@fs_path = ::File.expand_path(fs_path)
|
24
24
|
end
|
@@ -104,16 +104,16 @@ module Flutterby
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
# Walk the tree up, invoking the passed block for every
|
108
|
-
# found on the way, passing the
|
107
|
+
# Walk the tree up, invoking the passed block for every node
|
108
|
+
# found on the way, passing the node as its only argument.
|
109
109
|
#
|
110
110
|
def walk_up(val = nil, &blk)
|
111
111
|
val = blk.call(self, val)
|
112
112
|
parent ? parent.walk_up(val, &blk) : val
|
113
113
|
end
|
114
114
|
|
115
|
-
# Walk the graph from the root to this
|
116
|
-
# except the block will be called on higher level
|
115
|
+
# Walk the graph from the root to this node. Just like walk_up,
|
116
|
+
# except the block will be called on higher level nodes first.
|
117
117
|
#
|
118
118
|
def walk_down(val = nil, &blk)
|
119
119
|
val = parent ? parent.walk_up(val, &blk) : val
|
@@ -132,8 +132,8 @@ module Flutterby
|
|
132
132
|
if @fs_path
|
133
133
|
if ::File.directory?(fs_path)
|
134
134
|
Dir[::File.join(fs_path, "*")].each do |entry|
|
135
|
-
if
|
136
|
-
children <<
|
135
|
+
if node = Flutterby.from(entry)
|
136
|
+
children << node
|
137
137
|
end
|
138
138
|
end
|
139
139
|
else
|
data/lib/flutterby/server.rb
CHANGED
@@ -39,31 +39,8 @@ module Flutterby
|
|
39
39
|
|
40
40
|
parts = req.path.split("/").reject(&:empty?)
|
41
41
|
|
42
|
-
current = @root
|
43
|
-
|
44
42
|
result = catch :halt do
|
45
|
-
|
46
|
-
# halt if we're not supposed to serve current entity
|
47
|
-
throw :halt, :error_404 unless current.should_publish?
|
48
|
-
|
49
|
-
if current.folder? then
|
50
|
-
# If no further parts are requested, let's look for an index
|
51
|
-
# document and serve that instead.
|
52
|
-
if child = current.find(parts.empty? ? "index" : parts.shift)
|
53
|
-
current = child
|
54
|
-
else
|
55
|
-
throw :halt, :error_404
|
56
|
-
end
|
57
|
-
else
|
58
|
-
# Determine MIME type
|
59
|
-
mime_type = MIME::Types.type_for(current.ext) || "text/plain"
|
60
|
-
|
61
|
-
# Build response
|
62
|
-
res.headers["Content-Type"] = mime_type
|
63
|
-
res.body = [current.render]
|
64
|
-
throw :halt
|
65
|
-
end
|
66
|
-
end
|
43
|
+
serve(@root, parts, req, res)
|
67
44
|
end
|
68
45
|
|
69
46
|
case result
|
@@ -75,5 +52,31 @@ module Flutterby
|
|
75
52
|
|
76
53
|
res
|
77
54
|
end
|
55
|
+
|
56
|
+
def serve(node, parts, req, res)
|
57
|
+
# halt if we're not supposed to serve current node
|
58
|
+
throw :halt, :error_404 unless node.should_publish?
|
59
|
+
|
60
|
+
# If there are parts left, find them and delegate to the next
|
61
|
+
# node in the chain; otherwise, render this specific node.
|
62
|
+
#
|
63
|
+
if parts.any?
|
64
|
+
if child = node.find(parts.shift)
|
65
|
+
serve(child, parts, req, res)
|
66
|
+
else
|
67
|
+
throw :halt, :error_404
|
68
|
+
end
|
69
|
+
elsif child = node.find("index")
|
70
|
+
serve(child, parts, req, res)
|
71
|
+
else
|
72
|
+
# Determine MIME type
|
73
|
+
mime_type = MIME::Types.type_for(node.ext) || "text/plain"
|
74
|
+
|
75
|
+
# Build response
|
76
|
+
res.headers["Content-Type"] = mime_type
|
77
|
+
res.body = [node.render]
|
78
|
+
throw :halt
|
79
|
+
end
|
80
|
+
end
|
78
81
|
end
|
79
82
|
end
|
data/lib/flutterby/version.rb
CHANGED
data/lib/flutterby/view.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Flutterby
|
2
2
|
class View
|
3
|
-
attr_reader :
|
4
|
-
alias_method :page, :
|
3
|
+
attr_reader :node
|
4
|
+
alias_method :page, :node
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(node)
|
7
|
+
@node = node
|
8
8
|
end
|
9
9
|
|
10
10
|
def date_format(date, fmt)
|
@@ -16,7 +16,7 @@ module Flutterby
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def find(expr)
|
19
|
-
|
19
|
+
node.find(expr) or raise "No node found for #{expr}"
|
20
20
|
end
|
21
21
|
|
22
22
|
class << self
|
@@ -26,12 +26,14 @@ module Flutterby
|
|
26
26
|
|
27
27
|
# walk the tree up to dynamically extend the view
|
28
28
|
file.parent.walk_down do |e|
|
29
|
-
if
|
30
|
-
case
|
29
|
+
if view_node = e.find("_view.rb")
|
30
|
+
case view_node.ext
|
31
31
|
when "rb" then
|
32
|
-
|
32
|
+
mod = Module.new
|
33
|
+
mod.class_eval(view_node.source)
|
34
|
+
view.extend mod
|
33
35
|
else
|
34
|
-
raise "Unknown view extension #{
|
36
|
+
raise "Unknown view extension #{view_node.full_name}"
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|