radiant-fabulator-extension 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.0.9 2010-12-03
2
+
3
+ * 1 major enhancement:
4
+ * Added page and page-part elements to allow page creation
5
+
1
6
  === 0.0.8 2010-11-08
2
7
 
3
8
  * 1 bug fix:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.0.9
@@ -5,7 +5,7 @@ require 'fabulator_tags'
5
5
  require_dependency "#{File.expand_path(File.dirname(__FILE__))}/app/models/fabulator_page"
6
6
 
7
7
  class FabulatorExtension < Radiant::Extension
8
- version "0.0.7"
8
+ version "0.0.9"
9
9
  description "Applications as documents"
10
10
  url "http://github.com/jgsmith/radiant-fabulator"
11
11
 
@@ -1,5 +1,4 @@
1
1
  require 'fabulator/tag_lib'
2
- #require 'fabulator/radiant/actions/require_auth'
3
2
 
4
3
  module Fabulator
5
4
  RADIANT_NS="http://dh.tamu.edu/ns/fabulator/radiant/1.0#"
@@ -7,12 +6,19 @@ module Fabulator
7
6
  def initialize(message = "") super; end
8
7
  end
9
8
 
9
+ #require 'fabulator/radiant/actions/require_auth'
10
+ require 'fabulator/radiant/actions/page'
11
+ require 'fabulator/radiant/actions/page_part'
12
+
10
13
  module Radiant
11
14
  class Lib < Fabulator::TagLib
12
15
 
13
16
  namespace RADIANT_NS
14
17
 
15
18
  #action 'require-auth', Fabulator::Radiant::Actions::RequireAuth
19
+ # used to create/update pages
20
+ action 'page', Fabulator::Radiant::Actions::Page
21
+ action 'page-part', Fabulator::Radiant::Actions::PagePart
16
22
 
17
23
  #register_type 'user', {
18
24
  #}
@@ -21,6 +27,12 @@ module Fabulator
21
27
  method :CHILDREN do |p|
22
28
  Page.find(p.value.to_i).children.collect { |c| Lib.page_to_node(c, p) }
23
29
  end
30
+ coming_from [ FAB_NS, 'string' ] do
31
+ weight 0.9
32
+ converting do |p|
33
+ Lib.page_to_node(Page.find_by_parent_id(nil).find_by_url(p.root.value), p.root)
34
+ end
35
+ end
24
36
  end
25
37
 
26
38
  # page parts are attributes of a page
@@ -46,7 +58,7 @@ module Fabulator
46
58
 
47
59
  function 'find', [ RADIANT_NS, 'page' ] do |ctx, args|
48
60
  args[0].collect { |a|
49
- Lib.page_to_node(Page.find_by_parent_id(nil).find_by_url(a.to_s), ctx.root)
61
+ a.to([ RADIANT_NS, 'page'], ctx)
50
62
  }
51
63
  end
52
64
 
