Class: XX::Template::Basic
- Inherits:
-
Object
- Object
- XX::Template::Basic
- Defined in:
- lib/rcov/xx.rb
Overview
–{{{
Instance Method Summary collapse
-
#expand(binding, opts = {}) ⇒ Object
(also: #result)
–}}}.
-
#initialize(opts = {}, &b) ⇒ Basic
constructor
A new instance of Basic.
-
#inline_init(&b) ⇒ Object
–}}}.
-
#path_init(&b) ⇒ Object
–}}}.
Constructor Details
#initialize(opts = {}, &b) ⇒ Basic
Returns a new instance of Basic.
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/rcov/xx.rb', line 686 def initialize opts = {}, &b #--{{{ @path = opts['path'] || opts[:path] @inline = opts['inline'] || opts[:inline] @type = opts['type'] || opts[:type] @object = opts['object'] || opts[:object] @pretty = opts['pretty'] || opts[:pretty] @port = opts['port'] || opts[:port] || STDOUT bool = lambda{|value| value ? true : false} raise ArgumentError unless(bool[@path] ^ bool[@inline]) path_init(&b) if @path inline_init(&b) if @inline @type = case @type.to_s.downcase.strip when /^xhtml$/ XHTML when /^xml$/ XML when /^html4$/ HTML4 else XHTML end #--}}} end |
Instance Method Details
#expand(binding, opts = {}) ⇒ Object Also known as: result
–}}}
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 |
# File 'lib/rcov/xx.rb', line 726 def binding, opts = {} #--{{{ port = opts['port'] || opts[:port] || STDOUT pretty = opts['pretty'] || opts[:pretty] object = eval 'self', binding unless type === object __m = type klass = object.class klass.module_eval{ include __m } end doc = eval @template, binding display = pretty ? 'pretty' : 'to_str' doc.send display, port #--}}} end |
#inline_init(&b) ⇒ Object
–}}}
720 721 722 723 724 725 |
# File 'lib/rcov/xx.rb', line 720 def inline_init &b #--{{{ @template = (@inline || b.call).to_s @type ||= XHTML #--}}} end |
#path_init(&b) ⇒ Object
–}}}
714 715 716 717 718 719 |
# File 'lib/rcov/xx.rb', line 714 def path_init &b #--{{{ @template = IO.read @path @type = @path[%r/\.[^\.]+$/o] || XHTML unless @type #--}}} end |