uzuuzu-cms 0.0.1 → 0.0.2

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.
Files changed (42) hide show
  1. data/VERSION +1 -1
  2. data/lib/uzuuzu-cms.rb +2 -0
  3. data/lib/uzuuzu-cms/controller/admin/view/index.rhtml +35 -0
  4. data/lib/uzuuzu-cms/controller/contents.rb +6 -2
  5. data/lib/uzuuzu-cms/controller/error.rb +11 -0
  6. data/lib/uzuuzu-cms/controller/index.rb +0 -9
  7. data/lib/uzuuzu-cms/controller/initialize.rb +22 -87
  8. data/lib/uzuuzu-cms/controller/openid.rb +1 -1
  9. data/lib/uzuuzu-cms/controller/page.rb +43 -6
  10. data/lib/uzuuzu-cms/controller/user.rb +1 -2
  11. data/lib/uzuuzu-cms/controller/view/crud/destroy.rhtml +2 -2
  12. data/lib/uzuuzu-cms/controller/view/crud/edit.rhtml +2 -2
  13. data/lib/uzuuzu-cms/controller/view/crud/index.rhtml +2 -2
  14. data/lib/uzuuzu-cms/controller/view/crud/new.rhtml +2 -2
  15. data/lib/uzuuzu-cms/controller/view/crud/show.rhtml +2 -2
  16. data/lib/uzuuzu-cms/controller/view/error/404.rhtml +1 -1
  17. data/lib/uzuuzu-cms/controller/view/error/500.rhtml +1 -1
  18. data/lib/uzuuzu-cms/controller/view/initialize/step1.rhtml +7 -5
  19. data/lib/uzuuzu-cms/controller/view/initialize/step2.rhtml +6 -19
  20. data/lib/uzuuzu-cms/controller/view/openid/index.rhtml +3 -3
  21. data/lib/uzuuzu-cms/controller/view/user/entry.rhtml +4 -4
  22. data/lib/uzuuzu-cms/helper/page.rb +61 -0
  23. data/lib/uzuuzu-cms/model/authority.rb +18 -0
  24. data/lib/uzuuzu-cms/{controller/view/admin/index.rhtml → model/authority_group.rb} +0 -0
  25. data/lib/uzuuzu-cms/model/contents.rb +4 -2
  26. data/lib/uzuuzu-cms/model/info.rb +61 -89
  27. data/lib/uzuuzu-cms/model/layout.rb +19 -1
  28. data/lib/uzuuzu-cms/model/page.rb +57 -98
  29. data/lib/uzuuzu-cms/model/page_meta.rb +20 -0
  30. data/lib/uzuuzu-cms/model/user.rb +2 -0
  31. data/lib/uzuuzu-cms/wrapper/application.rb +6 -0
  32. data/lib/uzuuzu-cms/wrapper/controller.rb +17 -1
  33. data/lib/uzuuzu-cms/wrapper/helper.rb +6 -0
  34. data/lib/uzuuzu-cms/wrapper/lang/ja.yaml +5 -14
  35. data/lib/uzuuzu-cms/wrapper/model.rb +1 -1
  36. data/lib/uzuuzu-cms/wrapper/uzuuzu.rb +10 -0
  37. data/uzuuzu-cms.gemspec +11 -7
  38. metadata +12 -8
  39. data/lib/uzuuzu-cms/controller/plugin.rb +0 -16
  40. data/lib/uzuuzu-cms/controller/view/initialize/step3.rhtml +0 -24
  41. data/lib/uzuuzu-cms/controller/view/layout.rhtml +0 -25
  42. data/lib/uzuuzu-cms/model/page_body.rb +0 -37
@@ -1,13 +1,13 @@
1
1
 
2
2
  <div id="user_entry">
3
- <p>#{uzuuzu_string(:user_entry)}"</p>
4
- <form method="post" action="#{rs(:entry, @user.id)}">
3
+ <p><%= localize(:user_entry) %></p>
4
+ <form method="post" action="<%= r(:entry, @user.id) %>">
5
5
  <p>
