Module: Nagoro

Defined in:
lib/nagoro.rb,
lib/nagoro/pipe.rb,
lib/nagoro/tidy.rb,
lib/nagoro/binding.rb,
lib/nagoro/element.rb,
lib/nagoro/scanner.rb,
lib/nagoro/version.rb,
lib/nagoro/template.rb,
lib/nagoro/pipe/base.rb,
lib/nagoro/pipe/tidy.rb,
lib/nagoro/pipe/morph.rb,
lib/nagoro/pipe/compile.rb,
lib/nagoro/pipe/element.rb,
lib/nagoro/pipe/include.rb,
lib/nagoro/pipe/instruction.rb,
lib/nagoro/pipe/localization.rb

Defined Under Namespace

Modules: GeneratedElement, Pipe, Tidy Classes: BindingProvider, Element, Error, Scanner, Template

Constant Summary collapse

VERSION =
"2013.03"
DEFAULT_PIPES =
[ Pipe::Element, Pipe::Morph, Pipe::Include,
Pipe::Instruction, Pipe::Compile ]
DEFAULT_FILE =
'<nagoro eval>'
DEFAULT_LINE =
1

Class Method Summary collapse

Class Method Details

.compile(io, options = {}) ⇒ Object



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

def self.compile(io, options = {})
  Template.new.compile(io, options)
end

.element(name, obj = nil, &block) ⇒ Object



2
3
4
# File 'lib/nagoro/pipe/element.rb', line 2

def self.element(name, obj = nil, &block)
  Pipe::Element::ELEMENTS[name] = obj || block
end

.file_element(name, filename) ⇒ Object



6
7
8
# File 'lib/nagoro/pipe/element.rb', line 6

def self.file_element(name, filename)
  Pipe::Element::ELEMENTS[name] = FileElement(filename)
end

.FileElement(file) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nagoro/element.rb', line 28

def self.FileElement(file)
  element = Class.new(Element){
    define_method(:element_file){
      file
    }

    def render
      main = File.read(element_file)
      @delim = "T" << rand(8 << 100).to_s
      eval(%{<<#@delim\n#{main}\n#@delim})
    end
  }
  name = File.basename(file, File.extname(file))
  GeneratedElement::const_set(name, element)
  Pipe::Element::ELEMENTS.delete_if{|k,v| v == element}
  Pipe::Element::ELEMENTS[name] = element
  element
end

.render(obj, options = {}) ⇒ Object



13
14
15
# File 'lib/nagoro.rb', line 13

def self.render(obj, options = {})
  compile(obj, options).result
end

.tidy_render(obj, options = {}) ⇒ Object



17
18
19
# File 'lib/nagoro.rb', line 17

def self.tidy_render(obj, options = {})
  compile(obj, options).tidy_result
end