irwi_mod 0.0.1

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.
Files changed (51) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +12 -0
  3. data/app/views/base_wiki_pages/_wiki_page_actions.html.erb +5 -0
  4. data/app/views/base_wiki_pages/_wiki_page_history.html.erb +31 -0
  5. data/app/views/base_wiki_pages/_wiki_page_info.html.erb +3 -0
  6. data/app/views/base_wiki_pages/_wiki_page_style.html.erb +69 -0
  7. data/app/views/base_wiki_pages/all.html.erb +11 -0
  8. data/app/views/base_wiki_pages/compare.html.erb +15 -0
  9. data/app/views/base_wiki_pages/edit.html.erb +36 -0
  10. data/app/views/base_wiki_pages/history.html.erb +8 -0
  11. data/app/views/base_wiki_pages/index.html.erb +11 -0
  12. data/app/views/base_wiki_pages/new.html.erb +14 -0
  13. data/app/views/base_wiki_pages/no.html.erb +1 -0
  14. data/app/views/base_wiki_pages/not_allowed.html.erb +1 -0
  15. data/app/views/base_wiki_pages/show.html.erb +11 -0
  16. data/lib/generators/irwi_wiki/irwi_wiki_generator.rb +29 -0
  17. data/lib/generators/irwi_wiki/templates/controllers/wiki_pages_controller.rb +5 -0
  18. data/lib/generators/irwi_wiki/templates/helpers/wiki_pages_helper.rb +3 -0
  19. data/lib/generators/irwi_wiki/templates/migrate/create_wiki_pages.rb +44 -0
  20. data/lib/generators/irwi_wiki/templates/models/wiki_page.rb +5 -0
  21. data/lib/generators/irwi_wiki/templates/models/wiki_page_version.rb +5 -0
  22. data/lib/generators/irwi_wiki_attachments/irwi_wiki_attachments_generator.rb +22 -0
  23. data/lib/generators/irwi_wiki_attachments/templates/migrate/create_wiki_page_attachments.rb +19 -0
  24. data/lib/generators/irwi_wiki_attachments/templates/models/wiki_page_attachment.rb +9 -0
  25. data/lib/generators/irwi_wiki_views/irwi_wiki_views_generator.rb +13 -0
  26. data/lib/irwi_mod.rb +46 -0
  27. data/lib/irwi_mod/comparators/base.rb +20 -0
  28. data/lib/irwi_mod/comparators/diff_lcs.rb +54 -0
  29. data/lib/irwi_mod/comparators/spans/changed_span.rb +18 -0
  30. data/lib/irwi_mod/comparators/spans/not_changed_span.rb +20 -0
  31. data/lib/irwi_mod/config.rb +83 -0
  32. data/lib/irwi_mod/extensions/controllers.rb +18 -0
  33. data/lib/irwi_mod/extensions/controllers/wiki_page_attachments.rb +21 -0
  34. data/lib/irwi_mod/extensions/controllers/wiki_pages.rb +167 -0
  35. data/lib/irwi_mod/extensions/models.rb +24 -0
  36. data/lib/irwi_mod/extensions/models/wiki_page.rb +55 -0
  37. data/lib/irwi_mod/extensions/models/wiki_page_attachment.rb +9 -0
  38. data/lib/irwi_mod/extensions/models/wiki_page_version.rb +44 -0
  39. data/lib/irwi_mod/formatters/blue_cloth.rb +11 -0
  40. data/lib/irwi_mod/formatters/red_cloth.rb +11 -0
  41. data/lib/irwi_mod/formatters/simple_html.rb +10 -0
  42. data/lib/irwi_mod/formatters/wiki_cloth.rb +11 -0
  43. data/lib/irwi_mod/helpers.rb +13 -0
  44. data/lib/irwi_mod/helpers/wiki_page_attachments_helper.rb +25 -0
  45. data/lib/irwi_mod/helpers/wiki_pages_helper.rb +145 -0
  46. data/lib/irwi_mod/paginators/none.rb +16 -0
  47. data/lib/irwi_mod/paginators/will_paginate.rb +11 -0
  48. data/lib/irwi_mod/support/route_mapper.rb +36 -0
  49. data/lib/irwi_mod/support/template_finder.rb +11 -0
  50. data/lib/irwi_mod/version.rb +9 -0
  51. 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,12 @@
1
+ = Irwi-mod
2
+
3
+ Adds wiki functionality to your application. Based on http://github.com/alno/irwi
4
+
5
+ == Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ gem 'irwi-mod', :git => 'https://github.com/amr0th/mod-irwi.git'
10
+
11
+
12
+
@@ -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,3 @@
1
+ <div class="wiki_page_info">
2
+ <%=(wt "Revised on %{time} by %{user}", :time => l( page.updated_at, :format => :long ), :user => wiki_user( page.updator ) ).html_safe %>
3
+ </div>
@@ -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,11 @@
1
+ <%= wiki_page_style -%>
2
+
3
+ <h1><%=wt 'All pages' %></h1>
4
+
5
+ <ul>
6
+ <% wiki_paginate @pages do -%>
7
+ <% @pages.each do |page| -%>
8
+ <li><%= link_to page.title, wiki_page_path( page ) %></li>
9
+ <% end -%>
10
+ <% end -%>
11
+ </ul>
@@ -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", '&#x000A;').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,8 @@
1
+ <%= wiki_page_style %>
2
+
3
+ <h1><%=wt '%{page_title} - History', :page_title => @page.title %></h1>
4
+
5
+ <%= wiki_page_info %>
6
+ <%= wiki_page_actions %>
7
+
8
+ <%= wiki_page_history %>
@@ -0,0 +1,11 @@
1
+ <%= wiki_page_style -%>
2
+
3
+ <h1><%=wt 'Manuais Disponiveis' %></h1>
4
+
5
+ <ul>
6
+ <% wiki_paginate @pages do -%>
7
+ <% @pages.each do |page| -%>
8
+ <li><%= link_to page.title, wiki_page_path( page ) %></li>
9
+ <% end -%>
10
+ <% end -%>
11
+ </ul>
@@ -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,11 @@
1
+ <%= wiki_page_style %>
2
+
3
+ <h1><%=h @page.title %></h1>
4
+
5
+ <%= wiki_page_info %>
6
+ <%= wiki_page_actions %>
7
+
8
+ <div class="wiki_content">
9
+ <%=wiki_content @page.content %>
10
+ </div>
11
+
@@ -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,5 @@
1
+ class WikiPagesController < ApplicationController
2
+
3
+ acts_as_wiki_pages_controller
4
+
5
+ end
@@ -0,0 +1,3 @@
1
+ module WikiPagesHelper
2
+ acts_as_wiki_pages_helper
3
+ 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,5 @@
1
+ class WikiPage < ActiveRecord::Base
2
+
3
+ acts_as_wiki_page
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ class WikiPageVersion < ActiveRecord::Base
2
+
3
+ acts_as_wiki_page_version
4
+
5
+ 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