6
- #{uzuuzu_string(:user_entry_name)}:
6
+ <%= localize(:user_entry_name) %>:
7
7
  <input id="username" name="username" type="text" />
8
8
  </p>
9
9
  <p>
10
- <input type="submit" value="#{uzuuzu_string(:entry)}"/>
10
+ <input type="submit" value="<%= localize(:entry) %>"/>
11
11
  </p>
12
12
  </form>
13
13
  </div>
@@ -0,0 +1,61 @@
1
+ # coding: utf-8
2
+
3
+ module UzuUzu
4
+ module Helper
5
+ module Page
6
+ def page
7
+ @_page ||= controller.info
8
+ end
9
+
10
+ def contents(options={}, locals={})
11
+ @_contents ||= page.contents_render(options, locals)
12
+ end
13
+
14
+ def render_page(page, contents=nil, options={}, locals={})
15
+ @_page = page
16
+ @_contents = contents
17
+ body = page.render(options, locals)
18
+ body = render_engine(body)
19
+ @_page = nil
20
+ @_contents = nil
21
+ body
22
+ end
23
+
24
+ def render_plugin(page, body)
25
+ ::UzuUzu::Plugin.render(page, body)
26
+ end
27
+
28
+ def page_title
29
+ h page.page_title
30
+ end
31
+
32
+ def page_meta
33
+ if page.respond_to?(:page_metas)
34
+ page.page_metas.map do |meta|
35
+ meta(meta.name, meta.content)
36
+ end.join("\n")
37
+ else
38
+ meta("title", page_title)
39
+ end
40
+ end
41
+
42
+ def page_js
43
+ page.js_urls.map do |url|
44
+ js(url)
45
+ end.join("\n")
46
+ end
47
+
48
+ def page_css
49
+ page.css_urls.map do |url|
50
+ css(url)
51
+ end.join("\n")
52
+ end
53
+
54
+ def breadcrumbs(sep)
55
+ page.breadcrumbs.map do |breadcrumb|
56
+ ""
57
+ end.join("#{sep}\n")
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+
3
+ module UzuUzu
4
+ class Authority
5
+ include DataMapper::Resource
6
+ include DataMapper::Timestamps
7
+
8
+ property :id, Serial
9
+ property :level
10
+
11
+ end #User
12
+
13
+ if auto_upgrade?
14
+ repository do
15
+ User.auto_upgrade!
16
+ end
17
+ end
18
+ end #UzuUzu
@@ -28,8 +28,10 @@ module UzuUzu
28
28
  has n, :csses, :through => Resource
29
29
  has n, :javascripts, :through => Resource
30
30
 
31
- def render(instance=nil, options={}, locals={})
32
- UzuUzu.render_engine(instance, self.body, self.format, options, locals)
31
+ def render(options={}, locals={})
32
+ contents = "<div id=\"contents_#{self.id}\">\n"
33
+ contents += UzuUzu::Controller.current.render_engine(self.body, self.format, options, locals)
34
+ contents += "\n</div>"
33
35
  end
34
36
  end # Contents
35
37
 
@@ -10,31 +10,23 @@ module UzuUzu
10
10
  class User
11
11
  has n, :infos
12
12
  end
13
-
13
+
14
14
  class Css
15
15
  has n, :infos, :through => Resource
16
16
  end
17
-
17
+
18
18
  class Javascript
19
19
  has n, :infos, :through => Resource
20
20
  end
21
-
21
+
22
22
  class Layout
23
23
  has n, :infos
24
24
  end
