Module: Angelo::Tilt::ERB::ClassMethods

Defined in:
lib/angelo/tilt/erb.rb

Instance Method Summary collapse

Instance Method Details

#default_layout(type = DEFAULT_TYPE) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/angelo/tilt/erb.rb', line 47

def default_layout type = DEFAULT_TYPE
  @default_layout ||= {}
  if @default_layout[type].nil?
    l = view_glob(DEFAULT_LAYOUT % type)
    @default_layout[type] = ::Tilt::ERBTemplate.new l if File.exist? l
  end
  @default_layout[type]
end

#layout_templates(type = DEFAULT_TYPE) ⇒ Object



43
44
45
# File 'lib/angelo/tilt/erb.rb', line 43

def layout_templates type = DEFAULT_TYPE
  @layout_templates ||= templatify LAYOUTS_DIR, "*.#{type}.erb"
end

#templates(type = DEFAULT_TYPE) ⇒ Object



36
37
38
39
40
41
# File 'lib/angelo/tilt/erb.rb', line 36

def templates type = DEFAULT_TYPE
  @templates ||= {}
  @templates[type] ||= templatify('**', "*.#{type}.erb") do |v|
    v =~ /^#{LAYOUTS_DIR}#{File::SEPARATOR}/
  end
end

#templatify(*glob) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/angelo/tilt/erb.rb', line 25

def templatify *glob
  Dir[view_glob *glob].reduce({}) do |h,v|
    sym = v.gsub views_dir + File::SEPARATOR, ''
    return h if (block_given? && yield(v))
    sym.gsub! File::SEPARATOR, UNDERSCORE
    sym.gsub! /\.\w+?\.erb$/, EMPTY_STRING
    h[sym.to_sym] = ::Tilt::ERBTemplate.new v
    h
  end
end

#view_glob(*glob) ⇒ Object



21
22
23
# File 'lib/angelo/tilt/erb.rb', line 21

def view_glob *glob
  File.join views_dir, *glob
end