qcms 1.3.3

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 (53) hide show
  1. data/.gitignore +14 -0
  2. data/README +70 -0
  3. data/Rakefile +39 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/admin/admin_controller.rb +12 -0
  6. data/app/controllers/admin/documents_controller.rb +133 -0
  7. data/app/controllers/admin/meta_definitions_controller.rb +36 -0
  8. data/app/controllers/documents_controller.rb +187 -0
  9. data/app/controllers/sendmail_controller.rb +87 -0
  10. data/app/helpers/admin/documents_helper.rb +71 -0
  11. data/app/helpers/documents_helper.rb +30 -0
  12. data/app/helpers/sendmail_helper.rb +2 -0
  13. data/app/models/document.rb +292 -0
  14. data/app/models/document_mailer.rb +13 -0
  15. data/app/models/document_sweeper.rb +28 -0
  16. data/app/models/meta_definition.rb +57 -0
  17. data/app/models/sendmail.rb +18 -0
  18. data/app/views/admin/admin/system.html.erb +34 -0
  19. data/app/views/admin/documents/_form.html.erb +60 -0
  20. data/app/views/admin/documents/default.edit.html.erb +10 -0
  21. data/app/views/admin/documents/default.new.html.erb +10 -0
  22. data/app/views/admin/documents/default.show.html.erb +77 -0
  23. data/app/views/admin/documents/index.html.erb +32 -0
  24. data/app/views/admin/documents/shared/_resource_link.html.erb +6 -0
  25. data/app/views/document_mailer/new_document.erb +12 -0
  26. data/app/views/layouts/admin.html.erb +43 -0
  27. data/app/views/layouts/application.html.erb +44 -0
  28. data/app/views/pages/404.html.erb +28 -0
  29. data/app/views/pages/contact.html.erb +42 -0
  30. data/app/views/pages/default.html.erb +12 -0
  31. data/app/views/pages/feed.rss.builder +17 -0
  32. data/app/views/pages/home.html.erb +5 -0
  33. data/app/views/pages/search.html.erb +19 -0
  34. data/app/views/pages/shared/_archived_pages.erb +16 -0
  35. data/app/views/pages/shared/_related_pages.html.erb +13 -0
  36. data/app/views/pages/sitemap.html.erb +9 -0
  37. data/app/views/pages/template.erb +51 -0
  38. data/app/views/pages/thank_you.html.erb +1 -0
  39. data/app/views/sendmail/default.erb +12 -0
  40. data/config/sitemap.example.yml +39 -0
  41. data/db/migrate/20090824150210_create_documents.rb +37 -0
  42. data/db/migrate/20091208124512_create_meta_definition.rb +26 -0
  43. data/init.rb +1 -0
  44. data/install.rb +1 -0
  45. data/lib/qcms.rb +4 -0
  46. data/lib/tasks/cms.rake +237 -0
  47. data/qcms.gemspec +91 -0
  48. data/rails/init.rb +3 -0
  49. data/tasks/qcms_tasks.rake +223 -0
  50. data/test/qwerty_test.rb +8 -0
  51. data/test/test_helper.rb +3 -0
  52. data/uninstall.rb +1 -0
  53. metadata +107 -0
