Module: Irwi::Helpers::WikiPagesHelper
Instance Method Summary
collapse
#wiki_add_page_attachment_path, #wiki_remove_page_attachment_path, #wiki_show_attachments
#template_dir
Instance Method Details
#wiki_content(text) ⇒ Object
41
42
43
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 41
def wiki_content( text )
sanitize( auto_link( Irwi.config.formatter.format( wiki_linkify( wiki_show_attachments(text) ) ).html_safe))
end
|
#wiki_diff(old_text, new_text) ⇒ Object
45
46
47
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 45
def wiki_diff( old_text, new_text )
Irwi.config.comparator.render_changes(h(old_text), h(new_text)).html_safe
end
|
#wiki_link(title) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 75
def wiki_link( title )
if page = Irwi.config.page_class.find_by_title( title )
url_for( :controller => Irwi.config.controller_name, :action => :show, :path => page.path )
else
url_for( :controller => Irwi.config.controller_name, :action => :show, :path => CGI::escape(title) )
end
end
|
#wiki_linkify(str) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 59
def wiki_linkify( str )
str.gsub /\[\[
(?:([^\[\]\|]+)\|)?
([^\[\]]+)
\]\]
(\w+)?/xu do |m|
text = "#$2#$3"
link, anchor = if $1 then $1.split('#', 2) else $2 end
"<a href=\"#{wiki_link link}#{ '#' + anchor if anchor}\">#{text}</a>"
end.html_safe
end
|
#wiki_page_actions(page = nil) ⇒ Object
113
114
115
116
117
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 113
def wiki_page_actions(page = nil)
page ||= @page
render :partial => "#{template_dir '_wiki_page_actions'}/wiki_page_actions", :locals => { :page => page }
end
|
#wiki_page_attachments(page = @page) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 126
def wiki_page_attachments(page = @page)
return unless Irwi::config.page_attachment_class_name
page.attachments.each do |attachment|
concat image_tag(attachment.wiki_page_attachment.url(:thumb))
concat "Attachment_#{attachment.id}"
concat link_to(wt('Remove'), wiki_remove_page_attachment_path(attachment.id), :method => :delete)
end
form_for(Irwi.config.page_attachment_class.new,
:as => :wiki_page_attachment,
:url => wiki_add_page_attachment_path(page),
:html => { :multipart => true }) do |form|
concat form.file_field :wiki_page_attachment
concat form.hidden_field :page_id, :value => page.id
concat form.submit 'Add Attachment'
end
end
|
#wiki_page_compare_path(page = nil) ⇒ Object
26
27
28
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 26
def wiki_page_compare_path( page = nil )
wiki_page_path( page, :compare )
end
|
#wiki_page_edit_path(page = nil) ⇒ Object
18
19
20
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 18
def wiki_page_edit_path( page = nil )
wiki_page_path( page, :edit )
end
|
#wiki_page_form(config = {}, &block) ⇒ Object
Edit form for wiki page model
7
8
9
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 7
def wiki_page_form( config = {}, &block )
form_for( @page, { :as => :page, :url => url_for( :action => :update ), :html=> { :class => 'wiki_form', :method => :post } }.merge!( config ), &block )
end
|
#wiki_page_history(page = nil, versions = nil) ⇒ Object
119
120
121
122
123
124
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 119
def wiki_page_history(page = nil,versions = nil)
page ||= @page versions ||= @versions || page.versions
render :partial => "#{template_dir '_wiki_page_history'}/wiki_page_history", :locals => { :page => page, :versions => versions, :with_form => (versions.size > 1) }
end
|
#wiki_page_history_path(page = nil) ⇒ Object
22
23
24
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 22
def wiki_page_history_path( page = nil )
wiki_page_path( page, :history )
end
|
#wiki_page_info(page = nil) ⇒ Object
107
108
109
110
111
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 107
def wiki_page_info(page = nil)
page ||= @page
render :partial => "#{template_dir '_wiki_page_info'}/wiki_page_info", :locals => { :page => page }
end
|
#wiki_page_new_path ⇒ Object
11
12
13
14
15
16
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 11
def wiki_page_new_path
if params && params[:path].present?
page = CGI::escape(params[:path])
end
wiki_page_path( page, :new )
end
|
#wiki_page_path(page = nil, action = :show) ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 30
def wiki_page_path( page = nil, action = :show )
if page
page = page.path if page.respond_to? :path
page = nil if page.empty?
url_for( :action => action, :path => page )
else
url_for( :action => action )
end
end
|
#wiki_page_style ⇒ Object
103
104
105
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 103
def wiki_page_style
render :partial => "#{template_dir '_wiki_page_style'}/wiki_page_style"
end
|
#wiki_paginate(collection, &block) ⇒ Object
71
72
73
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 71
def wiki_paginate( collection, &block )
Irwi.config.paginator.paginated_section( self, collection, &block )
end
|
#wiki_user(user) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 49
def wiki_user( user )
return ("<" + wt("Unknown") + ">").html_safe unless user
if user.respond_to?(:name)
user.name
else
"User##{user.id}"
end
end
|
#wt(msg, *args) ⇒ Object
Instead of having to translate strings and defining a default value:
t("Hello World!", :default => 'Hello World!')
We define this method to define the value only once:
wt("Hello World!")
Note that interpolation still works …
wt("Hello {{world}}!", :world => @world)
96
97
98
99
100
101
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 96
def wt(msg, *args)
config = args.
config[:default] = msg if config[:default].blank?
config[:scope] = 'wiki'
I18n.t(msg, config)
end
|