Class: Rbexy::Runtime

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers::TagHelper, ComponentContext, ViewContextHelper
Defined in:
lib/rbexy/runtime.rb

Constant Summary collapse

DefaultTagBuilder =
ActionView::Helpers::TagHelper::TagBuilder

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ComponentContext

#create_context, #rbexy_context, #use_context

Methods included from ViewContextHelper

#rbexy_is_html_safe_array?, #rbexy_prep_output, #rbexy_tag

Constructor Details

#initialize(component_provider = nil) ⇒ Runtime

Returns a new instance of Runtime.



33
34
35
# File 'lib/rbexy/runtime.rb', line 33

def initialize(component_provider = nil)
  @rbexy_tag = self.class.create_tag_builder(self, component_provider)
end

Class Method Details

.create_tag_builder(context, provider = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rbexy/runtime.rb', line 15

def self.create_tag_builder(context, provider = nil)
  provider = provider ||
    provider_from_context(context) ||
    Rbexy.configuration.component_provider

  if provider
    ComponentTagBuilder.new(context, provider)
  else
    ActionView::Helpers::TagHelper::TagBuilder.new(context)
  end
end

.provider_from_context(context) ⇒ Object



27
28
29
30
31
# File 'lib/rbexy/runtime.rb', line 27

def self.provider_from_context(context)
  if context.respond_to?(:rbexy_component_provider)
    context.rbexy_component_provider
  end
end

Instance Method Details

#evaluate(code) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rbexy/runtime.rb', line 37

def evaluate(code)
  @output_buffer = ActionView::OutputBuffer.new
  instance_eval(code)
rescue => e
  e.set_backtrace(e.backtrace.map { |l| l.gsub("(eval)", "(rbx template string)") })
  raise e
end