@@ -0,0 +1,28 @@
1
+ <% @page_title = 'Page Not Found' %>
2
+ <h2>Oops</h2>
3
+
4
+ <p>Sorry we could not find the page you we looking for!</p>
5
+
6
+ <p>Here are some alternative suggestions</p>
7
+
8
+ <ul>
9
+ <li><a href="/sitemap">Sitemap</a></li>
10
+ </ul>
11
+
12
+ <% unless Document.with_state(:published).empty? %>
13
+ <h3>Recent pages</h3>
14
+
15
+
16
+ <p>Updated <%= time_ago_in_words Document.with_state(:published).latest.first.updated_at %> ago</p>
17
+
18
+ <ol id="latest_pages">
19
+ <% Document.with_state(:published).latest.only(10).each do |page| %>
20
+ <li>
21
+ [<%= page.label.titleize %>] <a href="<%= document_path(page) %>"><%= page.title %></a>
22
+ </li>
23
+ <% end %>
24
+ </ol>
25
+ <% else %>
26
+ <p> No pages have been added yet</p>
27
+ <% end %>
28
+
@@ -0,0 +1,42 @@
1
+ <h3>Contact Us</h3>
2
+
3
+ <%= form_tag sendmail_path %>
4
+
5
+ <p>First name:<br /><input type="text" name ="first_name" class="required" /></p>
6
+ <p>Last name:<br /><input type="text" name ="last_name" class="required" /></p>
7
+ <p>Email:<br /><input type="text" name ="email" class="required email" /></p>
8
+ <p>Message:<br><textarea name="message" id="message">Type your message here</textarea></p>
9
+
10
+
11
+ <input type="hidden" name="meta[from]" value="kris.leech@interkonect.com" />
12
+ <input type="hidden" name="meta[subject]" value="kris.leech@interkonect.com" />
13
+ <input type="hidden" name="meta[recipients]" value="kris.leech@interkonect.com" />
14
+ <!-- <input type="hidden" name="meta[redirect_to]" value="/thank-you" /> -->
15
+ <!-- <input type="hidden" name="meta[message]" value="Thank you!" /> -->
16
+ <input type="hidden" name="meta[show_page]" value="thank_you" />
17
+
18
+
19
+ <input type="submit" name="submit" value="Send" />
20
+ </form>
21
+
22
+
23
+ <p>Your email address will be kept confidential and used only to respond to your enquiry</p>
24
+
25
+
26
+
27
+ <%= javascript_include_tag 'jquery-validate/jquery.validate.min.js' %>
28
+ <script>
29
+ $(document).ready(function() {
30
+ $('form').validate();
31
+ });
32
+
33
+ $('#message').blur(function(){
34
+ if($(this).attr('value')=='') {
35
+ $(this).attr('value', 'Type your message here...')
36
+ }
37
+ });
38
+
39
+ $('#message').focus(function(){
40
+ $(this).attr('value', '');
41
+ });
42
+ </script>
@@ -0,0 +1,12 @@
1
+ <% if RAILS_ENV == 'development' %>
2
+ <% if current_user %>
3
+ <% form_tag generate_template_admin_document_path(@document.id) do %>
4
+ <input type="submit" value="Create Template" />
5
+ <% end %>
6
+ <p style="margin-top: 20px;">The template created will be app/views/pages/<%= @document.meta_definition.label_path.gsub('/', '.') %>.html.erb</p>
7
+ <% else %>
8
+ <p><a href="/login">Login</a> to create a blank template</p>
9
+ <% end %>
10
+ <% else %>
11
+ <% raise "No Template Found for #{request.path}" %>
12
+ <% end %>
@@ -0,0 +1,17 @@
1
+ xml.instruct! :xml, :version => "1.0"
2
+ xml.rss :version => "2.0" do
3
+ xml.channel do
4
+ xml.title "#{Settings.site.name} #{@document.permalink.upcase}"
5
+ xml.description @document.summary.blank? ? @document.summary : Settings.site.description
6
+ xml.link document_url(@document) + '.rss'
7
+
8
+ for document in @document.children.with_state(:published)
9
+ xml.item do
10
+ xml.title document.title
11
+ xml.description document.summary
12
+ xml.pubDate document.published_at.to_s(:rfc822)
13
+ xml.link document_url(document)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ <h2>Default Homepage</h2>
2
+
3
+ <p>Create a template called home.html.erb</p>
4
+
5
+
@@ -0,0 +1,19 @@
1
+ <% @documents.each do | document | %>
2
+ <div>
3
+ [<%= document.label.titleize %>]
4
+ <a href='<%= document_path(document) %>'><%= document.title %></a>
5
+ <%= document.summary %><BR>
6
+ <%= document.published_at %>
7
+ </div>
8
+ <% end %>
9
+
10
+ <p><%= will_paginate @documents %></p>
11
+
12
+ <script>
13
+ // Add the query string to the pagination links
14
+ $(function(){
15
+ $('.pagination a').each(function(){
16
+ $(this).attr('href', $(this).attr('href') + '&search[title_like]=<%= params[:search][:title_like] %>');
17
+ })
18
+ })
19
+ </script>
@@ -0,0 +1,16 @@
1
+ <%
2
+ year ||= Time.now.year
3
+ folder ||= @folder
4
+ heading ||= 'Archive'
5
+ %>
6
+
7
+ <% pages_by_month = folder.children.group_by(&:month) %>
8
+
9
+ <h3><%= heading %></h3>
10
+ <ul class="archive">
11
+ <% 1.upto(12) do | month | %>
12
+ <li><a href="<%= document_archive_path(folder.root.permalink, month.to_s, year.to_s) %>"><%= Date::MONTHNAMES[month] %></a>
13
+ <small>(<%= pages_by_month[Date::MONTHNAMES[month]] ? pages_by_month[Date::MONTHNAMES[month]].size.to_s : '0' %>)</small>
14
+ </li>
15
+ <% end %>
16
+ </ul>
@@ -0,0 +1,13 @@
1
+ <%
2
+ # Settings
3
+ heading ||= 'Related Pages'
4
+ page ||= @document
5
+ -%>
6
+ <% unless page.siblings.empty? %>
7
+ <h3><%= heading %></h3>
8
+ <ol id="related_pages">
9
+ <% page.siblings.each do |p| -%>
10
+ <li><a href="<%= document_path(p) %>"><%= p.title %></a></li>
11
+ <% end -%>
12
+ </ol>
13
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <style>
2
+ ul#pages { margin-left:20px; }
3
+ </style>
4
+
5
+ <ul>
6
+ <% Document.roots.public.each do | document | %>
7
+ <li><a href="<%= document_path(document) %>"><%= document.title %></a></li>
8
+ <% end %>
9
+ </ul>
@@ -0,0 +1,51 @@
1
+ <h2><%= @document.label.capitalize %></h2>
2
+
3
+ <div><%%= @document.title %></div>
4
+ <div><%%= @document.body %></div>
5
+ <div><%%= @document.published_at.to_s %></div>
6
+ <div><%%= time_ago_in_words @document.published_at %></div>
7
+ <div><%%= @document.author.name %></div>
8
+ <%% if @document.image.exists? %>
9
+ <div>
10
+ <img src="<%%= @document.image.url %>" alt="" />
11
+ </div>
12
+ <%% else %>
13
+ <!-- No image -->
14
+ <%% end %>
15
+
16
+ <hr />
17
+
18
+ <% @document.meta_definition.children.each do | md | %>
19
+ <% klass = md.label %>
20
+ <h3><%= klass.titleize.pluralize %></h3>
21
+ <%% unless @<%= klass.pluralize %>.empty? %>
22
+ <div id="<%= klass.pluralize %>">
23
+ <%% @<%= klass.pluralize %>.each do | <%= klass %> | %>
24
+ <div class="<%= klass %>">
25
+ <h4><a href="<%%= document_path(<%= klass %>) %>"><%%= <%= klass %>.title %></a></h4>
26
+ <div><%%= <%= klass %>.summary %></div>
27
+ <div><%%= <%= klass %>.body %></div>
28
+ <div><%%= <%= klass %>.published_at.to_s %></div>
29
+ <div><%%= time_ago_in_words <%= klass %>.published_at %></div>
30
+ <div><%%= <%= klass %>.author.name %></div>
31
+ <%% if <%= klass %>.image.exists? %>
32
+ <img src="<%%= <%= klass %>.image.url %>" alt="" />
33
+ <%% else %>
34
+ <!-- <img src="/images/missing_<%= klass %>_picture.png" alt="" /> -->
35
+ <%% end %>
36
+ </div>
37
+ <%% end %>
38
+ <p><%%= will_paginate @<%= klass.pluralize %> %></p>
39
+ </div>
40
+ <%% else %>
41
+ <p>Nothing here yet!</p>
42
+ <%% end %>
43
+ <hr />
44
+ <% end %>
45
+
46
+ <%% content_for :debug_info do %>
47
+ VIEW:<%%= __FILE__ %><br>
48
+ <%% end %>
49
+
50
+ <!-- Default Template Generated <%= Time.now.strftime('%d/%m/%Y %H:%M') %> -->
51
+ <!-- By <%= (current_user || User.anonymous).name %> -->
@@ -0,0 +1 @@
1
+ <p>Thank you for your message, we will get back to you shortly!</p>
@@ -0,0 +1,12 @@
1
+ <h2>Contact Form</h2>
2
+
3
+ <table>
4
+ <% @data.each do |k,v| -%>
5
+ <tr>
6
+ <td><strong><%= k.humanize.gsub(/^[a-z]|\s+[a-z]/) { |a| a.upcase } %></strong></td>
7
+ <td><%= v %></td>
8
+ </tr>
9
+ <% end -%>
10
+ </table>
11
+
12
+ <p>Sent <%= Time.now.strftime('%d/%b/%y @ %I:%M %p') %></p>
@@ -0,0 +1,39 @@
1
+ ---
2
+
3
+ page:
4
+ sort_by :title
5
+
6
+ blog:
7
+ children:
8
+ post:
9
+ sort_by: published_at
10
+ per_page: 10
11
+ children:
12
+ comment:
13
+ randomise_permalink: true
14
+ default_state: pending
15
+ body_length: 255
16
+ body_strip_html: true
17
+ sort_by: published_at
18
+ per_page: 20
19
+
20
+ about:
21
+ children:
22
+ page:
23
+ sort_by: position
24
+ per_page: 10
25
+ children:
26
+ link:
27
+ sort_by: title
28
+ per_page: 1000
29
+
30
+
31
+ gallery:
32
+ children:
33
+ gallery:
34
+ sort_by: title
35
+ per_page: 10
36
+ children:
37
+ picture:
38
+ sort_by: title
39
+ per_page: 10
@@ -0,0 +1,37 @@
1
+ class CreateDocuments < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :documents do |t|
4
+ t.string "title"
5
+ t.string "type"
6
+ t.text "summary"
7
+ t.text "body"
8
+ t.string "permalink"
9
+ t.string "state"
10
+ t.string "label"
11
+ t.text "path"
12
+ t.integer "author_id"
13
+ t.integer "parent_id"
14
+ t.string "meta_title"
15
+ t.string "meta_description"
16
+ t.string "meta_keywords"
17
+ t.integer "position", :default => 0
18
+ t.string "resource_file_name"
19
+ t.string "resource_content_type"
20
+ t.integer "resource_file_size"
21
+ t.string "resource_description"
22
+ t.datetime "published_at"
23
+ t.integer "meta_definition_id"
24
+ t.integer "hits", :default => 0
25
+ # Extra fields
26
+ t.text "cf_text_1"
27
+ t.string "cf_string_1"
28
+ t.string "cf_string_2"
29
+
30
+ t.timestamps
31
+ end
32
+ end
33
+
34
+ def self.down
35
+ drop_table :documents
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ class CreateMetaDefinition < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :meta_definitions do |t|
4
+ t.string :label_path
5
+ t.string :label
6
+ t.integer :parent_id
7
+ t.string :sort_by
8
+ t.integer :per_page
9
+ t.string :default_type # STI class
10
+ t.string :default_state
11
+ t.text :autherisation
12
+ t.text :field_map
13
+ t.text :flash_messages
14
+ t.boolean :randomise_permalink, :default => false
15
+ t.boolean :body_strip_html, :default => false
16
+ t.integer :body_length
17
+ t.boolean :record_hits, :default => false
18
+ t.integer :position, :default => 0
19
+ t.boolean :notify_admin, :default => 0
20
+ end
21
+ end
22
+
23
+ def self.down
24
+ drop_table :meta_definitions
25
+ end
26
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init"
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,4 @@
1
+ # Qwerty
2
+ module Qcms
3
+ VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
4
+ end
@@ -0,0 +1,237 @@
1
+ namespace :qwerty do
2
+ namespace :cms do
3
+
4
+ desc "Create some Lipsum entries for a section"
5
+ task :seed => [:environment] do
6
+
7
+ unless ENV['ids']
8
+ puts 'Supply ids of sections to seed, ids=4,5,12 OR ids=all'
9
+ Document.roots.each do | d |
10
+ puts d.title + ': ' + d.id.to_s
11
+ end
12
+ exit
13
+ end
14
+
15
+
16
+ if ENV['ids'] == 'all'
17
+ sections = Document.roots.map { |d| d.id }
18
+ else
19
+ sections = ENV['ids'].split(',')
20
+ end
21
+
22
+ require 'faker'
23
+
24
+ sections.each do | section_id |
25
+
26
+ section = Document.find(section_id)
27
+
28
+ next if section.meta_definition.children.empty?
29
+
30
+ label = ENV['label'] || section.meta_definition.children.first.label
31
+ num = (ENV['num'] || 15).to_i
32
+
33
+ section.children.by_label(label).each { |d| d.destroy }
34
+
35
+ puts 'Adding to ' + num.to_s + ' ' + label.pluralize + ' to ' + section.title
36
+
37
+ num.times do | ctr |
38
+ puts ctr.to_s
39
+ doc = Document.create!(
40
+ :title => label.titleize + ' #' + (ctr+1).to_s,
41
+ :author_id => User.first.id,
42
+ :state => 'published',
43
+ :published_at => Time.now - ctr.days,
44
+ :body => Faker::Lorem.paragraphs.join,
45
+ :parent_id => section.id,
46
+ :label => label
47
+ )
48
+ end
49
+ end
50
+ end
51
+
52
+ desc "Update meta_definitions from sitemap.yml"
53
+ task :update_meta_definitions => [:environment] do
54
+ puts 'Updating Meta Definitions'
55
+ sitemap = YAML::load(ERB.new(IO.read(File.join(RAILS_ROOT, 'config', 'sitemap.yml'))).result)
56
+ create_meta_definitions(sitemap)
57
+ if @errors_occured
58
+ puts '*' * 20
59
+ puts 'ERRORS OCCURED'
60
+ puts '*' * 20
61
+ end
62
+ end
63
+
64
+ def create_meta_definitions(metas, parent_id = nil)
65
+ metas.each do | k, v |
66
+ if MetaDefinition.exists?(:parent_id => parent_id, :label => k)
67
+
68
+ m = MetaDefinition.find(:first, :conditions => {:parent_id => parent_id, :label => k})
69
+ m.update_attributes(
70
+ :label => (v['label'] || k),
71
+ :parent_id => parent_id,
72
+ :per_page => v['per_page'],
73
+ :sort_by => v['sort_by'],
74
+ # :label_path => v['label_path'],
75
+ :default_type => v['default_type'] || 'Document',
76
+ :default_state => v['default_state'],
77
+ :randomise_permalink => v['randomise_permalink'] || false,
78
+ :body_length => v['body_length'],
79
+ :body_strip_html => v['body_strip_html'] || false,
80
+ :field_map => (YAML.dump(v['field_map']) unless v['field_map'].nil?),
81
+ :autherisation => (YAML.dump(v['autherisation']) unless v['autherisation'].nil?),
82
+ :flash_messages => (YAML.dump(v['flash_messages']) unless v['flash_messages'].nil?)
83
+
84
+
85
+ )
86
+ if m.errors.empty?
87
+ puts "[UPDATED] #{m.label_path}"
88
+ else
89
+ puts "[ERROR] #{m.label_path} #{m.id}"
90
+ puts m.errors.full_messages
91
+ @errors_occured = true
92
+ end
93
+
94
+ else
95
+ m = MetaDefinition.create!(
96
+ :label => (v['label'] || k),
97
+ :parent_id => parent_id,
98
+ :label_path => v['label_path'],
99
+ :per_page => v['per_page'],
100
+ :sort_by => v['sort_by'],
101
+ :default_type => v['default_type'] || 'Document',
102
+ :default_state => v['default_state'],
103
+ :randomise_permalink => v['randomise_permalink'] || false,
104
+ :body_length => v['body_length'],
105
+ :body_strip_html => v['body_strip_html'] || false,
106
+ :field_map => (YAML.dump(v['field_map']) unless v['field_map'].nil?),
107
+ :autherisation => (YAML.dump(v['autherisation']) unless v['autherisation'].nil?),
108
+ :flash_messages => (YAML.dump(v['flash_messages']) unless v['flash_messages'].nil?)
109
+ )
110
+
111
+ if m.root?
112
+ d = Document.new(
113
+ :permalink => m.label,
114
+ :author_id => User.first.id,
115
+ :state => 'published',
116
+ :published_at => Time.now,
117
+ :title => m.label.titleize,
118
+ :meta_definition_id => m.id,
119
+ :label => m.label) # label set manually for roots
120
+ d.type = m.default_type || 'Document'
121
+ d.save!
122
+ end
123
+
124
+ puts "[NEW] #{m.label_path}"
125
+ end
126
+
127
+ unless v['children'].nil?
128
+ create_meta_definitions(v['children'], m.id)
129
+ end
130
+ end
131
+ end
132
+
133
+ desc "Delete meta_definitions not in sitemap.yml"
134
+ task :delete_meta_definitions => [:environment] do
135
+ puts 'Deleting Meta Definitions'
136
+ sitemap = YAML::load(ERB.new(IO.read(File.join(RAILS_ROOT, 'config', 'sitemap.yml'))).result)
137
+ delete_meta_defintions(sitemap, MetaDefinition.roots)
138
+ end
139
+
140
+ def delete_meta_defintions(sitemap, metas)
141
+ metas.each do | md |
142
+ if sitemap && sitemap[md.label]
143
+ delete_meta_defintions(sitemap[md.label]['children'], md.children) if md.children
144
+ else
145
+ puts 'Deleting ' + md.label_path
146
+ md.destroy
147
+ end
148
+ end
149
+ end
150
+
151
+ desc "Overwrite sitemap.yml from Database"
152
+ task :update_sitemap_from_db => [:environment] do
153
+ meta_definitions = MetaDefinition.find(:all, :order => 'label_path', :conditions => { :parent_id => nil })
154
+ sitemap = make_sitemap(meta_definitions)
155
+ sitemap = sitemap.to_yaml.gsub("!ruby/symbol ", ":").sub("---","").split("\n").map(&:rstrip).join("\n").strip
156
+ File.open(File.join(RAILS_ROOT, 'config', 'sitemap.yml'), 'w') {|f| f.write(sitemap) }
157
+ end
158
+
159
+ def make_sitemap(meta_definitions)
160
+ fields = %w(notify_admins record_hits per_page sort_by default_type default_state randomise_permalink body_length body_strip_html field_map autherisation flash_messages)
161
+
162
+ sitemap = {}
163
+
164
+ meta_definitions.each do | md |
165
+ sitemap[md.label] = {}
166
+
167
+ fields.each do | field |
168
+ value = md.send(field)
169
+ value = 'true' if value.is_a? TrueClass
170
+ value = 'false' if value.is_a? FalseClass
171
+ sitemap[md.label][field] = value if value && !(value.respond_to?('empty?') && value.empty?)
172
+ end
173
+
174
+ # recursive
175
+ sitemap[md.label]['children'] = make_sitemap(md.children) unless md.children.empty?
176
+ end
177
+
178
+ return sitemap
179
+ end
180
+
181
+ desc "Generate Site from Meta Definitions"
182
+ task :build_site => [:update_meta_definitions] do
183
+ puts "Building Site"
184
+
185
+ if User.all.empty?
186
+ puts "Add some users first: rake qwerty:core:seed"
187
+ exit
188
+ end
189
+
190
+
191
+
192
+ MetaDefinition.roots.each do | meta_definition |
193
+ next if meta_definition.label == 'page' # special case
194
+ next if meta_definition.children.empty?
195
+ unless Document.exists?(:path => meta_definition.label_path)
196
+
197
+ puts "[NEW] #{meta_definition.label}"
198
+ d=Document.new(
199
+ :permalink => meta_definition.label,
200
+ :author_id => User.first.id,
201
+ :state => 'published',
202
+ :published_at => Time.now,
203
+ :title => meta_definition.label.titleize,
204
+ :meta_definition_id => meta_definition.id,
205
+ :label => meta_definition.label) # label set manually for roots
206
+ d.type = meta_definition.default_type || 'Document'
207
+ d.save!
208
+ else
209
+ puts "[SKIP] #{meta_definition.label} already exists"
210
+ end
211
+ end
212
+
213
+ # NOTE: If you get an 'nil' error here it is because you don't have a root document called 'page'
214
+ %w(home contact sitemap).each do | title |
215
+ unless Document.exists?(:permalink => title)
216
+ d=Document.new(
217
+ :permalink => title,
218
+ :author_id => User.first,
219
+ :title => title.titleize,
220
+ :state => 'published',
221
+ :published_at => Time.now,
222
+ :meta_definition_id => MetaDefinition.find_by_label_path('page').id,
223
+ :label => 'page')
224
+ d.type = 'Document'
225
+ d.save!
226
+ else
227
+ puts "[SKIP] #{title} already exists"
228
+ end
229
+ end
230
+ end
231
+
232
+ task :rebuild_site => [:environment] do
233
+ MetaDefinition.destroy_all # will cause deletion of all documents as well
234
+ Rake::Task['qwerty:cms:build_site'].invoke
235
+ end
236
+ end
237
+ end