flutterby 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/flutterby +7 -1
- data/lib/flutterby.rb +9 -1
- data/lib/flutterby/cli.rb +24 -2
- data/lib/flutterby/node.rb +71 -20
- data/lib/flutterby/server.rb +2 -2
- data/lib/flutterby/version.rb +1 -1
- data/lib/flutterby/view.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c87a6c4e67963aa5d66c2225d60b9e228a2d852
|
4
|
+
data.tar.gz: 896782e01a481af93bc5da7d9a277bc9252d9f29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52dcaab598ca23c831ff348a3fdeb56124a4ce663c45c36ba47d4211370d602f8b1e0389de27fc9ec830b79abe0761dcbfe5c64a47834de46f17b75418424e72
|
7
|
+
data.tar.gz: 760b7537767012d5b6d044c537d461bfd52514c2feeb5bf114d4213de1805add17e09eaff1225cb2af0381076f1c6f4f2f99201a644a638dce558ebee55d5392
|
data/exe/flutterby
CHANGED
data/lib/flutterby.rb
CHANGED
@@ -14,7 +14,11 @@ require "flutterby/server"
|
|
14
14
|
|
15
15
|
|
16
16
|
module Flutterby
|
17
|
-
|
17
|
+
extend self
|
18
|
+
|
19
|
+
attr_writer :logger
|
20
|
+
|
21
|
+
def from(fs_path, name: nil, parent: nil)
|
18
22
|
name ||= ::File.basename(fs_path)
|
19
23
|
|
20
24
|
if ::File.exist?(fs_path)
|
@@ -23,4 +27,8 @@ module Flutterby
|
|
23
27
|
raise "Path #{fs_path} could not be found."
|
24
28
|
end
|
25
29
|
end
|
30
|
+
|
31
|
+
def logger
|
32
|
+
@logger ||= Logger.new(STDOUT)
|
33
|
+
end
|
26
34
|
end
|
data/lib/flutterby/cli.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'commander'
|
2
2
|
require 'flutterby'
|
3
|
+
require 'benchmark'
|
4
|
+
|
5
|
+
Flutterby.logger.level = Logger::INFO
|
3
6
|
|
4
7
|
Commander.configure do
|
5
8
|
program :name, 'Flutterby'
|
@@ -16,8 +19,23 @@ Commander.configure do
|
|
16
19
|
c.action do |args, options|
|
17
20
|
options.default in: "./site/", out: "./_build/"
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
# Simplify logger output
|
23
|
+
Flutterby.logger.formatter = proc do |severity, datetime, progname, msg|
|
24
|
+
" • #{msg}\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
time = Benchmark.realtime do
|
28
|
+
# Import site
|
29
|
+
say color("📚 Importing site...", :bold)
|
30
|
+
root = Flutterby.from(options.in, name: "/")
|
31
|
+
say color("🌲 Read #{root.tree_size} nodes.", :green, :bold)
|
32
|
+
|
33
|
+
# Export site
|
34
|
+
say color("💾 Exporting site...", :bold)
|
35
|
+
root.export(into: options.out)
|
36
|
+
end
|
37
|
+
|
38
|
+
say color("✅ Done. (took #{sprintf "%.2f", time}s)", :green, :bold)
|
21
39
|
end
|
22
40
|
end
|
23
41
|
alias_command :b, :build
|
@@ -32,7 +50,11 @@ Commander.configure do
|
|
32
50
|
c.action do |args, options|
|
33
51
|
options.default in: "./site/", port: 4004
|
34
52
|
|
53
|
+
say color("📚 Importing site...", :bold)
|
35
54
|
root = Flutterby.from(options.in, name: "/")
|
55
|
+
say color("🌲 Read #{root.tree_size} nodes.", :green, :bold)
|
56
|
+
|
57
|
+
say color("🌤 Serving your site on port #{options.port}. Enjoy!", :bold)
|
36
58
|
server = Flutterby::Server.new(root, port: options.port)
|
37
59
|
server.run!
|
38
60
|
end
|
data/lib/flutterby/node.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
1
3
|
module Flutterby
|
2
4
|
class Node
|
3
5
|
attr_accessor :parent, :ext, :source, :body
|
@@ -32,21 +34,24 @@ module Flutterby
|
|
32
34
|
|
33
35
|
def reset_children!
|
34
36
|
@children = []
|
35
|
-
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_child(node)
|
40
|
+
node.parent = self
|
41
|
+
children << node
|
42
|
+
end
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
c.
|
40
|
-
|
44
|
+
def find_child(name)
|
45
|
+
if name.include?(".")
|
46
|
+
@children.find { |c| c.full_name == name }
|
47
|
+
else
|
48
|
+
@children.find { |c| c.name == name }
|
41
49
|
end
|
50
|
+
end
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
find { |c| c.full_name == name }
|
47
|
-
else
|
48
|
-
find { |c| c.name == name }
|
49
|
-
end
|
52
|
+
def tree_size
|
53
|
+
children.inject(children.length) do |count, child|
|
54
|
+
count + child.tree_size
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
@@ -81,6 +86,10 @@ module Flutterby
|
|
81
86
|
parent ? parent.root : self
|
82
87
|
end
|
83
88
|
|
89
|
+
def root?
|
90
|
+
root == self
|
91
|
+
end
|
92
|
+
|
84
93
|
def sibling(name)
|
85
94
|
parent && parent.find(name)
|
86
95
|
end
|
@@ -99,7 +108,7 @@ module Flutterby
|
|
99
108
|
when %r{^/} then
|
100
109
|
root.find($')
|
101
110
|
when %r{^([^/]+)/?} then
|
102
|
-
child =
|
111
|
+
child = find_child($1)
|
103
112
|
$'.empty? ? child : child.find($')
|
104
113
|
end
|
105
114
|
end
|
@@ -120,6 +129,16 @@ module Flutterby
|
|
120
129
|
blk.call(self, val)
|
121
130
|
end
|
122
131
|
|
132
|
+
# Walk the entire tree, top to bottom.
|
133
|
+
#
|
134
|
+
def walk_tree(val = nil, &blk)
|
135
|
+
val = blk.call(self, val)
|
136
|
+
children.each do |child|
|
137
|
+
val = child.walk_tree(val, &blk)
|
138
|
+
end
|
139
|
+
|
140
|
+
val
|
141
|
+
end
|
123
142
|
|
124
143
|
#
|
125
144
|
# Reading from filesystem
|
@@ -129,11 +148,13 @@ module Flutterby
|
|
129
148
|
@body = nil
|
130
149
|
reset_children!
|
131
150
|
|
151
|
+
# Load contents from filesystem
|
152
|
+
#
|
132
153
|
if @fs_path
|
133
154
|
if ::File.directory?(fs_path)
|
134
155
|
Dir[::File.join(fs_path, "*")].each do |entry|
|
135
|
-
if node = Flutterby.from(entry)
|
136
|
-
|
156
|
+
if node = Flutterby.from(entry, parent: self)
|
157
|
+
add_child(node)
|
137
158
|
end
|
138
159
|
end
|
139
160
|
else
|
@@ -153,8 +174,23 @@ module Flutterby
|
|
153
174
|
send(meth) if respond_to?(meth)
|
154
175
|
end
|
155
176
|
end
|
177
|
+
|
178
|
+
# If this node is the root node, perform some preprocessing
|
179
|
+
if root?
|
180
|
+
preprocess!
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def preprocess!
|
185
|
+
walk_tree do |node|
|
186
|
+
node.render_body! if node.should_preprocess?
|
187
|
+
end
|
156
188
|
end
|
157
189
|
|
190
|
+
def should_preprocess?
|
191
|
+
should_publish? && !folder? &&
|
192
|
+
(filters.include?("json") || filters.include?("yaml"))
|
193
|
+
end
|
158
194
|
|
159
195
|
#
|
160
196
|
# Rendering
|
@@ -164,8 +200,16 @@ module Flutterby
|
|
164
200
|
@view ||= View.for(self)
|
165
201
|
end
|
166
202
|
|
203
|
+
def render_body!
|
204
|
+
time = Benchmark.realtime do
|
205
|
+
Filters.apply!(self)
|
206
|
+
end
|
207
|
+
|
208
|
+
logger.info "Rendered #{url} in #{sprintf "%.1f", time * 1000}ms"
|
209
|
+
end
|
210
|
+
|
167
211
|
def body
|
168
|
-
|
212
|
+
render_body! if @body.nil?
|
169
213
|
@body
|
170
214
|
end
|
171
215
|
|
@@ -196,8 +240,11 @@ module Flutterby
|
|
196
240
|
|
197
241
|
def export(into:)
|
198
242
|
if should_publish?
|
199
|
-
|
200
|
-
|
243
|
+
time = Benchmark.realtime do
|
244
|
+
write_static(into: into)
|
245
|
+
end
|
246
|
+
|
247
|
+
logger.info "Exported #{url}"
|
201
248
|
end
|
202
249
|
end
|
203
250
|
|
@@ -243,11 +290,11 @@ module Flutterby
|
|
243
290
|
end
|
244
291
|
|
245
292
|
def read_json
|
246
|
-
data.merge!(JSON.parse(
|
293
|
+
data.merge!(JSON.parse(body))
|
247
294
|
end
|
248
295
|
|
249
296
|
def read_yaml
|
250
|
-
data.merge!(YAML.load(
|
297
|
+
data.merge!(YAML.load(body))
|
251
298
|
end
|
252
299
|
|
253
300
|
|
@@ -270,5 +317,9 @@ module Flutterby
|
|
270
317
|
def page?
|
271
318
|
!folder? && ext == "html"
|
272
319
|
end
|
320
|
+
|
321
|
+
def logger
|
322
|
+
Flutterby.logger
|
323
|
+
end
|
273
324
|
end
|
274
325
|
end
|
data/lib/flutterby/server.rb
CHANGED
@@ -15,7 +15,7 @@ module Flutterby
|
|
15
15
|
# puts "added absolute path: #{added}"
|
16
16
|
# puts "removed absolute path: #{removed}"
|
17
17
|
|
18
|
-
|
18
|
+
Flutterby.logger.info "Change detected, reloading everything!"
|
19
19
|
@root.reload!
|
20
20
|
end
|
21
21
|
|
@@ -30,7 +30,7 @@ module Flutterby
|
|
30
30
|
|
31
31
|
# Go!
|
32
32
|
listener.start
|
33
|
-
server.run self, Port: @port
|
33
|
+
server.run self, Port: @port, Logger: Flutterby.logger
|
34
34
|
end
|
35
35
|
|
36
36
|
def call(env)
|
data/lib/flutterby/version.rb
CHANGED
data/lib/flutterby/view.rb
CHANGED
@@ -25,8 +25,8 @@ module Flutterby
|
|
25
25
|
view = new(file)
|
26
26
|
|
27
27
|
# walk the tree up to dynamically extend the view
|
28
|
-
file.
|
29
|
-
if view_node = e.
|
28
|
+
file.walk_down do |e|
|
29
|
+
if view_node = e.sibling("_view.rb")
|
30
30
|
case view_node.ext
|
31
31
|
when "rb" then
|
32
32
|
mod = Module.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flutterby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hendrik Mans
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|