Class: Pageflow::WidgetType

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/widget_type.rb

Direct Known Subclasses

BuiltInWidgetType, Null

Defined Under Namespace

Classes: NotFoundError, Null

Instance Method Summary collapse

Instance Method Details

#enabled_in_editor?Boolean

Override to return false to hide widget in editor.

Returns:

  • (Boolean)


22
23
24
# File 'lib/pageflow/widget_type.rb', line 22

def enabled_in_editor?
  true
end

#enabled_in_preview?Boolean

Override to return false to hide widget in entry preview.

Returns:

  • (Boolean)


27
28
29
# File 'lib/pageflow/widget_type.rb', line 27

def enabled_in_preview?
  true
end

#insert_pointObject

Point in DOM where widget should be inserted. Possible values are ‘:bottom_of_entry` (default) or `:before_entry`.

Since:

  • 13.0



35
36
37
# File 'lib/pageflow/widget_type.rb', line 35

def insert_point
  :bottom_of_entry
end

#nameObject

Override to return a string in snake_case.

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/pageflow/widget_type.rb', line 12

def name
  raise(NotImplementedError, 'WidgetType subclass needs to define name method.')
end

#render(template, entry) ⇒ Object

Override to return html as string.



46
47
48
# File 'lib/pageflow/widget_type.rb', line 46

def render(template, entry)
  template.render(File.join('pageflow', name, 'widget'), entry: entry)
end

#render_head_fragment(template, entry) ⇒ Object

Override to return html that should be placed in the head element of the page. Not supported inside the editor.



59
60
61
# File 'lib/pageflow/widget_type.rb', line 59

def render_head_fragment(template, entry)
  ''
end

#render_head_fragment_with_configuration(template, entry, _configuration) ⇒ Object

Override instead of render_head_fragment to use the widget configuration. Return html as string that should be placed in the head element of the page.



53
54
55
# File 'lib/pageflow/widget_type.rb', line 53

def render_head_fragment_with_configuration(template, entry, _configuration)
  render_head_fragment(template, entry)
end

#render_with_configuration(template, entry, _configuration) ⇒ Object

Override instead of render to use the widget configuration. Return html as string.



41
42
43
# File 'lib/pageflow/widget_type.rb', line 41

def render_with_configuration(template, entry, _configuration)
  render(template, entry)
end

#rolesObject

Override to return array of role names.

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/pageflow/widget_type.rb', line 17

def roles
  raise(NotImplementedError, 'WidgetType subclass needs to define roles method.')
end

#translation_keyObject

Name to display in editor.



7
8
9
# File 'lib/pageflow/widget_type.rb', line 7

def translation_key
  "pageflow.#{name}.widget_type_name"
end