Class: Temple::Generators::ArrayBuffer

Inherits:
Array show all
Defined in:
lib/temple/generators/array_buffer.rb

Overview

Just like Array, but calls #join on the array.

_buf = []
_buf << "static"
_buf << dynamic
_buf.join("")

Direct Known Subclasses

StringBuffer

Constant Summary

Constants included from Utils

Utils::ESCAPE_HTML, Utils::ESCAPE_HTML_PATTERN

Instance Attribute Summary

Attributes included from Mixins::Options

#options

Instance Method Summary collapse

Methods inherited from Array

#create_buffer

Methods inherited from Temple::Generator

#create_buffer, #on, #on_capture, #on_code, #on_dynamic, #on_multi, #on_newline, #on_static, #postamble, #preamble, #restore_buffer, #save_buffer

Methods included from Mixins::Options

included, #initialize

Methods included from Mixins::CompiledDispatcher

#compile

Methods included from Utils

#empty_exp?, #escape_html, #escape_html_safe, #indent_dynamic, #unique_name

Instance Method Details

#call(exp) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/temple/generators/array_buffer.rb', line 13

def call(exp)
  case exp.first
  when :static
    [save_buffer, "#{buffer} = #{exp.last.inspect}", restore_buffer].compact.join('; ')
  when :dynamic
    [save_buffer, "#{buffer} = (#{exp.last}).to_s", restore_buffer].compact.join('; ')
  else
    super
  end
end

#return_bufferObject



24
25
26
27
# File 'lib/temple/generators/array_buffer.rb', line 24

def return_buffer
  freeze = options[:freeze_static] ? '.freeze' : ''
  "#{buffer} = #{buffer}.join(\"\"#{freeze})"
end