Module: InlineTemplateLoader

Defined in:
lib/inline_template_loader.rb,
lib/inline_template_loader/version.rb

Constant Summary collapse

VERSION =
"0.3.2"

Class Method Summary collapse

Class Method Details

.load(arg = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/inline_template_loader.rb', line 4

def self.load(arg = nil)
  if arg.is_a? ::Integer
    caller_pos = arg
  else
    caller_pos = 0
  end

  if arg.is_a? ::String
    file = arg
  else
    file = caller[caller_pos].split(':').first
  end

  templates = {}
  sym = nil

  app, data = ::IO.read(file).gsub("\r\n", "\n").split(/^__END__$/, 2)

  if data
    data.each_line do |line|
      if line =~ /^@@\s*(.*\S)\s*$/
        sym = $1.to_sym
      else
        if sym
          unless templates[sym]
            templates[sym] = line
          else
            templates[sym] += line
          end
        end
      end
    end
  end

  templates
end