Class: Rbml::Processor

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

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.read(file) ⇒ Object



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

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

.run(argv) ⇒ Object



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

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

Instance Method Details

#load_language(language) ⇒ Object



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

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



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

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

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



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

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



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

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

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



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

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