Class: Frontman::Context

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

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 Method Details

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



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

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



31
32
33
34
35
36
37
38
# File 'lib/frontman/context.rb', line 31

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)


66
67
68
# File 'lib/frontman/context.rb', line 66

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

#get_binding(&content) ⇒ Object



80
81
82
# File 'lib/frontman/context.rb', line 80

def get_binding(&content)
  binding { content }
end

#wrap_layout(layout, &block) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/frontman/context.rb', line 15

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



73
74
75
# File 'lib/frontman/context.rb', line 73

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