radiant-fabulator_exhibit-extension 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ === 0.0.4 2010-11-06
2
+ * 1 major enhancement
3
+ * Exhbit databases are now more than just blobs of text. Run the migration
4
+ to use the new schema
5
+ * 1 minor enhancement
6
+ * Items with multiple values are now shown with ex:separator,
7
+ ex:last-separator, and ex:pair-separator available for inserting
8
+ HTML between values
9
+
1
10
  === 0.0.3 2010-10-28
2
11
  * 2 major enhancement
3
12
  * Supports conditional parts in lenses (if-exists)
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ begin
8
8
  gem.homepage = "http://github.com/jgsmith/radiant-fabulator-exhibit"
9
9
  gem.authors = ["James Smith"]
10
10
  gem.add_dependency('radiant-fabulator-extension', '>= 0.0.7')
11
- gem.add_dependency('fabulator-exhibit', '>= 0.0.4')
11
+ gem.add_dependency('fabulator-exhibit', '>= 0.0.6')
12
12
  gem.add_dependency('json', '>= 1.4.3')
13
13
  gem.add_dependency('uuid', '>= 2.3.1')
14
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -8,4 +8,12 @@ class FabulatorExhibit < ActiveRecord::Base
8
8
 
9
9
  belongs_to :updated_by, :class_name => 'User'
10
10
  belongs_to :created_by, :class_name => 'User'
11
+
12
+ def data
13
+ self.database.to_json
14
+ end
15
+
16
+ def database
17
+ FabulatorExhibitExtension::Database.new(self)
18
+ end
11
19
  end
@@ -0,0 +1,9 @@
1
+ class FabulatorExhibitItem < ActiveRecord::Base
2
+ validates_presence_of :uuid
3
+ validates_uniqueness_of :uuid, :scope => [ :fabulator_exhibit_id ]
4
+
5
+ belongs_to :fabulator_exhibit
6
+
7
+ belongs_to :updated_by, :class_name => 'User'
8
+ belongs_to :created_by, :class_name => 'User'
9
+ end
@@ -0,0 +1,8 @@
1
+ class FabulatorExhibitProperty < ActiveRecord::Base
2
+ validates_presence_of :name
3
+ validates_uniqueness_of :name, :scope => [ :fabulator_exhibit_id ]
4
+
5
+ before_save :freeze_data
6
+
7
+ belongs_to :fabulator_exhibit
8
+ end
@@ -0,0 +1,8 @@
1
+ class FabulatorExhibitType < ActiveRecord::Base
2
+ validates_presence_of :name
3
+ validates_uniqueness_of :name, :scope => [ :fabulator_exhibit_id ]
4
+
5
+ before_save :freeze_data
6
+
7
+ belongs_to :fabulator_exhibit
8
+ end
@@ -0,0 +1,69 @@
1
+ # this will let us have multiple apps operating on a database at the same time
2
+ class CreateFabulatorExhibitContentTables < ActiveRecord::Migration
3
+ def self.up
4
+ create_table :fabulator_exhibit_items do |t|
5
+ t.references :fabulator_exhibit, :null => false
6
+ t.string :uuid, :null => false
7
+ t.text :data
8
+ t.references :updated_by
9
+ t.references :created_by
10
+ t.timestamps
11
+ end
12
+
13
+ create_table :fabulator_exhibit_types do |t|
14
+ t.references :fabulator_exhibit, :null => false
15
+ t.string :name, :null => false
16
+ t.text :data
17
+ # we may want some other stuff here, like which xsm we use
18
+ # to edit something of this type
19
+ end
20
+
21
+ create_table :fabulator_exhibit_properties do |t|
22
+ t.references :fabulator_exhibit, :null => false
23
+ t.string :name, :null => false
24
+ t.text :data
25
+ end
26
+
27
+ FabulatorExhibit.find(:all).each do |db|
28
+ data = (JSON.parse(db.data) rescue { 'items' => [], 'types' => {}, 'properties' => {} })
29
+ data['types'].each_pair do |k,t|
30
+ t_ob = FabulatorExhibitType.create({
31
+ :fabulator_exhibit_id => db.id,
32
+ :name => k,
33
+ :data => t.to_json
34
+ })
35
+ t_ob.save!
36
+ end
37
+
38
+ data['properties'].each_pair do |k,p|
39
+ p_ob = FabulatorExhibitProperty.create({
40
+ :fabulator_exhibit_id => db.id,
41
+ :name => k,
42
+ :data => p.to_json
43
+ })
44
+ p_ob.save!
45
+ end
46
+
47
+ data['items'].each do |i|
48
+ i_ob = FabulatorExhibitItem.create({
49
+ :fabulator_exhibit_id => db.id,
50
+ :uuid => i['id'],
51
+ :data => i.to_json
52
+ });
53
+ i_ob.save!
54
+ end
55
+ end
56
+ end
57
+
58
+ def self.down
59
+ FabulatorExhibit.find(:all).each do |db|
60
+ db.data = db.database.to_json
61
+ db.save!
62
+ end
63
+
64
+ drop_table :fabulator_exhibit_properties
65
+ drop_table :fabulator_exhibit_types
66
+ drop_table :fabulator_exhibit_items
67
+ end
68
+ end
69
+
@@ -2,7 +2,7 @@ require 'fabulator/exhibit'
2
2
  require 'json'
