Module: Amrita2::Runtime

Overview

:nodoc:

Defined Under Namespace

Classes: Context

Instance Method Summary collapse

Instance Method Details

#context_stackObject



310
311
312
# File 'lib/amrita2/core.rb', line 310

def context_stack
  Thread::current[:amrita_context_stack] ||= [ Context.new ]
end

#current_contextObject



314
315
316
# File 'lib/amrita2/core.rb', line 314

def current_context
  context_stack.first
end

#end_tag(e, out = "") ⇒ Object



276
277
278
279
# File 'lib/amrita2/core.rb', line 276

def end_tag(e, out="")
  out << "</#{e.expanded_name}>"
  out
end

#get_bindingObject



357
358
359
# File 'lib/amrita2/core.rb', line 357

def get_binding
  current_context.current_binding 
end

#get_context_dataObject



365
366
367
# File 'lib/amrita2/core.rb', line 365

def get_context_data
  current_context.current_data
end

#get_mainstreamObject



338
339
340
# File 'lib/amrita2/core.rb', line 338

def get_mainstream
  current_context.main_stream
end

#get_substream(key) ⇒ Object



342
343
344
# File 'lib/amrita2/core.rb', line 342

def get_substream(key)
  current_context.sub_stream(key)
end

#new_binding(b, &block) ⇒ Object



330
331
332
# File 'lib/amrita2/core.rb', line 330

def new_binding(b, &block)
  new_context(nil, :binding => b, :inherit_sub_streams => true, &block)
end

#new_context(stream = "", opt = {}, &block) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
# File 'lib/amrita2/core.rb', line 318

def new_context(stream = "", opt = {}, &block)
  context_stack.unshift Context.new(stream, context_stack[0], opt)
  yield
  if stream.kind_of?(String)
    SanitizedString[stream]
  else
    stream
  end
ensure
  context_stack.shift
end

#new_context_data(d, &block) ⇒ Object



334
335
336
# File 'lib/amrita2/core.rb', line 334

def new_context_data(d, &block)
  new_context(nil, :data => d, :inherit_sub_streams => true, &block)
end

#new_element(tag, attrs = {}) ⇒ Object



257
258
259
260
261
262
263
# File 'lib/amrita2/core.rb', line 257

def new_element(tag, attrs={})
  ret = REXML::Element.new(tag.to_s)
  attrs.each do |k,v|
    ret.attributes[k.to_s] = v.to_s
  end
  ret
end

#output_substream(key) ⇒ Object



346
347
348
349
350
351
# File 'lib/amrita2/core.rb', line 346

def output_substream(key)
  c = current_context
  s = c.sub_stream(key)
  c.main_stream << SanitizedString[s]
  c.clear_substream(key)
end

#set_binding(b) ⇒ Object



353
354
355
# File 'lib/amrita2/core.rb', line 353

def set_binding(b)
  current_context.current_binding = b
end

#set_context_data(d) ⇒ Object



361
362
363
# File 'lib/amrita2/core.rb', line 361

def set_context_data(d)
  current_context.current_data = d
end

#start_tag(e, out = "") ⇒ Object



265
266
267
268
269
270
271
272
273
274
# File 'lib/amrita2/core.rb', line 265

def start_tag(e, out="")
  out << "<#{e.expanded_name}"
  e.attributes.each_attribute do |attr|
    next if attr.value == ""
    out << " "
    attr.write(out)  
  end unless e.attributes.empty?
  out << ">"
  out
end