irwi 0.2.2 → 0.2.3

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.
@@ -70,6 +70,14 @@ If you want (and it's good idea) to specify which users can see or edit certain
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
 
73
+ == Attachments
74
+
75
+ Irwi allows easy attachment integration in your wiki. There area several simple steps to add attachments to wiki pages:
76
+ * Call <tt>irwi_wiki_attachments</tt> generator. It will create WikiPageAttachment class.
77
+ * Include <tt>config.gem "paperclip"</tt> in your <tt>environment.rb</tt> or, if you prefer another library modify generated code for it.
78
+ * Append to initializer (or create a new one) something like <tt>Irwi.config.page_attachment_class_name = 'WikiPageAttachment'</tt>.
79
+ * Run <tt>rake db:migrate</tt> and start using attachments in your wiki!
80
+
73
81
  == Localization
74
82
 
75
83
  == Rails prior to 2.3
@@ -80,4 +88,12 @@ If you have Rails prior to 2.3 when you should also call:
80
88
 
81
89
  To generate default wiki views.
82
90
 
91
+ == Contributors
92
+
93
+ * Alexey Noskov (http://github.com/alno)
94
+ * Ravi Bhim (http://github.com/ravibhim)
95
+ * http://github.com/valodzka
96
+
97
+ Feel free to add yourself when you add new features.
98
+
83
99
  Copyright (c) 2009 Alexey Noskov, released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -2,6 +2,12 @@
2
2
 
3
3
  <h1><%=wt 'Editing wiki page' %></h1>
4
4
 
5
+ <% if params[:preview] %>
6
+ <div class="wiki_content">
7
+ <%=wiki_content @page.content %>
8
+ </div>
9
+ <% end %>
10
+
5
11
  <% wiki_page_form do |f| %>
6
12
  <%= f.hidden_field :previous_version_number, :value => f.object.last_version_number %>
7
13
 
@@ -9,18 +15,10 @@
9
15
  <p><%=wt 'Content:' %><br /><%= f.text_area :content %></p>
10
16
  <p><%=wt 'Comment on this change (optional):' %><br /><%= f.text_field :comment %></p>
11
17
 
12
- <input type="submit" value="<%=wt 'Save page' %>" class="submit" />
18
+ <input type="submit" name="save" value="<%=wt 'Save page' %>" class="submit" />
19
+ <input type="submit" name="preview" value="<%=wt 'Preview' %>" class="submit" />
20
+ <input type="submit" name="cancel" value="<%=wt 'Cancel' %>" class="submit" />
13
21
  <% end %>
14
22
 
23
+ <% wiki_page_attachments(@page) %>
15
24
 
16
- <%- @page.attachments.each do |attachment| %>
17
- <%= image_tag attachment.wiki_page_attachment.url(:thumb) %>
18
- <%= "Attachment_#{attachment.id}" %>
19
- <%= link_to wt('Remove'), wiki_remove_page_attachment_path(attachment.id), :method => :delete %>
20
- <% end %>
21
-
22
- <% form_for :wiki_page_attachment, Irwi.config.page_attachment_class.new, :url => wiki_add_page_attachment_path(@page), :html => { :multipart => true } do |form| %>
23
- <%= form.file_field :wiki_page_attachment %>
24
- <%= form.hidden_field :page_id, :value => @page.id %>
25
- <%= form.submit 'Add Attachment' %>
26
- <% end %>
@@ -1,3 +1,3 @@
1
1
  module WikiPagesHelper
2
- include Irwi::Helpers::WikiPagesHelper
2
+ acts_as_wiki_pages_helper
3
3
  end
@@ -1,4 +1,4 @@
1
- class IrwiWikiUpdatesGenerator < Rails::Generator::Base
1
+ class IrwiWikiAttachmentsGenerator < Rails::Generator::Base
2
2
 
3
3
  def manifest
4
4
  record do |m|
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{irwi}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
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", "Ravi Bhim"]
12
- s.date = %q{2010-06-14}
12
+ s.date = %q{2010-06-24}
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 ravi.bhim@yahoo.com}
15
15
  s.extra_rdoc_files = [
@@ -40,10 +40,9 @@ Gem::Specification.new do |s|
40
40
  "generators/irwi_wiki/templates/migrate/create_wiki_pages.rb",
41
41
  "generators/irwi_wiki/templates/models/wiki_page.rb",
42
42
  "generators/irwi_wiki/templates/models/wiki_page_version.rb",
43
- "generators/irwi_wiki_updates/irwi_wiki_updates_generator.rb",
44
- "generators/irwi_wiki_updates/templates/migrate/create_wiki_page_attachments.rb",
45
- "generators/irwi_wiki_updates/templates/migrate/touched_file.txt",
46
- "generators/irwi_wiki_updates/templates/models/wiki_page_attachment.rb",
43
+ "generators/irwi_wiki_attachments/irwi_wiki_attachments_generator.rb",
44
+ "generators/irwi_wiki_attachments/templates/migrate/create_wiki_page_attachments.rb",
45
+ "generators/irwi_wiki_attachments/templates/models/wiki_page_attachment.rb",
47
46
  "generators/irwi_wiki_views/irwi_wiki_views_generator.rb",
48
47
  "irwi.gemspec",
49
48
  "lib/irwi.rb",
@@ -69,6 +68,7 @@ Gem::Specification.new do |s|
69
68
  "spec/comparators/diff_lcs_spec.rb",
70
69
  "spec/config_spec.rb",
71
70
  "spec/extensions/controllers/wiki_pages_spec.rb",
71
+ "spec/extensions/models/wiki_page_spec.rb",
72
72
  "spec/formatters/red_cloth_spec.rb",
73
73
  "spec/helpers/wiki_page_attachments_helper_spec.rb",
74
74
  "spec/helpers/wiki_pages_helper_spec.rb",
@@ -92,6 +92,7 @@ Gem::Specification.new do |s|
92
92
  "spec/spec_helper.rb",
93
93
  "spec/comparators/diff_lcs_spec.rb",
94
94
  "spec/extensions/controllers/wiki_pages_spec.rb",
95
+ "spec/extensions/models/wiki_page_spec.rb",
95
96
  "spec/config_spec.rb",
96
97
  "spec/paginators/will_paginate_spec.rb",
97
98
  "spec/paginators/none_spec.rb",
@@ -6,7 +6,10 @@ class Irwi::Config
6
6
 
7
7
  attr_accessor_with_default :page_class_name, 'WikiPage'
8
8
  attr_accessor_with_default :page_version_class_name, 'WikiPageVersion'
9
- attr_accessor_with_default :page_attachment_class_name, 'WikiPageAttachment'
9
+ attr_accessor_with_default :page_attachment_class_name do
10
+ # Can be for example 'WikiPageAttachment'
11
+ nil
12
+ end
10
13
 
11
14
  attr_accessor_with_default :page_version_foreign_key, 'page_id'
12
15
 
@@ -42,7 +45,7 @@ class Irwi::Config
42
45
  def page_attachment_class
43
46
  page_attachment_class_name.constantize
44
47
  end
45
-
48
+
46
49
  def user_class
47
50
  user_class_name.constantize
48
51
  end
@@ -60,4 +63,4 @@ class Irwi::Config
60
63
  system_pages[ action.to_s ] = path.to_s
61
64
  end
62
65
 
63
- end
66
+ end
@@ -76,7 +76,7 @@ module Irwi::Extensions::Controllers::WikiPages
76
76
  @page.updator = @current_user # Assing user, which updated page
77
77
  @page.creator = @current_user if @page.new_record? # Assign it's creator if it's new page
78
78
 
79
- if @page.save
79
+ if !params[:preview] && (params[:cancel] || @page.save)
80
80
  redirect_to url_for( :action => :show, :path => @page.path.split('/') ) # redirect to new page's path (if it changed)
81
81
  else
82
82
  render_template 'edit'
@@ -156,4 +156,4 @@ module Irwi::Extensions::Controllers::WikiPages
156
156
  base.helper_method :show_allowed?, :edit_allowed?, :history_allowed?, :destroy_allowed? # Access control methods are avaliable in views
157
157
  end
158
158
 
159
- end
159
+ end
@@ -40,7 +40,10 @@ module Irwi::Extensions::Models::WikiPage
40
40
  base.belongs_to :updator, :class_name => Irwi.config.user_class_name
41
41
 
42
42
  base.has_many :versions, :class_name => Irwi.config.page_version_class_name, :foreign_key => Irwi.config.page_version_foreign_key, :order => 'id DESC'
43
- base.has_many :attachments, :class_name => Irwi.config.page_attachment_class_name, :foreign_key => Irwi.config.page_version_foreign_key
43
+
44
+ if Irwi::config.page_attachment_class_name
45
+ base.has_many :attachments, :class_name => Irwi.config.page_attachment_class_name, :foreign_key => Irwi.config.page_version_foreign_key
46
+ end
44
47
 
45
48
  base.after_save :create_new_version
46
49
  end
@@ -49,8 +49,14 @@ module Irwi::Helpers::WikiPagesHelper
49
49
  end
50
50
 
51
51
  def wiki_linkify( str )
52
- str.gsub /\[\[([^\[\]]+)\]\]/ do |m|
53
- "<a href=\"#{wiki_link $1}\">#{$1}</a>"
52
+ str.gsub /\[\[
53
+ (?:([^\[\]\|]+)\|)?
54
+ ([^\[\]]+)
55
+ \]\]
56
+ (\w+)?/xu do |m|
57
+ text = "#$2#$3"
58
+ link = $1 || $2
59
+ "<a href=\"#{wiki_link link}\">#{text}</a>"
54
60
  end
55
61
  end
56
62
 
@@ -108,5 +114,24 @@ module Irwi::Helpers::WikiPagesHelper
108
114
 
109
115
  render :partial => "#{template_dir '_wiki_page_history'}/wiki_page_history", :locals => { :page => page, :versions => versions, :with_form => (versions.size > 1) }
110
116
  end
117
+
118
+ def wiki_page_attachments(page)
119
+ return unless Irwi::config.page_attachment_class_name
120
+
121
+ page.attachments.each do |attachment|
122
+ concat image_tag(attachment.wiki_page_attachment.url(:thumb))
123
+ concat "Attachment_#{attachment.id}"
124
+ concat link_to(wt('Remove'), wiki_remove_page_attachment_path(attachment.id), :method => :delete)
125
+ end
126
+
127
+ form_for(:wiki_page_attachment,
128
+ Irwi.config.page_attachment_class.new,
129
+ :url => wiki_add_page_attachment_path(@page),
130
+ :html => { :multipart => true }) do |form|
131
+ concat form.file_field :wiki_page_attachment
132
+ concat form.hidden_field :page_id, :value => @page.id
133
+ concat form.submit 'Add Attachment'
134
+ end
135
+ end
111
136
 
112
137
  end
@@ -29,6 +29,16 @@ ActionController::Base.instance_eval do
29
29
  #
30
30
  def acts_as_wiki_pages_controller( config = {} )
31
31
  include Irwi::Extensions::Controllers::WikiPages
32
+ include Irwi::Extensions::Controllers::WikiPageAttachments if Irwi::config.page_attachment_class_name
33
+ end
34
+
35
+ end
36
+
37
+ Module.class_eval do
38
+
39
+ def acts_as_wiki_pages_helper( config = {} )
40
+ include Irwi::Helpers::WikiPagesHelper
41
+ include Irwi::Helpers::WikiPageAttachmentsHelper if Irwi::config.page_attachment_class_name
32
42
  end
33
43
 
34
44
  end
@@ -0,0 +1,79 @@
1
+ require "spec/spec_helper"
2
+
3
+ require "active_record"
4
+
5
+ describe Irwi::Extensions::Models::WikiPage do
6
+
7
+ class AbstractPage < ActiveRecord::Base
8
+
9
+
10
+ def self.columns
11
+ c = ActiveRecord::ConnectionAdapters::Column
12
+
13
+ [
14
+ c.new("title", nil, "string", false),
15
+ c.new("path", nil, "string", false),
16
+ c.new("content", nil, "text", false)
17
+ ]
18
+ end
19
+
20
+ end
21
+
22
+ it { should_not be_nil }
23
+
24
+ before :all do
25
+ Irwi::config.page_attachment_class_name = nil
26
+
27
+ @cls = Class.new AbstractPage do
28
+ include Irwi::Extensions::Models::WikiPage
29
+ end
30
+ end
31
+
32
+ context "class" do
33
+
34
+ it { @cls.should respond_to(:find) }
35
+ it { @cls.should respond_to(:find_by_path_or_new) }
36
+
37
+ end
38
+
39
+ context "instance" do
40
+
41
+ before :each do
42
+ @obj = @cls.new
43
+ end
44
+
45
+ it { @obj.should respond_to(:save) }
46
+ it { @obj.should respond_to(:destroy) }
47
+
48
+ it { @obj.should respond_to(:comment) }
49
+ it { @obj.should respond_to(:previous_version_number) }
50
+
51
+ it { @obj.should respond_to(:versions) }
52
+
53
+ it { @obj.should_not respond_to(:attachments) }
54
+
55
+ end
56
+
57
+ context "with attachments" do
58
+
59
+ before :all do
60
+ Irwi::config.page_attachment_class_name = 'WikiPageAttachment'
61
+
62
+ @cls = Class.new AbstractPage do
63
+ include Irwi::Extensions::Models::WikiPage
64
+ end
65
+ end
66
+
67
+ context "instance" do
68
+
69
+ before :each do
70
+ @obj = @cls.new
71
+ end
72
+
73
+ it { @obj.should respond_to(:attachments) }
74
+
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -7,6 +7,7 @@ describe Irwi::Helpers::WikiPageAttachmentsHelper do
7
7
  context "included in class" do
8
8
 
9
9
  before(:each) do
10
+ Irwi.config.page_attachment_class_name = 'WikiPageAttachment'
10
11
  @m = Object.new
11
12
  @m.send :extend, Irwi::Helpers::WikiPagesHelper
12
13
  end
@@ -14,10 +15,6 @@ describe Irwi::Helpers::WikiPageAttachmentsHelper do
14
15
  describe :wiki_show_attachment do
15
16
  before do
16
17
  class WikiPageAttachment; end
17
- module ActiveRecord
18
- class RecordNotFound < StandardError
19
- end
20
- end
21
18
  end
22
19
 
23
20
  it 'replaces Attachment_1_thumb with its corresponding image tag' do
@@ -110,10 +110,11 @@ describe Irwi::Helpers::WikiPagesHelper do
110
110
  end
111
111
 
112
112
  specify "should linkify string" do
113
-
114
- @m.should_receive(:wiki_link).with('Some other page').and_return('url')
113
+ @m.should_receive(:wiki_link).exactly(3).times.with('Some other page').and_return('url')
115
114
 
116
115
  @m.wiki_linkify( '[[Some other page]] - link' ).should == '<a href="url">Some other page</a> - link'
116
+ @m.wiki_linkify( '[[Some other page|Go other page]] - link' ).should == '<a href="url">Go other page</a> - link'
117
+ @m.wiki_linkify( '[[Some other page]]s are there' ).should == '<a href="url">Some other pages</a> are there'
117
118
  end
118
119
 
119
120
  specify "should generate link for non-existent page" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexey Noskov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-14 00:00:00 +04:00
18
+ date: 2010-06-24 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -79,10 +79,9 @@ files:
79
79
  - generators/irwi_wiki/templates/migrate/create_wiki_pages.rb
80
80
  - generators/irwi_wiki/templates/models/wiki_page.rb
81
81
  - generators/irwi_wiki/templates/models/wiki_page_version.rb
82
- - generators/irwi_wiki_updates/irwi_wiki_updates_generator.rb
83
- - generators/irwi_wiki_updates/templates/migrate/create_wiki_page_attachments.rb
84
- - generators/irwi_wiki_updates/templates/migrate/touched_file.txt
85
- - generators/irwi_wiki_updates/templates/models/wiki_page_attachment.rb
82
+ - generators/irwi_wiki_attachments/irwi_wiki_attachments_generator.rb
83
+ - generators/irwi_wiki_attachments/templates/migrate/create_wiki_page_attachments.rb
84
+ - generators/irwi_wiki_attachments/templates/models/wiki_page_attachment.rb
86
85
  - generators/irwi_wiki_views/irwi_wiki_views_generator.rb
87
86
  - irwi.gemspec
88
87
  - lib/irwi.rb
@@ -108,6 +107,7 @@ files:
108
107
  - spec/comparators/diff_lcs_spec.rb
109
108
  - spec/config_spec.rb
110
109
  - spec/extensions/controllers/wiki_pages_spec.rb
110
+ - spec/extensions/models/wiki_page_spec.rb
111
111
  - spec/formatters/red_cloth_spec.rb
112
112
  - spec/helpers/wiki_page_attachments_helper_spec.rb
113
113
  - spec/helpers/wiki_pages_helper_spec.rb
@@ -155,6 +155,7 @@ test_files:
155
155
  - spec/spec_helper.rb
156
156
  - spec/comparators/diff_lcs_spec.rb
157
157
  - spec/extensions/controllers/wiki_pages_spec.rb
158
+ - spec/extensions/models/wiki_page_spec.rb
158
159
  - spec/config_spec.rb
159
160
  - spec/paginators/will_paginate_spec.rb
160
161
  - spec/paginators/none_spec.rb