frontman-ssg 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d044410bb8578a36c2876cf887a9e807053864fd28045c1bc92e4ecce769f49b
4
- data.tar.gz: 0e9400d87ef35ab925d80cc05b4ba9b122ab52d5c280ddb6a39ffb9b9c76c48e
3
+ metadata.gz: cee9b32f2e8bdbabfe4df7f7990312e7339d20c75b69a17b352f7b9a61f9b2b8
4
+ data.tar.gz: 73732a4d6061cf78465def47985914b210bf5f040f373e5b036ea5175868da52
5
5
  SHA512:
6
- metadata.gz: c54550757e0312a3f7e9051a37bb173f98c120f76b75b99b7634383ba687e5977dfd0bf8c82ecacfecf28e998742aa9c3459172086c734fba3287b1868176d4e
7
- data.tar.gz: b89cf82a4807cd97ce05e2a569afe1b6a92266d2aca5c942c68ba5360ac8ecf1419400526fd3955e9575670f48d3b5b57dd177117daf5fe1da8703faf36cb1ee
6
+ metadata.gz: b69ec17dee440b638399678de811876a351df133da02e4589b1df7117544b9822be6e1d8068798b19bc05b7911f85960aeaaeba4d2b51d8fc97bf4f0127daa49
7
+ data.tar.gz: dbce1d0412b30a5aaf46b01e01a833c8703d0b77b14f24e665a2c3bf058d9cf3861d23b7ea9a58603beb63c933e59e8afffb98378c0b9cc8ea1f22e949d4f477
@@ -29,6 +29,8 @@ Metrics/MethodLength:
29
29
  - 'lib/frontman/builder/builder.rb'
30
30
  - 'lib/frontman/commands/**/*'
31
31
  - 'lib/frontman/resource.rb'
32
+ - 'lib/frontman/context.rb'
33
+ - 'lib/frontman/helpers/render_helper.rb'
32
34
 
33
35
  Metrics/AbcSize:
34
36
  Exclude:
