flora 0.10.0 → 0.11.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 +4 -20
- data/lib/flora/factory.rb +4 -1
- data/lib/flora/project.rb +6 -6
- data/lib/flora/version.rb +1 -1
- data/lib/flora.rb +24 -3
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6fa0d4f3614285445c78586bf4d63163cb6419b8944dcb1e614a3e90f5b50925
|
|
4
|
+
data.tar.gz: 17aaa52cf397c066edb770f98959fa3b9f211e398c1bca87c365d2c157691f5e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c21a1b6b5ab70780a0e182f99d300239661c36f72cf3d8ea022a6be7edb8374e2b587233648d6939705bd073aeb1234a1e04e041f609f1ea7fcb82b36e99813b
|
|
7
|
+
data.tar.gz: a92dacb2c646acd722b018eb948d2380567b38438cbf3ee09cc387c689fc0fd2375205e0c0044823f8bd306625ab40a87c34a2764f5969349331b6a9c7e27268
|
data/lib/flora/app.rb
CHANGED
|
@@ -12,14 +12,15 @@ class Flora::App
|
|
|
12
12
|
@app = app
|
|
13
13
|
@dir = Pathname.new(dir)
|
|
14
14
|
@flora = flora
|
|
15
|
-
|
|
15
|
+
@@last_built ||= Time.at(0)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def call(env)
|
|
20
20
|
if should_rebuild?
|
|
21
|
+
@flora.reload_project
|
|
21
22
|
@flora.build(OUT_DIR)
|
|
22
|
-
|
|
23
|
+
@@last_built = Time.now.utc
|
|
23
24
|
# TODO: also trigger a reload in the browser
|
|
24
25
|
end
|
|
25
26
|
|
|
@@ -33,7 +34,7 @@ class Flora::App
|
|
|
33
34
|
# TODO: this is probably slow. I'm sure there's an easier kqueue-esq way
|
|
34
35
|
# of doing this.
|
|
35
36
|
@dir.find do |file|
|
|
36
|
-
return true if file.stat.mtime >
|
|
37
|
+
return true if file.stat.mtime > @@last_built
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
false
|
|
@@ -42,22 +43,6 @@ class Flora::App
|
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
|
|
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_project
|
|
54
|
-
|
|
55
|
-
@app.call(env)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
|
|
61
46
|
# UGLY. Is there a better way to do this?
|
|
62
47
|
class StaticWithoutHtml
|
|
63
48
|
|
|
@@ -84,7 +69,6 @@ class Flora::App
|
|
|
84
69
|
|
|
85
70
|
Rack::Builder.new do
|
|
86
71
|
use Rebuilder, path, flora
|
|
87
|
-
use Reloader, flora
|
|
88
72
|
use StaticWithoutHtml, OUT_DIR
|
|
89
73
|
use Rack::Static, urls: [''], root: OUT_DIR, index: 'index.html'
|
|
90
74
|
|
data/lib/flora/factory.rb
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# Factories assemble Projects into Websites.
|
|
2
2
|
class Flora::Factory
|
|
3
3
|
|
|
4
|
-
def initialize(project, config)
|
|
4
|
+
def initialize(project, config, logger)
|
|
5
5
|
@project = project
|
|
6
6
|
@config = config
|
|
7
|
+
@logger = logger
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
|
|
@@ -15,6 +16,8 @@ class Flora::Factory
|
|
|
15
16
|
out_filename = out_dir.join(blueprint.page_name)
|
|
16
17
|
FileUtils.mkdir_p(out_filename.dirname) unless out_filename.dirname.exist?
|
|
17
18
|
out_filename.write(blueprint.render)
|
|
19
|
+
|
|
20
|
+
@logger.debug("[Flora] #{blueprint.file} => #{out_filename}")
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
23
|
|
data/lib/flora/project.rb
CHANGED
|
@@ -14,14 +14,18 @@ class Flora::Project
|
|
|
14
14
|
@dir = dir
|
|
15
15
|
@loader = loader
|
|
16
16
|
@config = config
|
|
17
|
+
@mutex = Mutex.new
|
|
17
18
|
|
|
18
19
|
@blueprints = find_blueprints
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
def reload
|
|
23
|
-
|
|
24
|
-
@
|
|
24
|
+
# `flora serve` can sometimes hit this multiple times and cause errors.
|
|
25
|
+
@mutex.synchronize do
|
|
26
|
+
@loader.reload
|
|
27
|
+
@blueprints = find_blueprints
|
|
28
|
+
end
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
|
|
@@ -46,8 +50,4 @@ class Flora::Project
|
|
|
46
50
|
blueprints
|
|
47
51
|
end
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
def has_supporting_code?
|
|
51
|
-
end
|
|
52
|
-
|
|
53
53
|
end
|
data/lib/flora/version.rb
CHANGED
data/lib/flora.rb
CHANGED
|
@@ -2,15 +2,21 @@ require 'zeitwerk'
|
|
|
2
2
|
require 'nokogiri'
|
|
3
3
|
require 'kramdown'
|
|
4
4
|
require 'fileutils'
|
|
5
|
+
require 'logger'
|
|
5
6
|
|
|
6
7
|
loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
|
|
7
8
|
loader.setup
|
|
8
9
|
|
|
9
10
|
class Flora
|
|
10
11
|
|
|
12
|
+
attr_writer(:logger)
|
|
13
|
+
|
|
14
|
+
|
|
11
15
|
def initialize(dir)
|
|
12
16
|
dir = Pathname.new(dir)
|
|
13
17
|
|
|
18
|
+
@logger = Logger.new(STDOUT, level: ENV['FLORA_LOG'] || 'info')
|
|
19
|
+
|
|
14
20
|
# Inject Lilac into the Kernel so it's available everywhere. Just
|
|
15
21
|
# instance_eval isn't enough because it'll be missing in lib/ code.
|
|
16
22
|
#
|
|
@@ -34,17 +40,23 @@ class Flora
|
|
|
34
40
|
|
|
35
41
|
@config = @config_class.new(dir.join('_config.rb'), self)
|
|
36
42
|
@project = @project_class.new(dir, @project_loader, @config)
|
|
37
|
-
@factory = @factory_class.new(@project, @config)
|
|
43
|
+
@factory = @factory_class.new(@project, @config, @logger)
|
|
38
44
|
end
|
|
39
45
|
|
|
40
46
|
|
|
41
47
|
def build(out)
|
|
42
|
-
|
|
48
|
+
duration = bench do
|
|
49
|
+
@factory.assemble(Pathname.new(out))
|
|
50
|
+
end
|
|
51
|
+
@logger.info("[Flora] Built project (#{duration}s)")
|
|
43
52
|
end
|
|
44
53
|
|
|
45
54
|
|
|
46
55
|
def reload_project
|
|
47
|
-
|
|
56
|
+
duration = bench do
|
|
57
|
+
@project.reload
|
|
58
|
+
end
|
|
59
|
+
@logger.info("[Flora] Reloaded project (#{duration}s)")
|
|
48
60
|
end
|
|
49
61
|
|
|
50
62
|
|
|
@@ -58,6 +70,15 @@ class Flora
|
|
|
58
70
|
Flora::Project::Blueprint.include(mod::BlueprintMethods) if defined?(mod::BlueprintMethods)
|
|
59
71
|
end
|
|
60
72
|
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def bench
|
|
77
|
+
now = Time.now.utc
|
|
78
|
+
yield
|
|
79
|
+
Time.now.utc - now
|
|
80
|
+
end
|
|
81
|
+
|
|
61
82
|
end
|
|
62
83
|
|
|
63
84
|
# Built-in Blueprints need to be explicitly loaded or else they won't show up
|
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
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nick Vladimiroff
|
|
@@ -121,6 +121,20 @@ dependencies:
|
|
|
121
121
|
- - ">="
|
|
122
122
|
- !ruby/object:Gem::Version
|
|
123
123
|
version: '0'
|
|
124
|
+
- !ruby/object:Gem::Dependency
|
|
125
|
+
name: logger
|
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
type: :runtime
|
|
132
|
+
prerelease: false
|
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
124
138
|
email:
|
|
125
139
|
- nickvladimiroff@hey.com
|
|
126
140
|
executables:
|