irwi 0.1.11 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,6 +36,14 @@ Also it will add to your <tt>routes.rb</tt> something like:
36
36
 
37
37
  map.wiki_root '/wiki'
38
38
 
39
+ == Wiki syntax (links to other pages)
40
+
41
+ You can link pages by using
42
+
43
+ [[Some page title]]
44
+
45
+ construction in text. If linked page exists, when it will be replaced with link to this page, in other case it will be replaced with link to new page with such path/title.
46
+
39
47
  == Template definition
40
48
 
41
49
  You may create your own templates for controller actions (<tt>show</tt>, <tt>edit</tt> and <tt>history</tt>), in other case default built-in templates will be used.
@@ -47,9 +55,12 @@ Following helpers are defined by default and you may replace them with you own:
47
55
 
48
56
  == Configuration
49
57
 
50
- Configuration options are acessed via <tt>Irwi.options</tt> object. Currently supported options:
58
+ Configuration options are acessed via <tt>Irwi.config</tt> object. Currently supported options:
51
59
  * <tt>user_class_name</tt> - Name of user model class. By default - 'User'
52
- * <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).
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
+
62
+ Irwi.config.formatter = Irwi::Formatters::BlueCloth.new
63
+
53
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).
54
65
 
55
66
  == Access control
data/Rakefile CHANGED
@@ -7,9 +7,9 @@ begin
7
7
  gem.name = "irwi"
8
8
  gem.summary = %Q{Irwi is Ruby on Rails plugin which adds wiki functionality to your application. }
9
9
  gem.description = %Q{Irwi is Ruby on Rails plugin which adds wiki functionality to your application. }
10
- gem.email = "alexey.noskov@gmail.com"
10
+ gem.email = "alexey.noskov@gmail.com ravi.bhim@yahoo.com"
11
11
  gem.homepage = "http://github.com/alno/irwi"
12
- gem.authors = ["Alexey Noskov"]
12
+ gem.authors = ["Alexey Noskov", "Ravi Bhim"]
13
13
  gem.add_dependency "diff-lcs", ">= 1.1.2"
14
14
  gem.add_development_dependency "rspec", ">= 1.2.9"
15
15
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.11
1
+ 0.2.0
@@ -5,10 +5,22 @@
5
5
  <% wiki_page_form do |f| %>
6
6
  <%= f.hidden_field :previous_version_number, :value => f.object.last_version_number %>
7
7
 
8
- <p><%=wt 'Path:' %><br/><%= f.text_field :path %></p>
9
8
  <p><%=wt 'Title:' %><br /><%= f.text_field :title %></p>
10
9
  <p><%=wt 'Content:' %><br /><%= f.text_area :content %></p>
11
- <p><%=wt 'Comment:' %><br /><%= f.text_field :comment %></p>
10
+ <p><%=wt 'Comment on this change (optional):' %><br /><%= f.text_field :comment %></p>
12
11
 
13
12
  <input type="submit" value="<%=wt 'Save page' %>" class="submit" />
14
- <% end %>
13
+ <% end %>
14
+
15
+
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 %>
@@ -0,0 +1,13 @@
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 %></p>
10
+ <%= f.hidden_field :comment, :value => 'First Revision'%>
11
+
12
+ <input type="submit" value="<%=wt 'Create page' %>" class="submit" />
13
+ <% end %>
@@ -1 +1 @@
1
- <%=wt 'There are no such page. Do you want to <a href="{{edit_url}}">create it</a>?', :edit_url => wiki_page_edit_path %>
1
+ <%=wt 'There are no such page. Do you want to <a href="{{new_url}}">create it</a>?', :new_url => wiki_page_new_path %>
@@ -7,4 +7,5 @@
7
7
 
8
8
  <div class="wiki_content">
9
9
  <%=wiki_content @page.content %>
