irwi 0.2.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README.rdoc +9 -9
- data/app/views/base_wiki_pages/_wiki_page_info.html.erb +1 -1
- data/app/views/base_wiki_pages/compare.html.erb +1 -1
- data/app/views/base_wiki_pages/history.html.erb +1 -1
- data/app/views/base_wiki_pages/no.html.erb +1 -1
- data/lib/generators/irwi_wiki/irwi_wiki_generator.rb +29 -0
- data/{generators → lib/generators}/irwi_wiki/templates/controllers/wiki_pages_controller.rb +3 -3
- data/{generators → lib/generators}/irwi_wiki/templates/helpers/wiki_pages_helper.rb +1 -1
- data/{generators → lib/generators}/irwi_wiki/templates/migrate/create_wiki_pages.rb +15 -15
- data/{generators → lib/generators}/irwi_wiki/templates/models/wiki_page.rb +3 -3
- data/{generators → lib/generators}/irwi_wiki/templates/models/wiki_page_version.rb +3 -3
- data/lib/generators/irwi_wiki_attachments/irwi_wiki_attachments_generator.rb +22 -0
- data/{generators → lib/generators}/irwi_wiki_attachments/templates/migrate/create_wiki_page_attachments.rb +6 -6
- data/{generators → lib/generators}/irwi_wiki_attachments/templates/models/wiki_page_attachment.rb +1 -1
- data/lib/generators/irwi_wiki_views/irwi_wiki_views_generator.rb +13 -0
- data/lib/irwi.rb +34 -7
- data/lib/irwi/comparators/base.rb +6 -6
- data/lib/irwi/comparators/diff_lcs.rb +12 -12
- data/lib/irwi/comparators/spans/changed_span.rb +6 -6
- data/lib/irwi/comparators/spans/not_changed_span.rb +7 -7
- data/lib/irwi/config.rb +16 -14
- data/lib/irwi/extensions/controllers.rb +18 -0
- data/lib/irwi/extensions/controllers/wiki_page_attachments.rb +1 -1
- data/lib/irwi/extensions/controllers/wiki_pages.rb +47 -47
- data/lib/irwi/extensions/models.rb +24 -0
- data/lib/irwi/extensions/models/wiki_page.rb +16 -16
- data/lib/irwi/extensions/models/wiki_page_attachment.rb +4 -4
- data/lib/irwi/extensions/models/wiki_page_version.rb +17 -17
- data/lib/irwi/formatters/blue_cloth.rb +4 -4
- data/lib/irwi/formatters/red_cloth.rb +4 -4
- data/lib/irwi/helpers.rb +13 -0
- data/lib/irwi/helpers/wiki_page_attachments_helper.rb +4 -2
- data/lib/irwi/helpers/wiki_pages_helper.rb +36 -36
- data/lib/irwi/paginators/none.rb +6 -4
- data/lib/irwi/paginators/will_paginate.rb +4 -4
- data/lib/irwi/support/route_mapper.rb +22 -18
- data/lib/irwi/support/template_finder.rb +4 -4
- data/lib/irwi/version.rb +9 -0
- metadata +110 -81
- data/.document +0 -4
- data/.gitignore +0 -24
- data/Rakefile +0 -53
- data/VERSION +0 -1
- data/generators/irwi_wiki/irwi_wiki_generator.rb +0 -22
- data/generators/irwi_wiki_attachments/irwi_wiki_attachments_generator.rb +0 -18
- data/generators/irwi_wiki_views/irwi_wiki_views_generator.rb +0 -19
- data/irwi.gemspec +0 -120
- data/rails/init.rb +0 -44
- data/spec/comparators/diff_lcs_spec.rb +0 -45
- data/spec/config_spec.rb +0 -68
- data/spec/extensions/controllers/wiki_pages_spec.rb +0 -69
- data/spec/extensions/models/wiki_page_spec.rb +0 -79
- data/spec/formatters/red_cloth_spec.rb +0 -17
- data/spec/helpers/wiki_page_attachments_helper_spec.rb +0 -45
- data/spec/helpers/wiki_pages_helper_spec.rb +0 -158
- data/spec/paginators/none_spec.rb +0 -24
- data/spec/paginators/will_paginate_spec.rb +0 -28
- data/spec/rcov.opts +0 -2
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -15
- data/spec/support/route_mapper_spec.rb +0 -66
- data/spec/support/template_finder_spec.rb +0 -33
- data/tasks/riwiki_tasks.rake +0 -4
@@ -1,20 +1,20 @@
|
|
1
1
|
class Irwi::Comparators::Spans::NotChangedSpan
|
2
|
-
|
2
|
+
|
3
3
|
attr_accessor :value
|
4
|
-
|
4
|
+
|
5
5
|
def initialize( v )
|
6
6
|
@value = v
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def to_s
|
10
10
|
@value.to_s
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def action
|
14
14
|
'='
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
alias_method :old_value, :value
|
18
18
|
alias_method :new_value, :value
|
19
|
-
|
20
|
-
end
|
19
|
+
|
20
|
+
end
|
data/lib/irwi/config.rb
CHANGED
@@ -1,47 +1,49 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
1
3
|
class Irwi::Config
|
2
|
-
|
4
|
+
|
3
5
|
attr_accessor_with_default :controller_name, 'wiki_pages'
|
4
|
-
|
6
|
+
|
5
7
|
attr_accessor_with_default :user_class_name, 'User'
|
6
|
-
|
8
|
+
|
7
9
|
attr_accessor_with_default :page_class_name, 'WikiPage'
|
8
10
|
attr_accessor_with_default :page_version_class_name, 'WikiPageVersion'
|
9
11
|
attr_accessor_with_default :page_attachment_class_name do
|
10
|
-
# Can be for example 'WikiPageAttachment'
|
12
|
+
# Can be for example 'WikiPageAttachment'
|
11
13
|
nil
|
12
14
|
end
|
13
|
-
|
15
|
+
|
14
16
|
attr_accessor_with_default :page_version_foreign_key, 'page_id'
|
15
|
-
|
17
|
+
|
16
18
|
# Object using to format content
|
17
19
|
attr_accessor_with_default :formatter do
|
18
20
|
require 'irwi/formatters/red_cloth'
|
19
21
|
|
20
22
|
Irwi::Formatters::RedCloth.new
|
21
23
|
end
|
22
|
-
|
24
|
+
|
23
25
|
# Object using to compare pages
|
24
26
|
attr_accessor_with_default :comparator do
|
25
27
|
require 'irwi/comparators/diff_lcs'
|
26
28
|
|
27
29
|
Irwi::Comparators::DiffLcs.new
|
28
30
|
end
|
29
|
-
|
31
|
+
|
30
32
|
# Object using to paginate collections
|
31
33
|
attr_accessor_with_default :paginator do
|
32
34
|
require 'irwi/paginators/none'
|
33
35
|
|
34
36
|
Irwi::Paginators::None.new
|
35
37
|
end
|
36
|
-
|
38
|
+
|
37
39
|
def page_class
|
38
40
|
page_class_name.constantize
|
39
41
|
end
|
40
|
-
|
42
|
+
|
41
43
|
def page_version_class
|
42
44
|
page_version_class_name.constantize
|
43
45
|
end
|
44
|
-
|
46
|
+
|
45
47
|
def page_attachment_class
|
46
48
|
page_attachment_class_name.constantize
|
47
49
|
end
|
@@ -49,18 +51,18 @@ class Irwi::Config
|
|
49
51
|
def user_class
|
50
52
|
user_class_name.constantize
|
51
53
|
end
|
52
|
-
|
54
|
+
|
53
55
|
def system_pages
|
54
56
|
@system_pages ||= {
|
55
57
|
'all' => 'all'
|
56
58
|
}
|
57
59
|
end
|
58
|
-
|
60
|
+
|
59
61
|
# Add system page
|
60
62
|
# @param action [String,Symbol] controller action
|
61
63
|
# @param path [String] path in routes
|
62
64
|
def add_system_page( action, path )
|
63
65
|
system_pages[ action.to_s ] = path.to_s
|
64
66
|
end
|
65
|
-
|
67
|
+
|
66
68
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
|
3
|
+
module Irwi::Extensions::Controllers
|
4
|
+
autoload :WikiPages, 'irwi/extensions/controllers/wiki_pages'
|
5
|
+
autoload :WikiPageAttachments, 'irwi/extensions/controllers/wiki_page_attachments'
|
6
|
+
end
|
7
|
+
|
8
|
+
ActionController::Base.instance_eval do
|
9
|
+
|
10
|
+
# @param config [Hash] config for controller class
|
11
|
+
# @option page_class
|
12
|
+
#
|
13
|
+
def acts_as_wiki_pages_controller( config = {} )
|
14
|
+
include Irwi::Extensions::Controllers::WikiPages
|
15
|
+
include Irwi::Extensions::Controllers::WikiPageAttachments if Irwi::config.page_attachment_class_name
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -1,131 +1,131 @@
|
|
1
1
|
module Irwi::Extensions::Controllers::WikiPages
|
2
|
-
|
2
|
+
|
3
3
|
module ClassMethods
|
4
|
-
|
4
|
+
|
5
5
|
def page_class
|
6
6
|
@page_class ||= Irwi.config.page_class
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def set_page_class(arg)
|
10
10
|
@page_class = arg
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
module InstanceMethods
|
16
|
-
|
16
|
+
|
17
17
|
include Irwi::Extensions::Controllers::WikiPageAttachments
|
18
18
|
include Irwi::Support::TemplateFinder
|
19
|
-
|
19
|
+
|
20
20
|
def show
|
21
21
|
return not_allowed unless show_allowed?
|
22
|
-
|
22
|
+
|
23
23
|
render_template( @page.new_record? ? 'no' : 'show' )
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def history
|
27
27
|
return not_allowed unless history_allowed?
|
28
|
-
|
28
|
+
|
29
29
|
@versions = Irwi.config.paginator.paginate( @page.versions, :page => params[:page] ) # Paginating them
|
30
|
-
|
30
|
+
|
31
31
|
render_template( @page.new_record? ? 'no' : 'history' )
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def compare
|
35
35
|
return not_allowed unless history_allowed?
|
36
|
-
|
36
|
+
|
37
37
|
if @page.new_record?
|
38
38
|
render_template 'no'
|
39
39
|
else
|
40
40
|
new_num = params[:new].to_i || @page.last_version_number # Last version number
|
41
41
|
old_num = params[:old].to_i || 1 # First version number
|
42
|
-
|
42
|
+
|
43
43
|
old_num, new_num = new_num, old_num if new_num < old_num # Swapping them if last < first
|
44
|
-
|
44
|
+
|
45
45
|
versions = @page.versions.between( old_num, new_num ) # Loading all versions between first and last
|
46
|
-
|
46
|
+
|
47
47
|
@versions = Irwi.config.paginator.paginate( versions, :page => params[:page] ) # Paginating them
|
48
|
-
|
48
|
+
|
49
49
|
@new_version = @versions.first.number == new_num ? @versions.first : versions.first # Loading next version
|
50
50
|
@old_version = @versions.last.number == old_num ? @versions.last : versions.last # Loading previous version
|
51
|
-
|
51
|
+
|
52
52
|
render_template 'compare'
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def new
|
57
57
|
return not_allowed unless show_allowed? && edit_allowed?
|
58
|
-
|
58
|
+
|
59
59
|
render_template 'new'
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def edit
|
63
63
|
return not_allowed unless show_allowed? && edit_allowed?
|
64
|
-
|
64
|
+
|
65
65
|
render_template 'edit'
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def update
|
69
69
|
return not_allowed unless @page.new_record? || edit_allowed? # Check for rights (but not for new record, for it we will use second check only)
|
70
|
-
|
70
|
+
|
71
71
|
@page.attributes = params[:page] # Assign new attributes
|
72
72
|
@page.comment = params[:page][:comment]
|
73
|
-
|
73
|
+
|
74
74
|
return not_allowed unless edit_allowed? # Double check: used beacause action may become invalid after attributes update
|
75
|
-
|
75
|
+
|
76
76
|
@page.updator = @current_user # Assing user, which updated page
|
77
77
|
@page.creator = @current_user if @page.new_record? # Assign it's creator if it's new page
|
78
|
-
|
78
|
+
|
79
79
|
if !params[:preview] && (params[:cancel] || @page.save)
|
80
80
|
redirect_to url_for( :action => :show, :path => @page.path.split('/') ) # redirect to new page's path (if it changed)
|
81
81
|
else
|
82
82
|
render_template 'edit'
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def destroy
|
87
87
|
return not_allowed unless destroy_allowed?
|
88
|
-
|
88
|
+
|
89
89
|
@page.destroy
|
90
|
-
|
90
|
+
|
91
91
|
redirect_to url_for( :action => :show )
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def all
|
95
95
|
@pages = Irwi.config.paginator.paginate( page_class, :page => params[:page] ) # Loading and paginating all pages
|
96
|
-
|
96
|
+
|
97
97
|
render_template 'all'
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
protected
|
101
|
-
|
101
|
+
|
102
102
|
# Retrieves wiki_page_class for this controller
|
103
103
|
def page_class
|
104
104
|
self.class.page_class
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
# Renders user-specified or default template
|
108
108
|
def render_template( template )
|
109
109
|
render "#{template_dir template}/#{template}"
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
# Initialize @current_user instance variable
|
113
113
|
def setup_current_user
|
114
114
|
@current_user = respond_to?( :current_user, true ) ? current_user : nil # Find user by current_user method or return nil
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
# Initialize @page instance variable
|
118
118
|
def setup_page
|
119
|
-
@page = page_class.find_by_path_or_new( params[:path]
|
119
|
+
@page = page_class.find_by_path_or_new( params[:path] || '' ) # Find existing page by path or create new
|
120
120
|
end
|
121
|
-
|
122
|
-
# Method, which called when user tries to visit
|
121
|
+
|
122
|
+
# Method, which called when user tries to visit
|
123
123
|
def not_allowed
|
124
124
|
render_template 'not_allowed'
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
# Check is it allowed for current user to see current page. Designed to be redefined by application programmer
|
128
|
-
def show_allowed?
|
128
|
+
def show_allowed?
|
129
129
|
true
|
130
130
|
end
|
131
131
|
|
@@ -133,27 +133,27 @@ module Irwi::Extensions::Controllers::WikiPages
|
|
133
133
|
def history_allowed?
|
134
134
|
show_allowed?
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
# Check is it allowed for current user edit current page. Designed to be redefined by application programmer
|
138
138
|
def edit_allowed?
|
139
139
|
show_allowed?
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
# Check is it allowed for current user destroy current page. Designed to be redefined by application programmer
|
143
143
|
def destroy_allowed?
|
144
144
|
edit_allowed?
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
end
|
148
148
|
|
149
149
|
def self.included( base )
|
150
150
|
base.send :extend, Irwi::Extensions::Controllers::WikiPages::ClassMethods
|
151
151
|
base.send :include, Irwi::Extensions::Controllers::WikiPages::InstanceMethods
|
152
|
-
|
152
|
+
|
153
153
|
base.before_filter :setup_current_user # Setup @current_user instance variable before each action
|
154
154
|
# Setup @page instance variable before each action
|
155
155
|
base.before_filter :setup_page, :only => [ :show, :history, :compare, :new, :edit, :update, :destroy, :add_attachment ]
|
156
156
|
base.helper_method :show_allowed?, :edit_allowed?, :history_allowed?, :destroy_allowed? # Access control methods are avaliable in views
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Irwi::Extensions::Models
|
4
|
+
autoload :WikiPage, 'irwi/extensions/models/wiki_page'
|
5
|
+
autoload :WikiPageVersion, 'irwi/extensions/models/wiki_page_version'
|
6
|
+
autoload :WikiPageAttachment, 'irwi/extensions/models/wiki_page_attachment'
|
7
|
+
end
|
8
|
+
|
9
|
+
ActiveRecord::Base.instance_eval do
|
10
|
+
|
11
|
+
def acts_as_wiki_page( config = {} )
|
12
|
+
include Irwi::Extensions::Models::WikiPage
|
13
|
+
end
|
14
|
+
|
15
|
+
def acts_as_wiki_page_version( config = {} )
|
16
|
+
include Irwi::Extensions::Models::WikiPageVersion
|
17
|
+
end
|
18
|
+
|
19
|
+
def acts_as_wiki_page_attachment
|
20
|
+
include Irwi::Extensions::Models::WikiPageAttachment
|
21
|
+
yield if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -1,51 +1,51 @@
|
|
1
1
|
module Irwi::Extensions::Models::WikiPage
|
2
|
-
|
2
|
+
|
3
3
|
module ClassMethods
|
4
|
-
|
4
|
+
|
5
5
|
def find_by_path_or_new( path )
|
6
6
|
self.find_by_path( path ) || self.new( :path => path, :title => path )
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
module InstanceMethods
|
12
|
-
|
12
|
+
|
13
13
|
# Retrieve number of last version
|
14
14
|
def last_version_number
|
15
15
|
last = versions.first
|
16
16
|
last ? last.number : 0
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
protected
|
20
|
-
|
20
|
+
|
21
21
|
def create_new_version
|
22
22
|
n = last_version_number
|
23
|
-
|
23
|
+
|
24
24
|
v = versions.build
|
25
25
|
v.attributes = attributes.slice( *v.attribute_names )
|
26
26
|
v.comment = comment
|
27
27
|
v.number = n + 1
|
28
28
|
v.save!
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def self.included( base )
|
34
34
|
base.send :extend, Irwi::Extensions::Models::WikiPage::ClassMethods
|
35
35
|
base.send :include, Irwi::Extensions::Models::WikiPage::InstanceMethods
|
36
|
-
|
36
|
+
|
37
37
|
base.send :attr_accessor, :comment, :previous_version_number
|
38
|
-
|
38
|
+
|
39
39
|
base.belongs_to :creator, :class_name => Irwi.config.user_class_name
|
40
40
|
base.belongs_to :updator, :class_name => Irwi.config.user_class_name
|
41
|
-
|
41
|
+
|
42
42
|
base.has_many :versions, :class_name => Irwi.config.page_version_class_name, :foreign_key => Irwi.config.page_version_foreign_key, :order => 'id DESC'
|
43
43
|
|
44
44
|
if Irwi::config.page_attachment_class_name
|
45
45
|
base.has_many :attachments, :class_name => Irwi.config.page_attachment_class_name, :foreign_key => Irwi.config.page_version_foreign_key
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
base.after_save :create_new_version
|
49
49
|
end
|
50
|
-
|
51
|
-
end
|
50
|
+
|
51
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Irwi::Extensions::Models::WikiPageAttachment
|
2
|
-
|
2
|
+
|
3
3
|
DEFAULT_PAPERCLIP_OPTIONS = {:styles => { :medium => "300x300>", :thumb => "100x100>" }}
|
4
|
-
|
4
|
+
|
5
5
|
def self.included( base )
|
6
6
|
base.belongs_to :page, :class_name => Irwi.config.page_class_name
|
7
7
|
end
|
8
|
-
|
9
|
-
end
|
8
|
+
|
9
|
+
end
|