Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 344
- Log:
Massive changeset which brings the old, ROOL customised Instiki
version up to date, but without any ROOL customisations in this
latest checked-in version (which is 0.19.1). This is deliberate,
so that it's easy to see the changes made for the ROOL version
in a subsequent changeset. The 'app/views/shared' directory is not
part of Instiki but is kept to maintain the change history with
updated ROOL customisations, some of which involve the same files
in that same directory.
- Author:
- rool
- Date:
- Sat Mar 19 19:52:13 +0000 2011
- Size:
- 5255 Bytes
1 | # The methods added to this helper will be available to all templates in the application. |
2 | module ApplicationHelper |
3 | require 'instiki_stringsupport' |
4 | |
5 | # Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container |
6 | # where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and |
7 | # the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values |
8 | # become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag. |
9 | # |
10 | # Examples (call, result): |
11 | # html_options([["Dollar", "$"], ["Kroner", "DKK"]]) |
12 | # <option value="$">Dollar</option>\n<option value="DKK">Kroner</option> |
13 | # |
14 | # html_options([ "VISA", "Mastercard" ], "Mastercard") |
15 | # <option>VISA</option>\n<option selected>Mastercard</option> |
16 | # |
17 | # html_options({ "Basic" => "$20", "Plus" => "$40" }, "$40") |
18 | # <option value="$20">Basic</option>\n<option value="$40" selected>Plus</option> |
19 | def html_options(container, selected = nil) |
20 | container = container.to_a if Hash === container |
21 | |
22 | html_options = container.inject([]) do |options, element| |
23 | if element.is_a? Array |
24 | if element.last != selected |
25 | options << "<option value=\"#{element.last}\">#{element.first}</option>" |
26 | else |
27 | options << "<option value=\"#{element.last}\" selected=\"selected\">#{element.first}</option>" |
28 | end |
29 | else |
30 | options << ((element != selected) ? "<option>#{element}</option>" : "<option selected>#{element}</option>") |
31 | end |
32 | end |
33 | |
34 | html_options.join("\n").html_safe |
35 | end |
36 | |
37 | # Creates a hyperlink to a Wiki page, without checking if the page exists or not |
38 | def link_to_existing_page(page, text = nil, html_options = {}) |
39 | link_to( |
40 | text || page.plain_name, |
41 | {:web => @web.address, :action => 'show', :id => page.name, :only_path => true}, |
42 | html_options).html_safe |
43 | end |
44 | |
45 | # Creates a hyperlink to a Wiki page, or to a "new page" form if the page doesn't exist yet |
46 | def link_to_page(page_name, web = @web, text = nil, options = {}) |
47 | raise 'Web not defined' if web.nil? |
48 | UrlGenerator.new(@controller).make_link(@web, page_name, web, text, |
49 | options.merge(:base_url => "#{base_url}/#{web.address}")).html_safe |
50 | end |
51 | |
52 | def author_link(page, options = {}) |
53 | UrlGenerator.new(@controller).make_link(@web, page.author.name, page.web, nil, options).purify.html_safe |
54 | end |
55 | |
56 | # Create a hyperlink to a particular revision of a Wiki page |
57 | def link_to_revision(page, revision_number, text = nil, mode = nil, html_options = {}) |
58 | revision_number == page.revisions.size ? |
59 | link_to( |
60 | text || page.plain_name, |
61 | {:web => @web.address, :action => 'show', :id => page.name, |
62 | :mode => mode}, html_options).html_safe : |
63 | link_to( |
64 | text || page.plain_name + "(rev # #{revision_number})".html_safe, |
65 | {:web => @web.address, :action => 'revision', :id => page.name, |
66 | :rev => revision_number, :mode => mode}, html_options).html_safe |
67 | end |
68 | |
69 | # Create a hyperlink to the history of a particular Wiki page |
70 | def link_to_history(page, text = nil, html_options = {}) |
71 | link_to( |
72 | text || page.plain_name + "(history)".html_safe, |
73 | {:web => @web.address, :action => 'history', :id => page.name}, |
74 | html_options).html_safe |
75 | end |
76 | |
77 | def base_url |
78 | home_page_url = url_for :controller => 'admin', :action => 'create_system', :only_path => true |
79 | home_page_url.sub(%r-/create_system/?$-, '') |
80 | end |
81 | |
82 | # Creates a menu of categories |
83 | def categories_menu |
84 | if @categories.empty? |
85 | '' |
86 | else |
87 | ("<div id=\"categories\">\n" + |
88 | '<strong>Categories</strong>:' + |
89 | '[' + link_to_unless_current('Any', :web => @web.address, :action => self.action_name, :category => nil) + "]\n" + |
90 | @categories.map { |c| |
91 | link_to_unless_current(c.html_safe, :web => @web.address, :action => self.action_name, :category => c) |
92 | }.join(', ') + "\n" + |
93 | '</div>').html_safe |
94 | end |
95 | end |
96 | |
97 | # Performs HTML escaping on text, but keeps linefeeds intact (by replacing them with <br/>) |
98 | def escape_preserving_linefeeds(text) |
99 | h(text).gsub(/\n/, '<br/>').as_utf8 |
100 | end |
101 | |
102 | def format_date(date, include_time = true) |
103 | # Must use DateTime because Time doesn't support %e on at least some platforms |
104 | if include_time |
105 | DateTime.new(date.year, date.mon, date.day, date.hour, date.min, date.sec).strftime("%B %e, %Y %H:%M:%S") |
106 | else |
107 | DateTime.new(date.year, date.mon, date.day).strftime("%B %e, %Y") |
108 | end |
109 | end |
110 | |
111 | def rendered_content(page) |
112 | PageRenderer.new(page.revisions.last).display_content |
113 | end |
114 | |
115 | def truncate(text, *args) |
116 | options = args.extract_options! |
117 | options.reverse_merge!(:length => 30, :omission => "...") |
118 | return text.html_safe if text.num_chars <= options[:length] |
119 | len = options[:length] - options[:omission].as_utf8.num_chars |
120 | t = '' |
121 | text.split.collect do |word| |
122 | if t.num_chars + word.num_chars <= len |
123 | t << word + ' ' |
124 | else |
125 | return (t.chop + options[:omission]).html_safe |
126 | end |
127 | end |
128 | end |
129 | |
130 | end |