flora 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/lib/flora/app.rb +61 -4
- data/lib/flora/engine.rb +11 -8
- data/lib/flora/version.rb +1 -1
- data/lib/flora.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d37209dfce3b7a9f42b1f41f261ab64b404a13cfa07bb1246d36718395fb9aff
|
|
4
|
+
data.tar.gz: 145c6f72a9e6c82abad143f946bde715e200b693d5963f3568485b04622c14c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 283edf79dedaa559fa4132a16f4fb79f897fb969436cf252b23fa520aa172232ddc22c65665e2886f3390761e31678bef7b244ada7eac9edf6a6b20c5f8151ba
|
|
7
|
+
data.tar.gz: c1e279fa9e7a777bc60bec261c6e7a688f34d88d049865ee639564316ecfb30b1eadf82156ab599bb5f1981125c16841b11fb5b38ec187f1c2680b0d6a2e22ba
|
data/lib/flora/app.rb
CHANGED
|
@@ -2,6 +2,62 @@ require 'rack'
|
|
|
2
2
|
|
|
3
3
|
class Flora::App
|
|
4
4
|
|
|
5
|
+
# TODO: make this support multiple apps.
|
|
6
|
+
OUT_DIR = '/tmp/flora/'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Rebuilder
|
|
10
|
+
|
|
11
|
+
def initialize(app, dir, flora)
|
|
12
|
+
@app = app
|
|
13
|
+
@dir = Pathname.new(dir)
|
|
14
|
+
@flora = flora
|
|
15
|
+
@last_built = Time.at(0)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def call(env)
|
|
20
|
+
if should_rebuild?
|
|
21
|
+
@flora.build(OUT_DIR)
|
|
22
|
+
@last_built = Time.now.utc
|
|
23
|
+
# TODO: also trigger a reload in the browser
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@app.call(env)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def should_rebuild?
|
|
33
|
+
# TODO: this is probably slow. I'm sure there's an easier kqueue-esq way
|
|
34
|
+
# of doing this.
|
|
35
|
+
@dir.find do |file|
|
|
36
|
+
return true if file.stat.mtime > @last_built
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
false
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Reloader
|
|
46
|
+
|
|
47
|
+
def initialize(app, flora)
|
|
48
|
+
@app = app
|
|
49
|
+
@flora = flora
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def call(env)
|
|
53
|
+
@flora.reload_website_code
|
|
54
|
+
|
|
55
|
+
@app.call(env)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
5
61
|
# UGLY. Is there a better way to do this?
|
|
6
62
|
class StaticWithoutHtml
|
|
7
63
|
|
|
@@ -25,12 +81,13 @@ class Flora::App
|
|
|
25
81
|
|
|
26
82
|
def self.app(path)
|
|
27
83
|
flora = Flora.new(path)
|
|
28
|
-
# TODO: rebuild every req?
|
|
29
|
-
flora.build('/tmp/flora/')
|
|
30
84
|
|
|
31
85
|
Rack::Builder.new do
|
|
32
|
-
use
|
|
33
|
-
use
|
|
86
|
+
use Rebuilder, path, flora
|
|
87
|
+
use Reloader, flora
|
|
88
|
+
use StaticWithoutHtml, OUT_DIR
|
|
89
|
+
use Rack::Static, urls: [''], root: OUT_DIR, index: 'index.html'
|
|
90
|
+
|
|
34
91
|
map "/" do
|
|
35
92
|
run ->(env) do
|
|
36
93
|
[404, {'Content-Type' => 'text/plain'}, ['Page Not Found!']]
|
data/lib/flora/engine.rb
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
class Flora::Engine
|
|
2
2
|
|
|
3
|
+
attr_reader(:website_loader)
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
def initialize(path)
|
|
4
7
|
@path = Pathname.new(path)
|
|
5
8
|
@config = Config.new(self)
|
|
6
9
|
|
|
7
|
-
@
|
|
10
|
+
@website_loader = Zeitwerk::Loader.new
|
|
8
11
|
|
|
9
|
-
if
|
|
10
|
-
|
|
12
|
+
if website_has_supporting_code?
|
|
13
|
+
@website_loader.push_dir(@path.join('lib').to_s)
|
|
11
14
|
end
|
|
12
15
|
|
|
16
|
+
@website_loader.enable_reloading
|
|
17
|
+
@website_loader.setup
|
|
18
|
+
|
|
13
19
|
Kernel.prepend(Flora::Engine::Page::Html)
|
|
14
20
|
end
|
|
15
21
|
|
|
@@ -55,15 +61,12 @@ class Flora::Engine
|
|
|
55
61
|
|
|
56
62
|
private
|
|
57
63
|
|
|
58
|
-
def
|
|
64
|
+
def website_has_supporting_code?
|
|
59
65
|
@path.join('lib').exist?
|
|
60
66
|
end
|
|
61
67
|
|
|
62
68
|
|
|
63
|
-
def
|
|
64
|
-
@site_loader.push_dir(@path.join('lib').to_s)
|
|
65
|
-
@site_loader.enable_reloading
|
|
66
|
-
@site_loader.setup
|
|
69
|
+
def setup_website_loader
|
|
67
70
|
end
|
|
68
71
|
|
|
69
72
|
end
|
data/lib/flora/version.rb
CHANGED
data/lib/flora.rb
CHANGED