Class: PORTL::Engine

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/portl/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, scope = nil, options = {}) ⇒ Engine

Returns a new instance of Engine.



8
9
10
11
12
13
# File 'lib/portl/engine.rb', line 8

def initialize(data, scope=nil, options={})
  @data = data
  @scope = scope
  @options = options
  @output_buffer = ActionView::OutputBuffer.new
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/portl/engine.rb', line 4

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/portl/engine.rb', line 4

def options
  @options
end

#output_bufferObject

Returns the value of attribute output_buffer.



6
7
8
# File 'lib/portl/engine.rb', line 6

def output_buffer
  @output_buffer
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/portl/engine.rb', line 4

def scope
  @scope
end

Instance Method Details

#html_tag(tag, *args, &block) ⇒ Object

Creates an HTML tag.

Parameters:

  • tag (Symbol)

    The tag to generate.

  • args (*Array)

    Arguments to pass to the Rails ‘content_tag` helper.

  • block (&Proc)

    Code to render inside of the tag.

  • The (ActionView::OutputBuffer)

    updated buffer.



28
29
30
31
32
33
34
# File 'lib/portl/engine.rb', line 28

def html_tag(tag, *args, &block)
  if PORTL::HTML::NON_CLOSING_TAGS.include?(tag)
    output_buffer << raw("<#{tag}#{tag_options(args[0], true)}>")
  else
    output_buffer << (tag, *args, &block)
  end
end

#resultString

Compiles the data within the supplied scope and returns the result.

Returns:

  • (String)

    The result of the compiled code.



18
19
20
# File 'lib/portl/engine.rb', line 18

def result
  eval(data)
end

#text(value) ⇒ ActionView::OutputBuffer

Adds plain text to the output buffer.

Parameters:

  • value (String)

    The text to add.

Returns:

  • (ActionView::OutputBuffer)

    The updated buffer.



40
41
42
# File 'lib/portl/engine.rb', line 40

def text(value)
  output_buffer << raw(value)
end