irwi 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/irwi.gemspec +3 -1
- data/lib/irwi/config.rb +14 -0
- data/lib/irwi/extensions/controllers/wiki_pages.rb +1 -1
- data/lib/irwi/extensions/models/wiki_page.rb +1 -1
- data/lib/irwi/helpers/wiki_pages_helper.rb +16 -2
- data/spec/formatters/red_cloth_spec.rb +17 -0
- data/spec/helpers/wiki_pages_helper_spec.rb +35 -0
- metadata +3 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/irwi.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{irwi}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
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"]
|
@@ -57,6 +57,7 @@ Gem::Specification.new do |s|
|
|
57
57
|
"spec/comparators/diff_lcs_spec.rb",
|
58
58
|
"spec/config_spec.rb",
|
59
59
|
"spec/extensions/controllers/wiki_pages_spec.rb",
|
60
|
+
"spec/formatters/red_cloth_spec.rb",
|
60
61
|
"spec/helpers/wiki_pages_helper_spec.rb",
|
61
62
|
"spec/rcov.opts",
|
62
63
|
"spec/spec.opts",
|
@@ -75,6 +76,7 @@ Gem::Specification.new do |s|
|
|
75
76
|
"spec/support/template_finder_spec.rb",
|
76
77
|
"spec/support/route_mapper_spec.rb",
|
77
78
|
"spec/config_spec.rb",
|
79
|
+
"spec/formatters/red_cloth_spec.rb",
|
78
80
|
"spec/extensions/controllers/wiki_pages_spec.rb",
|
79
81
|
"spec/helpers/wiki_pages_helper_spec.rb",
|
80
82
|
"spec/spec_helper.rb"
|
data/lib/irwi/config.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class Irwi::Config
|
2
2
|
|
3
|
+
attr_accessor_with_default :controller_name, 'wiki_pages'
|
4
|
+
|
3
5
|
attr_accessor_with_default :user_class_name, 'User'
|
4
6
|
|
5
7
|
attr_accessor_with_default :page_class_name, 'WikiPage'
|
@@ -15,4 +17,16 @@ class Irwi::Config
|
|
15
17
|
Irwi::Comparators::DiffLcs.new
|
16
18
|
end
|
17
19
|
|
20
|
+
def page_class
|
21
|
+
page_class_name.constantize
|
22
|
+
end
|
23
|
+
|
24
|
+
def page_vrsion_class
|
25
|
+
page_version_class_name.constantize
|
26
|
+
end
|
27
|
+
|
28
|
+
def user_class
|
29
|
+
user_class_name.constantize
|
30
|
+
end
|
31
|
+
|
18
32
|
end
|
@@ -24,7 +24,7 @@ module Irwi::Helpers::WikiPagesHelper
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def wiki_content( text )
|
27
|
-
sanitize( Irwi.config.formatter.format( text ) )
|
27
|
+
sanitize( wiki_linkify( Irwi.config.formatter.format( text ) ) )
|
28
28
|
end
|
29
29
|
|
30
30
|
def wiki_diff( old_text, new_text )
|
@@ -32,11 +32,25 @@ module Irwi::Helpers::WikiPagesHelper
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def wiki_user( user )
|
35
|
-
return '<Unknown>'
|
35
|
+
return '<Unknown>' unless user
|
36
36
|
|
37
37
|
"User##{user.id}"
|
38
38
|
end
|
39
39
|
|
40
|
+
def wiki_linkify( str )
|
41
|
+
str.gsub /\[\[([^\[\]]+)\]\]/ do |m|
|
42
|
+
"<a href=\"#{wiki_link $1}\">#{$1}</a>"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def wiki_link( title )
|
47
|
+
if page = Irwi.config.page_class.find_by_title( title )
|
48
|
+
url_for( :controller => Irwi.config.controller_name, :action => :show, :path => page.path )
|
49
|
+
else
|
50
|
+
url_for( :controller => Irwi.config.controller_name, :action => :show, :path => title )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
40
54
|
##
|
41
55
|
# Instead of having to translate strings and defining a default value:
|
42
56
|
#
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
describe Irwi::Formatters::RedCloth do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@f = Irwi::Formatters::RedCloth.new
|
7
|
+
end
|
8
|
+
|
9
|
+
specify "should proces bold text" do
|
10
|
+
@f.format('*Place* ff').should == '<p><strong>Place</strong> ff</p>'
|
11
|
+
end
|
12
|
+
|
13
|
+
specify "should proces italic text" do
|
14
|
+
@f.format('_Mom_ ff').should == '<p><em>Mom</em> ff</p>'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -27,6 +27,9 @@ describe Irwi::Helpers::WikiPagesHelper do
|
|
27
27
|
it { @m.should respond_to :wiki_page_history }
|
28
28
|
it { @m.should respond_to :wiki_page_style }
|
29
29
|
|
30
|
+
it { @m.should respond_to :wiki_link }
|
31
|
+
it { @m.should respond_to :wiki_linkify }
|
32
|
+
|
30
33
|
it { @m.should respond_to :wt }
|
31
34
|
|
32
35
|
specify "should format and sanitize content with current formatter and #sanitize" do
|
@@ -69,6 +72,38 @@ describe Irwi::Helpers::WikiPagesHelper do
|
|
69
72
|
@m.wiki_page_history( page ).should == 'partial_body'
|
70
73
|
end
|
71
74
|
|
75
|
+
specify "should linkify string" do
|
76
|
+
|
77
|
+
@m.should_receive(:wiki_link).with('Some other page').and_return('url')
|
78
|
+
|
79
|
+
@m.wiki_linkify( '[[Some other page]] - link' ).should == '<a href="url">Some other page</a> - link'
|
80
|
+
end
|
81
|
+
|
82
|
+
specify "should generate link for non-existent page" do
|
83
|
+
page_class = mock "WikiPageClass"
|
84
|
+
page_class.should_receive(:find_by_title).with('Page title').and_return(nil)
|
85
|
+
|
86
|
+
Irwi.config.should_receive(:page_class).and_return(page_class)
|
87
|
+
|
88
|
+
@m.should_receive(:url_for).with( :controller => 'wiki_pages', :action => :show, :path => 'Page title' ).and_return('url')
|
89
|
+
|
90
|
+
@m.wiki_link( 'Page title' ).should == 'url'
|
91
|
+
end
|
92
|
+
|
93
|
+
specify "should generate link for existent page" do
|
94
|
+
page = mock "WikiPage"
|
95
|
+
page.should_receive(:path).and_return('page_path')
|
96
|
+
|
97
|
+
page_class = mock "WikiPageClass"
|
98
|
+
page_class.should_receive(:find_by_title).with('Page title').and_return(page)
|
99
|
+
|
100
|
+
Irwi.config.should_receive(:page_class).and_return(page_class)
|
101
|
+
|
102
|
+
@m.should_receive(:url_for).with( :controller => 'wiki_pages', :action => :show, :path => 'page_path' ).and_return('url')
|
103
|
+
|
104
|
+
@m.wiki_link( 'Page title' ).should == 'url'
|
105
|
+
end
|
106
|
+
|
72
107
|
end
|
73
108
|
|
74
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irwi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Noskov
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- spec/comparators/diff_lcs_spec.rb
|
83
83
|
- spec/config_spec.rb
|
84
84
|
- spec/extensions/controllers/wiki_pages_spec.rb
|
85
|
+
- spec/formatters/red_cloth_spec.rb
|
85
86
|
- spec/helpers/wiki_pages_helper_spec.rb
|
86
87
|
- spec/rcov.opts
|
87
88
|
- spec/spec.opts
|
@@ -122,6 +123,7 @@ test_files:
|
|
122
123
|
- spec/support/template_finder_spec.rb
|
123
124
|
- spec/support/route_mapper_spec.rb
|
124
125
|
- spec/config_spec.rb
|
126
|
+
- spec/formatters/red_cloth_spec.rb
|
125
127
|
- spec/extensions/controllers/wiki_pages_spec.rb
|
126
128
|
- spec/helpers/wiki_pages_helper_spec.rb
|
127
129
|
- spec/spec_helper.rb
|