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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b44217297cbd020d161b21d49829be840dd7ec4b99327108aa1b0c14e4f3286
4
- data.tar.gz: 32871444dfee770b17d99e57aa4753e1f8a40e02d3743e7e52e3a1ef77098a8d
3
+ metadata.gz: d37209dfce3b7a9f42b1f41f261ab64b404a13cfa07bb1246d36718395fb9aff
4
+ data.tar.gz: 145c6f72a9e6c82abad143f946bde715e200b693d5963f3568485b04622c14c4
5
5
  SHA512:
6
- metadata.gz: 6567dab062a120dca84dabec2246266c5f482fcc2ba8899c541f2d4fd5a0801f7e6c7a9ef8f4af47896495dcf1768ce6eb763eea9df8b33db935a70fdc561617
7
- data.tar.gz: f24f358cb9c3da51053b2c1301f2d5c0f85aaebadf1956558f623839e8c24acc241157b77962f7772e83a6e7d3542a768e488d0efbd6785878ba5431386dd747
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 StaticWithoutHtml, '/tmp/flora'
33
- use Rack::Static, urls: [''], root: '/tmp/flora', index: 'index.html'
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
- @site_loader = Zeitwerk::Loader.new
10
+ @website_loader = Zeitwerk::Loader.new
8
11
 
9
- if site_has_supporting_code?
10
- setup_site_loader
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 site_has_supporting_code?
64
+ def website_has_supporting_code?
59
65
  @path.join('lib').exist?
60
66
  end
61
67
 
62
68
 
63
- def setup_site_loader
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
@@ -1,3 +1,3 @@
1
1
  class Flora
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/flora.rb CHANGED
@@ -18,4 +18,9 @@ class Flora
18
18
  @engine.build(out)
19
19
  end
20
20
 
21
+
22
+ def reload_website_code
23
+ @engine.website_loader.reload
24
+ end
25
+
21
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Vladimiroff