class PORTL::Engine

Attributes

data[R]
options[R]
output_buffer[RW]
scope[R]

Public Class Methods

new(data, scope=nil, options={}) click to toggle source
# 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

Public Instance Methods

html_tag(tag, *args, &block) click to toggle source

Creates an HTML tag.

@param [Symbol] tag The tag to generate. @param [*Array] args Arguments to pass to the Rails ‘content_tag` helper. @param [&Proc] block Code to render inside of the tag. @param [ActionView::OutputBuffer] The updated buffer.

# 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 << content_tag(tag, *args, &block)
  end
end
result() click to toggle source

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

@return [String] The result of the compiled code.

# File lib/portl/engine.rb, line 18
def result
  eval(data)
end
text(value) click to toggle source

Adds plain text to the output buffer.

@param [String] value The text to add. @return [ActionView::OutputBuffer] The updated buffer.

# File lib/portl/engine.rb, line 40
def text(value)
  output_buffer << raw(value)
end