25
-
26
- class PageBody
27
- has n, :info_headers, 'UzuUzu::Info', :child_key => [ :header_id ]
28
- has n, :info_footers, 'UzuUzu::Info', :child_key => [ :footer_id ]
29
- has n, :info_navigators, 'UzuUzu::Info', :child_key => [ :navigator_id ]
30
- has n, :info_lefts, 'UzuUzu::Info', :child_key => [ :left_id ]
31
- has n, :info_rights, 'UzuUzu::Info', :child_key => [ :right_id ]
32
- end
33
-
25
+
34
26
  class Page
35
27
  has n, :infos
36
28
  end
37
-
29
+
38
30
  class Info
39
31
  include DataMapper::Resource
40
32
 
@@ -45,119 +37,99 @@ module UzuUzu
45
37
  :length => 255
46
38
  property :step, Integer,
47
39
  :default => 1
48
- property :use_navigator, Boolean,
49
- :default => false
50
-
40
+
51
41
  belongs_to :top_page, 'UzuUzu::Page', :required => false
52
42
  belongs_to :layout
53
- belongs_to :admin, 'UzuUzu::User', :required => false
54
- belongs_to :header, 'UzuUzu::PageBody'
55
- belongs_to :footer, 'UzuUzu::PageBody'
56
- belongs_to :navigator, 'UzuUzu::PageBody'
57
- belongs_to :left, 'UzuUzu::PageBody'
58
- belongs_to :right, 'UzuUzu::PageBody'
59
43
 
60
44
  has n, :csses, 'UzuUzu::Css', :through => Resource
61
45
  has n, :javascripts, 'UzuUzu::Javascript', :through => Resource
62
-
63
46
  def self.uniq
64
47
  ret = nil
65
48
  UzuUzu.transaction do |tr|
66
49
  tr.begin
67
50
  ary = self.all
68
51
  if ary.empty?
69
- ret = self.new
70
- ret.title = "UzuUzu"
71
- ret.layout = ::UzuUzu::Layout.first
72
- ret.header = ::UzuUzu::PageBody.new
73
- ret.footer = ::UzuUzu::PageBody.new
74
- ret.navigator = ::UzuUzu::PageBody.new
75
- ret.left = ::UzuUzu::PageBody.new
76
- ret.right = ::UzuUzu::PageBody.new
77
- if ret.save
78
- tr.commit
79
- else
80
- tr.rollback
81
- end
82
- break
52
+ fixture_load
83
53
  end
84
-
54
+ ary = self.all
55
+
85
56
  ret = ary.pop
86
57
  ary.each do |record|
87
58
  record.destroy
88
59
  end
89
-
90
60
  tr.commit
91
61
  end
92
62
  ret
93
63
  end #self.uniq
64
+ #
65
+ def self.fixture_load
66
+ # fixture load
67
+ ::UzuUzu.logger.debug 'fixture load start'
68
+ Dir.glob('./fixture/**/*.*').each do |path|
69
+ ::UzuUzu.logger.debug "fixture file : #{path}"
70
+ paths = path.split('/')
71
+ model_name = ::File.basename(paths.pop, '.*')
72
+ while !paths.blank? && paths[-1] != 'fixture'
73
+ model_name = "#{paths.pop.camel_case}::#{model_name.camel_case}"
74
+ end
75
+ begin
76
+ ::UzuUzu.logger.debug "fixture model name : #{model_name}"
77
+ model = eval("::#{model_name}")
78
+ ::UzuUzu::DataStore::Fixture.import_file(model, path, true)
79
+ rescue NameError => e
80
+ ::UzuUzu.logger.error(e.to_s)
81
+ end
82
+ end
83
+ ::UzuUzu.logger.debug 'fixture load end'
84
+ end # fixture_load
94
85
 
95
86
  def initialize?
96
- self.step == 4
87
+ self.step >= 2
97
88
  end
98
-
89
+
99
90
  def self.initialize?
100
91
  info = self.uniq
101
92
  info.initialize?
102
93
  end
