mr-edward 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/src/builder.rb +14 -3
- data/src/context.rb +9 -3
- data/src/page.rb +14 -3
- data/src/version.rb +2 -2
- 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: 7be307969fab3a27723edc33011ed4c014d156f30d5c4fdae7ef3835afcb32c4
|
|
4
|
+
data.tar.gz: 578b5c36886e86b9862a318397f9c7b33ab2db00769364c40e86cc12a7f5d061
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7cd05155e1c21850e379f6425f2995f0bc8932d54f89bd7dd48c34e9959ded031d1c154152a97a8e7020b4f34062ccad79b76bad4472039a7e8d8de95227db53
|
|
7
|
+
data.tar.gz: 41310aedffa6129e459d55b898f2ecbdd21c3afb50e57e34c8e2355140cd371b92d4d5bf8c63c6f6ada87f1dc6b0b6ff23d3482074d2621b6bfba26fc7aa45a8
|
data/src/builder.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Edward
|
|
|
6
6
|
# Builds a website
|
|
7
7
|
class Builder
|
|
8
8
|
|
|
9
|
-
attr_reader :target
|
|
9
|
+
attr_reader :target, :pages
|
|
10
10
|
|
|
11
11
|
def initialize
|
|
12
12
|
@target = "_site"
|
|
@@ -21,9 +21,14 @@ module Edward
|
|
|
21
21
|
FileUtils.rm_r @target if File.exist? @target
|
|
22
22
|
FileUtils.mkdir_p @target
|
|
23
23
|
|
|
24
|
+
@pages = []
|
|
25
|
+
|
|
24
26
|
Dir.glob("**/*") do |path|
|
|
25
27
|
visit_file path if visit_file?(path)
|
|
26
28
|
end
|
|
29
|
+
|
|
30
|
+
write_pages
|
|
31
|
+
|
|
27
32
|
end
|
|
28
33
|
|
|
29
34
|
def visit_file? path
|
|
@@ -37,14 +42,20 @@ module Edward
|
|
|
37
42
|
def visit_file path
|
|
38
43
|
if Page.page?(path)
|
|
39
44
|
page = Edward::Page.new(path)
|
|
40
|
-
|
|
45
|
+
@pages << page
|
|
41
46
|
FileUtils.mkdir_p "#{@target}/#{page.dirname}"
|
|
42
|
-
File.write("#{@target}/#{page.new_path}", page.render)
|
|
43
47
|
else
|
|
44
48
|
copy_plain path
|
|
45
49
|
end
|
|
46
50
|
end
|
|
47
51
|
|
|
52
|
+
def write_pages
|
|
53
|
+
for page in @pages
|
|
54
|
+
puts "converting #{page.path} => #{page.dirname}/#{page.new_name}"
|
|
55
|
+
File.write("#{@target}/#{page.new_path}", page.render(self))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
48
59
|
# simply copy the file
|
|
49
60
|
def copy_plain path
|
|
50
61
|
FileUtils.mkdir_p "#{@target}/#{File.dirname path}"
|
data/src/context.rb
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
module Edward
|
|
2
|
-
# Context for a template to run in
|
|
2
|
+
# Context for a template to run in.
|
|
3
|
+
# It has a reference to its page and the builder.
|
|
3
4
|
class RenderContext
|
|
4
|
-
def initialize page
|
|
5
|
+
def initialize page, builder
|
|
5
6
|
@page = page
|
|
7
|
+
@pages = builder.pages
|
|
6
8
|
end
|
|
7
9
|
|
|
10
|
+
def pages_with_tag tag
|
|
11
|
+
@pages.filter { it.tag? tag }
|
|
12
|
+
end
|
|
13
|
+
|
|
8
14
|
# Include a partial file.
|
|
9
15
|
# The file is searched for in _include,
|
|
10
16
|
# rendered and returned.
|
|
@@ -14,7 +20,7 @@ module Edward
|
|
|
14
20
|
def include file, locals = {}, &block
|
|
15
21
|
include_path = "_include/" + file
|
|
16
22
|
yaml, content = Page.extract_front_matter(File.read(include_path))
|
|
17
|
-
options = (yaml&.dig(:options) || {}).merge(fixed_locals: "(
|
|
23
|
+
options = (yaml&.dig(:options) || {}).merge(fixed_locals: "(local:)")
|
|
18
24
|
Tilt[include_path].new(options) { content }.render(self, { local: locals }, &block)
|
|
19
25
|
end
|
|
20
26
|
end
|
data/src/page.rb
CHANGED
|
@@ -28,8 +28,9 @@ module Edward
|
|
|
28
28
|
!Tilt.templates_for(path).empty? && YAML_FRONT_MATTER_REGEXP.match(File.read(path))
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def render
|
|
32
|
-
|
|
31
|
+
def render builder
|
|
32
|
+
ctx = Edward::RenderContext.new(self, builder)
|
|
33
|
+
@template.render(ctx, nil, &proc { @block.call(ctx) })
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
def self.extract_front_matter content
|
|
@@ -50,7 +51,7 @@ module Edward
|
|
|
50
51
|
transform_option_keys(self[:options])
|
|
51
52
|
inner_template = @template
|
|
52
53
|
inner_block = @block
|
|
53
|
-
@block = proc { inner_template.render(
|
|
54
|
+
@block = proc { |ctx| inner_template.render(ctx, nil, &inner_block) }
|
|
54
55
|
@template = Tilt[layout_path].new(self[:options]) { content }
|
|
55
56
|
end
|
|
56
57
|
|
|
@@ -71,6 +72,16 @@ module Edward
|
|
|
71
72
|
"#{dirname}/#{new_name}"
|
|
72
73
|
end
|
|
73
74
|
|
|
75
|
+
# The directory name if new_name is index.html.
|
|
76
|
+
# Otherwise the full new path.
|
|
77
|
+
def href
|
|
78
|
+
if new_name == "index.html"
|
|
79
|
+
dirname
|
|
80
|
+
else
|
|
81
|
+
"#{dirname}/#{new_name}"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
74
85
|
def tag? tag
|
|
75
86
|
@yaml&.dig(:tags)&.include? tag
|
|
76
87
|
end
|
data/src/version.rb
CHANGED