stiki 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/LICENSE +176 -0
  2. data/README.rdoc +65 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/project_monster_wiki/application.js +15 -0
  5. data/app/assets/javascripts/project_monster_wiki/authors.js +2 -0
  6. data/app/assets/javascripts/project_monster_wiki/pages.js +2 -0
  7. data/app/assets/javascripts/project_monster_wiki/spaces.js +2 -0
  8. data/app/assets/stylesheets/stiki/application.css.scss +17 -0
  9. data/app/assets/stylesheets/stiki/authors.css +4 -0
  10. data/app/assets/stylesheets/stiki/pages.css +54 -0
  11. data/app/assets/stylesheets/stiki/spaces.css +4 -0
  12. data/app/controllers/stiki/application_controller.rb +6 -0
  13. data/app/controllers/stiki/authors_controller.rb +6 -0
  14. data/app/controllers/stiki/pages_controller.rb +94 -0
  15. data/app/controllers/stiki/spaces_controller.rb +42 -0
  16. data/app/helpers/stiki/application_helper.rb +17 -0
  17. data/app/helpers/stiki/authors_helper.rb +4 -0
  18. data/app/helpers/stiki/pages_helper.rb +4 -0
  19. data/app/helpers/stiki/spaces_helper.rb +4 -0
  20. data/app/models/stiki/author.rb +9 -0
  21. data/app/models/stiki/page.rb +33 -0
  22. data/app/models/stiki/space.rb +16 -0
  23. data/app/views/stiki/pages/_form.html.erb +35 -0
  24. data/app/views/stiki/pages/edit.html.erb +13 -0
  25. data/app/views/stiki/pages/index.html.erb +51 -0
  26. data/app/views/stiki/pages/new.html.erb +13 -0
  27. data/app/views/stiki/pages/show.html.erb +86 -0
  28. data/app/views/stiki/spaces/index.html.erb +52 -0
  29. data/config/routes.rb +13 -0
  30. data/db/migrate/20120731063610_create_stiki_spaces.rb +10 -0
  31. data/db/migrate/20120731063657_create_stiki_pages.rb +13 -0
  32. data/db/migrate/20120731063721_create_stiki_authors.rb +14 -0
  33. data/lib/stiki/authenticate/devise.rb +19 -0
  34. data/lib/stiki/authenticate.rb +7 -0
  35. data/lib/stiki/authorize/cancan.rb +9 -0
  36. data/lib/stiki/authorize.rb +7 -0
  37. data/lib/stiki/engine.rb +6 -0
  38. data/lib/stiki/model/map_author.rb +10 -0
  39. data/lib/stiki/model.rb +7 -0
  40. data/lib/stiki/version.rb +3 -0
  41. data/lib/stiki.rb +70 -0
  42. data/lib/tasks/stiki_tasks.rake +4 -0
  43. data/spec/controllers/stiki/pages_controller_spec.rb +82 -0
  44. data/spec/controllers/stiki/spaces_controller_spec.rb +43 -0
  45. data/spec/factories/pages.rb +7 -0
  46. data/spec/factories/spaces.rb +5 -0
  47. data/spec/lib/authenticate/devise_spec.rb +26 -0
  48. data/spec/lib/stiki_spec.rb +47 -0
  49. data/spec/models/stiki/author_spec.rb +6 -0
  50. data/spec/models/stiki/page_spec.rb +8 -0
  51. data/spec/models/stiki/space_spec.rb +7 -0
  52. data/spec/spec_helper.rb +77 -0
  53. data/test/dummy/README.rdoc +261 -0
  54. data/test/dummy/Rakefile +7 -0
  55. data/test/dummy/app/assets/javascripts/application.js +15 -0
  56. data/test/dummy/app/assets/stylesheets/application.css +18 -0
  57. data/test/dummy/app/controllers/application_controller.rb +3 -0
  58. data/test/dummy/app/helpers/application_helper.rb +2 -0
  59. data/test/dummy/app/views/layouts/application.html.erb +22 -0
  60. data/test/dummy/config/application.rb +59 -0
  61. data/test/dummy/config/boot.rb +10 -0
  62. data/test/dummy/config/database.yml +25 -0
  63. data/test/dummy/config/environment.rb +5 -0
  64. data/test/dummy/config/environments/development.rb +37 -0
  65. data/test/dummy/config/environments/production.rb +67 -0
  66. data/test/dummy/config/environments/test.rb +37 -0
  67. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/test/dummy/config/initializers/inflections.rb +15 -0
  69. data/test/dummy/config/initializers/mime_types.rb +5 -0
  70. data/test/dummy/config/initializers/secret_token.rb +7 -0
  71. data/test/dummy/config/initializers/session_store.rb +8 -0
  72. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  73. data/test/dummy/config/locales/en.yml +5 -0
  74. data/test/dummy/config/routes.rb +4 -0
  75. data/test/dummy/config.ru +4 -0
  76. data/test/dummy/db/development.sqlite3 +0 -0
  77. data/test/dummy/db/schema.rb +46 -0
  78. data/test/dummy/db/test.sqlite3 +0 -0
  79. data/test/dummy/log/development.log +69 -0
  80. data/test/dummy/log/test.log +59362 -0
  81. data/test/dummy/public/404.html +26 -0
  82. data/test/dummy/public/422.html +26 -0
  83. data/test/dummy/public/500.html +25 -0
  84. data/test/dummy/public/favicon.ico +0 -0
  85. data/test/dummy/script/rails +6 -0
  86. data/test/test_helper.rb +15 -0
  87. metadata +319 -0