103
-
104
- def render(instance=nil, contents=nil, options={})
105
- locals = {
106
- :@header => self.header.render(instance, options),
107
- :@footer => self.footer.render(instance, options),
108
- :@left => self.left.render(instance, options),
109
- :@right => self.right.render(instance, options),
110
- :@css => self.csses.to_a.map{|css|css.url},
111
- :@js => self.javascripts.to_a.map{|js|js.url}
112
- }
113
- locals[:@navigator] = self.navigator.render(instance, options) if self.use_navigator
114
- locals[:@contents] = contents
115
- locals[:@contents] ||= yield if block_given?
116
- locals[:@contents] ||= ""
117
- UzuUzu.render_engine(instance, self.layout.body, self.layout.format, options, locals)
118
- end # render
119
-
120
- def header
121
- page_body_property(super, :header)
122
- end # header
123
94
 
124
- def footer
125
- page_body_property(super, :footer)
126
- end # footer
95
+ def breadcrumbs
96
+ []
97
+ end
98
+
99
+ def layout_fix
100
+ self.layout
101
+ end
127
102
 
128
- def left
129
- page_body_property(super, :left)
130
- end # left
103
+ def css_urls
104
+ self.csses.map do |css|
105
+ css.url
106
+ end
107
+ end
131
108
 
132
- def right
133
- page_body_property(super, :right)
134
- end # right
109
+ def js_urls
110
+ self.javascripts.map do |js|
111
+ js.url
112
+ end
113
+ end
135
114
 
136
- def navigator
137
- page_body_property(super, :navigator)
138
- end # navigator
115
+ def contents_render(options={}, locals={})
116
+ ''
117
+ end
139
118
 
140
- private
141
- def page_body_property(value, property_name)
142
- if value.nil?
143
- UzuUzu.transaction do |tr|
144
- tr.commit do
145
- value = ::UzuUzu::PageBody.new
146
- self.send("#{property_name}=", value)
147
- self.save
148
- end
149
- end
150
- end
151
- value
152
- end
153
-
119
+ def page_title
120
+ self.title
121
+ end
122
+
123
+ def render(options={}, locals={})
124
+ self.layout.render(options, locals)
125
+ end # render
154
126
  end #Info
155
-
127
+
156
128
  if auto_upgrade?
157
129
  repository do
158
130
  Info.auto_upgrade!
159
131
  InfoJavascript.auto_upgrade!
160
- CssInfo.auto_upgrade!
132
+ CssInfo.auto_upgrade!
161
133
  end
162
134
  end
163
135
  end #UzuUzu
@@ -1,6 +1,15 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module UzuUzu
4
+
5
+ class Css
6
+ has n, :layouts, :through => Resource
7
+ end
8
+
9
+ class Javascript
10
+ has n, :layouts, :through => Resource
11
+ end
12
+
4
13
  class Layout
5
14
  include DataMapper::Resource
6
15
 
@@ -12,11 +21,20 @@ module UzuUzu
12
21
  :required => true
13
22
  property :body, Text,
14
23
  :required => true
15
- end #Page
24
+
25
+ has n, :csses, 'UzuUzu::Css', :through => Resource
26
+ has n, :javascripts, 'UzuUzu::Javascript', :through => Resource
27
+
28
+ def render(options={}, locals={})
29
+ UzuUzu::Controller.current.render_engine(self.body, self.format, options, locals)
30
+ end # render
31
+ end # Layout
16
32
 
17
33
  if auto_upgrade?
18
34
  repository do
19
35
  Layout.auto_upgrade!
36
+ JavascriptLayout.auto_upgrade!
37
+ CssLayout.auto_upgrade!
20
38
  end
21
39
  end
22
40
  end #UzuUzu
@@ -2,7 +2,8 @@
2
2
  require 'uzuuzu-cms/model/css'
3
3
  require 'uzuuzu-cms/model/javascript'
4
4
  require 'uzuuzu-cms/model/layout'