3
3
 
4
4
  class FabulatorExhibitExtension < Radiant::Extension
5
- version "0.0.3"
5
+ version "0.0.4"
6
6
  description "Exhibit extension to the Fabulator extension"
7
7
  url "http://github.com/jgsmith/radiant-fabulator-exhibit"
8
8
 
@@ -14,13 +14,16 @@ class FabulatorExhibitExtension < Radiant::Extension
14
14
  end
15
15
 
16
16
  def activate
17
- #raise FabulatorExhibitExtension::MissingRequirement.new('FabulatorExtension must be installed and loaded first.') unless defined?(FabulatorExtension)
18
-
19
- %w{exhibit.js data.js expressions.js views.js facets.js}.each do |s|
17
+ %w{exhibit.js
18
+ util.js
19
+ data.js
20
+ expressions.js
21
+ views.js
22
+ facets.js
23
+ }.each do |s|
20
24
  FabulatorExtension.scripts << "fabulator/exhibit/#{s}"
21
25
  end
22
- #FabulatorExtension.scripts << 'fabulator/exhibit/exhibit.js'
23
- #FabulatorExtension.scripts << 'fabulator/exhibit/exhibit-expressions.js'
26
+
24
27
  FabulatorExtension.css << 'fabulator/exhibit/exhibit.css'
25
28
 
26
29
  tab 'Fabulator' do
@@ -33,34 +36,14 @@ class FabulatorExhibitExtension < Radiant::Extension
33
36
  end
34
37
  admin.exhibits = load_default_fabulator_exhibit_regions
35
38
 
36
- ## TODO: better database so we can have multiple applications accessing
37
- ## the same database at the same time
38
39
  Fabulator::Exhibit::Lib.class_eval do
39
40
  def self.fetch_database(nom)
40
41
  db = FabulatorExhibit.find(:first, :conditions => [ 'name = ?', nom ])
41
- if db.nil?
42
- return { :items => [], :types => {}, :properties => {} }
43
- else
44
- data = (JSON.parse(db.data) rescue { 'items' => [], 'types' => {}, 'properties' => {} })
45
- ret = { :items => { }, :types => data['types'], :properties => data['properties'] }
46
- ret[:properties] = { } if ret[:properties].nil?
47
- ret[:types] = { } if ret[:types].nil?
48
- data['items'].each do |i|
49
- ret[:items][i['id']] = i
50
- end
51
- return ret
52
- end
42
+ return db.database
53
43
  end
54
44
 
55
45
  def self.store_database(nom, data)