@@ -0,0 +1,126 @@
1
+ module Fabulator
2
+ module Radiant
3
+ module Actions
4
+ class Page < Fabulator::Action
5
+
6
+ namespace Fabulator::RADIANT_NS
7
+
8
+ attribute 'child-of', :static => false, :eval => true, :as => 'parent'
9
+ attribute :title, :static => false, :eval => true
10
+ attribute :slug, :static => false, :eval => true
11
+ attribute :status, :static => false, :eval => true
12
+ attribute :layout, :static => false, :eval => true
13
+ attribute :description, :static => false, :eval => true
14
+ attribute :breadcrumb, :static => false, :eval => true
15
+
16
+ has_select
17
+ has_actions
18
+
19
+ def run(context, autovivify = false)
20
+ @context.with(context) do |ctx|
21
+ ## collect page parts
22
+ parents = self.parent(ctx)
23
+ if parents.nil? || parents.empty? # default is root page
24
+ parents = self.select(ctx)
25
+ end
26
+
27
+ if parents.nil? || parents.empty? # default is root page
28
+ parents = [ ctx.root.anon_node('/') ]
29
+ end
30
+
31
+ parents = parents.collect{ |pp| pp.to([ Fabulator::RADIANT_NS, 'page' ], ctx) } - [ nil ]
32
+ # TODO: remove any non-found pages (404 pages, for example)
33
+
34
+ return [] if parents.empty?
35
+
36
+ s = self.slug(ctx).first
37
+
38
+ return [] if s.nil? && !self.has_select?
39
+
40
+ using_children = false
41
+
42
+ if s.nil?
43
+ s = parents.first
44
+
45
+ else
46
+ using_children = true
47
+ s = s.to_s
48
+ end
49
+
50
+ ctx.set_scoped_info('radiant/page/parts', { })
51
+ self.run_actions(ctx)
52
+
53
+ ## update or create page - requires parent to exist
54
+ page_parts_info = ctx.get_scoped_info('radiant/page/parts')
55
+
56
+ parents.each do |page_id|
57
+ page = ::Page.find(page_id.value)
58
+ if using_children
59
+ child = page.children.select{ |c| c.slug == s }.first
60
+ if child.nil?
61
+ child = page.class.new_with_defaults()
62
+
63
+ child.slug = s
64
+ child.parent_id = page.id
65
+ end
66
+ else
67
+ child = page
68
+ end
69
+
70
+ begin
71
+ child.status = Status[self.status(ctx).first.to_s]
72
+ rescue
73
+ # ignore status changes if status doesn't exist
74
+ end
75
+
76
+ begin
77
+ child.description = self.description(ctx).first.to_s
78
+ rescue
79
+ end
80
+
81
+ begin
82
+ child.title = self.title(ctx).first.to_s
83
+ rescue
84
+ end
85
+
86
+ begin
87
+ child.breadcrumb = self.breadcrumb(ctx).first.to_s || child.title
88
+ rescue
89
+ child.breadcrumb = child.title
90
+ end
91
+
92
+ if child.breadcrumb.nil? || child.breadcrumb == ''
93
+ child.breadcrumb = child.title
94
+ end
95
+
96
+ child.class_name = child.class.name
97
+
98
+ page_parts_info.each_pair do |part_name, part_info|
99
+ part = child.part(part_name)
100
+ if part.nil?
101
+ part = ::PagePart.new(:name => part_name)
102
+ end
103
+ if part_info[:filter]
104
+ part.filter_id = part_info[:filter]
105
+ end
106
+ part.content = part_info[:content]
107
+ if !child.has_part?(part_name)
108
+ child.parts.concat part
109
+ end
110
+ end
111
+ child.save!
112
+ child.parts.each do |part|
113
+ if part.content.nil?
114
+ part.content = ''
115
+ part.save
116
+ end
117
+ end
118
+ end
119
+ end
120
+ [] # we return nothing
121
+ end
122
+
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,34 @@
1
+ module Fabulator
2
+ module Radiant
3
+ module Actions
4
+ class PagePart < Fabulator::Action
5
+
6
+ namespace Fabulator::RADIANT_NS
7
+
8
+ attribute :name, :static => false, :eval => true
9
+ attribute :filter, :static => false, :eval => true
10
+
11
+ has_select
12
+ has_actions
13
+
14
+ def run(context, autovivify = false)
15
+ content = []
16
+ @context.with(context) do |ctx|
17
+ if self.has_select?
18
+ content = self.select(ctx)
19
+ else
20
+ content = self.run_actions(ctx)
21
+ end
22
+ content = content.collect{ |c| c.to([FAB_NS, 'string'], ctx).value }.join('')
23
+ ctx.get_scoped_info('radiant/page/parts')[self.name(ctx).first.to_s] = {
24
+ :content => content,
25
+ :filter => self.filter(ctx).first.to_s
26
+ }
27
+ end
28
+ []
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
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-11-08 00:00:00 +00:00
18
+ date: 2010-12-03 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -65,6 +65,8 @@ files:
65
65
  - fabulator_extension.rb
66
66
  - lib/fabulator/radiant.rb
67
67
  - lib/fabulator/radiant/actions.rb
68
+ - lib/fabulator/radiant/actions/page.rb
69
+ - lib/fabulator/radiant/actions/page_part.rb
68
70
  - lib/fabulator/radiant/actions/require_auth.rb
69
71
  - lib/fabulator_filter.rb
70
72
  - lib/radiant-fabulator-extension.rb