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
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module IrwiMod::Extensions::Models
|
4
|
+
autoload :WikiPage, 'irwi_mod/extensions/models/wiki_page'
|
5
|
+
autoload :WikiPageVersion, 'irwi_mod/extensions/models/wiki_page_version'
|
6
|
+
autoload :WikiPageAttachment, 'irwi_mod/extensions/models/wiki_page_attachment'
|
7
|
+
end
|
8
|
+
|
9
|
+
ActiveRecord::Base.instance_eval do
|
10
|
+
|
11
|
+
def acts_as_wiki_page( config = {} )
|
12
|
+
include IrwiMod::Extensions::Models::WikiPage
|
13
|
+
end
|
14
|
+
|
15
|
+
def acts_as_wiki_page_version( config = {} )
|
16
|
+
include IrwiMod::Extensions::Models::WikiPageVersion
|
17
|
+
end
|
18
|
+
|
19
|
+
def acts_as_wiki_page_attachment
|
20
|
+
include IrwiMod::Extensions::Models::WikiPageAttachment
|
21
|
+
yield if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module IrwiMod::Extensions::Models::WikiPage
|
2
|
+
|
3
|
+
module ClassMethods
|
4
|
+
|
5
|
+
def find_by_path_or_new( path )
|
6
|
+
self.find_by_path( path ) || self.new( :path => path, :title => CGI::unescape(path) )
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
|
13
|
+
# Retrieve number of last version
|
14
|
+
def last_version_number
|
15
|
+
last = versions.first
|
16
|
+
last ? last.number : 0
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def create_new_version
|
22
|
+
n = last_version_number
|
23
|
+
|
24
|
+
v = versions.build
|
25
|
+
v.attributes = attributes.slice( *v.attribute_names )
|
26
|
+
v.comment = comment
|
27
|
+
v.number = n + 1
|
28
|
+
v.save!
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.included( base )
|
34
|
+
base.send :extend, IrwiMod::Extensions::Models::WikiPage::ClassMethods
|
35
|
+
base.send :include, IrwiMod::Extensions::Models::WikiPage::InstanceMethods
|
36
|
+
|
37
|
+
base.attr_protected :id
|
38
|
+
|
39
|
+
base.send :attr_accessor, :comment, :previous_version_number
|
40
|
+
|
41
|
+
base.belongs_to :creator, :class_name => IrwiMod.config.user_class_name
|
42
|
+
base.belongs_to :updator, :class_name => IrwiMod.config.user_class_name
|
43
|
+
|
44
|
+
base.has_many :versions, :class_name => IrwiMod.config.page_version_class_name, :foreign_key => IrwiMod.config.page_version_foreign_key, :order => 'id DESC'
|
45
|
+
|
46
|
+
if IrwiMod::config.page_attachment_class_name
|
47
|
+
base.has_many :attachments, :class_name => IrwiMod.config.page_attachment_class_name, :foreign_key => IrwiMod.config.page_version_foreign_key
|
48
|
+
end
|
49
|
+
|
50
|
+
base.before_save {|record| record.content = '' if record.content.nil? }
|
51
|
+
base.before_save {|record| record.path = record.title} #Change by RH - I have to save the path
|
52
|
+
base.after_save :create_new_version
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module IrwiMod::Extensions::Models::WikiPageVersion
|
2
|
+
|
3
|
+
module ClassMethods
|
4
|
+
|
5
|
+
end
|
6
|
+
|
7
|
+
module InstanceMethods
|
8
|
+
|
9
|
+
def next
|
10
|
+
self.class.first :conditions => ["id > ? AND page_id = ?", id, page_id], :order => 'id ASC'
|
11
|
+
end
|
12
|
+
|
13
|
+
def previous
|
14
|
+
self.class.first :conditions => ["id < ? AND page_id = ?", id, page_id], :order => 'id DESC'
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def raise_on_update
|
20
|
+
raise ActiveRecordError.new "Can't modify existing version"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included( base )
|
26
|
+
base.send :extend, IrwiMod::Extensions::Models::WikiPageVersion::ClassMethods
|
27
|
+
base.send :include, IrwiMod::Extensions::Models::WikiPageVersion::InstanceMethods
|
28
|
+
|
29
|
+
base.attr_protected :id
|
30
|
+
|
31
|
+
base.belongs_to :page, :class_name => IrwiMod.config.page_class_name
|
32
|
+
base.belongs_to :updator, :class_name => IrwiMod.config.user_class_name
|
33
|
+
|
34
|
+
base.before_update :raise_on_update
|
35
|
+
|
36
|
+
base.scope :between, lambda { | first, last |
|
37
|
+
first = first.to_i
|
38
|
+
last = last.to_i
|
39
|
+
first, last = last, first if last < first # Reordering if neeeded
|
40
|
+
{ :conditions => [ 'number >= ? AND number <= ?', first, last ] }
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module IrwiMod::Helpers
|
2
|
+
autoload :WikiPagesHelper, 'irwi_mod/helpers/wiki_pages_helper'
|
3
|
+
autoload :WikiPageAttachmentsHelper, 'irwi_mod/helpers/wiki_page_attachments_helper'
|
4
|
+
end
|
5
|
+
|
6
|
+
Module.class_eval do
|
7
|
+
|
8
|
+
def acts_as_wiki_pages_helper( config = {} )
|
9
|
+
include IrwiMod::Helpers::WikiPagesHelper
|
10
|
+
include IrwiMod::Helpers::WikiPageAttachmentsHelper if IrwiMod::config.page_attachment_class_name
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'active_record/errors'
|
2
|
+
|
3
|
+
module IrwiMod::Helpers::WikiPageAttachmentsHelper
|
4
|
+
|
5
|
+
def wiki_add_page_attachment_path(page)
|
6
|
+
page = page.path if page.respond_to? :path
|
7
|
+
url_for(:action => 'add_attachment', :path => page)
|
8
|
+
end
|
9
|
+
|
10
|
+
def wiki_remove_page_attachment_path(attachment_id)
|
11
|
+
url_for(:action => 'remove_attachment', :attachment_id => attachment_id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def wiki_show_attachments(str)
|
15
|
+
str.gsub /Attachment_([\d]+)_([\w]+)/ do |m|
|
16
|
+
begin
|
17
|
+
attachment = IrwiMod.config.page_attachment_class.find($1)
|
18
|
+
image_tag attachment.wiki_page_attachment.url($2.to_sym), :class => 'wiki_page_attachment'
|
19
|
+
rescue ActiveRecord::RecordNotFound
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module IrwiMod::Helpers::WikiPagesHelper
|
2
|
+
|
3
|
+
include IrwiMod::Support::TemplateFinder
|
4
|
+
include IrwiMod::Helpers::WikiPageAttachmentsHelper
|
5
|
+
|
6
|
+
# Edit form for wiki page model
|
7
|
+
def wiki_page_form( config = {}, &block )
|
8
|
+
form_for( @page, { :as => :page, :url => url_for( :action => :update ), :html=> { :class => 'wiki_form', :method => :post } }.merge!( config ), &block )
|
9
|
+
end
|
10
|
+
|
11
|
+
def wiki_page_new_path
|
12
|
+
if params && params[:path].present?
|
13
|
+
page = CGI::escape(params[:path])
|
14
|
+
end
|
15
|
+
wiki_page_path( page, :new )
|
16
|
+
end
|
17
|
+
|
18
|
+
def wiki_page_edit_path( page = nil )
|
19
|
+
wiki_page_path( page, :edit )
|
20
|
+
end
|
21
|
+
|
22
|
+
def wiki_page_history_path( page = nil )
|
23
|
+
wiki_page_path( page, :history )
|
24
|
+
end
|
25
|
+
|
26
|
+
def wiki_page_compare_path( page = nil )
|
27
|
+
wiki_page_path( page, :compare )
|
28
|
+
end
|
29
|
+
|
30
|
+
def wiki_page_path( page = nil, action = :show )
|
31
|
+
if page
|
32
|
+
page = page.path if page.respond_to? :path
|
33
|
+
page = nil if page.empty?
|
34
|
+
|
35
|
+
url_for( :action => action, :path => page )
|
36
|
+
else
|
37
|
+
url_for( :action => action )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def wiki_content( text )
|
42
|
+
sanitize( auto_link( IrwiMod.config.formatter.format( wiki_linkify( wiki_show_attachments(text) ) ) ) )
|
43
|
+
end
|
44
|
+
|
45
|
+
def wiki_diff( old_text, new_text )
|
46
|
+
IrwiMod.config.comparator.render_changes(h(old_text), h(new_text)).html_safe
|
47
|
+
end
|
48
|
+
|
49
|
+
def wiki_user( user )
|
50
|
+
return ("<" + wt("Unknown") + ">").html_safe unless user
|
51
|
+
|
52
|
+
if user.respond_to?(:name)
|
53
|
+
user.name
|
54
|
+
else
|
55
|
+
"User##{user.id}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def wiki_linkify( str )
|
60
|
+
str.gsub /\[\[
|
61
|
+
(?:([^\[\]\|]+)\|)?
|
62
|
+
([^\[\]]+)
|
63
|
+
\]\]
|
64
|
+
(\w+)?/xu do |m|
|
65
|
+
text = "#$2#$3"
|
66
|
+
link, anchor = if $1 then $1.split('#', 2) else $2 end
|
67
|
+
"<a href=\"#{wiki_link link}#{ '#' + anchor if anchor}\">#{text}</a>"
|
68
|
+
end.html_safe
|
69
|
+
end
|
70
|
+
|
71
|
+
def wiki_paginate( collection, &block )
|
72
|
+
IrwiMod.config.paginator.paginated_section( self, collection, &block )
|
73
|
+
end
|
74
|
+
|
75
|
+
def wiki_link( title )
|
76
|
+
if page = IrwiMod.config.page_class.find_by_title( title )
|
77
|
+
url_for( :controller => IrwiMod.config.controller_name, :action => :show, :path => page.path )
|
78
|
+
else
|
79
|
+
url_for( :controller => IrwiMod.config.controller_name, :action => :show, :path => title)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Instead of having to translate strings and defining a default value:
|
85
|
+
#
|
86
|
+
# t("Hello World!", :default => 'Hello World!')
|
87
|
+
#
|
88
|
+
# We define this method to define the value only once:
|
89
|
+
#
|
90
|
+
# wt("Hello World!")
|
91
|
+
#
|
92
|
+
# Note that interpolation still works ...
|
93
|
+
#
|
94
|
+
# wt("Hello {{world}}!", :world => @world)
|
95
|
+
#
|
96
|
+
def wt(msg, *args)
|
97
|
+
config = args.extract_options!
|
98
|
+
config[:default] = msg if config[:default].blank?
|
99
|
+
config[:scope] = 'wiki'
|
100
|
+
I18n.t(msg, config)
|
101
|
+
end
|
102
|
+
|
103
|
+
def wiki_page_style
|
104
|
+
render :partial => "#{template_dir '_wiki_page_style'}/wiki_page_style"
|
105
|
+
end
|
106
|
+
|
107
|
+
def wiki_page_info(page = nil)
|
108
|
+
page ||= @page # By default take page from instance variable
|
109
|
+
|
110
|
+
render :partial => "#{template_dir '_wiki_page_info'}/wiki_page_info", :locals => { :page => page }
|
111
|
+
end
|
112
|
+
|
113
|
+
def wiki_page_actions(page = nil)
|
114
|
+
page ||= @page # By default take page from instance variable
|
115
|
+
|
116
|
+
render :partial => "#{template_dir '_wiki_page_actions'}/wiki_page_actions", :locals => { :page => page }
|
117
|
+
end
|
118
|
+
|
119
|
+
def wiki_page_history(page = nil,versions = nil)
|
120
|
+
page ||= @page # By default take page from instance variable
|
121
|
+
versions ||= @versions || page.versions
|
122
|
+
|
123
|
+
render :partial => "#{template_dir '_wiki_page_history'}/wiki_page_history", :locals => { :page => page, :versions => versions, :with_form => (versions.size > 1) }
|
124
|
+
end
|
125
|
+
|
126
|
+
def wiki_page_attachments(page = @page)
|
127
|
+
return unless IrwiMod::config.page_attachment_class_name
|
128
|
+
|
129
|
+
page.attachments.each do |attachment|
|
130
|
+
concat image_tag(attachment.wiki_page_attachment.url(:thumb))
|
131
|
+
concat "Attachment_#{attachment.id}"
|
132
|
+
concat link_to(wt('Remove'), wiki_remove_page_attachment_path(attachment.id), :method => :delete)
|
133
|
+
end
|
134
|
+
|
135
|
+
form_for(IrwiMod.config.page_attachment_class.new,
|
136
|
+
:as => :wiki_page_attachment,
|
137
|
+
:url => wiki_add_page_attachment_path(page),
|
138
|
+
:html => { :multipart => true }) do |form|
|
139
|
+
concat form.file_field :wiki_page_attachment
|
140
|
+
concat form.hidden_field :page_id, :value => page.id
|
141
|
+
concat form.submit 'Add Attachment'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
|
3
|
+
class IrwiMod::Paginators::None
|
4
|
+
|
5
|
+
def paginate( collection, options = {} )
|
6
|
+
find_options = options.except :page, :per_page, :total_entries, :finder
|
7
|
+
|
8
|
+
collection.find( :all, find_options )
|
9
|
+
end
|
10
|
+
|
11
|
+
def paginated_section( view, collection, &block )
|
12
|
+
yield
|
13
|
+
return
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'action_dispatch'
|
2
|
+
|
3
|
+
module IrwiMod::Support::RouteMapper
|
4
|
+
|
5
|
+
# Defining wiki root mount point
|
6
|
+
def wiki_root( root, config = {} )
|
7
|
+
opts = {
|
8
|
+
:controller => 'wiki_pages',
|
9
|
+
:root => root
|
10
|
+
}.merge(config)
|
11
|
+
|
12
|
+
IrwiMod.config.system_pages.each do |page_action, page_path| # Adding routes for system pages
|
13
|
+
get( "#{root}/#{page_path}", opts.merge({ :action => page_action.dup }) )
|
14
|
+
end
|
15
|
+
|
16
|
+
get( "#{root}/compare/(*path)", opts.merge({ :action => 'compare', :as => 'compare_wiki_page' }) ) # Comparing two versions of page
|
17
|
+
get( "#{root}/new/(*path)", opts.merge({ :action => 'new', :as => 'new_wiki_page' }) ) # Wiki new route
|
18
|
+
get( "#{root}/edit/(*path)", opts.merge({ :action => 'edit', :as => 'edit_wiki_page' }) ) # Wiki edit route
|
19
|
+
get( "#{root}/history/(*path)", opts.merge({ :action => 'history', :as => 'history_wiki_page' }) ) # Wiki history route
|
20
|
+
|
21
|
+
# Attachments
|
22
|
+
post("#{root}/attach/(*path)", opts.merge({:action => 'add_attachment' }))
|
23
|
+
delete("#{root}/attach/:attachment_id", opts.merge({:action => 'remove_attachment' }))
|
24
|
+
|
25
|
+
get( "#{root}", opts.merge({ :action => 'index', :as => 'wiki_page_index' }) ) # Wiki pages route
|
26
|
+
delete( "#{root}/(*path)", opts.merge({ :action => 'destroy', :as => 'destroy_wiki_page' }) ) # Wiki destroy route
|
27
|
+
post( "#{root}/(*path)", opts.merge({ :action => 'update', :as => 'update_wiki_page' }) ) # Save wiki pages route
|
28
|
+
get( "#{root}/(*path)", opts.merge({ :action => 'show', :as => 'wiki_page' }) ) # Wiki pages route
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
ActionDispatch::Routing::Mapper.instance_eval do
|
35
|
+
include IrwiMod::Support::RouteMapper
|
36
|
+
end
|