Module: Angelo::Tilt::ERB::ClassMethods
- Defined in:
- lib/angelo/tilt/erb.rb
Instance Method Summary collapse
- #default_layout(type = DEFAULT_TYPE) ⇒ Object
- #layout_templates(type = DEFAULT_TYPE) ⇒ Object
- #templates(type = DEFAULT_TYPE) ⇒ Object
- #templatify(*glob) ⇒ Object
- #view_glob(*glob) ⇒ Object
Instance Method Details
#default_layout(type = DEFAULT_TYPE) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/angelo/tilt/erb.rb', line 52 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
48 49 50 |
# File 'lib/angelo/tilt/erb.rb', line 48 def layout_templates type = DEFAULT_TYPE @layout_templates ||= templatify LAYOUTS_DIR, "*.#{type}.erb" end |
#templates(type = DEFAULT_TYPE) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/angelo/tilt/erb.rb', line 41 def templates type = DEFAULT_TYPE @templates ||= {} @templates[type] ||= templatify('**', "*.#{type}.erb") do |v| v =~ /^#{LAYOUTS_DIR}#{File::SEPARATOR}/ end end |
#templatify(*glob) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/angelo/tilt/erb.rb', line 30 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
26 27 28 |
# File 'lib/angelo/tilt/erb.rb', line 26 def view_glob *glob File.join views_dir, *glob end |