10
- </div>
10
+ </div>
11
+
@@ -0,0 +1,18 @@
1
+ class IrwiWikiUpdatesGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ %w[create_wiki_page_attachments].each do |mig|
6
+ unless Dir.entries(File.join(Rails.root,'db','migrate')).grep(/#{mig}/).present?
7
+ puts "Copying migration #{mig}"
8
+ m.migration_template "migrate/#{mig}.rb", 'db/migrate', :migration_file_name => mig
9
+ sleep(1) # To avoid migration file version collision.
10
+ end
11
+ end
12
+
13
+ # Models
14
+ m.file 'models/wiki_page_attachment.rb', 'app/models/wiki_page_attachment.rb'
15
+ end
16
+ end
17
+
18
+ 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
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{irwi}
8
- s.version = "0.1.11"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Alexey Noskov"]
12
- s.date = %q{2009-12-05}
11
+ s.authors = ["Alexey Noskov", "Ravi Bhim"]
12
+ s.date = %q{2010-06-14}
13
13
  s.description = %q{Irwi is Ruby on Rails plugin which adds wiki functionality to your application. }
14
- s.email = %q{alexey.noskov@gmail.com}
14
+ s.email = %q{alexey.noskov@gmail.com ravi.bhim@yahoo.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README.rdoc"
17
17
  ]
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "app/views/base_wiki_pages/compare.html.erb",
31
31
  "app/views/base_wiki_pages/edit.html.erb",
32
32
  "app/views/base_wiki_pages/history.html.erb",
33
+ "app/views/base_wiki_pages/new.html.erb",
33
34
  "app/views/base_wiki_pages/no.html.erb",
34
35
  "app/views/base_wiki_pages/not_allowed.html.erb",
35
36
  "app/views/base_wiki_pages/show.html.erb",
@@ -39,6 +40,10 @@ Gem::Specification.new do |s|
39
40
  "generators/irwi_wiki/templates/migrate/create_wiki_pages.rb",
40
41
  "generators/irwi_wiki/templates/models/wiki_page.rb",
41
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",
42
47
  "generators/irwi_wiki_views/irwi_wiki_views_generator.rb",
43
48
  "irwi.gemspec",
44
49
  "lib/irwi.rb",
@@ -47,11 +52,14 @@ Gem::Specification.new do |s|
47
52
  "lib/irwi/comparators/spans/changed_span.rb",
48
53
  "lib/irwi/comparators/spans/not_changed_span.rb",
49
54
  "lib/irwi/config.rb",
55
+ "lib/irwi/extensions/controllers/wiki_page_attachments.rb",
50
56
  "lib/irwi/extensions/controllers/wiki_pages.rb",
51
57
  "lib/irwi/extensions/models/wiki_page.rb",
58
+ "lib/irwi/extensions/models/wiki_page_attachment.rb",
52
59
  "lib/irwi/extensions/models/wiki_page_version.rb",
53
60
  "lib/irwi/formatters/blue_cloth.rb",
54
61
  "lib/irwi/formatters/red_cloth.rb",
62
+ "lib/irwi/helpers/wiki_page_attachments_helper.rb",
55
63
  "lib/irwi/helpers/wiki_pages_helper.rb",
56
64
  "lib/irwi/paginators/none.rb",
57
65
  "lib/irwi/paginators/will_paginate.rb",
@@ -62,6 +70,7 @@ Gem::Specification.new do |s|
62
70
  "spec/config_spec.rb",
63
71
  "spec/extensions/controllers/wiki_pages_spec.rb",
64
72
  "spec/formatters/red_cloth_spec.rb",
73
+ "spec/helpers/wiki_page_attachments_helper_spec.rb",
65
74
  "spec/helpers/wiki_pages_helper_spec.rb",
66
75
  "spec/paginators/none_spec.rb",
67
76
  "spec/paginators/will_paginate_spec.rb",
@@ -75,19 +84,20 @@ Gem::Specification.new do |s|
75
84
  s.homepage = %q{http://github.com/alno/irwi}
76
85
  s.rdoc_options = ["--charset=UTF-8"]
77
86
  s.require_paths = ["lib"]
78
- s.rubygems_version = %q{1.3.5}
87
+ s.rubygems_version = %q{1.3.6}
79
88
  s.summary = %q{Irwi is Ruby on Rails plugin which adds wiki functionality to your application.}
80
89
  s.test_files = [
81
- "spec/comparators/diff_lcs_spec.rb",
90
+ "spec/support/route_mapper_spec.rb",
82
91
  "spec/support/template_finder_spec.rb",
83
- "spec/support/route_mapper_spec.rb",
84
- "spec/config_spec.rb",
85
- "spec/formatters/red_cloth_spec.rb",
86
- "spec/extensions/controllers/wiki_pages_spec.rb",
87
- "spec/helpers/wiki_pages_helper_spec.rb",
88
92
  "spec/spec_helper.rb",
93
+ "spec/comparators/diff_lcs_spec.rb",
94
+ "spec/extensions/controllers/wiki_pages_spec.rb",
95
+ "spec/config_spec.rb",
89
96
  "spec/paginators/will_paginate_spec.rb",
90
- "spec/paginators/none_spec.rb"
97
+ "spec/paginators/none_spec.rb",
98
+ "spec/helpers/wiki_pages_helper_spec.rb",
99
+ "spec/helpers/wiki_page_attachments_helper_spec.rb",
100
+ "spec/formatters/red_cloth_spec.rb"
91
101
  ]
92
102
 
93
103
  if s.respond_to? :specification_version then
@@ -6,6 +6,7 @@ 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
10
 
10
11
  attr_accessor_with_default :page_version_foreign_key, 'page_id'
11
12
 
@@ -38,6 +39,10 @@ class Irwi::Config
38
39
  page_version_class_name.constantize
39
40
  end
40
41
 
42
+ def page_attachment_class
43
+ page_attachment_class_name.constantize
44
+ end
45
+
41
46
  def user_class
42
47
  user_class_name.constantize
43
48
  end
@@ -0,0 +1,21 @@
1
+ module Irwi::Extensions::Controllers::WikiPageAttachments
2
+
3
+ def add_attachment
4
+ attachment = page_attachment_class.new(params[:wiki_page_attachment])
5
+ attachment.save
6
+ redirect_to url_for( :action => :edit)
7
+ end
8
+
9
+ def remove_attachment
10
+ attachment = page_attachment_class.find(params[:attachment_id])
11
+ attachment.destroy
12
+ redirect_to url_for(:path => attachment.page.path, :action => :edit)
13
+ end
14
+
15
+ protected
16
+
17
+ def page_attachment_class
18
+ Irwi.config.page_attachment_class
19
+ end
20
+
21
+ end
@@ -14,6 +14,7 @@ module Irwi::Extensions::Controllers::WikiPages
14
14
 
15
15
  module InstanceMethods
16
16
 
17
+ include Irwi::Extensions::Controllers::WikiPageAttachments
17
18
  include Irwi::Support::TemplateFinder
18
19
 
19
20
  def show
@@ -52,6 +53,12 @@ module Irwi::Extensions::Controllers::WikiPages
52
53
  end
53
54
  end
54
55
 
56
+ def new
57
+ return not_allowed unless show_allowed? && edit_allowed?
58
+
59
+ render_template 'new'
60
+ end
61
+
55
62
  def edit
56
63
  return not_allowed unless show_allowed? && edit_allowed?
57
64
 
@@ -62,6 +69,7 @@ module Irwi::Extensions::Controllers::WikiPages
62
69
  return not_allowed unless @page.new_record? || edit_allowed? # Check for rights (but not for new record, for it we will use second check only)
63
70
 
64
71
  @page.attributes = params[:page] # Assign new attributes
72
+ @page.comment = params[:page][:comment]
65
73
 
66
74
  return not_allowed unless edit_allowed? # Double check: used beacause action may become invalid after attributes update
67
75
 
@@ -142,9 +150,9 @@ module Irwi::Extensions::Controllers::WikiPages
142
150
  base.send :extend, Irwi::Extensions::Controllers::WikiPages::ClassMethods
143
151
  base.send :include, Irwi::Extensions::Controllers::WikiPages::InstanceMethods
144
152
 
145
- base.before_filter :setup_current_user # Setup @current_user instance variable before each action
146
- base.before_filter :setup_page, :only => [ :show, :history, :compare, :edit, :update, :destroy ] # Setup @page instance variable before each action
147
-
153
+ base.before_filter :setup_current_user # Setup @current_user instance variable before each action
154
+ # Setup @page instance variable before each action
155
+ base.before_filter :setup_page, :only => [ :show, :history, :compare, :new, :edit, :update, :destroy, :add_attachment ]
148
156
  base.helper_method :show_allowed?, :edit_allowed?, :history_allowed?, :destroy_allowed? # Access control methods are avaliable in views
149
157
  end
150
158
 
@@ -23,6 +23,7 @@ module Irwi::Extensions::Models::WikiPage
23
23
 
24
24
  v = versions.build
25
25
  v.attributes = attributes.slice( *v.attribute_names )
26
+ v.comment = comment
26
27
  v.number = n + 1
27
28
  v.save!
28
29
  end
@@ -39,6 +40,7 @@ module Irwi::Extensions::Models::WikiPage
39
40
  base.belongs_to :updator, :class_name => Irwi.config.user_class_name
40
41
 
41
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
42
44
 
43
45
  base.after_save :create_new_version
44
46
  end
@@ -0,0 +1,9 @@
1
+ module Irwi::Extensions::Models::WikiPageAttachment
2
+
3
+ DEFAULT_PAPERCLIP_OPTIONS = {:styles => { :medium => "300x300>", :thumb => "100x100>" }}
4
+
5
+ def self.included( base )
6
+ base.belongs_to :page, :class_name => Irwi.config.page_class_name
7
+ end
8
+
9
+ end
@@ -0,0 +1,23 @@
1
+ module Irwi::Helpers::WikiPageAttachmentsHelper
2
+
3
+ def wiki_add_page_attachment_path(page)
4
+ page = page.path if page.respond_to? :path
5
+ url_for(:action => 'add_attachment', :path => page)
6
+ end
7
+
8
+ def wiki_remove_page_attachment_path(attachment_id)
9
+ url_for(:action => 'remove_attachment', :attachment_id => attachment_id)
10
+ end
11
+
12
+ def wiki_show_attachments(str)
13
+ str.gsub /Attachment_([\d]+)_([\w]+)/ do |m|
14
+ begin
15
+ attachment = Irwi.config.page_attachment_class.find($1)
16
+ image_tag attachment.wiki_page_attachment.url($2.to_sym), :class => 'wiki_page_attachment'
17
+ rescue ActiveRecord::RecordNotFound
18
+ nil
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -1,12 +1,17 @@
1
1
  module Irwi::Helpers::WikiPagesHelper
2
2
 
3
3
  include Irwi::Support::TemplateFinder
4
+ include Irwi::Helpers::WikiPageAttachmentsHelper
4
5
 
5
6
  # Edit form for wiki page model
6
7
  def wiki_page_form( config = {}, &block )
7
8
  form_for( :page, @page, { :url => url_for( :action => :update ), :html=> { :class => 'wiki_form' } }.merge!( config ), &block )
8
9
  end
9
10
 
11
+ def wiki_page_new_path( page = nil )
12
+ wiki_page_path( page, :new )
13
+ end
14
+
10
15
  def wiki_page_edit_path( page = nil )
11
16
  wiki_page_path( page, :edit )
12
17
  end
@@ -30,7 +35,7 @@ module Irwi::Helpers::WikiPagesHelper
30
35
  end
31
36
 
32
37
  def wiki_content( text )
33
- sanitize( auto_link( Irwi.config.formatter.format( wiki_linkify( text ) ) ) )
38
+ sanitize( auto_link( Irwi.config.formatter.format( wiki_linkify( wiki_show_attachments(text) ) ) ) )
34
39
  end
35
40
 
36
41
  def wiki_diff( old_text, new_text )
@@ -104,4 +109,4 @@ module Irwi::Helpers::WikiPagesHelper
104
109
  render :partial => "#{template_dir '_wiki_page_history'}/wiki_page_history", :locals => { :page => page, :versions => versions, :with_form => (versions.size > 1) }
105
110
  end
106
111
 
107
- end
112
+ end
@@ -1,23 +1,30 @@
1
1
  module Irwi::Support::RouteMapper
2
2
 
3
3
  # Defining wiki root mount point
4
- def wiki_root( path, config = {} )
4
+ def wiki_root( root, config = {} )
5
5
  opts = {
6
6
  :controller => 'wiki_pages',
7
- :root => path
7
+ :root => root
8
8
  }.merge(config)
9
9
 
10
10
  Irwi.config.system_pages.each do |page_action, page_path| # Adding routes for system pages
11
- connect( "#{path}/#{page_path}", opts.merge({ :action => page_action }) )
11
+ connect( "#{root}/#{page_path}", opts.merge({ :action => page_action }) )
12
12
  end
13
13
 
14
- connect( "#{path}/compare/*path", opts.merge({ :action => 'compare' }) ) # Comparing two versions of page
15
- connect( "#{path}/edit/*path", opts.merge({ :action => 'edit' }) ) # Wiki edit route
16
- connect( "#{path}/history/*path", opts.merge({ :action => 'history' }) ) # Wiki history route
14
+ connect( "#{root}/compare/*path", opts.merge({ :action => 'compare' }) ) # Comparing two versions of page
15
+ connect( "#{root}/new/*path", opts.merge({ :action => 'new' }) ) # Wiki new route
16
+ connect( "#{root}/edit/*path", opts.merge({ :action => 'edit' }) ) # Wiki edit route
17
+ connect( "#{root}/history/*path", opts.merge({ :action => 'history' }) ) # Wiki history route
17
18
 
18
- connect( "#{path}/*path", opts.merge({ :action => 'destroy', :conditions => { :method => :delete } }) ) # Wiki destroy route
19
- connect( "#{path}/*path", opts.merge({ :action => 'update', :conditions => { :method => :post } }) ) # Save wiki pages route
20
- connect( "#{path}/*path", opts.merge({ :action => 'show', :conditions => { :method => :get } }) ) # Wiki pages route
19
+ # Attachments
20
+ connect("#{root}/attach/*path", opts.merge({:action => 'add_attachment', :conditions => {:method => :post}}))
21
+ connect("#{root}/attach/:attachment_id", opts.merge({:action => 'remove_attachment', :conditions => {:method => :delete}}))
22
+
23
+
24
+ connect( "#{root}/*path", opts.merge({ :action => 'destroy', :conditions => { :method => :delete } }) ) # Wiki destroy route
25
+ connect( "#{root}/*path", opts.merge({ :action => 'update', :conditions => { :method => :post } }) ) # Save wiki pages route
26
+ connect( "#{root}/*path", opts.merge({ :action => 'show', :conditions => { :method => :get } }) ) # Wiki pages route
27
+ #connect( "#{root}/*path", opts.merge({ :action => 'show', :conditions => { :method => :get } }) ) # Wiki pages route
21
28
  end
22
29
 
23
30
  end
@@ -7,16 +7,19 @@ end
7
7
 
8
8
  ActiveRecord::Base.instance_eval do
9
9
 
10
- #
11
10
  def acts_as_wiki_page( config = {} )
12
11
  include Irwi::Extensions::Models::WikiPage
13
12
  end
14
13
 
15
- #
16
14
  def acts_as_wiki_page_version( config = {} )
17
15
  include Irwi::Extensions::Models::WikiPageVersion
18
16
  end
19
17
 
18
+ def acts_as_wiki_page_attachment
19
+ include Irwi::Extensions::Models::WikiPageAttachment
20
+ yield if block_given?
21
+ end
22
+
20
23
  end
21
24
 
22
25
  ActionController::Base.instance_eval do
@@ -25,8 +25,8 @@ describe Irwi::Extensions::Controllers::WikiPages do
25
25
 
26
26
  context "class" do
27
27
 
28
- it { @cls.should respond_to :set_page_class }
29
- it { @cls.should respond_to :page_class }
28
+ it { @cls.should respond_to(:set_page_class) }
29
+ it { @cls.should respond_to(:page_class) }
30
30
 
31
31
  specify "should have WikiPage as default page_class" do
32
32
  @cls.page_class.should == WikiPage
@@ -40,22 +40,23 @@ describe Irwi::Extensions::Controllers::WikiPages do
40
40
  @obj = @cls.new
41
41
  end
42
42
 
43
- it { @obj.should respond_to :page_class }
43
+ it { @obj.should respond_to(:page_class) }
44
44
 
45
45
  specify "should have WikiPage as default page_class" do
46
46
  @obj.send(:page_class).should == WikiPage
47
47
  end
48
48
 
49
- it { @obj.should respond_to :render_template }
50
- it { @obj.should respond_to :setup_current_user }
51
- it { @obj.should respond_to :setup_page }
49
+ it { @obj.should respond_to(:render_template) }
50
+ it { @obj.should respond_to(:setup_current_user) }
51
+ it { @obj.should respond_to(:setup_page) }
52
52
 
53
- it { @obj.should respond_to :show }
54
- it { @obj.should respond_to :edit }
55
- it { @obj.should respond_to :update }
56
- it { @obj.should respond_to :history }
57
- it { @obj.should respond_to :compare }
58
- it { @obj.should respond_to :destroy }
53
+ it { @obj.should respond_to(:show) }
54
+ it { @obj.should respond_to(:new) }
55
+ it { @obj.should respond_to(:edit) }
56
+ it { @obj.should respond_to(:update) }
57
+ it { @obj.should respond_to(:history) }
58
+ it { @obj.should respond_to(:compare) }
59
+ it { @obj.should respond_to(:destroy) }
59
60
 
60
61
  specify "should correctly handle current_user" do
61
62
  @obj.send(:setup_current_user)
@@ -0,0 +1,48 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Irwi::Helpers::WikiPageAttachmentsHelper do
4
+
5
+ it { should_not be_nil }
6
+
7
+ context "included in class" do
8
+
9
+ before(:each) do
10
+ @m = Object.new
11
+ @m.send :extend, Irwi::Helpers::WikiPagesHelper
12
+ end
13
+
14
+ describe :wiki_show_attachment do
15
+ before do
16
+ class WikiPageAttachment; end
17
+ module ActiveRecord
18
+ class RecordNotFound < StandardError
19
+ end
20
+ end
21
+ end
22
+
23
+ it 'replaces Attachment_1_thumb with its corresponding image tag' do
24
+ paperclip_attachment = mock('paperclip attachment')
25
+ attachment = mock(WikiPageAttachment, :wiki_page_attachment => paperclip_attachment)
26
+
27
+ WikiPageAttachment.should_receive(:find).with('1').and_return(attachment)
28
+ paperclip_attachment.should_receive(:url).with(:thumb).and_return(:thumb_image)
29
+ @m.should_receive(:image_tag).with(:thumb_image, :class => 'wiki_page_attachment').and_return('thumb_image_markup')
30
+
31
+ @m.wiki_show_attachments('Foo Attachment_1_thumb Bar').should == 'Foo thumb_image_markup Bar'
32
+ end
33
+
34
+ it 'does not affect text without attachments' do
35
+ @m.wiki_show_attachments('Foo Bar').should == 'Foo Bar'
36
+ end
37
+
38
+ it 'ignores absent attachments' do
39
+ paperclip_attachment = mock('paperclip attachment')
40
+ attachment = mock(WikiPageAttachment, :wiki_page_attachment => paperclip_attachment)
41
+ WikiPageAttachment.should_receive(:find).with('10').and_raise(ActiveRecord::RecordNotFound)
42
+
43
+ @m.wiki_show_attachments('Foo Attachment_10_thumb Bar').should == 'Foo Bar'
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -11,12 +11,12 @@ describe Irwi::Helpers::WikiPagesHelper do
11
11
  @m.send :extend, Irwi::Helpers::WikiPagesHelper
12
12
  end
13
13
 
14
- it { @m.should respond_to :wiki_page_form }
14
+ it { @m.should respond_to(:wiki_page_form) }
15
15
 
16
- it { @m.should respond_to :wiki_page_edit_path }
17
- it { @m.should respond_to :wiki_page_history_path }
18
- it { @m.should respond_to :wiki_page_compare_path }
19
- it { @m.should respond_to :wiki_page_path }
16
+ it { @m.should respond_to(:wiki_page_edit_path) }
17
+ it { @m.should respond_to(:wiki_page_history_path) }
18
+ it { @m.should respond_to(:wiki_page_compare_path) }
19
+ it { @m.should respond_to(:wiki_page_path) }
20
20
 
21
21
  specify "should form url_for by wiki_page_edit_path" do
22
22
  @m.should_receive(:url_for).with(:action => :edit).and_return('epath')
@@ -54,19 +54,19 @@ describe Irwi::Helpers::WikiPagesHelper do
54
54
  @m.wiki_page_path('123').should == 'spath'
55
55
  end
56
56
 
57
- it { @m.should respond_to :wiki_content }
58
- it { @m.should respond_to :wiki_diff }
59
- it { @m.should respond_to :wiki_user }
57
+ it { @m.should respond_to(:wiki_content) }
58
+ it { @m.should respond_to(:wiki_diff) }
59
+ it { @m.should respond_to(:wiki_user) }
60
60
 
61
- it { @m.should respond_to :wiki_page_info }
62
- it { @m.should respond_to :wiki_page_actions }
63
- it { @m.should respond_to :wiki_page_history }
64
- it { @m.should respond_to :wiki_page_style }
61
+ it { @m.should respond_to(:wiki_page_info) }
62
+ it { @m.should respond_to(:wiki_page_actions) }
63
+ it { @m.should respond_to(:wiki_page_history) }
64
+ it { @m.should respond_to(:wiki_page_style) }
65
65
 
66
- it { @m.should respond_to :wiki_link }
67
- it { @m.should respond_to :wiki_linkify }
66
+ it { @m.should respond_to(:wiki_link) }
67
+ it { @m.should respond_to(:wiki_linkify) }
68
68
 
69
- it { @m.should respond_to :wt }
69
+ it { @m.should respond_to(:wt) }
70
70
 
71
71
  specify "should format and sanitize content with current formatter and #sanitize" do
72
72
  Irwi.config.formatter = mock 'Formatter'
@@ -143,4 +143,4 @@ describe Irwi::Helpers::WikiPagesHelper do
143
143
 
144
144
  end
145
145
 
146
- end
146
+ end
@@ -1,4 +1,5 @@
1
1
  require "spec/spec_helper"
2
+ require 'action_controller'
2
3
 
3
4
  describe Irwi::Support::RouteMapper do
4
5
 
@@ -12,9 +13,54 @@ describe Irwi::Support::RouteMapper do
12
13
  end
13
14
 
14
15
  specify "should provide wiki_root method" do
15
- @m.should respond_to :wiki_root
16
+ @m.should respond_to(:wiki_root)
16
17
  end
17
18
 
18
19
  end
20
+
21
+ describe 'wiki routes' do
22
+ before do
23
+ @set = ActionController::Routing::RouteSet.new
24
+ @mapper = ActionController::Routing::RouteSet::Mapper.new(@set)
25
+
26
+ ActionController::Routing::RouteSet::Mapper.instance_eval do
27
+ include Irwi::Support::RouteMapper
28
+ end
29
+ @mapper.wiki_root('/wiki')
30
+ end
31
+
32
+ def check_route path, params = {}
33
+ @set.generate(params).should == path
34
+ @set.recognize_path(path).should == params
35
+ end
36
+
37
+ it 'has a route of listing all the wikis' do
38
+ check_route '/wiki/all', :controller => 'wiki_pages', :action => 'all', :root => '/wiki'
39
+ end
40
+
41
+ %w[compare new edit history].each do |act|
42
+ it "has a route for #{act} wiki" do
43
+ check_route "/wiki/#{act}/wiki_path", :controller => 'wiki_pages', :action => act, :root => '/wiki', :path => ['wiki_path']
44
+ end
45
+ end
46
+
47
+ # Unable to perform the recognize path test because of conditions. If you can , write it.
48
+ %w[show update destroy].each do |act|
49
+ it "has a route for #{act} wiki" do
50
+ @set.generate({:controller => 'wiki_pages', :action => act, :root => '/wiki', :path => ['wiki_path']}).should == '/wiki/wiki_path'
51
+ end
52
+ end
53
+
54
+ describe 'attachment routes' do
55
+ it 'has a route for adding an attachment' do
56
+ @set.generate({:controller => 'wiki_pages', :action => 'add_attachment', :root => '/wiki', :path => ['wiki_path']}).should == '/wiki/attach/wiki_path'
57
+ end
58
+
59
+ it 'has a route for deleting an attachment' do
60
+ @set.generate({:controller => 'wiki_pages', :action => 'remove_attachment', :root => '/wiki', :attachment_id => 1}).should == '/wiki/attach/1'
61
+ end
62
+ end
63
+
64
+ end
19
65
 
20
- end
66
+ end
@@ -13,7 +13,7 @@ describe Irwi::Support::TemplateFinder do
13
13
  end
14
14
 
15
15
  specify "should provide template_dir method" do
16
- @m.should respond_to :template_dir
16
+ @m.should respond_to(:template_dir)
17
17
  end
18
18
 
19
19
  specify "should select template at controller_path when exists" do
metadata CHANGED
@@ -1,39 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irwi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Alexey Noskov
13
+ - Ravi Bhim
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-05 00:00:00 +03:00
18
+ date: 2010-06-14 00:00:00 +04:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: diff-lcs
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 1
31
+ - 2
23
32
  version: 1.1.2
24
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: rspec
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
30
39
  requirements:
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 2
45
+ - 9
33
46
  version: 1.2.9
34
- version:
47
+ type: :development
48
+ version_requirements: *id002
35
49
  description: "Irwi is Ruby on Rails plugin which adds wiki functionality to your application. "
36
- email: alexey.noskov@gmail.com
50
+ email: alexey.noskov@gmail.com ravi.bhim@yahoo.com
37
51
  executables: []
38
52
 
39
53
  extensions: []
@@ -55,6 +69,7 @@ files:
55
69
  - app/views/base_wiki_pages/compare.html.erb
56
70
  - app/views/base_wiki_pages/edit.html.erb
57
71
  - app/views/base_wiki_pages/history.html.erb
72
+ - app/views/base_wiki_pages/new.html.erb
58
73
  - app/views/base_wiki_pages/no.html.erb
59
74
  - app/views/base_wiki_pages/not_allowed.html.erb
60
75
  - app/views/base_wiki_pages/show.html.erb
@@ -64,6 +79,10 @@ files:
64
79
  - generators/irwi_wiki/templates/migrate/create_wiki_pages.rb
65
80
  - generators/irwi_wiki/templates/models/wiki_page.rb
66
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
67
86
  - generators/irwi_wiki_views/irwi_wiki_views_generator.rb
68
87
  - irwi.gemspec
69
88
  - lib/irwi.rb
@@ -72,11 +91,14 @@ files:
72
91
  - lib/irwi/comparators/spans/changed_span.rb
73
92
  - lib/irwi/comparators/spans/not_changed_span.rb
74
93
  - lib/irwi/config.rb
94
+ - lib/irwi/extensions/controllers/wiki_page_attachments.rb
75
95
  - lib/irwi/extensions/controllers/wiki_pages.rb
76
96
  - lib/irwi/extensions/models/wiki_page.rb
97
+ - lib/irwi/extensions/models/wiki_page_attachment.rb
77
98
  - lib/irwi/extensions/models/wiki_page_version.rb
78
99
  - lib/irwi/formatters/blue_cloth.rb
79
100
  - lib/irwi/formatters/red_cloth.rb
101
+ - lib/irwi/helpers/wiki_page_attachments_helper.rb
80
102
  - lib/irwi/helpers/wiki_pages_helper.rb
81
103
  - lib/irwi/paginators/none.rb
82
104
  - lib/irwi/paginators/will_paginate.rb
@@ -87,6 +109,7 @@ files:
87
109
  - spec/config_spec.rb
88
110
  - spec/extensions/controllers/wiki_pages_spec.rb
89
111
  - spec/formatters/red_cloth_spec.rb
112
+ - spec/helpers/wiki_page_attachments_helper_spec.rb
90
113
  - spec/helpers/wiki_pages_helper_spec.rb
91
114
  - spec/paginators/none_spec.rb
92
115
  - spec/paginators/will_paginate_spec.rb
@@ -109,29 +132,32 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
132
  requirements:
110
133
  - - ">="
111
134
  - !ruby/object:Gem::Version
135
+ segments:
136
+ - 0
112
137
  version: "0"
113
- version:
114
138
  required_rubygems_version: !ruby/object:Gem::Requirement
115
139
  requirements:
116
140
  - - ">="
117
141
  - !ruby/object:Gem::Version
142
+ segments:
143
+ - 0
118
144
  version: "0"
119
- version:
120
145
  requirements: []
121
146
 
122
147
  rubyforge_project:
123
- rubygems_version: 1.3.5
148
+ rubygems_version: 1.3.6
124
149
  signing_key:
125
150
  specification_version: 3
126
151
  summary: Irwi is Ruby on Rails plugin which adds wiki functionality to your application.
127
152
  test_files:
128
- - spec/comparators/diff_lcs_spec.rb
129
- - spec/support/template_finder_spec.rb
130
153
  - spec/support/route_mapper_spec.rb
131
- - spec/config_spec.rb
132
- - spec/formatters/red_cloth_spec.rb
133
- - spec/extensions/controllers/wiki_pages_spec.rb
134
- - spec/helpers/wiki_pages_helper_spec.rb
154
+ - spec/support/template_finder_spec.rb
135
155
  - spec/spec_helper.rb
156
+ - spec/comparators/diff_lcs_spec.rb
157
+ - spec/extensions/controllers/wiki_pages_spec.rb
158
+ - spec/config_spec.rb
136
159
  - spec/paginators/will_paginate_spec.rb
137
160
  - spec/paginators/none_spec.rb
161
+ - spec/helpers/wiki_pages_helper_spec.rb
162
+ - spec/helpers/wiki_page_attachments_helper_spec.rb
163
+ - spec/formatters/red_cloth_spec.rb