Class: Frontman::Context

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
ForwardCallsToApp
Defined in:
lib/frontman/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ForwardCallsToApp

included, #method_missing, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Frontman::ForwardCallsToApp

Instance Attribute Details

#buffer_hashObject (readonly)

Returns the value of attribute buffer_hash.



15
16
17
# File 'lib/frontman/context.rb', line 15

def buffer_hash
  @buffer_hash
end

Instance Method Details

#append_content(key, content = nil, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/frontman/context.rb', line 50

def append_content(key, content = nil, &block)
  content = get_content_buffer(content, &(block if block_given?))

  # We store the the content block inside the current page
  # because we don't know which renderer/layout/template will need it
  current_page = Frontman::App.instance.current_page

  return if current_page.nil?

  key = key.to_sym
  current_page.content_blocks[key] ||= ''
  if current_page.content_blocks[key].frozen?
    current_page.content_blocks[key] = current_page.content_blocks[key].dup
  end

  current_page.content_blocks[key].concat(content)
end

#content_for(key, content = nil, &block) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/frontman/context.rb', line 34

def content_for(key, content = nil, &block)
  content = get_content_buffer(content, &(block if block_given?))

  # We store the the content block inside the current page
  # because we don't know which renderer/layout/template will need it
  current_page = Frontman::App.instance.current_page
  current_page.content_blocks[key.to_sym] = content unless current_page.nil?
end

#content_for?(key) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/frontman/context.rb', line 69

def content_for?(key)
  Frontman::App.instance.current_page.content_blocks.key?(key.to_sym)
end

#get_binding(&content) ⇒ Object



83
84
85
# File 'lib/frontman/context.rb', line 83

def get_binding(&content)
  binding { content }
end

#wrap_layout(layout, &block) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/frontman/context.rb', line 18

def wrap_layout(layout, &block)
  layout_dir = Frontman::Config.get(:layout_dir, fallback: 'views/layouts')
  layout_path = File.join(layout_dir, layout)

  content = get_content_buffer(nil, &block)

  Resource.from_path(layout_path, nil, false).render(content)
end

#yield_content(key, *_args) ⇒ Object



76
77
78
# File 'lib/frontman/context.rb', line 76

def yield_content(key, *_args)
  Frontman::App.instance.current_page.content_blocks[key.to_sym]
end