5
- require 'uzuuzu-cms/model/page_body'
5
+ require 'uzuuzu-cms/model/contents'
6
+ require 'uzuuzu-cms/model/page_meta'
6
7
 
7
8
  module UzuUzu
8
9
  class Css
@@ -17,15 +18,17 @@ module UzuUzu
17
18
  has n, :pages
18
19
  end
19
20
 
20
- class PageBody
21
- has n, :pages
22
- has n, :page_headers, 'UzuUzu::Page', :child_key => :header_id
23
- has n, :page_footers, 'UzuUzu::Page', :child_key => :footer_id
24
- has n, :page_navigators, 'UzuUzu::Page', :child_key => :navigator_id
25
- has n, :page_lefts, 'UzuUzu::Page', :child_key => :left_id
26
- has n, :page_rights, 'UzuUzu::Page', :child_key => :right_id
21
+ class ContentsPage
22
+ include DataMapper::Resource
23
+
24
+ belongs_to :page, :key => true
25
+ belongs_to :contents, 'UzuUzu::Contents', :key => true
27
26
  end
28
-
27
+
28
+ class Contents
29
+ has n, :pages, :through => Resource, :via => :page
30
+ end
31
+
29
32
  class Page
30
33
  include DataMapper::Resource
31
34
  include DataMapper::Timestamps
@@ -37,28 +40,18 @@ module UzuUzu
37
40
  property :title, String,
38
41
  :required => true,
39
42
  :length => 255
40
- property :use_navigator, Boolean
41
43
  timestamps :at
42
44
 
43
45
  belongs_to :layout,
44
46
  :required => false
45
47
  belongs_to :parent, 'UzuUzu::Page',
46
48
  :required => false
47
- belongs_to :page_body
48
- belongs_to :header, 'UzuUzu::PageBody',
49
- :required => false
50
- belongs_to :footer, 'UzuUzu::PageBody',
51
- :required => false
52
- belongs_to :navigator, 'UzuUzu::PageBody',
53
- :required => false
54
- belongs_to :left, 'UzuUzu::PageBody',
55
- :required => false
56
- belongs_to :right, 'UzuUzu::PageBody',
57
- :required => false
58
-
49
+
59
50
  has n, :csses, :through => Resource
60
51
  has n, :javascripts, :through => Resource
61
- has n, :childs, 'UzuUzu::Page', :child_key => :parent
52
+ has n, :contents, 'UzuUzu::Contents', :through => Resource, :via => :contents
53
+ has n, :page_metas, :through => Resource
54
+ has n, :childs, 'UzuUzu::Page', :child_key => :parent_id
62
55
 
63
56
  def reverse_look_up(column=nil)
64
57
  if column
@@ -81,13 +74,6 @@ module UzuUzu
81
74
  end
82
75
  _breadcrumbs.reverse
83
76
  end
84
-
85
- #
86
- #
87
- #
88
- def self.top_page
89
- self.first(:top_page => true)
90
- end
91
77
 
92
78
  #
93
79
  #
@@ -122,90 +108,60 @@ module UzuUzu
122
108
  tree_map
123
109
  end
124
110
 
125
- def abs_layout
111
+ def layout_fix
126
112
  value = self.layout
127
- value ||= self.parent.abs_layout unless self.parent.nil?
128
- value ||= Info.uniq.layout
129
- value
130
- end
131
-
132
- def abs_header
133
- value = self.header
134
- value ||= self.parent.abs_header unless self.parent.nil?
135
- value ||= Info.uniq.header
136
- value
137
- end
138
-
139
- def abs_footer
140
- value = self.footer
141
- value ||= self.parent.abs_footer unless self.parent.nil?
142
- value ||= Info.uniq.footer
113
+ value ||= self.parent.abs_layout if self.parent
114
+ value ||= ::UzuUzu.info.layout
143
115
  value
144
116
  end
145
117
 