data/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
data/README.rdoc ADDED
@@ -0,0 +1,65 @@
1
+ = The Icky Stiki Wiki
2
+
3
+ Stiki is a Rails Engine for adding simple wiki support to site. Stiki is comprised of Spaces that have multiple Pages. A Page is
4
+ comprised of a Title and Wiki Body.
5
+
6
+ Stiki is designed to work with twitter-bootstrap, but will work with any site that uses a compatible css.
7
+
8
+ Presently only wiki format supported is MarkDown.
9
+
10
+ == Installation
11
+
12
+ In Rails 3, add this to your Gemfile and run the bundle command.
13
+
14
+ gem "stiki"
15
+
16
+ == Getting Started
17
+
18
+ First, you will need to create the Stiki database migations:
19
+
20
+ rake stiki_engine:install:migrations
21
+
22
+ and migrate your database
23
+
24
+ rake db:migrate
25
+
26
+ Second, you will need to add Stiki to your config/routes.rb
27
+
28
+ mount Stiki::Engine => "/wiki"
29
+
30
+ That is all! Now you can start up your rails app and goto /wiki to start having wiki fun.
31
+
32
+ == Stiki Configuration
33
+
34
+ To configure Stiki, create a config in config/initializers/stiki.rb
35
+
36
+ Stiki.config do |stiki|
37
+ # Optional user class, required for author and devise
38
+ stiki.user_class = 'User'
39
+
40
+ # Method to be called on user_class to display user name. Defaults to to_s
41
+ stiki.user_name_via = :user_name
42
+
43
+ # Optional, use devise for authentication
44
+ stiki.authenticate_by = :devise
45
+ stiki.authenticate_pages = :all # other options are :only => [actions] or :except => [actions]
46
+ stiki.authenticate_spaces = :all # other options are :only => [actions] or :except => [actions]
47
+
48
+ # Optional, use cancan for authorization
49
+ stiki.authorize_by = :cancan
50
+ end
51
+
52
+ === Reloading Stiki in the development environment
53
+
54
+ To have Stiki reload correctly while running in the Rails development environment, add this to your
55
+ config/environments/development.rb
56
+
57
+ config.to_prepare do
58
+ Stiki.reload
59
+ end
60
+
61
+ == License
62
+ Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
63
+
64
+ http://www.apache.org/licenses/LICENSE-2.0
65
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Icky Stiki Wiki'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,17 @@
1
+
2
+ @import "authors";
3
+ @import "pages";
4
+ @import "spaces";
5
+
6
+ .stiki {
7
+ .breadcrumb {
8
+
9
+ margin-bottom: 0;
10
+
11
+ .btn-group {
12
+ li {
13
+ display: block;
14
+ }
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,54 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ .stiki {
7
+ .page {
8
+ .breadcrumb {
9
+ .divider {
10
+ font-size: 32px;
11
+ }
12
+ }
13
+
14
+ .page-list {
15
+ cursor:pointer;
16
+
17
+ li {
18
+ padding: 2px;
19
+
20
+ a {
21
+ float: left;
22
+ font-size: 18px;
23
+ }
24
+ }
25
+ }
26
+
27
+ .list:hover {
28
+ color: green;
29
+ }
30
+
31
+ .title {
32
+ h1 {
33
+ .icon-chevron-left {
34
+ position: relative;
35
+ top: 13px;
36
+ }
37
+ }
38
+ }
39
+
40
+ .author {
41
+
42
+ .badge {
43
+ margin-left: 3px;
44
+ }
45
+ }
46
+
47
+ .delete {
48
+ form {
49
+ margin: 0;
50
+ }
51
+ }
52
+ }
53
+
54
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,6 @@
1
+ module Stiki
2
+ class ApplicationController < ActionController::Base
3
+ include Stiki::ApplicationHelper
4
+ layout "application"
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ require_dependency "stiki/application_controller"
2
+
3
+ module Stiki
4
+ class AuthorsController < ApplicationController
5
+ end
6
+ end
@@ -0,0 +1,94 @@
1
+ require_dependency "stiki/application_controller"
2
+ require 'redcarpet'
3
+
4
+ module Stiki
5
+ class PagesController < ApplicationController
6
+ before_filter :get_space
7
+
8
+ def index
9
+ @spaces = Space.all
10
+ @pages = @space.pages
11
+ end
12
+
13
+ def show
14
+ @spaces = Space.all
15
+ @pages = @space.pages
16
+
17
+ @page = Page.find_by_slug( params[:id] )
18
+
19
+ if @page.nil?
20
+ flash[:error] = "Wiki Pages does not exist: #{params[:id]}"
21
+ redirect_to stiki_routes.space_pages_path(@space)
22
+ else
23
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
24
+ :autolink => true, :space_after_headers => true)
25
+ @markup = markdown.render( @page.body ).html_safe
26
+ end
27
+ end
28
+
29
+ def new
30
+ @page = Page.new
31
+ end
32
+
33
+ def edit
34
+ @page = Page.find( params[:id] )
35
+
36
+ end
37
+
38
+ def create
39
+ @page = Page.new(params[:page])
40
+ @page.space = @space
41
+
42
+ if Stiki.authenticate_by == :devise
43
+ author = Author.new
44
+ author.user = self.send( "current_#{Stiki::Helper.user_model_name}".to_sym )
45
+ author.creator = true
46
+ @page.authors << author
47
+ end
48
+
49
+ if @page.save
50
+ redirect_to stiki_routes.space_page_path(@space, @page)
51
+ else
52
+ flash[:error] = "Error creating Page"
53
+ render "stiki/pages/new"
54
+ end
55
+ end
56
+
57
+ def update
58
+ @page = Page.find( params[:id] )
59
+
60
+ @page.attributes = params[:page]
61
+
62
+ if Stiki.authenticate_by == :devise
63
+ author = Author.new
64
+ author.user = self.send( "current_#{Stiki::Helper.user_model_name}".to_sym )
65
+ @page.authors << author
66
+ end
67
+
68
+ if @page.save
69
+ @page.mark_badges
70
+ redirect_to stiki_routes.space_page_path(@space, @page)
71
+ else
72
+ flash[:error] = "Error editing Page"
73
+ render "stiki/pages/edit"
74
+ end
75
+ end
76
+
77
+ def destroy
78
+ @page = Page.find( params[:id] )
79
+
80
+ @page.destroy
81
+
82
+ redirect_to stiki_routes.space_pages_path(@space)
83
+ end
84
+
85
+ protected
86
+ def get_space
87
+ @space = Space.find_by_slug( params[:space_id] )
88
+ if @space.nil?
89
+ flash[:error] = "Wiki Space does not exist: #{params[:space_id]}"
90
+ redirect_to stiki_routes.spaces_path
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,42 @@
1
+ require_dependency "stiki/application_controller"
2
+
3
+ module Stiki
4
+ class SpacesController < ApplicationController
5
+ def index
6
+ @spaces = Space.all
7
+ @space = Space.new
8
+ end
9
+
10
+ # def show handled by PageController#index
11
+
12
+ def create
13
+ @space = Space.new(params[:space])
14
+
15
+ if Stiki.authenticate_by == :devise
16
+ author = Author.new
17
+ author.user = self.send( "current_#{Stiki::Helper.user_model_name}".to_sym )
18
+ author.creator = true
19
+ @space.authors << author
20
+ end
21
+
22
+ unless @space.save
23
+ flash[:error] = "Error creating new Space"
24
+ end
25
+
26
+ redirect_to stiki_routes.spaces_path
27
+ end
28
+
29
+ def destroy
30
+ @space = Space.find( params[:id] )
31
+
32
+ if @space.pages.size > 0
33
+ flash[:error] = "Cannot delete a Wiki Space that has Wiki Pages"
34
+ else
35
+ @space.destroy
36
+ flash[:info] = "The Space #{@space.name} has been deleted"
37
+ end
38
+
39
+ redirect_to stiki_routes.spaces_path
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ module Stiki
2
+ module ApplicationHelper
3
+ def stiki_routes
4
+ Stiki::Engine.routes.url_helpers
5
+ end
6
+
7
+ def has_access( action, model )
8
+ if Stiki.authorize_by == :cancan
9
+ can? action, model
10
+ end
11
+ end
12
+
13
+ def user_name( author )
14
+ author.user.send( Stiki.user_name_via ) if author && author.user
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module Stiki
2
+ module AuthorsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Stiki
2
+ module PagesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Stiki
2
+ module SpacesHelper
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module Stiki
2
+ class Author < ActiveRecord::Base
3
+ self.table_name = "stiki_authors"
4
+
5
+ belongs_to :authorable, :polymorphic => true
6
+
7
+ validates :creator, :uniqueness => {:scope => :authorable_id}
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ require 'friendly_id'
2
+
3
+ module Stiki
4
+ class Page < ActiveRecord::Base
5
+ self.table_name = "stiki_pages"
6
+
7
+ extend ::FriendlyId
8
+ friendly_id :title, use: :slugged
9
+
10
+ belongs_to :space
11
+ has_many :authors, :as => :authorable do
12
+ def <<(*authors)
13
+ # prevent duplicate authors
14
+ existing_users = proxy_association.owner.authors.map(&:user_id)
15
+ super( authors.select { |auth| !existing_users.include?( auth.user_id ) } )
16
+ end
17
+ end
18
+
19
+ attr_accessible :body, :title
20
+
21
+ validates :title, :uniqueness => {:scope => :space_id}, :presence => true
22
+ validates :body, :presence => true
23
+
24
+ def mark_badges
25
+ if authors.size > 1
26
+ # XXX: need revisions to determine last edit and most edits
27
+ #last = authors.order( 'updated_at DESC' ).first
28
+ #authors.where( ["#{Stiki::Author.table_name}.id != ?", last.id] ).update_all( :last_edit => false );
29
+ #authors.where( ["#{Stiki::Author.table_name}.id = ?", last.id] ).update_all( :last_edit => true );
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ module Stiki
2
+ class Space < ActiveRecord::Base
3
+ self.table_name = "stiki_spaces"
4
+
5
+ extend ::FriendlyId
6
+ friendly_id :name, use: :slugged
7
+
8
+ has_many :pages
9
+ has_many :authors, :as => :authorable
10
+ has_one :creator, :class_name => 'Author', :conditions => "creator = true", :as => :authorable
11
+
12
+ attr_accessible :name
13
+
14
+ validates :name, :uniqueness => true, :presence => true
15
+ end
16
+ end