radiant-fabulator-extension 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/app/models/fabulator_page.rb +7 -89
- data/fabulator_extension.rb +14 -3
- data/lib/fabulator/radiant/actions.rb +6 -6
- data/lib/fabulator/radiant/actions/require_auth.rb +9 -0
- metadata +8 -7
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ begin
|
|
7
7
|
gem.email = "jgsmith@tamu.edu"
|
8
8
|
gem.homepage = "http://github.com/jgsmith/radiant-fabulator"
|
9
9
|
gem.authors = ["James Smith"]
|
10
|
-
gem.add_dependency('fabulator', '>= 0.0.
|
10
|
+
gem.add_dependency('fabulator', '>= 0.0.4')
|
11
11
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
12
12
|
end
|
13
13
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -190,7 +190,7 @@ class FabulatorPage < Page
|
|
190
190
|
end
|
191
191
|
root = c
|
192
192
|
|
193
|
-
xml =
|
193
|
+
xml = "<view><form id='#{form_base}'>" + xml + %{</form></view>}
|
194
194
|
doc = text_parser.parse(c, xml)
|
195
195
|
|
196
196
|
# add default values
|
@@ -199,93 +199,6 @@ class FabulatorPage < Page
|
|
199
199
|
doc.to_html
|
200
200
|
end
|
201
201
|
|
202
|
-
# borrowed heavily from http://cpansearch.perl.org/src/JSMITH/Gestinanna-0.02/lib/Gestinanna/ContentProvider/XSM.pm
|
203
|
-
def add_default_values(doc, ctx)
|
204
|
-
REXML::XPath.each(doc.root, %{
|
205
|
-
//text
|
206
|
-
| //textline
|
207
|
-
| //textbox
|
208
|
-
| //editbox
|
209
|
-
| //file
|
210
|
-
| //password
|
211
|
-
| //selection
|
212
|
-
| //grid
|
213
|
-
}) do |el|
|
214
|
-
own_id = el.attribute('id')
|
215
|
-
next if own_id.nil? || own_id.to_s == ''
|
216
|
-
|
217
|
-
default = 0
|
218
|
-
is_grid = false
|
219
|
-
if el.local_name == 'grid'
|
220
|
-
default = REXML::XPath.match(el, './default | ./row/default | ./column/default')
|
221
|
-
is_grid = true
|
222
|
-
else
|
223
|
-
default = REXML::XPath.match(el, './default')
|
224
|
-
end
|
225
|
-
|
226
|
-
#missing = el.attribute('missing')
|
227
|
-
|
228
|
-
ancestors = REXML::XPath.match(el, %{
|
229
|
-
ancestor::option[@id != '']
|
230
|
-
| ancestor::group[@id != '']
|
231
|
-
| ancestor::form[@id != '']
|
232
|
-
| ancestor::container[@id != '']
|
233
|
-
})
|
234
|
-
ids = ancestors.collect{|a| a.attribute('id')}.select{|a| !a.nil? }
|
235
|
-
ids << own_id
|
236
|
-
id = ids.collect{|i| i.to_s}.join('.')
|
237
|
-
ids = id.split('.')
|
238
|
-
if !ctx.nil? && (default.is_a?(Array) && default.empty? || !default)
|
239
|
-
# create a new node 'default'
|
240
|
-
l = ctx.traverse_path(ids)
|
241
|
-
if !l.nil? && !l.empty?
|
242
|
-
if is_grid
|
243
|
-
count = (el.attribute('count').to_s rescue '')
|
244
|
-
how_many = 'multiple'
|
245
|
-
direction = 'both'
|
246
|
-
if count =~ %r{^(multiple|single)(-by-(row|column))?$}
|
247
|
-
how_many = $1
|
248
|
-
direction = $3 || 'both'
|
249
|
-
end
|
250
|
-
if direction == 'both'
|
251
|
-
l.collect{|ll| ll.value }.each do |v|
|
252
|
-
default = el.add_element('default')
|
253
|
-
default.add_text(v)
|
254
|
-
end
|
255
|
-
elsif direction == 'row' || direction == 'column'
|
256
|
-
REXML::XPath.each(el, "./#{direction}").each do |div|
|
257
|
-
id = (div.attribute('id').to_s rescue '')
|
258
|
-
next if id == ''
|
259
|
-
l.collect{|c| c.traverse_path(id)}.flatten.collect{|c| c.value }. each do |v|
|
260
|
-
default = div.add_element('default')
|
261
|
-
default.add_text(v)
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
else
|
266
|
-
l.collect{|ll| ll.value }.each do |v|
|
267
|
-
default = el.add_element('default')
|
268
|
-
default.add_text(v)
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
# now handle missing info for el
|
274
|
-
|
275
|
-
if !missing_args.nil? && missing_args.include?(id)
|
276
|
-
el.add_attribute('missing', '1')
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
end
|
281
|
-
|
282
|
-
desc %{
|
283
|
-
Defines XML namespace prefix to URI mappings.
|
284
|
-
}
|
285
|
-
tag 'xmlns' do |tag|
|
286
|
-
tag.expand
|
287
|
-
end
|
288
|
-
|
289
202
|
desc %{
|
290
203
|
Iterates through a set of data nodes.
|
291
204
|
|
@@ -303,6 +216,8 @@ class FabulatorPage < Page
|
|
303
216
|
sort_by = tag.attr['sort']
|
304
217
|
sort_dir = tag.attr['order'] || 'asc'
|
305
218
|
|
219
|
+
as = tag.attr['as']
|
220
|
+
|
306
221
|
if !sort_by.nil? && sort_by != ''
|
307
222
|
parser = Fabulator::Expr::Parser.new
|
308
223
|
sort_by_f = parser.parse(sort_by, c)
|
@@ -316,6 +231,9 @@ class FabulatorPage < Page
|
|
316
231
|
items.each do |i|
|
317
232
|
next if i.empty?
|
318
233
|
tag.locals.fabulator_context = c.with_root(i)
|
234
|
+
if !as.blank?
|
235
|
+
tag.locals.fabulator_context.set_var(as, i)
|
236
|
+
end
|
319
237
|
res = res + tag.expand
|
320
238
|
end
|
321
239
|
res
|
@@ -357,7 +275,7 @@ class FabulatorPage < Page
|
|
357
275
|
c = get_fabulator_context(tag)
|
358
276
|
items = c.nil? ? [] : c.eval_expression(selection)
|
359
277
|
if items.is_a?(Array)
|
360
|
-
if items.empty?
|
278
|
+
if items.empty? || !items[0].value
|
361
279
|
return ''
|
362
280
|
else
|
363
281
|
@chosen[0] = true
|
data/fabulator_extension.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
$: << File.expand_path(File.dirname(__FILE__))+'/lib'
|
2
2
|
|
3
3
|
require 'fabulator'
|
4
|
+
require 'fabulator/template'
|
4
5
|
require 'fabulator/radiant'
|
5
6
|
|
6
7
|
require_dependency "#{File.expand_path(File.dirname(__FILE__))}/app/models/fabulator_page"
|
@@ -27,7 +28,9 @@ class FabulatorExtension < Radiant::Extension
|
|
27
28
|
end
|
28
29
|
|
29
30
|
PagePart.class_eval do
|
30
|
-
|
31
|
+
validates_each :content do |record, attr, value|
|
32
|
+
record.compile_xml
|
33
|
+
end
|
31
34
|
|
32
35
|
def compile_xml
|
33
36
|
if self.page.class_name == 'FabulatorPage' &&
|
@@ -41,14 +44,22 @@ class FabulatorExtension < Radiant::Extension
|
|
41
44
|
isa = nil
|
42
45
|
sm = nil
|
43
46
|
if isa.nil?
|
44
|
-
|
47
|
+
begin
|
48
|
+
sm = Fabulator::Core::StateMachine.new.compile_xml(self.content)
|
49
|
+
rescue => e
|
50
|
+
self.errors.add(:content, "Compiling the XML application resulted in the following error: #{e}")
|
51
|
+
end
|
45
52
|
else
|
46
53
|
supersm_page = self.page.find_by_url(isa)
|
47
54
|
if supersm_page.nil? || supersm_page.is_a?(FileNotFoundPage) || !supersm_page.is_a?(FabulatorPage) || supersm_page.state_machine.nil?
|
48
55
|
raise "File Not Found: unable to find #{isa}"
|
49
56
|
end
|
50
57
|
sm = supersm_page.state_machine.clone
|
51
|
-
|
58
|
+
begin
|
59
|
+
sm.compile_xml(self.content)
|
60
|
+
rescue => e
|
61
|
+
self.errors.add(:content, "Compiling the XML application resulted in the following error: #{e}")
|
62
|
+
end
|
52
63
|
end
|
53
64
|
self.page.compiled_xml = YAML::dump(sm)
|
54
65
|
end
|
@@ -21,7 +21,7 @@ module Fabulator
|
|
21
21
|
|
22
22
|
register_type 'page', {
|
23
23
|
:ops => {
|
24
|
-
:children => Proc.new { |p| p.value.children.collect { |c| Lib.page_to_node(c, p) } },
|
24
|
+
:children => Proc.new { |p| Page.find(p.value.to_i).children.collect { |c| Lib.page_to_node(c, p) } },
|
25
25
|
},
|
26
26
|
}
|
27
27
|
|
@@ -57,7 +57,6 @@ module Fabulator
|
|
57
57
|
if !u.nil?
|
58
58
|
n = ctx.root.anon_node(u.id) #, [ RADIANT_NS, 'user' ])
|
59
59
|
n.set_attribute('admin', u.admin?)
|
60
|
-
Rails.logger.info("Returning: #{YAML::dump(n)}")
|
61
60
|
return [ n ]
|
62
61
|
else
|
63
62
|
return [ ]
|
@@ -66,13 +65,14 @@ Rails.logger.info("Returning: #{YAML::dump(n)}")
|
|
66
65
|
|
67
66
|
def self.page_to_node(p, ctx)
|
68
67
|
return nil if p.nil?
|
69
|
-
p_node = ctx.root.anon_node(p, [ RADIANT_NS, 'page' ])
|
68
|
+
p_node = ctx.root.anon_node(p.id, [ RADIANT_NS, 'page' ])
|
70
69
|
p_node.name = p.slug
|
71
70
|
p.parts.each do |pp|
|
72
|
-
pp_node = ctx.root.anon_node(pp.content, [ RADIANT_NS, 'page-part' ])
|
73
|
-
pp_node.name = pp.name
|
71
|
+
#pp_node = ctx.root.anon_node(pp.content, [ RADIANT_NS, 'page-part' ])
|
72
|
+
#pp_node.name = pp.name
|
74
73
|
#pp_node.set_attribute('filter', pp.filter)
|
75
|
-
p_node.set_attribute(pp.name, pp_node)
|
74
|
+
#p_node.set_attribute(pp.name, pp_node)
|
75
|
+
p_node.set_attribute(pp.name, pp.content)
|
76
76
|
end
|
77
77
|
p_node.set_attribute('title', p.title)
|
78
78
|
p_node.set_attribute('breadcrumb', p.breadcrumb)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-fabulator-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Smith
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-17 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 23
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 0
|
33
|
-
-
|
34
|
-
version: 0.0.
|
33
|
+
- 4
|
34
|
+
version: 0.0.4
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
description: Creates a Fabulator page type allowing applications to be built using the fabulator engine.
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- fabulator_extension.rb
|
55
55
|
- lib/fabulator/radiant.rb
|
56
56
|
- lib/fabulator/radiant/actions.rb
|
57
|
+
- lib/fabulator/radiant/actions/require_auth.rb
|
57
58
|
- lib/radiant-fabulator-extension.rb
|
58
59
|
has_rdoc: true
|
59
60
|
homepage: http://github.com/jgsmith/radiant-fabulator
|