146
- def abs_left
147
- value = self.left
148
- value ||= self.parent.abs_left unless self.parent.nil?
149
- value ||= Info.uniq.left
150
- value
151
- end
152
-
153
- def abs_right
154
- value = self.right
155
- value ||= self.parent.abs_right unless self.parent.nil?
156
- value ||= Info.uniq.right
157
- value
158
- end
159
-
160
- def abs_navigator
161
- value = self.navigator
162
- value ||= self.parent.abs_navigator unless self.parent.nil?
163
- value ||= Info.uniq.navigator
164
- value
165
- end
166
-
167
- def abs_use_navigator
168
- value = self.use_navigator
169
- value ||= self.parent.abs_use_navigator unless self.parent.nil?
170
- value ||= Info.uniq.use_navigator
171
- value
172
- end
173
-
174
- def abs_csses
118
+ def css_urls
175
119
  value = []
176
120
  self.csses.each do |css|
177
121
  value << css
178
122
  end
179
- value += self.parent.abs_csses unless self.parent.nil?
180
- value += Info.uniq.csses if self.parent.nil?
181
- value
123
+ value += self.parent.abs_csses if self.parent
124
+ value += self.layout_fix.csses if self.layout_fix
125
+ value += ::UzuUzu.info.csses unless self.parent
126
+ self.contents.each do |content|
127
+ value += content.csses
128
+ end
129
+ value.map do |css|
130
+ css.url
131
+ end
182
132
  end
183
133
 
184
- def abs_javascripts
134
+ def js_urls
185
135
  value = []
186
136
  self.javascripts.each do |js|
187
137
  value << js
188
138
  end
189
- value += self.parent.abs_javascripts unless self.parent.nil?
190
- value += Info.uniq.javascripts if self.parent.nil?
191
- value
139
+ value += self.parent.abs_javascripts if self.parent
140
+ value += self.layout_fix.javascripts if self.layout_fix
141
+ value += ::UzuUzu.info.javascripts unless self.parent
142
+ self.contents.each do |content|
143
+ value += content.javascripts
144
+ end
145
+ value.map do |js|
146
+ js.url
147
+ end
148
+ end
149
+
150
+ def contents_render(options={}, locals={})
151
+ unless @contents_body
152
+ @contents_body = contents.map do |content|
153
+ content.render(options, locals)
154
+ end.join("\n")
155
+ end
156
+ @contents_body
157
+ end
158
+
159
+ def page_title
160
+ "#{self.title} - #{::UzuUzu.info.title}"
192
161
  end
193
162
 
194
- def render(instance=nil, contents=nil, options={})
195
- locals = {
196
- :@header => self.abs_header.render(instance, options),
197
- :@footer => self.abs_footer.render(instance, options),
198
- :@left => self.abs_left.render(instance, options),
199
- :@right => self.abs_right.render(instance, options),
200
- :@css => self.abs_csses.map{|css|css.url},
201
- :@js => self.abs_javascripts.map{|js|js.url}
202
- }
203
- locals[:@navigator] = self.abs_navigator.render(instance, options) if self.abs_use_navigator
204
- locals[:@contents] = contents
205
- locals[:@contents] ||= yield if block_given?
206
- locals[:@contents] ||= self.page_body.render(instance, options)
207
- locals[:@contents] ||= ""
208
- UzuUzu.render_engine(instance, self.abs_layout.body, self.abs_layout.format, options, locals)
163
+ def render(options={}, locals={})
164
+ self.layout_fix.render(options, locals)
209
165
  end # render
210
166
  end #Page
211
167
 
@@ -214,6 +170,9 @@ module UzuUzu
214
170
  Page.auto_upgrade!
215
171
  JavascriptPage.auto_upgrade!
216
172
  CssPage.auto_upgrade!
173
+ ContentsPage.auto_upgrade!
174
+ PageMeta.auto_upgrade!
175
+ PagePageMeta.auto_upgrade!
217
176
  end
218
177
  end
219
178
  end #UzuUzu