Sha256: 03b4486de49bda02ab6ff357a24b831312a3a66e2c400798118d7d2d3aa60924

Contents?: true

Size: 1.22 KB

Versions: 24

Compression:

Stored size: 1.22 KB

Contents

module Pageflow
  class WidgetType
    # Name to display in editor.
    def translation_key
      "pageflow.#{name}.widget_type_name"
    end

    # Override to return a string in snake_case.
    def name
      raise(NotImplementedError, 'WidgetType subclass needs to define name method.')
    end

    # Override to return array of role names.
    def roles
      raise(NotImplementedError, 'WidgetType subclass needs to define roles method.')
    end

    # Override to return false to hide widget in editor.
    def enabled_in_editor?
      true
    end

    # Override to return false to hide widget in entry preview.
    def enabled_in_preview?
      true
    end

    # Override to return html as string.
    def render(template, entry)
      template.render(File.join('pageflow', name, 'widget'), entry: entry)
    end

    # Override to return html that should be placed in the head
    # element of the page. Not supported inside the editor.
    def render_head_fragment(template, entry)
      ''
    end

    class Null < WidgetType
      def initialize(role)
        @role = role
      end

      def name
        'null'
      end

      def roles
        [@role]
      end

      def render(*)
        ''
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
pageflow-12.0.4 lib/pageflow/widget_type.rb
pageflow-12.0.3 lib/pageflow/widget_type.rb
pageflow-12.0.2 lib/pageflow/widget_type.rb
pageflow-12.0.1 lib/pageflow/widget_type.rb
pageflow-12.0.0 lib/pageflow/widget_type.rb
pageflow-12.0.0.rc7 lib/pageflow/widget_type.rb
pageflow-12.0.0.rc6 lib/pageflow/widget_type.rb
pageflow-0.11.4 lib/pageflow/widget_type.rb
pageflow-12.0.0.rc5 lib/pageflow/widget_type.rb
pageflow-12.0.0.rc4 lib/pageflow/widget_type.rb
pageflow-12.0.0.rc3 lib/pageflow/widget_type.rb
pageflow-12.0.0.rc2 lib/pageflow/widget_type.rb
pageflow-12.0.0.rc1 lib/pageflow/widget_type.rb
pageflow-0.11.3 lib/pageflow/widget_type.rb
pageflow-0.11.2 lib/pageflow/widget_type.rb
pageflow-0.11.1 lib/pageflow/widget_type.rb
pageflow-0.11.0 lib/pageflow/widget_type.rb
pageflow-0.10.0 lib/pageflow/widget_type.rb
pageflow-0.9.2 lib/pageflow/widget_type.rb
pageflow-0.9.1 lib/pageflow/widget_type.rb