irwi 0.1.4 → 0.1.5
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.
- data/.document +1 -2
- data/.gitignore +3 -0
- data/VERSION +1 -1
- data/app/views/base_wiki_pages/_wiki_page_history.html.erb +1 -1
- data/app/views/base_wiki_pages/all.html.erb +11 -0
- data/app/views/base_wiki_pages/compare.html.erb +3 -1
- data/app/views/base_wiki_pages/history.html.erb +4 -1
- data/irwi.gemspec +10 -3
- data/lib/irwi/config.rb +21 -1
- data/lib/irwi/extensions/controllers/wiki_pages.rb +19 -4
- data/lib/irwi/extensions/models/wiki_page.rb +1 -1
- data/lib/irwi/helpers/wiki_pages_helper.rb +19 -9
- data/lib/irwi/paginators/none.rb +13 -0
- data/lib/irwi/paginators/will_paginate.rb +11 -0
- data/lib/irwi/support/route_mapper.rb +4 -0
- data/spec/config_spec.rb +10 -0
- data/spec/helpers/wiki_pages_helper_spec.rb +36 -0
- data/spec/paginators/none_spec.rb +24 -0
- data/spec/paginators/will_paginate_spec.rb +28 -0
- metadata +9 -2
data/.document
CHANGED
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/irwi.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{irwi}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexey Noskov"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-11-01}
|
13
13
|
s.description = %q{Irwi is Ruby on Rails plugin which adds wiki functionality to your application. }
|
14
14
|
s.email = %q{alexey.noskov@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"app/views/base_wiki_pages/_wiki_page_history.html.erb",
|
27
27
|
"app/views/base_wiki_pages/_wiki_page_info.html.erb",
|
28
28
|
"app/views/base_wiki_pages/_wiki_page_style.html.erb",
|
29
|
+
"app/views/base_wiki_pages/all.html.erb",
|
29
30
|
"app/views/base_wiki_pages/compare.html.erb",
|
30
31
|
"app/views/base_wiki_pages/edit.html.erb",
|
31
32
|
"app/views/base_wiki_pages/history.html.erb",
|
@@ -51,6 +52,8 @@ Gem::Specification.new do |s|
|
|
51
52
|
"lib/irwi/formatters/blue_cloth.rb",
|
52
53
|
"lib/irwi/formatters/red_cloth.rb",
|
53
54
|
"lib/irwi/helpers/wiki_pages_helper.rb",
|
55
|
+
"lib/irwi/paginators/none.rb",
|
56
|
+
"lib/irwi/paginators/will_paginate.rb",
|
54
57
|
"lib/irwi/support/route_mapper.rb",
|
55
58
|
"lib/irwi/support/template_finder.rb",
|
56
59
|
"rails/init.rb",
|
@@ -59,6 +62,8 @@ Gem::Specification.new do |s|
|
|
59
62
|
"spec/extensions/controllers/wiki_pages_spec.rb",
|
60
63
|
"spec/formatters/red_cloth_spec.rb",
|
61
64
|
"spec/helpers/wiki_pages_helper_spec.rb",
|
65
|
+
"spec/paginators/none_spec.rb",
|
66
|
+
"spec/paginators/will_paginate_spec.rb",
|
62
67
|
"spec/rcov.opts",
|
63
68
|
"spec/spec.opts",
|
64
69
|
"spec/spec_helper.rb",
|
@@ -79,7 +84,9 @@ Gem::Specification.new do |s|
|
|
79
84
|
"spec/formatters/red_cloth_spec.rb",
|
80
85
|
"spec/extensions/controllers/wiki_pages_spec.rb",
|
81
86
|
"spec/helpers/wiki_pages_helper_spec.rb",
|
82
|
-
"spec/spec_helper.rb"
|
87
|
+
"spec/spec_helper.rb",
|
88
|
+
"spec/paginators/will_paginate_spec.rb",
|
89
|
+
"spec/paginators/none_spec.rb"
|
83
90
|
]
|
84
91
|
|
85
92
|
if s.respond_to? :specification_version then
|
data/lib/irwi/config.rb
CHANGED
@@ -9,19 +9,26 @@ class Irwi::Config
|
|
9
9
|
|
10
10
|
attr_accessor_with_default :page_version_foreign_key, 'page_id'
|
11
11
|
|
12
|
+
# Object using to format content
|
12
13
|
attr_accessor_with_default :formatter do
|
13
14
|
Irwi::Formatters::RedCloth.new
|
14
15
|
end
|
15
16
|
|
17
|
+
# Object using to compare pages
|
16
18
|
attr_accessor_with_default :comparator do
|
17
19
|
Irwi::Comparators::DiffLcs.new
|
18
20
|
end
|
19
21
|
|
22
|
+
# Object using to paginate collections
|
23
|
+
attr_accessor_with_default :paginator do
|
24
|
+
Irwi::Paginators::None.new
|
25
|
+
end
|
26
|
+
|
20
27
|
def page_class
|
21
28
|
page_class_name.constantize
|
22
29
|
end
|
23
30
|
|
24
|
-
def
|
31
|
+
def page_version_class
|
25
32
|
page_version_class_name.constantize
|
26
33
|
end
|
27
34
|
|
@@ -29,4 +36,17 @@ class Irwi::Config
|
|
29
36
|
user_class_name.constantize
|
30
37
|
end
|
31
38
|
|
39
|
+
def system_pages
|
40
|
+
@system_pages ||= {
|
41
|
+
'all' => 'all'
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
# Add system page
|
46
|
+
# @param action [String,Symbol] controller action
|
47
|
+
# @param path [String] path in routes
|
48
|
+
def add_system_page( action, path )
|
49
|
+
system_pages[ action.to_s ] = path.to_s
|
50
|
+
end
|
51
|
+
|
32
52
|
end
|
@@ -25,6 +25,8 @@ module Irwi::Extensions::Controllers::WikiPages
|
|
25
25
|
def history
|
26
26
|
return not_allowed unless history_allowed?
|
27
27
|
|
28
|
+
@versions = Irwi.config.paginator.paginate( @page.versions, :page => params[:page] ) # Paginating them
|
29
|
+
|
28
30
|
render_template( @page.new_record? ? 'no' : 'history' )
|
29
31
|
end
|
30
32
|
|
@@ -34,10 +36,17 @@ module Irwi::Extensions::Controllers::WikiPages
|
|
34
36
|
if @page.new_record?
|
35
37
|
render_template 'no'
|
36
38
|
else
|
37
|
-
|
39
|
+
new_num = params[:new].to_i || @page.last_version_number # Last version number
|
40
|
+
old_num = params[:old].to_i || 1 # First version number
|
41
|
+
|
42
|
+
old_num, new_num = new_num, old_num if new_num < old_num # Swapping them if last < first
|
38
43
|
|
39
|
-
|
40
|
-
|
44
|
+
versions = @page.versions.between( old_num, new_num ) # Loading all versions between first and last
|
45
|
+
|
46
|
+
@versions = Irwi.config.paginator.paginate( versions, :page => params[:page] ) # Paginating them
|
47
|
+
|
48
|
+
@new_version = @versions.first.number == new_num ? @versions.first : versions.first # Loading next version
|
49
|
+
@old_version = @versions.last.number == old_num ? @versions.last : versions.last # Loading previous version
|
41
50
|
|
42
51
|
render_template 'compare'
|
43
52
|
end
|
@@ -74,6 +83,12 @@ module Irwi::Extensions::Controllers::WikiPages
|
|
74
83
|
redirect_to url_for( :action => :show )
|
75
84
|
end
|
76
85
|
|
86
|
+
def all
|
87
|
+
@pages = Irwi.config.paginator.paginate( page_class, :page => params[:page] ) # Loading and paginating all pages
|
88
|
+
|
89
|
+
render_template 'all'
|
90
|
+
end
|
91
|
+
|
77
92
|
protected
|
78
93
|
|
79
94
|
# Retrieves wiki_page_class for this controller
|
@@ -128,7 +143,7 @@ module Irwi::Extensions::Controllers::WikiPages
|
|
128
143
|
base.send :include, Irwi::Extensions::Controllers::WikiPages::InstanceMethods
|
129
144
|
|
130
145
|
base.before_filter :setup_current_user # Setup @current_user instance variable before each action
|
131
|
-
base.before_filter :setup_page # Setup @page instance variable before each action
|
146
|
+
base.before_filter :setup_page, :only => [ :show, :history, :compare, :edit, :update, :destroy ] # Setup @page instance variable before each action
|
132
147
|
|
133
148
|
base.helper_method :show_allowed?, :edit_allowed?, :history_allowed?, :destroy_allowed? # Access control methods are avaliable in views
|
134
149
|
end
|
@@ -38,7 +38,7 @@ module Irwi::Extensions::Models::WikiPage
|
|
38
38
|
base.belongs_to :creator, :class_name => Irwi.config.user_class_name
|
39
39
|
base.belongs_to :updator, :class_name => Irwi.config.user_class_name
|
40
40
|
|
41
|
-
base.has_many :versions, :class_name => Irwi.config.page_version_class_name, :foreign_key => Irwi.config.page_version_foreign_key, :order => 'id
|
41
|
+
base.has_many :versions, :class_name => Irwi.config.page_version_class_name, :foreign_key => Irwi.config.page_version_foreign_key, :order => 'id DESC'
|
42
42
|
|
43
43
|
base.after_save :create_new_version
|
44
44
|
end
|
@@ -7,20 +7,26 @@ module Irwi::Helpers::WikiPagesHelper
|
|
7
7
|
form_for( :page, @page, { :url => url_for( :action => :update ), :html=> { :class => 'wiki_form' } }.merge!( config ), &block )
|
8
8
|
end
|
9
9
|
|
10
|
-
def wiki_page_edit_path
|
11
|
-
|
10
|
+
def wiki_page_edit_path( page = nil )
|
11
|
+
wiki_page_path( page, :edit )
|
12
12
|
end
|
13
13
|
|
14
|
-
def wiki_page_history_path
|
15
|
-
|
14
|
+
def wiki_page_history_path( page = nil )
|
15
|
+
wiki_page_path( page, :history )
|
16
16
|
end
|
17
17
|
|
18
|
-
def wiki_page_compare_path
|
19
|
-
|
18
|
+
def wiki_page_compare_path( page = nil )
|
19
|
+
wiki_page_path( page, :compare )
|
20
20
|
end
|
21
21
|
|
22
|
-
def wiki_page_path
|
23
|
-
|
22
|
+
def wiki_page_path( page = nil, action = :show )
|
23
|
+
if page
|
24
|
+
page = page.path if page.respond_to? :path
|
25
|
+
|
26
|
+
url_for( :action => action, :path => page )
|
27
|
+
else
|
28
|
+
url_for( :action => action )
|
29
|
+
end
|
24
30
|
end
|
25
31
|
|
26
32
|
def wiki_content( text )
|
@@ -43,6 +49,10 @@ module Irwi::Helpers::WikiPagesHelper
|
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
52
|
+
def wiki_paginate( collection, &block )
|
53
|
+
Irwi.config.paginator.paginated_section( self, collection, &block )
|
54
|
+
end
|
55
|
+
|
46
56
|
def wiki_link( title )
|
47
57
|
if page = Irwi.config.page_class.find_by_title( title )
|
48
58
|
url_for( :controller => Irwi.config.controller_name, :action => :show, :path => page.path )
|
@@ -89,7 +99,7 @@ module Irwi::Helpers::WikiPagesHelper
|
|
89
99
|
|
90
100
|
def wiki_page_history(page = nil,versions = nil)
|
91
101
|
page ||= @page # By default take page from instance variable
|
92
|
-
versions ||= page.versions
|
102
|
+
versions ||= @versions || page.versions
|
93
103
|
|
94
104
|
render :partial => "#{template_dir '_wiki_page_history'}/wiki_page_history", :locals => { :page => page, :versions => versions, :with_form => (versions.size > 1) }
|
95
105
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Irwi::Paginators::None
|
2
|
+
|
3
|
+
def paginate( collection, options = {} )
|
4
|
+
find_options = options.except :page, :per_page, :total_entries, :finder
|
5
|
+
|
6
|
+
collection.find( :all, find_options )
|
7
|
+
end
|
8
|
+
|
9
|
+
def paginated_section( view, collection, &block )
|
10
|
+
yield
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -6,6 +6,10 @@ module Irwi::Support::RouteMapper
|
|
6
6
|
:controller => 'wiki_pages',
|
7
7
|
:root => path
|
8
8
|
}.merge(config)
|
9
|
+
|
10
|
+
Irwi.config.system_pages.each do |page_action, page_path| # Adding routes for system pages
|
11
|
+
connect( "#{path}/#{page_path}", opts.merge({ :action => page_action }) )
|
12
|
+
end
|
9
13
|
|
10
14
|
connect( "#{path}/compare/*path", opts.merge({ :action => 'compare' }) ) # Comparing two versions of page
|
11
15
|
connect( "#{path}/edit/*path", opts.merge({ :action => 'edit' }) ) # Wiki edit route
|
data/spec/config_spec.rb
CHANGED
@@ -55,4 +55,14 @@ describe Irwi::Config do
|
|
55
55
|
@o.comparator.should == :diff_lcs_comparator
|
56
56
|
end
|
57
57
|
|
58
|
+
specify "should contain 'all' action in system pages" do
|
59
|
+
Irwi.config.system_pages['all'].should == 'all'
|
60
|
+
end
|
61
|
+
|
62
|
+
specify "should add action in system pages" do
|
63
|
+
Irwi.config.system_pages['custom'].should be_nil
|
64
|
+
Irwi.config.add_system_page :custom, '!custom_page'
|
65
|
+
Irwi.config.system_pages['custom'].should == '!custom_page'
|
66
|
+
end
|
67
|
+
|
58
68
|
end
|
@@ -18,6 +18,42 @@ describe Irwi::Helpers::WikiPagesHelper do
|
|
18
18
|
it { @m.should respond_to :wiki_page_compare_path }
|
19
19
|
it { @m.should respond_to :wiki_page_path }
|
20
20
|
|
21
|
+
specify "should form url_for by wiki_page_edit_path" do
|
22
|
+
@m.should_receive(:url_for).with(:action => :edit).and_return('epath')
|
23
|
+
|
24
|
+
@m.wiki_page_edit_path.should == 'epath'
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "should form url_for by wiki_page_edit_path with path" do
|
28
|
+
@m.should_receive(:url_for).with(:action => :edit, :path => 'qwerty').and_return('epath')
|
29
|
+
|
30
|
+
@m.wiki_page_edit_path('qwerty').should == 'epath'
|
31
|
+
end
|
32
|
+
|
33
|
+
specify "should form url_for by wiki_page_history_path" do
|
34
|
+
@m.should_receive(:url_for).with(:action => :history).and_return('hpath')
|
35
|
+
|
36
|
+
@m.wiki_page_history_path.should == 'hpath'
|
37
|
+
end
|
38
|
+
|
39
|
+
specify "should form url_for by wiki_page_compare_path" do
|
40
|
+
@m.should_receive(:url_for).with(:action => :compare).and_return('cpath')
|
41
|
+
|
42
|
+
@m.wiki_page_compare_path.should == 'cpath'
|
43
|
+
end
|
44
|
+
|
45
|
+
specify "should form url_for by wiki_page_path" do
|
46
|
+
@m.should_receive(:url_for).with(:action => :show).and_return('spath')
|
47
|
+
|
48
|
+
@m.wiki_page_path.should == 'spath'
|
49
|
+
end
|
50
|
+
|
51
|
+
specify "should form url_for by wiki_page_path with path" do
|
52
|
+
@m.should_receive(:url_for).with(:action => :show, :path => '123').and_return('spath')
|
53
|
+
|
54
|
+
@m.wiki_page_path('123').should == 'spath'
|
55
|
+
end
|
56
|
+
|
21
57
|
it { @m.should respond_to :wiki_content }
|
22
58
|
it { @m.should respond_to :wiki_diff }
|
23
59
|
it { @m.should respond_to :wiki_user }
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
describe Irwi::Paginators::None do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@p = Irwi::Paginators::None.new
|
7
|
+
end
|
8
|
+
|
9
|
+
specify "should paginate collection - call find" do
|
10
|
+
coll = mock "Collection"
|
11
|
+
coll.should_receive(:find).with(:all,{}).and_return("full collection")
|
12
|
+
|
13
|
+
@p.paginate( coll, :page => 10 ).should == "full collection"
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should render paginated section" do
|
17
|
+
a = nil
|
18
|
+
@p.paginated_section "view", "collection" do
|
19
|
+
a = true
|
20
|
+
end
|
21
|
+
a.should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
describe Irwi::Paginators::WillPaginate do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
end
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@p = Irwi::Paginators::WillPaginate.new
|
10
|
+
end
|
11
|
+
|
12
|
+
specify "should paginate collection" do
|
13
|
+
coll = mock "Collection"
|
14
|
+
coll.should_receive(:paginate).with( :page => 15 ).and_return("paginated_collection")
|
15
|
+
|
16
|
+
@p.paginate( coll, :page => 15 ).should == "paginated_collection"
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "should render paginated collection" do
|
20
|
+
block = lambda { 11 }
|
21
|
+
coll = []
|
22
|
+
view = mock "View"
|
23
|
+
view.should_receive(:paginated_section).with( coll, &block ).and_return("result")
|
24
|
+
|
25
|
+
@p.paginated_section( view, coll, &block ).should == "result"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irwi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Noskov
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-01 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- app/views/base_wiki_pages/_wiki_page_history.html.erb
|
52
52
|
- app/views/base_wiki_pages/_wiki_page_info.html.erb
|
53
53
|
- app/views/base_wiki_pages/_wiki_page_style.html.erb
|
54
|
+
- app/views/base_wiki_pages/all.html.erb
|
54
55
|
- app/views/base_wiki_pages/compare.html.erb
|
55
56
|
- app/views/base_wiki_pages/edit.html.erb
|
56
57
|
- app/views/base_wiki_pages/history.html.erb
|
@@ -76,6 +77,8 @@ files:
|
|
76
77
|
- lib/irwi/formatters/blue_cloth.rb
|
77
78
|
- lib/irwi/formatters/red_cloth.rb
|
78
79
|
- lib/irwi/helpers/wiki_pages_helper.rb
|
80
|
+
- lib/irwi/paginators/none.rb
|
81
|
+
- lib/irwi/paginators/will_paginate.rb
|
79
82
|
- lib/irwi/support/route_mapper.rb
|
80
83
|
- lib/irwi/support/template_finder.rb
|
81
84
|
- rails/init.rb
|
@@ -84,6 +87,8 @@ files:
|
|
84
87
|
- spec/extensions/controllers/wiki_pages_spec.rb
|
85
88
|
- spec/formatters/red_cloth_spec.rb
|
86
89
|
- spec/helpers/wiki_pages_helper_spec.rb
|
90
|
+
- spec/paginators/none_spec.rb
|
91
|
+
- spec/paginators/will_paginate_spec.rb
|
87
92
|
- spec/rcov.opts
|
88
93
|
- spec/spec.opts
|
89
94
|
- spec/spec_helper.rb
|
@@ -127,3 +132,5 @@ test_files:
|
|
127
132
|
- spec/extensions/controllers/wiki_pages_spec.rb
|
128
133
|
- spec/helpers/wiki_pages_helper_spec.rb
|
129
134
|
- spec/spec_helper.rb
|
135
|
+
- spec/paginators/will_paginate_spec.rb
|
136
|
+
- spec/paginators/none_spec.rb
|