Class: Fabulator::Exhibit::Actions::Lib

Inherits:
TagLib
  • Object
show all
Defined in:
lib/fabulator/exhibit/actions.rb

Constant Summary collapse

@@databases =
{ }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.accumulate_item_info(&block) ⇒ Object



46
47
48
49
50
51
# File 'lib/fabulator/exhibit/actions.rb', line 46

def self.accumulate_item_info(&block)
  @@item ||=[]
  @@item.unshift({})
  yield
  @@item.shift
end

.add_info(nom, t, item) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fabulator/exhibit/actions.rb', line 61

def self.add_info(nom, t, item)
  @@databases ||= {}
  @@databases[nom] ||= self.fetch_database(nom)
  @@databases[nom][t][item['id']] ||= { }
  @@databases[nom][t][item['id']].merge!(item)
  @@databases[nom][t][item['id']].each_pair do |k,v|
    if v.nil? || (v.is_a?(Array) && v.empty?) ||
       v.is_a?(String) && v == ""
      @@databases[nom][t][item['id']].delete(k)
    end
  end
  case t
    when :types, :properties
      @@databases[nom][t][item['id']].delete(:id)
  end
end

.add_item_to_accumulator(k, v) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/fabulator/exhibit/actions.rb', line 53

def self.add_item_to_accumulator(k,v)
  return if @@item.empty?
  if v.is_a?(Array) && v.size == 1
    v = v[0]
  end
  @@item[0][k] = v
end

.fetch_database(nom) ⇒ Object

should set up an empty database with :items, :types, and :properties



24
25
26
# File 'lib/fabulator/exhibit/actions.rb', line 24

def self.fetch_database(nom)
  raise "fetch_database is not implemented by the framework."
end

.get_database(nom) ⇒ Object



32
33
34
# File 'lib/fabulator/exhibit/actions.rb', line 32

def self.get_database(nom)
  @@databases[nom] ||= self.fetch_database(nom)
end

.remove_info(nom, t, id) ⇒ Object



78
79
80
81
82
# File 'lib/fabulator/exhibit/actions.rb', line 78

def self.remove_info(nom, t, id)
  @@databases[nom] ||= self.fetch_database(nom)
  return if @@databases[nom][t].empty?
  @@databases[nom][t].delete(id)
end

.set_database(nom, data) ⇒ Object



36
37
38
# File 'lib/fabulator/exhibit/actions.rb', line 36

def self.set_database(nom, data)
  @@databases[nom] = data
end

.store_database(nom, data) ⇒ Object



28
29
30
# File 'lib/fabulator/exhibit/actions.rb', line 28

def self.store_database(nom, data)
  raise "store_database is not imeplemented by the framework."
end

.store_databasesObject



40
41
42
43
44
# File 'lib/fabulator/exhibit/actions.rb', line 40

def self.store_databases
  @@databases.keys.each do |k|
    self.store_database(k, @@databases[k])
  end
end

Instance Method Details

#itemsObject

need to make this an iterator



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/fabulator/exhibit/actions.rb', line 105

function 'items' do |ctx, args|
  nom = ctx.attribute(EXHIBIT_NS, 'database', { :inherited => true, :static => true })
  db = Fabulator::Exhibit::Actions::Lib.get_database(nom)
  ret = ctx.root.anon_node(nil)
  db[:items].each_pair{ |id, item|
    i = ret.create_child(id, nil)
    item.each_pair do |k,v|
      next if k == "id"
      v = [ v ] unless v.is_a?(Array)
      v.each do |vv|
        i.create_child(k,vv)
      end
    end
  }
  [ ret ]
end