flora 0.9.1 → 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/README.md +7 -4
- data/lib/flora/app.rb +4 -20
- data/lib/flora/config.rb +6 -1
- data/lib/flora/factory.rb +4 -1
- data/lib/flora/project.rb +8 -16
- data/lib/flora/version.rb +1 -1
- data/lib/flora.rb +33 -4
- 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/README.md
CHANGED
|
@@ -33,10 +33,10 @@ Lilac is Flora's DSL for writing HTML. Tags are just methods named the same as t
|
|
|
33
33
|
Looking for a way to make reusable components? Write a function! For example:
|
|
34
34
|
|
|
35
35
|
```ruby
|
|
36
|
-
# lib/
|
|
37
|
-
|
|
36
|
+
# lib/my_helpers.rb
|
|
37
|
+
module MyHelpers
|
|
38
38
|
|
|
39
|
-
def
|
|
39
|
+
def cool_title(text)
|
|
40
40
|
div(class: 'title') do
|
|
41
41
|
h1 do
|
|
42
42
|
text
|
|
@@ -46,10 +46,13 @@ class CoolTitle
|
|
|
46
46
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
# _config.rb
|
|
50
|
+
extend_view(MyHelpers)
|
|
51
|
+
|
|
49
52
|
# index.rb
|
|
50
53
|
html do
|
|
51
54
|
body do
|
|
52
|
-
|
|
55
|
+
cool_title('My blog')
|
|
53
56
|
end
|
|
54
57
|
end
|
|
55
58
|
```
|
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/config.rb
CHANGED
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
|
@@ -10,25 +10,22 @@ class Flora::Project
|
|
|
10
10
|
IGNORES = ['.git/*', 'lib/**', '**_*.rb']
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
def initialize(dir, config)
|
|
13
|
+
def initialize(dir, loader, config)
|
|
14
14
|
@dir = dir
|
|
15
|
+
@loader = loader
|
|
15
16
|
@config = config
|
|
17
|
+
@mutex = Mutex.new
|
|
16
18
|
|
|
17
19
|
@blueprints = find_blueprints
|
|
18
|
-
|
|
19
|
-
@loader = Zeitwerk::Loader.new
|
|
20
|
-
if has_supporting_code?
|
|
21
|
-
@loader.push_dir(@dir.join('lib').to_s)
|
|
22
|
-
end
|
|
23
|
-
@loader.enable_reloading
|
|
24
|
-
@loader.setup
|
|
25
|
-
@loader.eager_load
|
|
26
20
|
end
|
|
27
21
|
|
|
28
22
|
|
|
29
23
|
def reload
|
|
30
|
-
|
|
31
|
-
@
|
|
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
|
|
32
29
|
end
|
|
33
30
|
|
|
34
31
|
|
|
@@ -53,9 +50,4 @@ class Flora::Project
|
|
|
53
50
|
blueprints
|
|
54
51
|
end
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
def has_supporting_code?
|
|
58
|
-
@dir.join('lib').exist?
|
|
59
|
-
end
|
|
60
|
-
|
|
61
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
|
#
|
|
@@ -24,19 +30,33 @@ class Flora
|
|
|
24
30
|
@project_class = Class.new(Project)
|
|
25
31
|
@factory_class = Class.new(Factory)
|
|
26
32
|
|
|
33
|
+
# This has to be loaded before Config so Config can reference lib/ code.
|
|
34
|
+
@project_loader = Zeitwerk::Loader.new
|
|
35
|
+
if dir.join('lib').exist?
|
|
36
|
+
@project_loader.push_dir(dir.join('lib'))
|
|
37
|
+
end
|
|
38
|
+
@project_loader.enable_reloading
|
|
39
|
+
@project_loader.setup
|
|
40
|
+
|
|
27
41
|
@config = @config_class.new(dir.join('_config.rb'), self)
|
|
28
|
-
@project = @project_class.new(dir, @config)
|
|
29
|
-
@factory = @factory_class.new(@project, @config)
|
|
42
|
+
@project = @project_class.new(dir, @project_loader, @config)
|
|
43
|
+
@factory = @factory_class.new(@project, @config, @logger)
|
|
30
44
|
end
|
|
31
45
|
|
|
32
46
|
|
|
33
47
|
def build(out)
|
|
34
|
-
|
|
48
|
+
duration = bench do
|
|
49
|
+
@factory.assemble(Pathname.new(out))
|
|
50
|
+
end
|
|
51
|
+
@logger.info("[Flora] Built project (#{duration}s)")
|
|
35
52
|
end
|
|
36
53
|
|
|
37
54
|
|
|
38
55
|
def reload_project
|
|
39
|
-
|
|
56
|
+
duration = bench do
|
|
57
|
+
@project.reload
|
|
58
|
+
end
|
|
59
|
+
@logger.info("[Flora] Reloaded project (#{duration}s)")
|
|
40
60
|
end
|
|
41
61
|
|
|
42
62
|
|
|
@@ -50,6 +70,15 @@ class Flora
|
|
|
50
70
|
Flora::Project::Blueprint.include(mod::BlueprintMethods) if defined?(mod::BlueprintMethods)
|
|
51
71
|
end
|
|
52
72
|
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def bench
|
|
77
|
+
now = Time.now.utc
|
|
78
|
+
yield
|
|
79
|
+
Time.now.utc - now
|
|
80
|
+
end
|
|
81
|
+
|
|
53
82
|
end
|
|
54
83
|
|
|
55
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:
|