Class: Rag::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/rag/new.rb

Constant Summary collapse

Rc =

used in hello.tt

Rag::Rc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(o = {}) ⇒ Template

Returns a new instance of Template.

Parameters:

  • o (Hash) (defaults to: {})

    options

Options Hash (o):

  • :source_root (String) — default: ""


143
144
145
# File 'lib/rag/new.rb', line 143

def initialize(o={})
  @source_root = o[:source_root] || ""
end

Instance Attribute Details

#source_rootObject (readonly)

Returns the value of attribute source_root.



139
140
141
# File 'lib/rag/new.rb', line 139

def source_root
  @source_root
end

Class Method Details

.render(source, o = {}, &blk) ⇒ Object

Parameters:

  • o (Hash) (defaults to: {})

    options pass to initialize



133
134
135
136
137
# File 'lib/rag/new.rb', line 133

def self.render(source, o={}, &blk)
  scope = Template.new(o) 

  Tilt["erb"].new(source).render(scope, scope.locals, &blk)
end

Instance Method Details

#have_ext(ext) ⇒ Object



155
156
157
# File 'lib/rag/new.rb', line 155

def have_ext(ext)
  Rc.exts.include? ext
end

#localsObject

for tilt



160
161
162
# File 'lib/rag/new.rb', line 160

def locals
  Rc._to_hash
end

#render(path) ⇒ Object

path absolute or relative.



148
149
150
151
152
153
# File 'lib/rag/new.rb', line 148

def render(path)
  path = Pa(Pa.absolute?(path) ? path : Pa.join(source_root, path))
  path = path.build(fname: (path.base[0]=="_" ? "" : "_")+path.base)

  Tilt::ERBTemplate.new(path.p).render(self, locals)
end