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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa91b42f64b52a8f3a568cd3a95ac7d366d997ea
4
- data.tar.gz: 6ee2175701e8b15dae84f1a8665f0473678851fa
3
+ metadata.gz: a2c1bd44e0401ad1f8046a70b01ca191d8d8661c
4
+ data.tar.gz: 74e111066e2dcdf84c50db61daab894e069d7376
5
5
  SHA512:
6
- metadata.gz: e4b993b640531755f04c6115ee949c26d7cb1d0f4ff2adaac173397cf1b94b688ef3e051369880f369ab9dd9e779ac4d11dabb9924d843ad71bb5be0277eb912
7
- data.tar.gz: ca707746919b8e08c0563506d67ecc9a32fa9d32c8c373164b9f2ae18102abfef51680c3506fd3e7a1c3106325f0a342e6a8caa4e93701ddfafb4d522c7d86dd
6
+ metadata.gz: f0a76a23bd09f814804040af24d20df03e7ddcbfa3f1c88833019b356db31ec8f3c228c85a592e86f237d41a71bfd10a9c21af7bc92ff26ad4f6f5d15fb7f73e
7
+ data.tar.gz: 7bde567d6c410cab6bee564921f6598b0549ed45b322fb96f0daab9fbb11dfbde57f8abc7a8ca46b316fa99f51e17f0a34fffed592f85d9bc0a476384fc0bf3d
@@ -18,7 +18,7 @@ module Flutterby
18
18
  #
19
19
  @ext = @filters.last
20
20
 
21
- # If a filesystem path was given, read the entity from disk
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 entity
108
- # found on the way, passing the entity as its only argument.
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 entity. Just like walk_up,
116
- # except the block will be called on higher level entities first.
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 entity = Flutterby.from(entry)
136
- children << entity
135
+ if node = Flutterby.from(entry)
136
+ children << node
137
137
  end
138
138
  end
139
139
  else
@@ -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
- loop do
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
@@ -1,3 +1,3 @@
1
1
  module Flutterby
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  module Flutterby
2
2
  class View
3
- attr_reader :entity
4
- alias_method :page, :entity
3
+ attr_reader :node
4
+ alias_method :page, :node
5
5
 
6
- def initialize(entity)
7
- @entity = entity
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
- entity.find(expr) or raise "No entity found for #{expr}"
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 view_entity = e.find("_view.rb")
30
- case view_entity.ext
29
+ if view_node = e.find("_view.rb")
30
+ case view_node.ext
31
31
  when "rb" then
32
- view.instance_eval(view_entity.source)
32
+ mod = Module.new
33
+ mod.class_eval(view_node.source)
34
+ view.extend mod
33
35
  else
34
- raise "Unknown view extension #{view_entity.full_name}"
36
+ raise "Unknown view extension #{view_node.full_name}"
35
37
  end
36
38
  end
37
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flutterby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik Mans