Module: Irwi::Helpers::WikiPagesHelper
Instance Method Summary
collapse
#wiki_add_page_attachment_path, #wiki_remove_page_attachment_path, #wiki_show_attachments
Instance Method Details
#wiki_content(text) ⇒ Object
37
38
39
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 37
def wiki_content( text )
sanitize( auto_link( Irwi.config.formatter.format( wiki_linkify( wiki_show_attachments(text) ) ) ) )
end
|
#wiki_diff(old_text, new_text) ⇒ Object
41
42
43
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 41
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
67
68
69
70
71
72
73
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 67
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 => title )
end
end
|
#wiki_linkify(str) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 51
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
105
106
107
108
109
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 105
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) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 118
def wiki_page_attachments(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(:wiki_page_attachment,
Irwi.config.page_attachment_class.new,
: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
23
24
25
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 23
def wiki_page_compare_path( page = nil )
wiki_page_path( page, :compare )
end
|
#wiki_page_edit_path(page = nil) ⇒ Object
15
16
17
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 15
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, @page, { :url => url_for( :action => :update ), :html=> { :class => 'wiki_form' } }.merge!( config ), &block )
end
|
#wiki_page_history(page = nil, versions = nil) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 111
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
19
20
21
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 19
def wiki_page_history_path( page = nil )
wiki_page_path( page, :history )
end
|
#wiki_page_info(page = nil) ⇒ Object
99
100
101
102
103
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 99
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(page = nil) ⇒ Object
11
12
13
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 11
def wiki_page_new_path( page = nil )
wiki_page_path( page, :new )
end
|
#wiki_page_path(page = nil, action = :show) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 27
def wiki_page_path( page = nil, action = :show )
if page
page = page.path if page.respond_to? :path
url_for( :action => action, :path => page )
else
url_for( :action => action )
end
end
|
#wiki_page_style ⇒ Object
95
96
97
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 95
def wiki_page_style
render :partial => "#{template_dir '_wiki_page_style'}/wiki_page_style"
end
|
#wiki_paginate(collection, &block) ⇒ Object
63
64
65
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 63
def wiki_paginate( collection, &block )
Irwi.config.paginator.paginated_section( self, collection, &block )
end
|
#wiki_user(user) ⇒ Object
45
46
47
48
49
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 45
def wiki_user( user )
return '<Unknown>'.html_safe unless user
"User##{user.id}"
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)
88
89
90
91
92
93
|
# File 'lib/irwi/helpers/wiki_pages_helper.rb', line 88
def wt(msg, *args)
config = args.
config[:default] = msg
config[:scope] = 'wiki'
I18n.t(msg, config)
end
|