Sha256: ab92096e074b20f82e844395feefacf9d757552b2b46fe35abd8297a8d0fdd3c
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
module Nyanko class Function attr_reader :block, :unit, :label class << self def units @units ||= [] end def current_unit units.last end end def initialize(unit, label, &block) @unit = unit @label = label @block = block end def invoke(context, options = {}) with_unit_stack(context) do with_unit_view_path(context) do capture_exception(context) do result = context.instance_eval(&block) result = decorate(result, context, options[:type]) if context.view? result end end end end def css_classes if Config.compatible_css_class %W[ extension ext_#{unit.unit_name} ext_#{unit.unit_name}-#{label} ] else %W[ unit unit__#{unit.unit_name} unit__#{unit.unit_name}__#{label} ] end end private def with_unit_stack(context) context.units << @unit self.class.units << @unit yield ensure self.class.units.pop context.units.pop end def with_unit_view_path(context) context.view_paths.unshift unit.resolver yield ensure context.view_paths.paths.shift end def capture_exception(context) yield rescue Exception => exception ExceptionHandler.handle(exception, unit) context.run_default end def decorate(str, context, type) case type when :plain str when :inline context.content_tag(:span, str, :class => css_classes) else context.content_tag(:div, str, :class => css_classes) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nyanko-0.0.8 | lib/nyanko/function.rb |