Class: RBlade::ComponentStore

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

Class Method Summary collapse

Class Method Details

.add_path(path, namespace = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/rblade/component_store.rb', line 34

def self.add_path path, namespace = nil
  path = path.to_s
  if !path.end_with? "/"
    path += "/"
  end

  @@template_paths[namespace] ||= []
  @@template_paths[namespace] << path
end

.clearObject



52
53
54
55
56
# File 'lib/rblade/component_store.rb', line 52

def self.clear
  @@component_definitions = ""
  @@component_method_names = {}
  @@component_name_stack = []
end

.component(full_name) ⇒ Object

Retrieve the method name for a component, and compile it if it hasn’t already been compiled



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
# File 'lib/rblade/component_store.rb', line 8

def self.component full_name
  # If this is a relative path, prepend with the previous component name's base
  if full_name.start_with? "."
    full_name = @@component_name_stack.last.gsub(/\.[^\.]+$/, "") + full_name
  end

  # Ensure each component is only compiled once
  unless @@component_method_names[full_name].nil?
    return @@component_method_names[full_name]
  end

  @@component_name_stack << full_name

  namespace = nil
  name = full_name

  if name.match? "::"
    namespace, name = full_name.split("::")
  end

  method_name = compile_component full_name, File.read(find_component_file(namespace, name))
  @@component_name_stack.pop

  method_name
end

.getObject



48
49
50
# File 'lib/rblade/component_store.rb', line 48

def self.get
  @@component_definitions
end

.view_name(view_name) ⇒ Object



44
45
46
# File 'lib/rblade/component_store.rb', line 44

def self.view_name view_name
  @@component_name_stack.push view_name
end