irwi_mod 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +12 -0
- data/app/views/base_wiki_pages/_wiki_page_actions.html.erb +5 -0
- data/app/views/base_wiki_pages/_wiki_page_history.html.erb +31 -0
- data/app/views/base_wiki_pages/_wiki_page_info.html.erb +3 -0
- data/app/views/base_wiki_pages/_wiki_page_style.html.erb +69 -0
- data/app/views/base_wiki_pages/all.html.erb +11 -0
- data/app/views/base_wiki_pages/compare.html.erb +15 -0
- data/app/views/base_wiki_pages/edit.html.erb +36 -0
- data/app/views/base_wiki_pages/history.html.erb +8 -0
- data/app/views/base_wiki_pages/index.html.erb +11 -0
- data/app/views/base_wiki_pages/new.html.erb +14 -0
- data/app/views/base_wiki_pages/no.html.erb +1 -0
- data/app/views/base_wiki_pages/not_allowed.html.erb +1 -0
- data/app/views/base_wiki_pages/show.html.erb +11 -0
- data/lib/generators/irwi_wiki/irwi_wiki_generator.rb +29 -0
- data/lib/generators/irwi_wiki/templates/controllers/wiki_pages_controller.rb +5 -0
- data/lib/generators/irwi_wiki/templates/helpers/wiki_pages_helper.rb +3 -0
- data/lib/generators/irwi_wiki/templates/migrate/create_wiki_pages.rb +44 -0
- data/lib/generators/irwi_wiki/templates/models/wiki_page.rb +5 -0
- data/lib/generators/irwi_wiki/templates/models/wiki_page_version.rb +5 -0
- data/lib/generators/irwi_wiki_attachments/irwi_wiki_attachments_generator.rb +22 -0
- data/lib/generators/irwi_wiki_attachments/templates/migrate/create_wiki_page_attachments.rb +19 -0
- data/lib/generators/irwi_wiki_attachments/templates/models/wiki_page_attachment.rb +9 -0
- data/lib/generators/irwi_wiki_views/irwi_wiki_views_generator.rb +13 -0
- data/lib/irwi_mod.rb +46 -0
- data/lib/irwi_mod/comparators/base.rb +20 -0
- data/lib/irwi_mod/comparators/diff_lcs.rb +54 -0
- data/lib/irwi_mod/comparators/spans/changed_span.rb +18 -0
- data/lib/irwi_mod/comparators/spans/not_changed_span.rb +20 -0
- data/lib/irwi_mod/config.rb +83 -0
- data/lib/irwi_mod/extensions/controllers.rb +18 -0
- data/lib/irwi_mod/extensions/controllers/wiki_page_attachments.rb +21 -0
- data/lib/irwi_mod/extensions/controllers/wiki_pages.rb +167 -0
- data/lib/irwi_mod/extensions/models.rb +24 -0
- data/lib/irwi_mod/extensions/models/wiki_page.rb +55 -0
- data/lib/irwi_mod/extensions/models/wiki_page_attachment.rb +9 -0
- data/lib/irwi_mod/extensions/models/wiki_page_version.rb +44 -0
- data/lib/irwi_mod/formatters/blue_cloth.rb +11 -0
- data/lib/irwi_mod/formatters/red_cloth.rb +11 -0
- data/lib/irwi_mod/formatters/simple_html.rb +10 -0
- data/lib/irwi_mod/formatters/wiki_cloth.rb +11 -0
- data/lib/irwi_mod/helpers.rb +13 -0
- data/lib/irwi_mod/helpers/wiki_page_attachments_helper.rb +25 -0
- data/lib/irwi_mod/helpers/wiki_pages_helper.rb +145 -0
- data/lib/irwi_mod/paginators/none.rb +16 -0
- data/lib/irwi_mod/paginators/will_paginate.rb +11 -0
- data/lib/irwi_mod/support/route_mapper.rb +36 -0
- data/lib/irwi_mod/support/template_finder.rb +11 -0
- data/lib/irwi_mod/version.rb +9 -0
- metadata +231 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alexey Noskov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
<ul class="wiki_page_actions">
|
2
|
+
<%= content_tag('li', link_to( wt( 'History' ), wiki_page_history_path(@page) )) if history_allowed? %>
|
3
|
+
<%= content_tag('li', link_to( wt( 'Edit' ), wiki_page_edit_path(@page) )) if edit_allowed? %>
|
4
|
+
<%= content_tag('li', link_to( wt( 'Destroy' ), wiki_page_path(@page), :method => :delete, :confirm => wt( "Destroyed page can't be restored. Are you sure?" ) )) if destroy_allowed? %>
|
5
|
+
</ul>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<% if with_form %>
|
2
|
+
<form action="<%=wiki_page_compare_path%>" method="get">
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<table class="wiki_history">
|
6
|
+
<tr class="wiki_history_header">
|
7
|
+
<td><%=wt 'Version' %></td>
|
8
|
+
<td><%=wt 'Date' %></td>
|
9
|
+
<td><%=wt 'Author' %></td>
|
10
|
+
<td><%=wt 'Comment' %></td>
|
11
|
+
</tr>
|
12
|
+
<% versions.each do |v| %>
|
13
|
+
<tr>
|
14
|
+
<td>
|
15
|
+
<%=v.number%>
|
16
|
+
<% if with_form %>
|
17
|
+
<input type="radio" name="old" value="<%=v.number%>" <%= 'checked="true" ' if v == versions[-1] %>/>
|
18
|
+
<input type="radio" name="new" value="<%=v.number%>" <%= 'checked="true" ' if v == versions[-2] %>/>
|
19
|
+
<% end %>
|
20
|
+
</td>
|
21
|
+
<td><%=l( v.updated_at, :format => :long ) %></td>
|
22
|
+
<td><%= wiki_user( v.updator ) %></td>
|
23
|
+
<td><%= v.comment %></td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
</table>
|
27
|
+
|
28
|
+
<% if with_form %>
|
29
|
+
<%= submit_tag wt 'Compare selected versions' %>
|
30
|
+
</form>
|
31
|
+
<% end %>
|
@@ -0,0 +1,69 @@
|
|
1
|
+
<style>
|
2
|
+
|
3
|
+
.wiki_page_info {
|
4
|
+
font-style: italic;
|
5
|
+
color: #666;
|
6
|
+
margin-left: 5px;
|
7
|
+
float: left;
|
8
|
+
}
|
9
|
+
|
10
|
+
.wiki_page_actions {
|
11
|
+
text-align: right;
|
12
|
+
width: 100%;
|
13
|
+
padding: 0px;
|
14
|
+
}
|
15
|
+
|
16
|
+
.wiki_page_actions li {
|
17
|
+
display: inline;
|
18
|
+
margin: 0px;
|
19
|
+
padding: 0px;
|
20
|
+
}
|
21
|
+
|
22
|
+
.wiki_content,
|
23
|
+
.wiki_diff,
|
24
|
+
.wiki_history {
|
25
|
+
border: 1px dashed #666;
|
26
|
+
margin-top: 10px;
|
27
|
+
margin-bottom: 10px;
|
28
|
+
padding: 10px;
|
29
|
+
}
|
30
|
+
|
31
|
+
.wiki_history {
|
32
|
+
width: 100%;
|
33
|
+
}
|
34
|
+
|
35
|
+
.wiki_history_header td {
|
36
|
+
border-bottom: 2px dashed black;
|
37
|
+
}
|
38
|
+
|
39
|
+
.wiki_form {
|
40
|
+
display: block;
|
41
|
+
width: 100%;
|
42
|
+
border: 1px dashed #666;
|
43
|
+
}
|
44
|
+
|
45
|
+
.wiki_form p {
|
46
|
+
padding: 10px;
|
47
|
+
}
|
48
|
+
|
49
|
+
.wiki_form p input,
|
50
|
+
.wiki_form p textarea {
|
51
|
+
width: 100%;
|
52
|
+
}
|
53
|
+
|
54
|
+
.wiki_form .submit {
|
55
|
+
margin-left: 20px;
|
56
|
+
margin-bottom: 10px;
|
57
|
+
}
|
58
|
+
|
59
|
+
.wiki_diff span.added {
|
60
|
+
background: #D4FFAB;
|
61
|
+
color: #509A05;
|
62
|
+
}
|
63
|
+
|
64
|
+
.wiki_diff span.removed {
|
65
|
+
background: #FFD8D8;
|
66
|
+
color: #EF2828;
|
67
|
+
}
|
68
|
+
|
69
|
+
</style>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= wiki_page_style %>
|
2
|
+
|
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
|
+
|
5
|
+
<%=wt 'Changes list:' %>
|
6
|
+
|
7
|
+
<%= wiki_paginate @versions do%>
|
8
|
+
<%= wiki_page_history @page, @versions %>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<%=wt 'Changes in content:' %>
|
12
|
+
|
13
|
+
<div class="wiki_diff">
|
14
|
+
<%= wiki_diff @old_version.content, @new_version.content %>
|
15
|
+
</div>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<%= wiki_page_style %>
|
2
|
+
|
3
|
+
<h1><%=wt 'Editing wiki page' %></h1>
|
4
|
+
|
5
|
+
<% if params[:preview] %>
|
6
|
+
<div class="wiki_content">
|
7
|
+
<%=wiki_content @page.content %>
|
8
|
+
</div>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<%= wiki_page_form do |f| %>
|
12
|
+
<%= f.hidden_field :previous_version_number, :value => f.object.last_version_number %>
|
13
|
+
<%= hidden_field_tag :path, @page.path %>
|
14
|
+
|
15
|
+
<p><%=wt 'Title:' %><br /><%= f.text_field :title %></p>
|
16
|
+
<%# If our 'content' contains newlines, Erubis will indent them (to make the
|
17
|
+
produced HTML look nicer). However those indenting spaces *will* appear
|
18
|
+
in the textarea in the user's browser and will get POSTed by the browser
|
19
|
+
when submitting the form and thus would get written to the wiki content
|
20
|
+
into the database. The gsub's below replace the linebreaks ('\r\n')
|
21
|
+
with UTF8 linefeeds (same way HAML solves this problem), which are
|
22
|
+
ignored by Erubis and should be correctly displayed as linebreaks by
|
23
|
+
modern browsers. %>
|
24
|
+
<p><%=wt 'Content:' %><br />
|
25
|
+
<%= f.text_area(:content,
|
26
|
+
:value => f.object.content.gsub("\n", '
').gsub("\r",''),
|
27
|
+
:class => 'ckeditor').html_safe %></p>
|
28
|
+
<p><%=wt 'Comment on this change (optional):' %><br /><%= f.text_field :comment %></p>
|
29
|
+
|
30
|
+
<input type="submit" name="save" value="<%=wt 'Save page' %>" class="submit" />
|
31
|
+
<input type="submit" name="preview" value="<%=wt 'Preview' %>" class="submit" />
|
32
|
+
<input type="submit" name="cancel" value="<%=wt 'Cancel' %>" class="submit" />
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<%= wiki_page_attachments(@page) %>
|
36
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%= wiki_page_style %>
|
2
|
+
|
3
|
+
<h1><%=wt 'Creating a new wiki page' %></h1>
|
4
|
+
|
5
|
+
<%= wiki_page_form do |f| %>
|
6
|
+
<%= f.hidden_field :previous_version_number, :value => f.object.last_version_number %>
|
7
|
+
|
8
|
+
<p><%=wt 'Title:' %><br /><%= f.text_field :title %></p>
|
9
|
+
<p><%=wt 'Content:' %><br /><%= f.text_area :content, :class => 'ckeditor' %></p>
|
10
|
+
<%= f.hidden_field :comment, :value => 'First Revision'%>
|
11
|
+
<%= hidden_field_tag :path, @page.path %>
|
12
|
+
|
13
|
+
<input type="submit" value="<%=wt 'Create page' %>" class="submit" />
|
14
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%=(wt 'There is no such page', :default => 'There is 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 @@
|
|
1
|
+
<%=wt 'You are not allowed to be here; please go back.' %>
|
@@ -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
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class CreateWikiPages < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :wiki_pages do |t|
|
5
|
+
t.integer :creator_id
|
6
|
+
t.integer :updator_id
|
7
|
+
|
8
|
+
t.string :path
|
9
|
+
t.string :title
|
10
|
+
|
11
|
+
t.text :content
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :wiki_pages, :creator_id
|
17
|
+
add_index :wiki_pages, :path, :unique => true
|
18
|
+
|
19
|
+
create_table :wiki_page_versions do |t|
|
20
|
+
t.integer :page_id, :null => false # Reference to page
|
21
|
+
t.integer :updator_id # Reference to user, updated page
|
22
|
+
|
23
|
+
t.integer :number # Version number
|
24
|
+
|
25
|
+
t.string :comment
|
26
|
+
|
27
|
+
t.string :path
|
28
|
+
t.string :title
|
29
|
+
|
30
|
+
t.text :content
|
31
|
+
|
32
|
+
t.timestamp :updated_at
|
33
|
+
end
|
34
|
+
|
35
|
+
add_index :wiki_page_versions, :page_id
|
36
|
+
add_index :wiki_page_versions, :updator_id
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.down
|
40
|
+
drop_table :wiki_page_versions
|
41
|
+
drop_table :wiki_pages
|
42
|
+
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
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateWikiPageAttachments < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :wiki_page_attachments do |t|
|
5
|
+
t.integer :page_id, :null => false # Reference to page
|
6
|
+
t.string :wiki_page_attachment_file_name
|
7
|
+
t.string :wiki_page_attachment_content_type
|
8
|
+
t.integer :wiki_page_attachment_file_size
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :wiki_page_attachments
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'paperclip'
|
2
|
+
|
3
|
+
class WikiPageAttachment < ActiveRecord::Base
|
4
|
+
acts_as_wiki_page_attachment do
|
5
|
+
has_attached_file :wiki_page_attachment, :styles => { :medium => "300x300>", :thumb => "100x100>" }
|
6
|
+
validates_attachment_presence :wiki_page_attachment, :message => " is missing."
|
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
|
+
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 File.expand_path("../../../../app/views/base_wiki_pages", __FILE__) 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
|