irwi 0.0.0

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 (49) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +53 -0
  5. data/Rakefile +53 -0
  6. data/VERSION +1 -0
  7. data/app/views/base_wiki_pages/_wiki_page_actions.html.erb +4 -0
  8. data/app/views/base_wiki_pages/_wiki_page_history.html.erb +31 -0
  9. data/app/views/base_wiki_pages/_wiki_page_info.html.erb +3 -0
  10. data/app/views/base_wiki_pages/_wiki_page_style.html.erb +69 -0
  11. data/app/views/base_wiki_pages/compare.html.erb +13 -0
  12. data/app/views/base_wiki_pages/edit.html.erb +14 -0
  13. data/app/views/base_wiki_pages/history.html.erb +7 -0
  14. data/app/views/base_wiki_pages/no.html.erb +1 -0
  15. data/app/views/base_wiki_pages/not_allowed.html.erb +1 -0
  16. data/app/views/base_wiki_pages/show.html.erb +10 -0
  17. data/generators/irwi_wiki/irwi_wiki_generator.rb +22 -0
  18. data/generators/irwi_wiki/templates/controllers/wiki_pages_controller.rb +5 -0
  19. data/generators/irwi_wiki/templates/helpers/wiki_pages_helper.rb +3 -0
  20. data/generators/irwi_wiki/templates/migrate/create_wiki_pages.rb +44 -0
  21. data/generators/irwi_wiki/templates/models/wiki_page.rb +5 -0
  22. data/generators/irwi_wiki/templates/models/wiki_page_version.rb +5 -0
  23. data/irwi.gemspec +99 -0
  24. data/lib/irwi.rb +7 -0
  25. data/lib/irwi/comparators/base.rb +17 -0
  26. data/lib/irwi/comparators/diff_lcs.rb +52 -0
  27. data/lib/irwi/comparators/spans/changed_span.rb +18 -0
  28. data/lib/irwi/comparators/spans/not_changed_span.rb +20 -0
  29. data/lib/irwi/config.rb +18 -0
  30. data/lib/irwi/extensions/controllers/wiki_pages.rb +123 -0
  31. data/lib/irwi/extensions/models/wiki_page.rb +46 -0
  32. data/lib/irwi/extensions/models/wiki_page_version.rb +40 -0
  33. data/lib/irwi/formatters/blue_cloth.rb +11 -0
  34. data/lib/irwi/formatters/red_cloth.rb +11 -0
  35. data/lib/irwi/helpers/wiki_pages_helper.rb +83 -0
  36. data/lib/irwi/support/route_mapper.rb +17 -0
  37. data/lib/irwi/support/template_finder.rb +11 -0
  38. data/rails/init.rb +31 -0
  39. data/spec/comparators/diff_lcs_spec.rb +37 -0
  40. data/spec/config_spec.rb +58 -0
  41. data/spec/extensions/controllers/wiki_pages_spec.rb +53 -0
  42. data/spec/helpers/wiki_pages_helper_spec.rb +74 -0
  43. data/spec/rcov.opts +2 -0
  44. data/spec/spec.opts +4 -0
  45. data/spec/spec_helper.rb +15 -0
  46. data/spec/support/route_mapper_spec.rb +20 -0
  47. data/spec/support/template_finder_spec.rb +33 -0
  48. data/tasks/riwiki_tasks.rake +4 -0
  49. metadata +127 -0
