irwi 0.2.4 → 0.4.0
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/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
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -8,13 +8,13 @@ Setup gemcutter as gem source:
|
|
8
8
|
|
9
9
|
sudo gem install gemcutter
|
10
10
|
gem tumble
|
11
|
-
|
11
|
+
|
12
12
|
And install irwi gem (recommended):
|
13
13
|
|
14
14
|
sudo gem install irwi
|
15
|
-
|
15
|
+
|
16
16
|
And add to your environment.rb:
|
17
|
-
|
17
|
+
|
18
18
|
config.gem "irwi", :source => "http://gemcutter.org"
|
19
19
|
|
20
20
|
Or in your application directory call:
|
@@ -58,15 +58,15 @@ Following helpers are defined by default and you may replace them with you own:
|
|
58
58
|
Configuration options are acessed via <tt>Irwi.config</tt> object. Currently supported options:
|
59
59
|
* <tt>user_class_name</tt> - Name of user model class. By default - 'User'
|
60
60
|
* <tt>formatter</tt> - Formatter instance, which process wiki content before output. It should have method <tt>format</tt>, which gets a string and returns it formatted. By default instance of <tt>Irwi::Formatters::RedCloth</tt> is used (requires RedCloth gem). Other built-in formatter is <tt>Irwi::Formatters::BlueCloth</tt> (requires BlueCloth gem). Option accepts formatter instance, not class, so correct usage is:
|
61
|
-
|
61
|
+
|
62
62
|
Irwi.config.formatter = Irwi::Formatters::BlueCloth.new
|
63
|
-
|
63
|
+
|
64
64
|
* <tt>comparator</tt> - Comparator instance, which builds and renders a set of changes between to texts. By default instance of <tt>Irwi::Comparators::DiffLcs</tt> is used (requires diff-lcs gem).
|
65
65
|
|
66
66
|
== Access control
|
67
67
|
|
68
68
|
If you want (and it's good idea) to specify which users can see or edit certain pages you should simply override following methods in your controller:
|
69
|
-
* <tt>show_allowed?</tt> - should return <tt>true</tt> when it's allowed for current user to see current page (@page).
|
69
|
+
* <tt>show_allowed?</tt> - should return <tt>true</tt> when it's allowed for current user to see current page (@page).
|
70
70
|
* <tt>history_allowed?</tt> - should return <tt>true</tt> when it's allowed for user to see history of current page (@page) and compare it's versions.
|
71
71
|
* <tt>edit_allowed?</tt> - should return <tt>true</tt> when it's allowed for current user to modify current page (@page).
|
72
72
|
|
@@ -83,14 +83,14 @@ Irwi allows easy attachment integration in your wiki. There area several simple
|
|
83
83
|
== Rails prior to 2.3
|
84
84
|
|
85
85
|
If you have Rails prior to 2.3 when you should also call:
|
86
|
-
|
86
|
+
|
87
87
|
script/generate irwi_wiki_views
|
88
|
-
|
88
|
+
|
89
89
|
To generate default wiki views.
|
90
90
|
|
91
91
|
== I18n Issues
|
92
92
|
|
93
|
-
If you get some weird errors like
|
93
|
+
If you get some weird errors like
|
94
94
|
|
95
95
|
missing interpolation argument in "%{count} %B %Y, %H:%M"
|
96
96
|
|
@@ -1,3 +1,3 @@
|
|
1
1
|
<div class="wiki_page_info">
|
2
|
-
<%=wt "Revised on {
|
2
|
+
<%=(wt "Revised on %{time} by %{user}", :time => l( page.updated_at, :format => :long ), :user => wiki_user( page.updator ) ).html_safe %>
|
3
3
|
</div>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%= wiki_page_style %>
|
2
2
|
|
3
|
-
<h1><%=wt '{
|
3
|
+
<h1><%=wt '%{page_title} - Comparing versions %{old_version} and %{new_version}', :page_title => h( @page.title ), :old_version => @old_version.number, :new_version => @new_version.number %></h1>
|
4
4
|
|
5
5
|
<%=wt 'Changes list:' %>
|
6
6
|
|
@@ -1 +1 @@
|
|
1
|
-
<%=wt 'There are no such page. Do you want to <a href="{
|
1
|
+
<%=(wt 'There are no such page. Do you want to <a href="%{new_url}">create it</a>?', :new_url => wiki_page_new_path ).html_safe %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails/generators/active_record/migration'
|
2
|
+
|
3
|
+
class IrwiWikiGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
extend ActiveRecord::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
|
+
|
10
|
+
def generate_wiki
|
11
|
+
|
12
|
+
# Controllers
|
13
|
+
copy_file 'controllers/wiki_pages_controller.rb', 'app/controllers/wiki_pages_controller.rb'
|
14
|
+
|
15
|
+
# Helpers
|
16
|
+
copy_file 'helpers/wiki_pages_helper.rb', 'app/helpers/wiki_pages_helper.rb'
|
17
|
+
|
18
|
+
# Models
|
19
|
+
copy_file 'models/wiki_page.rb', 'app/models/wiki_page.rb'
|
20
|
+
copy_file 'models/wiki_page_version.rb', 'app/models/wiki_page_version.rb'
|
21
|
+
|
22
|
+
# Migrations
|
23
|
+
migration_template 'migrate/create_wiki_pages.rb', 'db/migrate/create_wiki_pages'
|
24
|
+
|
25
|
+
# Routes
|
26
|
+
route "wiki_root '/wiki'"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -4,41 +4,41 @@ class CreateWikiPages < ActiveRecord::Migration
|
|
4
4
|
create_table :wiki_pages do |t|
|
5
5
|
t.integer :creator_id
|
6
6
|
t.integer :updator_id
|
7
|
-
|
7
|
+
|
8
8
|
t.string :path
|
9
9
|
t.string :title
|
10
|
-
|
10
|
+
|
11
11
|
t.text :content
|
12
|
-
|
12
|
+
|
13
13
|
t.timestamps
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
add_index :wiki_pages, :creator_id
|
17
17
|
add_index :wiki_pages, :path, :unique => true
|
18
|
-
|
18
|
+
|
19
19
|
create_table :wiki_page_versions do |t|
|
20
|
-
t.integer :page_id, :null => false # Reference to page
|
20
|
+
t.integer :page_id, :null => false # Reference to page
|
21
21
|
t.integer :updator_id # Reference to user, updated page
|
22
|
-
|
22
|
+
|
23
23
|
t.integer :number # Version number
|
24
|
-
|
24
|
+
|
25
25
|
t.string :comment
|
26
|
-
|
26
|
+
|
27
27
|
t.string :path
|
28
28
|
t.string :title
|
29
|
-
|
29
|
+
|
30
30
|
t.text :content
|
31
|
-
|
31
|
+
|
32
32
|
t.timestamp :updated_at
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
add_index :wiki_page_versions, :page_id
|
36
36
|
add_index :wiki_page_versions, :updator_id
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def self.down
|
40
40
|
drop_table :wiki_page_versions
|
41
41
|
drop_table :wiki_pages
|
42
42
|
end
|
43
|
-
|
44
|
-
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators/active_record/migration'
|
2
|
+
|
3
|
+
class IrwiWikiAttachmentsGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
extend ActiveRecord::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
|
+
|
10
|
+
def generate_attachments
|
11
|
+
%w[create_wiki_page_attachments].each do |mig|
|
12
|
+
unless Dir.entries(File.join(Rails.root,'db','migrate')).grep(/#{mig}/).present?
|
13
|
+
migration_template "migrate/#{mig}.rb", "db/migrate/#{mig}"
|
14
|
+
sleep(1) # To avoid migration file version collision.
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Models
|
19
|
+
copy_file 'models/wiki_page_attachment.rb', 'app/models/wiki_page_attachment.rb'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -2,18 +2,18 @@ class CreateWikiPageAttachments < ActiveRecord::Migration
|
|
2
2
|
|
3
3
|
def self.up
|
4
4
|
create_table :wiki_page_attachments do |t|
|
5
|
-
t.integer :page_id, :null => false # Reference to page
|
5
|
+
t.integer :page_id, :null => false # Reference to page
|
6
6
|
t.string :wiki_page_attachment_file_name
|
7
7
|
t.string :wiki_page_attachment_content_type
|
8
8
|
t.integer :wiki_page_attachment_file_size
|
9
|
-
|
9
|
+
|
10
10
|
t.timestamps
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.down
|
16
16
|
drop_table :wiki_page_attachments
|
17
17
|
end
|
18
|
-
|
19
|
-
end
|
18
|
+
|
19
|
+
end
|
data/{generators → lib/generators}/irwi_wiki_attachments/templates/models/wiki_page_attachment.rb
RENAMED
@@ -6,4 +6,4 @@ class WikiPageAttachment < ActiveRecord::Base
|
|
6
6
|
validates_attachment_presence :wiki_page_attachment, :message => " is missing."
|
7
7
|
validates_attachment_content_type :wiki_page_attachment, :content_type => ['image/jpeg','image/jpg','image/png','image/x-png','image/gif','image/pjpeg'], :message => ' must be a JPEG, PNG or GIF.'
|
8
8
|
end
|
9
|
-
end
|
9
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class IrwiWikiViewsGenerator < Rails::Generators::Base
|
2
|
+
|
3
|
+
source_root File.expand_path("../../../../app/views/base_wiki_pages", __FILE__)
|
4
|
+
|
5
|
+
def views
|
6
|
+
empty_directory 'app/views/base_wiki_pages'
|
7
|
+
|
8
|
+
Dir.foreach source_root do |file| # Searching for files in app/views
|
9
|
+
copy_file( file, 'app/views/base_wiki_pages/' + file ) if file != '.' && file != '..'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
data/lib/irwi.rb
CHANGED
@@ -1,16 +1,43 @@
|
|
1
|
+
require 'active_support/dependencies'
|
2
|
+
|
1
3
|
module Irwi
|
2
4
|
|
3
|
-
module Formatters
|
4
|
-
|
5
|
+
module Formatters
|
6
|
+
autoload :BlueCloth, 'irwi/formatters/blue_cloth'
|
7
|
+
autoload :RedCloth, 'irwi/formatters/red_cloth'
|
8
|
+
end
|
9
|
+
|
10
|
+
module Comparators
|
11
|
+
autoload :DiffLcs, 'irwi/comparators/diff_lcs'
|
12
|
+
autoload :Base, 'irwi/comparators/base'
|
13
|
+
module Spans
|
14
|
+
autoload :ChangedSpan, 'irwi/comparators/spans/changed_span'
|
15
|
+
autoload :NotChangedSpan, 'irwi/comparators/spans/not_changed_span'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
5
19
|
module Extensions; end
|
6
|
-
|
7
|
-
module Paginators
|
8
|
-
|
9
|
-
|
20
|
+
|
21
|
+
module Paginators
|
22
|
+
autoload :None, 'irwi/paginators/none'
|
23
|
+
autoload :WillPaginate, 'irwi/paginators/will_paginate'
|
24
|
+
end
|
25
|
+
|
26
|
+
module Support
|
27
|
+
autoload :TemplateFinder, 'irwi/support/template_finder'
|
28
|
+
end
|
29
|
+
|
10
30
|
def self.config
|
11
31
|
require 'irwi/config'
|
12
32
|
|
13
33
|
@@config ||= Irwi::Config.new
|
14
34
|
end
|
15
|
-
|
35
|
+
|
16
36
|
end
|
37
|
+
|
38
|
+
require 'irwi/extensions/controllers'
|
39
|
+
require 'irwi/extensions/models'
|
40
|
+
require 'irwi/support/route_mapper' # Routes
|
41
|
+
require 'irwi/helpers'
|
42
|
+
|
43
|
+
ActionController::Base.append_view_path File.expand_path('../../app/views', __FILE__) # Append default views
|
@@ -2,19 +2,19 @@ require 'irwi/comparators/spans/changed_span'
|
|
2
2
|
require 'irwi/comparators/spans/not_changed_span'
|
3
3
|
|
4
4
|
class Irwi::Comparators::Base
|
5
|
-
|
5
|
+
|
6
6
|
def render_changes( old_text, new_text )
|
7
7
|
build_changes( old_text, new_text ).join('').gsub( /\r?\n/, '<br />' )
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
protected
|
11
|
-
|
11
|
+
|
12
12
|
def new_not_changed( value )
|
13
13
|
Irwi::Comparators::Spans::NotChangedSpan.new( value )
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def new_changed( action, old_value, new_value )
|
17
17
|
Irwi::Comparators::Spans::ChangedSpan.new( action, old_value, new_value )
|
18
18
|
end
|
19
|
-
|
20
|
-
end
|
19
|
+
|
20
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'irwi/comparators/base'
|
2
2
|
|
3
3
|
class Irwi::Comparators::DiffLcs < Irwi::Comparators::Base
|
4
|
-
|
4
|
+
|
5
5
|
def initialize
|
6
6
|
super
|
7
|
-
|
7
|
+
|
8
8
|
require 'diff/lcs'
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def build_changes( old_text, new_text )
|
12
|
-
diffs = Diff::LCS.sdiff( (old_text || '').mb_chars, (new_text || '').mb_chars ) # Building symmetric diff sequence
|
13
|
-
changes = [] # Array for our result changes
|
14
|
-
|
12
|
+
diffs = Diff::LCS.sdiff( (old_text || '').mb_chars, (new_text || '').mb_chars ) # Building symmetric diff sequence
|
13
|
+
changes = [] # Array for our result changes
|
14
|
+
|
15
15
|
diffs.each do |change|
|
16
16
|
case change.action
|
17
17
|
when '=' then
|
@@ -20,7 +20,7 @@ class Irwi::Comparators::DiffLcs < Irwi::Comparators::Base
|
|
20
20
|
else
|
21
21
|
changes << new_not_changed( change.old_element )
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
when '+' then
|
25
25
|
if !changes.empty? && changes.last.action == '+' # Append to last addition, if exists
|
26
26
|
changes.last.new_value << change.new_element
|
@@ -29,14 +29,14 @@ class Irwi::Comparators::DiffLcs < Irwi::Comparators::Base
|
|
29
29
|
else
|
30
30
|
changes << new_changed( '+', nil, change.new_element )
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
when '-' then
|
34
34
|
if !changes.empty? && changes.last.action == '-' # Append to last deletion, if exists
|
35
35
|
changes.last.old_value << change.old_element
|
36
36
|
else
|
37
37
|
changes << new_changed( '-', change.old_element, nil )
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
when '!' then
|
41
41
|
if !changes.empty? && changes.last.action == '!' # Append to last replace, if exists
|
42
42
|
changes.last.old_value << change.old_element
|
@@ -44,11 +44,11 @@ class Irwi::Comparators::DiffLcs < Irwi::Comparators::Base
|
|
44
44
|
else
|
45
45
|
changes << new_changed( '!', change.old_element, change.new_element )
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
changes
|
52
52
|
end
|
53
|
-
|
54
|
-
end
|
53
|
+
|
54
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
class Irwi::Comparators::Spans::ChangedSpan
|
2
|
-
|
3
|
-
attr_accessor :action, :old_value, :new_value
|
4
|
-
|
2
|
+
|
3
|
+
attr_accessor :action, :old_value, :new_value
|
4
|
+
|
5
5
|
def initialize( act, ov, nv )
|
6
6
|
@action = act
|
7
7
|
@old_value = ov
|
8
8
|
@new_value = nv
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def to_s
|
12
12
|
s = ''
|
13
13
|
s << "<span class=\"removed\">#{@old_value}</span>" if @old_value
|
14
14
|
s << "<span class=\"added\">#{@new_value}</span>" if @new_value
|
15
15
|
s
|
16
16
|
end
|
17
|
-
|
18
|
-
end
|
17
|
+
|
18
|
+
end
|