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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a9220176669d7089cdf418e72f2694c9155ac9f4f1e7221396cbc313b1b311b
4
- data.tar.gz: 3062475cca120f2246d75ae857c229bbd417d00cd106faaee1ed0c82c52f8535
3
+ metadata.gz: 7be307969fab3a27723edc33011ed4c014d156f30d5c4fdae7ef3835afcb32c4
4
+ data.tar.gz: 578b5c36886e86b9862a318397f9c7b33ab2db00769364c40e86cc12a7f5d061
5
5
  SHA512:
6
- metadata.gz: 60827cee11a1dff53cc072b97d23354ec1df9770fd91df71898caa2824b4cdfbcbe5ada7c5ec5631284fe89c0d21f2f9625c8cfeecf129bc12df96b52c1564bb
7
- data.tar.gz: 39aeb57d0c7c60dd8486f698d02baccddda67ace4f0dacb1b1378ac7fc530d7f307b2b9c585d054376267ee236b94656a2ec2a3603dcfa0a4372784da487ca96
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
- puts "converting #{page.path} => #{page.dirname}/#{page.new_name}"
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: "(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
- @template.render(Edward::RenderContext.new(self), nil, &@block)
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(Edward::RenderContext.new(self), nil, &inner_block) }
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
@@ -1,4 +1,4 @@
1
- # generated with rake release[0.4.0]
1
+ # generated with rake release[0.5.0]
2
2
  module Edward
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
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.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rein Fernhout