@@ -0,0 +1,17 @@
1
+ module Irwi::Support::RouteMapper
2
+
3
+ # Defining wiki root mount point
4
+ def wiki_root( path, config = {} )
5
+ opts = {
6
+ :controller => 'wiki_pages',
7
+ :root => path
8
+ }.merge(config)
9
+
10
+ connect( "#{path}/compare/*path", opts.merge({ :action => 'compare' }) ) # Comparing two versions of page
11
+ connect( "#{path}/edit/*path", opts.merge({ :action => 'edit' }) ) # Wiki edit route
12
+ connect( "#{path}/history/*path", opts.merge({ :action => 'history' }) ) # Wiki history route
13
+ connect( "#{path}/*path", opts.merge({ :action => 'update', :conditions => { :method => :post } }) ) # Save wiki pages route
14
+ connect( "#{path}/*path", opts.merge({ :action => 'show', :conditions => { :method => :get } }) ) # Wiki pages route
15
+ end
16
+
17
+ end
@@ -0,0 +1,11 @@
1
+ module Irwi::Support::TemplateFinder
2
+
3
+ protected
4
+
5
+ def template_dir(template)
6
+ dir = respond_to?( :controller_path ) ? controller_path : controller.controller_path
7
+ dir = 'base_wiki_pages' if Dir.glob( "app/views/#{dir}/#{template}.html.*" ).empty? # Select default if there are no template in resource directory
8
+ dir
9
+ end
10
+
11
+ end
@@ -0,0 +1,31 @@
1
+ require 'irwi' # Main irwi class
2
+ require 'irwi/support/route_mapper' # Routes
3
+
4
+ ActionController::Routing::RouteSet::Mapper.instance_eval do
5
+ include Irwi::Support::RouteMapper
6
+ end
7
+
8
+ ActiveRecord::Base.instance_eval do
9
+
10
+ #
11
+ def acts_as_wiki_page( config = {} )
12
+ include Irwi::Extensions::Models::WikiPage
13
+ end
14
+
15
+ #
16
+ def acts_as_wiki_page_version( config = {} )
17
+ include Irwi::Extensions::Models::WikiPageVersion
18
+ end
19
+
20
+ end
21
+
22
+ ActionController::Base.instance_eval do
23
+
24
+ # @param config [Hash] config for controller class
25
+ # @option page_class
26
+ #
27
+ def acts_as_wiki_pages_controller( config = {} )
28
+ include Irwi::Extensions::Controllers::WikiPages
29
+ end
30
+
31
+ end
@@ -0,0 +1,37 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Irwi::Comparators::DiffLcs do
4
+
5
+ before(:each) do
6
+ @c = Irwi::Comparators::DiffLcs.new
7
+ end
8
+
9
+ specify "should render change for replaced text" do
10
+ @c.render_changes('AAA','BbB').should == '<span class="removed">AAA</span><span class="added">BbB</span>'
11
+ end
12
+
13
+ specify "should render no changes for same text" do
14
+ @c.render_changes('vdsds','vdsds').should == 'vdsds'
15
+ end
16
+
17
+ specify "should render addition" do
18
+ @c.render_changes('AAA','AABbA').should == 'AA<span class="added">Bb</span>A'
19
+ end
20
+
21
+ specify "should render deletion" do
22
+ @c.render_changes('AdvsADA','AdDA').should == 'Ad<span class="removed">vsA</span>DA'
23
+ end
24
+
25
+ specify "should render changed with addition" do
26
+ @c.render_changes('qwerty','qwasdfy').should == 'qw<span class="removed">ert</span><span class="added">asdf</span>y'
27
+ end
28
+
29
+ specify "should survive on nil in old" do
30
+ @c.render_changes(nil,'AdDA').should == '<span class="added">AdDA</span>'
31
+ end
32
+
33
+ specify "should survive on nil in new" do
34
+ @c.render_changes('AdDA',nil).should == '<span class="removed">AdDA</span>'
35
+ end
36
+
37
+ end
@@ -0,0 +1,58 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Irwi::Config do
4
+
5
+ before(:each) do
6
+ @o = Irwi::Config.new
7
+ end
8
+
9
+ specify "should save selected user_class_name" do
10
+ @o.user_class_name = 'MyUserClass'
11
+ @o.user_class_name.should == 'MyUserClass'
12
+ end
13
+
14
+ specify "should select 'User' as user_class_name by default" do
15
+ @o.user_class_name.should == 'User'
16
+ end
17
+
18
+ specify "should save selected page_class_name" do
19
+ @o.page_class_name = 'MyPageClass'
20
+ @o.page_class_name.should == 'MyPageClass'
21
+ end
22
+
23
+ specify "should select 'WikiPage' as page_class_name by default" do
24
+ @o.page_class_name.should == 'WikiPage'
25
+ end
26
+
27
+ specify "should save selected page_version_class_name" do
28
+ @o.page_version_class_name = 'MyVersionClass'
29
+ @o.page_version_class_name.should == 'MyVersionClass'
30
+ end
31
+
32
+ specify "should select 'WikiPageVersion' as page_version_class_name by default" do
33
+ @o.page_version_class_name.should == 'WikiPageVersion'
34
+ end
35
+
36
+ specify "should save selected formatter" do
37
+ @o.formatter = :my_formatter
38
+ @o.formatter.should == :my_formatter
39
+ end
40
+
41
+ specify "should select RedCloth as formatter by default" do
42
+ Irwi::Formatters::RedCloth.should_receive(:new).and_return(:red_cloth_formatter)
43
+
44
+ @o.formatter.should == :red_cloth_formatter
45
+ end
46
+
47
+ specify "should save selected comparator" do
48
+ @o.comparator = :my_formatter
49
+ @o.comparator.should == :my_formatter
50
+ end
51
+
52
+ specify "should select DiffLcs as comparator by default" do
53
+ Irwi::Comparators::DiffLcs.should_receive(:new).and_return(:diff_lcs_comparator)
54
+
55
+ @o.comparator.should == :diff_lcs_comparator
56
+ end
57
+
58
+ end
@@ -0,0 +1,53 @@
1
+ require "spec/spec_helper"
2
+
3
+ require "action_controller"
4
+
5
+ describe Irwi::Extensions::Controllers::WikiPages do
6
+
7
+ class WikiPage; end
8
+ class WikiPagesController < ActionController::Base
9
+ include Irwi::Extensions::Controllers::WikiPages
10
+ end
11
+
12
+ it { should_not be_nil }
13
+
14
+ before(:all) do
15
+ @cls = WikiPagesController
16
+ end
17
+
18
+ context "class" do
19
+
20
+ it { @cls.should respond_to :set_page_class }
21
+ it { @cls.should respond_to :page_class }
22
+
23
+ specify "should have WikiPage as default page_class" do
24
+ @cls.page_class.should == WikiPage
25
+ end
26
+
27
+ end
28
+
29
+ context "instance" do
30
+
31
+ before(:each) do
32
+ @obj = @cls.new
33
+ end
34
+
35
+ it { @obj.should respond_to :page_class }
36
+
37
+ specify "should have WikiPage as default page_class" do
38
+ @obj.send(:page_class).should == WikiPage
39
+ end
40
+
41
+ it { @obj.should respond_to :render_template }
42
+ it { @obj.should respond_to :setup_current_user }
43
+ it { @obj.should respond_to :setup_page }
44
+
45
+ it { @obj.should respond_to :show }
46
+ it { @obj.should respond_to :edit }
47
+ it { @obj.should respond_to :update }
48
+ it { @obj.should respond_to :history }
49
+ it { @obj.should respond_to :compare }
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,74 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Irwi::Helpers::WikiPagesHelper 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
+ it { @m.should respond_to :wiki_page_form }
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 }
20
+
21
+ it { @m.should respond_to :wiki_content }
22
+ it { @m.should respond_to :wiki_diff }
23
+ it { @m.should respond_to :wiki_user }
24
+
25
+ it { @m.should respond_to :wiki_page_info }
26
+ it { @m.should respond_to :wiki_page_actions }
27
+ it { @m.should respond_to :wiki_page_history }
28
+ it { @m.should respond_to :wiki_page_style }
29
+
30
+ it { @m.should respond_to :wt }
31
+
32
+ specify "should format and sanitize content with current formatter and #sanitize" do
33
+ Irwi.config.formatter = mock 'Formatter'
34
+ Irwi.config.formatter.should_receive(:format).with('Page content').and_return('Formatted content')
35
+
36
+ @m.should_receive(:sanitize).with('Formatted content').and_return('Formatted and sanitized content')
37
+
38
+ @m.wiki_content( 'Page content' ).should == 'Formatted and sanitized content'
39
+ end
40
+
41
+ specify "should render wiki_page_info partial" do
42
+ @m.should_receive(:template_dir).and_return('partial_dir')
43
+ @m.should_receive(:render).with(:partial => "partial_dir/wiki_page_info", :locals => { :page => 'MyPage' }).and_return('partial_body')
44
+
45
+ @m.wiki_page_info( 'MyPage' ).should == 'partial_body'
46
+ end
47
+
48
+ specify "should render wiki_page_actions partial" do
49
+ @m.should_receive(:template_dir).and_return('partial_dir')
50
+ @m.should_receive(:render).with(:partial => "partial_dir/wiki_page_actions", :locals => { :page => 'MyPage' }).and_return('partial_body')
51
+
52
+ @m.wiki_page_actions( 'MyPage' ).should == 'partial_body'
53
+ end
54
+
55
+ specify "should render wiki_page_history partial" do
56
+ @m.should_receive(:template_dir).and_return('partial_dir')
57
+ @m.should_receive(:render).with(:partial => "partial_dir/wiki_page_history", :locals => { :page => 'MyPage', :versions => [1,2], :with_form => true }).and_return('partial_body')
58
+
59
+ @m.wiki_page_history( 'MyPage', [1,2] ).should == 'partial_body'
60
+ end
61
+
62
+ specify "should render wiki_page_history partial (with default versions)" do
63
+ page = mock 'MyPage'
64
+ page.should_receive(:versions).and_return([1])
65
+
66
+ @m.should_receive(:template_dir).and_return('partial_dir')
67
+ @m.should_receive(:render).with(:partial => "partial_dir/wiki_page_history", :locals => { :page => page, :versions => [1], :with_form => false }).and_return('partial_body')
68
+
69
+ @m.wiki_page_history( page ).should == 'partial_body'
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+
3
+ require 'active_support'
4
+ require 'active_support/test_case'
5
+
6
+ ActiveSupport::Dependencies.load_paths << "#{File.dirname(__FILE__)}/../lib"
7
+ ActiveSupport::Dependencies.load_paths << "#{File.dirname(__FILE__)}/../app/models"
8
+ ActiveSupport::Dependencies.load_paths << "#{File.dirname(__FILE__)}/../app/controllers"
9
+
10
+ # Requires supporting files with custom matchers and macros, etc,
11
+ # in ./support/ and its subdirectories.
12
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
+
14
+ Spec::Runner.configure do |config|
15
+ end
@@ -0,0 +1,20 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Irwi::Support::RouteMapper 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::Support::RouteMapper
12
+ end
13
+
14
+ specify "should provide wiki_root method" do
15
+ @m.should respond_to :wiki_root
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,33 @@
1
+ require "spec/spec_helper"
2
+
3
+ describe Irwi::Support::TemplateFinder 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::Support::TemplateFinder
12
+ @m.stub!(:controller_path).and_return('my_controller')
13
+ end
14
+
15
+ specify "should provide template_dir method" do
16
+ @m.should respond_to :template_dir
17
+ end
18
+
19
+ specify "should select template at controller_path when exists" do
20
+ Dir.should_receive(:glob).with("app/views/my_controller/my_template.html.*").and_return(['some_template'])
21
+
22
+ @m.send( :template_dir, 'my_template' ).should == 'my_controller'
23
+ end
24
+
25
+ specify "should select template in base dir when it doesn't exists at controller_path" do
26
+ Dir.should_receive(:glob).with("app/views/my_controller/my_template.html.*").and_return([])
27
+
28
+ @m.send( :template_dir, 'my_template' ).should == 'base_wiki_pages'
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :riwiki do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irwi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexey Noskov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-25 00:00:00 +04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: diff-lcs
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.9
34
+ version:
35
+ description: "Irwi is Ruby on Rails plugin which adds wiki functionality to your application. "
36
+ email: alexey.noskov@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - MIT-LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - app/views/base_wiki_pages/_wiki_page_actions.html.erb
51
+ - app/views/base_wiki_pages/_wiki_page_history.html.erb
52
+ - app/views/base_wiki_pages/_wiki_page_info.html.erb
53
+ - app/views/base_wiki_pages/_wiki_page_style.html.erb
54
+ - app/views/base_wiki_pages/compare.html.erb
55
+ - app/views/base_wiki_pages/edit.html.erb
56
+ - app/views/base_wiki_pages/history.html.erb
57
+ - app/views/base_wiki_pages/no.html.erb
58
+ - app/views/base_wiki_pages/not_allowed.html.erb
59
+ - app/views/base_wiki_pages/show.html.erb
60
+ - generators/irwi_wiki/irwi_wiki_generator.rb
61
+ - generators/irwi_wiki/templates/controllers/wiki_pages_controller.rb
62
+ - generators/irwi_wiki/templates/helpers/wiki_pages_helper.rb
63
+ - generators/irwi_wiki/templates/migrate/create_wiki_pages.rb
64
+ - generators/irwi_wiki/templates/models/wiki_page.rb
65
+ - generators/irwi_wiki/templates/models/wiki_page_version.rb
66
+ - irwi.gemspec
67
+ - lib/irwi.rb
68
+ - lib/irwi/comparators/base.rb
69
+ - lib/irwi/comparators/diff_lcs.rb
70
+ - lib/irwi/comparators/spans/changed_span.rb
71
+ - lib/irwi/comparators/spans/not_changed_span.rb
72
+ - lib/irwi/config.rb
73
+ - lib/irwi/extensions/controllers/wiki_pages.rb
74
+ - lib/irwi/extensions/models/wiki_page.rb
75
+ - lib/irwi/extensions/models/wiki_page_version.rb
76
+ - lib/irwi/formatters/blue_cloth.rb
77
+ - lib/irwi/formatters/red_cloth.rb
78
+ - lib/irwi/helpers/wiki_pages_helper.rb
79
+ - lib/irwi/support/route_mapper.rb
80
+ - lib/irwi/support/template_finder.rb
81
+ - rails/init.rb
82
+ - spec/comparators/diff_lcs_spec.rb
83
+ - spec/config_spec.rb
84
+ - spec/extensions/controllers/wiki_pages_spec.rb
85
+ - spec/helpers/wiki_pages_helper_spec.rb
86
+ - spec/rcov.opts
87
+ - spec/spec.opts
88
+ - spec/spec_helper.rb
89
+ - spec/support/route_mapper_spec.rb
90
+ - spec/support/template_finder_spec.rb
91
+ - tasks/riwiki_tasks.rake
92
+ has_rdoc: true
93
+ homepage: http://github.com/alno/irwi
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --charset=UTF-8
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.3.5
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Irwi is Ruby on Rails plugin which adds wiki functionality to your application.
120
+ test_files:
121
+ - spec/comparators/diff_lcs_spec.rb
122
+ - spec/support/template_finder_spec.rb
123
+ - spec/support/route_mapper_spec.rb
124
+ - spec/config_spec.rb
125
+ - spec/extensions/controllers/wiki_pages_spec.rb
126
+ - spec/helpers/wiki_pages_helper_spec.rb
127
+ - spec/spec_helper.rb