class Voom::Presenters::DSL::UserInterface

Attributes

components[R]
context[R]
name[R]
namespace[R]
params[R]
router[R]

Public Class Methods

new(context:, parent: nil, router: nil, name: nil, namespace: [], &block) click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 28
def initialize(context:, parent: nil, router: nil, name: nil, namespace: [], &block)
  @parent = parent
  @router = router || @parent&.send(:router)
  @context = context || {}
  @block = block
  @header = nil
  @drawer = nil
  @components = []
  @footer = nil
  @name = name
  @namespace = namespace
  @plugins = []
  @csrf_meta_tags = authenticity_token_meta_tags(@context.fetch(:session, nil))
  add_global_helpers
  initialize_plugins
end

Public Instance Methods

_plugins_()
Alias for: plugins
attach(presenter, **params, &yield_block) click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 73
def attach(presenter, **params, &yield_block)
  pom = super
  @header ||= pom.header
  @drawer ||= pom.drawer
  @footer ||= pom.footer
end
csrf_meta_tags() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 112
def csrf_meta_tags
  Presenters::Settings.config.presenters.web_client.protect_from_forgery ? @csrf_meta_tags : nil
end
drawer(name = nil, **attribs, &block) click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 56
def drawer(name = nil, **attribs, &block)
  return @drawer if locked?
  @drawer = Components::Drawer.new(parent: self, title: name,
                                   **attribs, &block)
end
expand_instance(freeze: true) click to toggle source

Called by the definition.expand method to evaluate a user interface with a different context This should be made unavailable to the dsl

# File lib/voom/presenters/dsl/user_interface.rb, line 82
def expand_instance(freeze: true)
  instance_eval(&@block)
  lock!
  deep_freeze if freeze
  self
end
header(title = nil, **attribs, &block) click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 50
def header(title = nil, **attribs, &block)
  return @header if locked?
  @header = Components::Header.new(parent: self, title: title,
                                   **attribs, &block)
end
page(title = nil, **attribs, &block) click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 45
def page(title = nil, **attribs, &block)
  return @page if locked?
  @page = Components::Page.new(parent: self, **attribs, &block)
end
plugin(*plugin_names) click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 101
def plugin(*plugin_names)
  @plugins.push(*plugin_names)
  self.class.include_plugins(:DSLComponents, :DSLHelpers, plugins: plugin_names)
end
plugins() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 106
def plugins
  return @plugins if locked?
  return @plugins if @plugins
end
Also aliased as: _plugins_
progress(**attributes, &block) click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 69
def progress(**attributes, &block)
  self << Components::Progress.new(parent: self, **attributes, &block)
end
type() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 97
def type
  :presenter
end
url(**context_) click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 89
def url(**context_)
  return '#' unless @router
  context = context_.dup
  link_to = context.delete(:link)
  post_to = context.delete(:command)
  @router.url(render: link_to, command: post_to, context: context)
end

Private Instance Methods

_helpers_() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 127
def _helpers_
  return @helpers if @helpers
end
add_global_helpers() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 136
def add_global_helpers
  Presenters::Settings.config.presenters.helpers.each do |helper|
    self.helpers(helper)
  end
end
deep_freeze() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 118
def deep_freeze
  IceNine.deep_freeze(self) if Presenters::Settings.config.presenters.deep_freeze
  self
end
initialize_plugins() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 142
def initialize_plugins
  self.class.include_plugins(:DSLComponents, :DSLHelpers, plugins: @plugins)
end
lock!() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 146
def lock!
  @locked = true
end
locked?() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 150
def locked?
  @locked
end
parent(for_type) click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 123
def parent(for_type)
  nil
end
yield_block() click to toggle source
# File lib/voom/presenters/dsl/user_interface.rb, line 131
def yield_block
  return @_yield_block_ if @_yield_block_
  @parent.send(:yield_block) if @parent
end