mr-edward 0.4.0 → 0.6.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 +26 -13
- data/src/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cba75b99f925e933379311f179ad9bfd42de5837b8f620adf73dd9a3a3790bbc
|
|
4
|
+
data.tar.gz: 527c2cc38460e315b16338b82e8bc7ffaeddf15afa0ab2b8e7f92a29903937b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e50f960d5ac335485ac800ede80e1835927e446bd389261857a2a5288408699957d2f137328d85ba94b2b18c47aee59528f28d1ee2786e8377ba0a1eed0770b
|
|
7
|
+
data.tar.gz: ff50d23ecaf57f3ad070924845f831dc848732133c3e1830c60a1a057a80864ddb4b29ea44debb0e61b43980259b93bba6291f0814a744a57ee9a50f53728ba3
|
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
|
@@ -17,21 +17,22 @@ module Edward
|
|
|
17
17
|
@template = Tilt[path].new(self[:options]) { @content }
|
|
18
18
|
add_layout(self[:layout]) if self[:layout]
|
|
19
19
|
end
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
# transform extensions from options to strings (for use in pipeline)
|
|
22
22
|
def transform_option_keys options
|
|
23
23
|
options&.transform_keys! { |k| Tilt.default_mapping.registered?(k.to_s) ? k.to_s : k }
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
# check if a file starts with yaml doc and can be mapped by tilt
|
|
27
27
|
def self.page? path
|
|
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
|
|
36
37
|
if content =~ YAML_FRONT_MATTER_REGEXP
|
|
37
38
|
yaml = YAML.safe_load(Regexp.last_match(1), symbolize_names: true, permitted_classes: [Symbol])
|
|
@@ -41,36 +42,48 @@ module Edward
|
|
|
41
42
|
[nil, content]
|
|
42
43
|
end
|
|
43
44
|
end
|
|
44
|
-
|
|
45
|
+
|
|
45
46
|
# wrap this page in a layout
|
|
46
47
|
def add_layout name
|
|
47
48
|
layout_path = "_layouts/#{name}"
|
|
48
49
|
yaml, content = Page.extract_front_matter(File.read(layout_path))
|
|
50
|
+
next_layout = yaml[:layout]
|
|
49
51
|
@yaml = yaml.deep_merge!(@yaml, knockout_prefix: "--") if yaml
|
|
50
52
|
transform_option_keys(self[:options])
|
|
51
53
|
inner_template = @template
|
|
52
54
|
inner_block = @block
|
|
53
|
-
@block = proc { inner_template.render(
|
|
55
|
+
@block = proc { |ctx| inner_template.render(ctx, nil, &inner_block) }
|
|
54
56
|
@template = Tilt[layout_path].new(self[:options]) { content }
|
|
57
|
+
add_layout(next_layout) if next_layout
|
|
55
58
|
end
|
|
56
|
-
|
|
59
|
+
|
|
57
60
|
def name
|
|
58
61
|
File.basename(@path)
|
|
59
62
|
end
|
|
60
|
-
|
|
63
|
+
|
|
61
64
|
# the name of the new file
|
|
62
65
|
def new_name
|
|
63
66
|
File.basename(@path, ".*")
|
|
64
67
|
end
|
|
65
|
-
|
|
68
|
+
|
|
66
69
|
def dirname
|
|
67
70
|
File.dirname(@path)
|
|
68
71
|
end
|
|
69
|
-
|
|
72
|
+
|
|
70
73
|
def new_path
|
|
71
74
|
"#{dirname}/#{new_name}"
|
|
72
75
|
end
|
|
73
|
-
|
|
76
|
+
|
|
77
|
+
# The directory name if new_name is index.html.
|
|
78
|
+
# Otherwise the full new path.
|
|
79
|
+
def href
|
|
80
|
+
if new_name == "index.html"
|
|
81
|
+
"/" + dirname
|
|
82
|
+
else
|
|
83
|
+
"/#{dirname}/#{new_name}"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
74
87
|
def tag? tag
|
|
75
88
|
@yaml&.dig(:tags)&.include? tag
|
|
76
89
|
end
|
|
@@ -78,6 +91,6 @@ module Edward
|
|
|
78
91
|
def [](*keys)
|
|
79
92
|
@yaml&.dig(*keys)
|
|
80
93
|
end
|
|
81
|
-
|
|
94
|
+
|
|
82
95
|
end
|
|
83
96
|
end
|
data/src/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mr-edward
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rein Fernhout
|
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
97
|
requirements: []
|
|
98
|
-
rubygems_version: 4.0.
|
|
98
|
+
rubygems_version: 4.0.6
|
|
99
99
|
specification_version: 4
|
|
100
100
|
summary: Statis site generator
|
|
101
101
|
test_files: []
|