Class: Vapid::Directive

Inherits:
Object show all
Includes:
Padrino::Helpers::TagHelpers
Defined in:
lib/vapid/directive.rb

Overview

Base class for directives

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression) ⇒ Directive

Returns a new instance of Directive.



107
108
109
# File 'lib/vapid/directive.rb', line 107

def initialize(expression)
  parse_expression(expression)
end

Instance Attribute Details

#subjectObject (readonly)

Returns the value of attribute subject.



13
14
15
# File 'lib/vapid/directive.rb', line 13

def subject
  @subject
end

Class Method Details

.destroyable?Boolean

Whether the directive can be destroyed (usually via a checkbox).

Returns:

  • (Boolean)


38
39
40
# File 'lib/vapid/directive.rb', line 38

def destroyable?
  destroy
end

.modifies_content?Boolean

Whether the directive writes content to the database.

Returns:

  • (Boolean)


24
25
26
# File 'lib/vapid/directive.rb', line 24

def modifies_content?
  respond_to?(:form_field)
end

.previewable?Boolean

Whether the directive previews the content.

Returns:

  • (Boolean)


31
32
33
# File 'lib/vapid/directive.rb', line 31

def previewable?
  preview
end

.serialize_input(input) ⇒ String

Serializes input before it’s saved to the database

Returns:

  • (String)


45
46
47
# File 'lib/vapid/directive.rb', line 45

def serialize_input(input)
  input.to_s
end

Instance Method Details

#render(input = nil) ⇒ Object

Renders content

Parameters:

  • input (String) (defaults to: nil)

Returns:

  • (Object)

    a Nokogiri-friendly hash of modifiers, or the original input value



115
116
117
118
119
# File 'lib/vapid/directive.rb', line 115

def render(input = nil)
  @input = deserialize_input(input)
  apply_filters
  render_all
end