@@ -5,7 +5,11 @@ We document all notable changes to the project in the file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [semantic versioning](http://semver.org/).
6
6
 
7
7
  # Release Notes
8
- ## [Unreleased](https://github.com/algolia/frontman/compare/0.1.0...master)
8
+ ## [Unreleased](https://github.com/algolia/frontman/compare/0.1.1...master)
9
+
10
+ ## [0.1.1](https://github.com/algolia/frontman/tree/0.1.1) - 2021-01-05
11
+ ### Fixed
12
+ * Empty buffer bug when using a nested `content_for` block in HAML templates ([`#43`](https://github.com/algolia/frontman/pull/43))
9
13
 
10
14
  ## [0.1.0](https://github.com/algolia/frontman/tree/0.1.0) - 2021-01-05
11
15
 
@@ -4,6 +4,7 @@
4
4
  require 'frontman/app'
5
5
  require 'frontman/concerns/forward_calls_to_app'
6
6
  require 'frontman/config'
7
+ require 'securerandom'
7
8
  require 'sorbet-runtime'
8
9
 
9
10
  module Frontman
@@ -11,6 +12,8 @@ module Frontman
11
12
  extend T::Sig
12
13
  include Frontman::ForwardCallsToApp
13
14
 
15
+ attr_reader :buffer_hash
16
+
14
17
  sig { params(layout: String, block: T.proc.void).returns(String) }
15
18
  def wrap_layout(layout, &block)
16
19
  layout_dir = Frontman::Config.get(:layout_dir, fallback: 'views/layouts')
@@ -113,6 +116,9 @@ module Frontman
113
116
 
114
117
  sig { params(content: T.untyped).returns(String) }
115
118
  def get_content_buffer(content)
119
+ @parent_hash = @buffer_hash || nil
120
+ @buffer_hash = SecureRandom.hex
121
+
116
122
  # Haml is not designed to do handle wrap_layout properly so we need to
117
123
  # hack the buffer of haml that is set inside the context by haml
118
124
  save_buffer
@@ -130,6 +136,8 @@ module Frontman
130
136
  # Restore the buffer so the rendering of the file can continue
131
137
  restore_buffer
132
138
 
139
+ @buffer_hash = @parent_hash
140
+
133
141
  content
134
142
  end
135
143
  end
@@ -22,7 +22,17 @@ module RenderHelper
22
22
  r = Frontman::Resource.from_path(
23
23
  File.join(partial_dir, template), nil, false
24
24
  )
25
- r.render(nil, data)
25
+
26
+ # While rendering, if there's no current page we set it to to the resource
27
+ # This allows using `content_for` directives in partials
28
+ current_page = Frontman::App.instance.current_page
29
+ Frontman::App.instance.current_page = r if current_page.nil?
30
+
31
+ content = r.render(nil, data)
32
+
33
+ Frontman::App.instance.current_page = current_page
34
+
35
+ content
26
36
  end
27
37
 
28
38
  sig do
@@ -6,6 +6,11 @@ require 'frontman/renderers/renderer'
6
6
 
7
7
  module Frontman
8
8
  class ErbRenderer < Frontman::Renderer
9
+ def initialize
10
+ @buffer = {}
11
+ super
12
+ end
13
+
9
14
  def compile(layout)
10
15
  Erubis::Eruby.new(layout, bufvar: '@_erbout')
11
16
  end
@@ -23,13 +28,15 @@ module Frontman
23
28
 
24
29
  return unless buffer
25
30
 
26
- @buffer = buffer
31
+ @buffer[context.buffer_hash] = buffer
27
32
  context.instance_variable_set(:@_erbout, '')
28
33
  end
29
34
 
30
35
  def restore_buffer(context)
31
- context.instance_variable_set(:@_erbout, @buffer) if @buffer
32
- @buffer = nil
36
+ return unless @buffer[context.buffer_hash]
37
+
38
+ context.instance_variable_set(:@_erbout, @buffer[context.buffer_hash])
39
+ @buffer.delete(context.buffer_hash)
33
40
  end
34
41
 
35
42
  def load_buffer(context)
@@ -8,6 +8,7 @@ module Frontman
8
8
  class HamlRenderer < Renderer
9
9
  def initialize
10
10
  Haml::Options.defaults[:format] = :html5
11
+ @buffer = {}
11
12
  super
12
13
  end
13
14
 
@@ -26,12 +27,11 @@ module Frontman
26
27
  end
27
28
 
28
29
  def save_buffer(context)
29
- @buffer = nil
30
30
  haml_locals = context.instance_variable_get(:@_haml_locals)
31
31
 
32
32
  return unless haml_locals
33
33
 
34
- @buffer = haml_locals[:_hamlout].buffer
34
+ @buffer[context.buffer_hash] = haml_locals[:_hamlout].buffer
35
35
  # empty the buffer so we can capture everything from the new render
36
36
  haml_locals[:_hamlout].buffer = ''
37
37
  context.instance_variable_set(:@_haml_locals, haml_locals)
@@ -42,9 +42,9 @@ module Frontman
42
42
 
43
43
  return unless haml_locals
44
44
 
45
- haml_locals[:_hamlout].buffer = @buffer
45
+ haml_locals[:_hamlout].buffer = @buffer[context.buffer_hash]
46
46
  context.instance_variable_set(:@_haml_locals, haml_locals)
47
- @buffer = nil
47
+ @buffer.delete(context.buffer_hash)
48
48
  end
49
49
  end
50
50
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Frontman
4
4
  # Current Version
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
@@ -20,7 +20,7 @@ describe Frontman::Bootstrapper do
20
20
  it 'should find all resources in a given folder' do
21
21
  resources = Frontman::Bootstrapper.resources_from_dir('spec/frontman/mocks')
22
22
 
23
- expect(resources.size).to eq 16 # Number of non-YAML files in this folder
23
+ expect(resources.size).to eq 17 # Number of non-YAML files in this folder
24
24
  end
25
25
  end
26
26
  end
@@ -38,6 +38,13 @@ describe RenderHelper do
38
38
  expect(subject.partial('paragraph.haml', text: 'Testing'))
39
39
  .to eq("<p>\nThe passed text: Testing\n</p>\n")
40
40
  end
41
+
42
+ it 'should handle content_for in partials' do
43
+ Frontman::Config.set(:partial_dir, 'spec/frontman/mocks/partials')
44
+
45
+ expect(subject.partial('content_for.haml'))
46
+ .to eq("<ul>\n<li>\nNested `content_for` block\n\n</li>\n\n<li>\nThis is a test!\n</li>\n</ul>\n")
47
+ end
41
48
  end
42
49
 
43
50
  context 'render page' do
@@ -0,0 +1,10 @@
1
+ - content_for :test_data do
2
+ - content_for :item_text do
3
+ Nested `content_for` block
4
+ %li
5
+ = yield_content :item_text
6
+
7
+ %ul
8
+ = yield_content :test_data
9
+ %li
10
+ This is a test!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frontman-ssg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devin Beeuwkes
@@ -529,6 +529,7 @@ files:
529
529
  - spec/frontman/mocks/layouts/raw_without_body.haml
530
530
  - spec/frontman/mocks/nested/data.yml
531
531
  - spec/frontman/mocks/nested/more_data.yml
532
+ - spec/frontman/mocks/partials/content_for.haml
532
533
  - spec/frontman/mocks/partials/paragraph.haml
533
534
  - spec/frontman/mocks/snippet/html_file.html
534
535
  - spec/frontman/mocks/snippet/html_file.yml