radius.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. require 'tilt/template'
  2. module Tilt
  3. # Radius Template
  4. # http://github.com/jlong/radius/
  5. class RadiusTemplate < Template
  6. def self.engine_initialized?
  7. defined? ::Radius
  8. end
  9. def self.context_class
  10. @context_class ||= Class.new(Radius::Context) do
  11. attr_accessor :tilt_scope
  12. def tag_missing(name, attributes)
  13. tilt_scope.__send__(name)
  14. end
  15. def dup
  16. i = super
  17. i.tilt_scope = tilt_scope
  18. i
  19. end
  20. end
  21. end
  22. def initialize_engine
  23. require_template_library 'radius'
  24. end
  25. def prepare
  26. end
  27. def evaluate(scope, locals, &block)
  28. context = self.class.context_class.new
  29. context.tilt_scope = scope
  30. context.define_tag("yield") do
  31. block.call
  32. end
  33. locals.each do |tag, value|
  34. context.define_tag(tag) do
  35. value
  36. end
  37. end
  38. options = {:tag_prefix => 'r'}.merge(@options)
  39. parser = Radius::Parser.new(context, options)
  40. parser.parse(data)
  41. end
  42. end
  43. end