Class: Voom::Presenters::DSL::UserInterface

Constant Summary

Constants included from ProtectFromForgery

ProtectFromForgery::AUTHENTICITY_TOKEN_LENGTH

Instance Attribute Summary collapse

Attributes included from Components::Mixins::Event

#events

Instance Method Summary collapse

Methods included from Pluggable

include_plugins, plugin_module

Methods included from Serializer

#to_hash

Methods included from Components::Mixins::Event

#event

Methods included from Namespace

#_expand_namespace_

Methods included from Components::Mixins::DateTimeFields

#date_field, #datetime_field, #time_field

Methods included from Components::Mixins::TextFields

#hidden_field, #number_field, #rich_text_area, #text_area, #text_field

Methods included from Components::Mixins::Icons

#icon

Methods included from Components::Mixins::Snackbars

#snackbar

Methods included from Components::Mixins::Dialogs

#dialog

Methods included from Components::Mixins::Helpers

#helpers

Methods included from Components::Mixins::Common

#avatar, #badge, #card, #form, #list, #table, #unordered_list

Methods included from Components::Mixins::Tables

#table

Methods included from Components::Mixins::ImageLists

#image_list

Methods included from Components::Mixins::Images

#image

Methods included from Components::Mixins::TabBars

#tab_bar

Methods included from Components::Mixins::Menus

#menu

Methods included from Components::Mixins::Content

#content

Methods included from Components::Mixins::ExpansionPanels

#expansion_panel

Methods included from Components::Mixins::Buttons

#button

Methods included from Components::Mixins::Grids

#grid

Methods included from Components::Mixins::Typography

#blank, #body, #body2, #caption, #headline, #headline1, #headline2, #headline3, #headline4, #headline5, #headline6, #link, #overline, #page_title, #separator, #subtitle, #subtitle2, #text, #title

Methods included from Components::Mixins::Append

#<<, #yield_to

Methods included from Components::Mixins::Toggles

#checkbox, #icon_toggle, #radio_button, #switch

Methods included from ProtectFromForgery

#authenticity_token_meta_tags, #form_authenticity_token, #xor_byte_strings

Constructor Details

#initialize(context:, parent: nil, router: nil, name: nil, namespace: [], &block) ⇒ UserInterface

Returns a new instance of UserInterface.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



24
25
26
# File 'lib/voom/presenters/dsl/user_interface.rb', line 24

def components
  @components
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/voom/presenters/dsl/user_interface.rb', line 24

def name
  @name
end

Instance Method Details

#attach(presenter, **params, &yield_block) ⇒ Object



73
74
75
76
77
78
# 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_tagsObject



112
113
114
# 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) ⇒ Object



56
57
58
59
60
# 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) ⇒ Object

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



82
83
84
85
86
87
# 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


63
64
65
66
67
# File 'lib/voom/presenters/dsl/user_interface.rb', line 63

def footer(**attribs, &block)
  return @footer if locked?
  @footer = Components::Footer.new(parent: self,
                                   **attribs, &block)
end

#header(title = nil, **attribs, &block) ⇒ Object



50
51
52
53
54
# 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) ⇒ Object



45
46
47
48
# 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) ⇒ Object



101
102
103
104
# 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

#pluginsObject Also known as: _plugins_



106
107
108
109
# File 'lib/voom/presenters/dsl/user_interface.rb', line 106

def plugins
  return @plugins if locked?
  return @plugins if @plugins
end

#progress(**attributes, &block) ⇒ Object



69
70
71
# File 'lib/voom/presenters/dsl/user_interface.rb', line 69

def progress(**attributes, &block)
  self << Components::Progress.new(parent: self, **attributes, &block)
end

#typeObject



97
98
99
# File 'lib/voom/presenters/dsl/user_interface.rb', line 97

def type
  :presenter
end

#url(**context_) ⇒ Object



89
90
91
92
93
94
95
# 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