Module: VersatileRJS::Container

Included in:
Page, Proxy::EachProxy
Defined in:
lib/versatile_rjs/container.rb

Constant Summary collapse

DELIMITER_WITHOUT_NEW_LINE =
';'
DELIMITER_WITH_NEW_LINE =
DELIMITER_WITHOUT_NEW_LINE + "\n"

Instance Method Summary collapse

Instance Method Details

#add_statement(statement) ⇒ Object



12
13
14
# File 'lib/versatile_rjs/container.rb', line 12

def add_statement(statement)
  statements << statement
end

#statementsObject



8
9
10
# File 'lib/versatile_rjs/container.rb', line 8

def statements
  @statements ||= []
end

#to_script(with_new_line = false) ⇒ Object



16
17
18
19
20
21
# File 'lib/versatile_rjs/container.rb', line 16

def to_script(with_new_line = false)
  delimiter = with_new_line ? DELIMITER_WITH_NEW_LINE : DELIMITER_WITHOUT_NEW_LINE
  statement = statements.map(&:to_json).join(delimiter)
  statement += ';'
  statement_prefix(statement).to_s + statement + statement_suffix(statement).to_s
end