Class: Rbml::Processor

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

Constant Summary collapse

ROUTES =
{:xhtml => "Doc", 
:cli => "Cli", 
:shell => "Shell"}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.read(file) ⇒ Object



33
34
35
# File 'lib/processor.rb', line 33

def self.read(file)
  File.read(file)
end

.run(argv) ⇒ Object



37
38
39
# File 'lib/processor.rb', line 37

def self.run(argv)
  new.instance_eval File.read(argv)
end

Instance Method Details

#load_language(language) ⇒ Object



28
29
30
31
# File 'lib/processor.rb', line 28

def load_language(language)
  require "#{route_for(language.to_sym).downcase}/#{language}"
  "Language::#{route_for(language.to_sym)}::#{language.camelize}".to_m
end

#method_nameObject



12
# File 'lib/processor.rb', line 12

def method_name; caller[0][/`([^']*)'/, 1]; end

#render(method_name, language, options, &block) ⇒ Object



24
25
26
# File 'lib/processor.rb', line 24

def render(method_name, language, options, &block)
  Rbml.const_get(route_for(method_name.to_sym)).render(language, options, &block)
end

#route_for(name) ⇒ Object



8
9
10
# File 'lib/processor.rb', line 8

def route_for(name)
  ROUTES.fetch(name)
end

#spawn(options, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/processor.rb', line 14

def spawn(options, *args, &block)
  language = if args.first.kind_of?(Hash) and args.first[:as_language]
     args[:as_language]
  else
     method_name rescue $script_extention
  end
  language = load_language(language)
  render(method_name, language, options, &block)
end