56
- db = FabulatorExhibit.find(:first, :conditions => [ 'name = ?', nom ])
57
- if db.nil?
58
- raise "The Exhibit database #{nom} does not exist."
59
- end
60
- to_save = { :items => data[:items].values, :properties => data[:properties], :types => data[:types] }
61
- db.data = to_save.to_json
62
- db.items_count = to_save[:items].size
63
- db.save
46
+ return
64
47
  end
65
48
  end
66
49
  end
@@ -85,3 +68,5 @@ class FabulatorExhibitExtension < Radiant::Extension
85
68
  end
86
69
  end
87
70
  end
71
+
72
+ require 'fabulator_exhibit_extension/database'
@@ -0,0 +1,274 @@
1
+ class FabulatorExhibitExtension
2
+ class Database
3
+ def initialize(db)
4
+ @db = db
5
+ end
6
+
7
+ def to_json
8
+ '{ "items":' + self[:items].to_json + ', ' +
9
+ ' "types":' + self[:types].to_json + ', ' +
10
+ ' "properties":' + self[:properties].to_json +
11
+ '}'
12
+ end
13
+
14
+ def [](t)
15
+ case t.to_sym
16
+ when :items
17
+ return ItemCollection.new(@db)
18
+ when :properties
19
+ return PropertyCollection.new(@db)
20
+ when :types
21
+ return TypeCollection.new(@db)
22
+ end
23
+ end
24
+ end
25
+
26
+ class ItemCollection
27
+ def initialize(db)
28
+ @db = db
29
+ end
30
+
31
+ def [](nom)
32
+ ob = nil
33
+ begin
34
+ ob = @db.fabulator_exhibit_items.find(:first, [ 'uuid = ?', nom ])
35
+ rescue
36
+ ob = nil
37
+ end
38
+ if ob.nil?
39
+ ob = FabulatorExhibitItem.new({
40
+ :uuid => nom,
41
+ :fabulator_exhibit_id => @db.id
42
+ })
43
+ end
44
+ Item.new(ob)
45
+ end
46
+
47
+ def include?(nom)
48
+ ob = nil
49
+ begin
50
+ ob = @db.fabulator_exhibit_items.find(:first, [ 'uuid = ?', nom ])
51
+ rescue
52
+ ob = nil
53
+ end
54
+ return !ob.nil?
55
+ end
56
+
57
+ def []=(nom, hash)
58
+ ob = self[nom]
59
+ hash.each_pair do |k,v|
60
+ ob[k] = v
61
+ end
62
+ ob.save
63
+ end
64
+
65
+ def to_json
66
+ '[' +
67
+ @db.fabulator_exhibit_items.find(:all).collect{ |i| i.data }.join(", ") +
68
+ ']'
69
+ end
70
+ end
71
+
72
+ class PropertyCollection
73
+ def initialize(db)
74
+ @db = db
75
+ end
76
+
77
+ def [](nom)
78
+ ob = nil
79
+ begin
80
+ ob = @db.fabulator_exhibit_properties.find(:first, [ 'name = ?', nom ])
81
+ rescue
82
+ ob = nil
83
+ end
84
+ if ob.nil?
85
+ ob = FabulatorExhibitProperty.new({
86
+ :name => nom,
87
+ :fabulator_exhibit_id => @db.id
88
+ })
89
+ end
90
+ Property.new(ob)
91
+ end
92
+
93
+ def []=(nom, hash)
94
+ ob = self[nom]
95
+ hash.each_pair do |k,v|
96
+ ob[k] = v
97
+ end
98
+ ob.save
99
+ end
100
+
101
+ def to_json
102
+ '{' +
103
+ @db.fabulator_exhibit_properties.find(:all).collect{ |p|
104
+ p.name.to_json + ":" + p.data
105
+ }.join(", ") +
106
+ '}'
107
+ end
108
+ end
109
+
110
+ class TypeCollection
111
+ def initialize(db)
112
+ @db = db
113
+ end
114
+
115
+ def [](nom)
116
+ ob = nil
117
+ begin
118
+ ob = @db.fabulator_exhibit_types.find(:first, [ 'name = ?', nom ])
119
+ rescue
120
+ ob = nil
121
+ end
122
+ if ob.nil?
123
+ ob = FabulatorExhibitType.new({
124
+ :name => nom,
125
+ :fabulator_exhibit_id => @db.id
126
+ })
127
+ end
128
+ Type.new(ob)
129
+ end
130
+
131
+ def []=(nom, hash)
132
+ ob = self[nom]
133
+ hash.each_pair do |k,v|
134
+ ob[k] = v
135
+ end
136
+ ob.save
137
+ end
138
+
139
+ def to_json
140
+ '{' +
141
+ @db.fabulator_exhibit_types.find(:all).collect{ |t|
142
+ t.name.to_json + ":" + t.data
143
+ }.join(", ") +
144
+ '}'
145
+ end
146
+ end
147
+
148
+ class Item
149
+ def initialize(i)
150
+ @item = i
151
+ @raw_data = ( JSON.parse(i.data) rescue {} )
152
+ end
153
+
154
+ def [](k)
155
+ @raw_data[k]
156
+ end
157
+
158
+ def []=(k,v)
159
+ @raw_data[k] = v
160
+ self.save
161
+ end
162
+
163
+ def delete(k)
164
+ @raw_data.delete(k)
165
+ self.save
166
+ end
167
+
168
+ def each_pair(&block)
169
+ @raw_data.each_pair do |k,v|
170
+ yield k,v
171
+ end
172
+ end
173
+
174
+ def merge!(hash)
175
+ @raw_data.merge!(hash)
176
+ self.save
177
+ end
178
+
179
+ def save
180
+ @item.data = @raw_data.to_json
181
+ @item.save
182
+ end
183
+
184
+ def save!
185
+ @item.data = @raw_data.to_json
186
+ @item.save!
187
+ end
188
+ end
189
+
190
+ class Type
191
+ def initialize(t)
192
+ @type = t
193
+ @raw_data = ( JSON.parse(t.data) rescue {} )
194
+ end
195
+
196
+ def [](k)
197
+ @raw_data[k]
198
+ end
199
+
200
+ def []=(k,v)
201
+ @raw_data[k] = v
202
+ self.save
203
+ end
204
+
205
+ def delete(k)
206
+ @raw_data.delete(k)
207
+ self.save
208
+ end
209
+
210
+ def each_pair(&block)
211
+ @raw_data.each_pair do |k,v|
212
+ yield k,v
213
+ end
214
+ end
215
+
216
+ def merge!(hash)
217
+ @raw_data.merge!(hash)
218
+ self.save
219
+ end
220
+
221
+ def save
222
+ @type.data = @raw_data.to_json
223
+ @type.save
224
+ end
225
+
226
+ def save!
227
+ @type.data = @raw_data.to_json
228
+ @type.save!
229
+ end
230
+ end
231
+
232
+ class Property
233
+ def initialize(p)
234
+ @property = p
235
+ @raw_data = ( JSON.parse(p.data) rescue {} )
236
+ end
237
+
238
+ def [](k)
239
+ @raw_data[k]
240
+ end
241
+
242
+ def []=(k,v)
243
+ @raw_data[k] = v
244
+ self.save
245
+ end
246
+
247
+ def delete(k)
248
+ @raw_data.delete(k)
249
+ self.save
250
+ end
251
+
252
+ def each_pair(&block)
253
+ @raw_data.each_pair do |k,v|
254
+ yield k,v
255
+ end
256
+ end
257
+
258
+ def merge!(hash)
259
+ @raw_data.merge!(hash)
260
+ self.save
261
+ end
262
+
263
+ def save
264
+ @property.data = @raw_data.to_json
265
+ @property.save
266
+ end
267
+
268
+ def save!
269
+ @property.data = @raw_data.to_json
270
+ @property.save!
271
+ end
272
+ end
273
+
274
+ end