Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 2
- Log:
Initial import of Instiki 0.11.0 sources from a downloaded Tarball.
Instiki is a Ruby On Rails based Wiki clone.
- Author:
- adh
- Date:
- Sat Jul 22 14:54:51 +0100 2006
- Size:
- 3735 Bytes
1 | # The methods added to this helper will be available to all templates in the application. |
2 | module ApplicationHelper |
3 | |
4 | # Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container |
5 | # where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and |
6 | # the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values |
7 | # become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag. |
8 | # |
9 | # Examples (call, result): |
10 | # html_options([["Dollar", "$"], ["Kroner", "DKK"]]) |
11 | # <option value="$">Dollar</option>\n<option value="DKK">Kroner</option> |
12 | # |
13 | # html_options([ "VISA", "Mastercard" ], "Mastercard") |
14 | # <option>VISA</option>\n<option selected>Mastercard</option> |
15 | # |
16 | # html_options({ "Basic" => "$20", "Plus" => "$40" }, "$40") |
17 | # <option value="$20">Basic</option>\n<option value="$40" selected>Plus</option> |
18 | def html_options(container, selected = nil) |
19 | container = container.to_a if Hash === container |
20 | |
21 | html_options = container.inject([]) do |options, element| |
22 | if element.respond_to?(:first) && element.respond_to?(:last) |
23 | if element.last != selected |
24 | options << "<option value=\"#{element.last}\">#{element.first}</option>" |
25 | else |
26 | options << "<option value=\"#{element.last}\" selected>#{element.first}</option>" |
27 | end |
28 | else |
29 | options << ((element != selected) ? "<option>#{element}</option>" : "<option selected>#{element}</option>") |
30 | end |
31 | end |
32 | |
33 | html_options.join("\n") |
34 | end |
35 | |
36 | # Creates a hyperlink to a Wiki page, without checking if the page exists or not |
37 | def link_to_existing_page(page, text = nil, html_options = {}) |
38 | link_to( |
39 | text || page.plain_name, |
40 | {:web => @web.address, :action => 'show', :id => page.name, :only_path => true}, |
41 | html_options) |
42 | end |
43 | |
44 | # Creates a hyperlink to a Wiki page, or to a "new page" form if the page doesn't exist yet |
45 | def link_to_page(page_name, web = @web, text = nil, options = {}) |
46 | raise 'Web not defined' if web.nil? |
47 | UrlGenerator.new(@controller).make_link(page_name, web, text, |
48 | options.merge(:base_url => "#{base_url}/#{web.address}")) |
49 | end |
50 | |
51 | def author_link(page, options = {}) |
52 | UrlGenerator.new(@controller).make_link(page.author.name, page.web, nil, options) |
53 | end |
54 | |
55 | def base_url |
56 | home_page_url = url_for :controller => 'admin', :action => 'create_system', :only_path => true |
57 | home_page_url.sub(%r-/create_system/?$-, '') |
58 | end |
59 | |
60 | # Creates a menu of categories |
61 | def categories_menu |
62 | if @categories.empty? |
63 | '' |
64 | else |
65 | "<div id=\"categories\">\n" + |
66 | '<strong>Categories</strong>:' + |
67 | '[' + link_to_unless_current('Any', :web => @web.address, :action => @action_name) + "]\n" + |
68 | @categories.map { |c| |
69 | link_to_unless_current(c, :web => @web.address, :action => @action_name, :category => c) |
70 | }.join(', ') + "\n" + |
71 | '</div>' |
72 | end |
73 | end |
74 | |
75 | # Performs HTML escaping on text, but keeps linefeeds intact (by replacing them with <br/>) |
76 | def escape_preserving_linefeeds(text) |
77 | h(text).gsub(/\n/, '<br/>') |
78 | end |
79 | |
80 | def format_date(date, include_time = true) |
81 | # Must use DateTime because Time doesn't support %e on at least some platforms |
82 | if include_time |
83 | DateTime.new(date.year, date.mon, date.day, date.hour, date.min, date.sec).strftime("%B %e, %Y %H:%M:%S") |
84 | else |
85 | DateTime.new(date.year, date.mon, date.day).strftime("%B %e, %Y") |
86 | end |
87 | end |
88 | |
89 | def rendered_content(page) |
90 | PageRenderer.new(page.revisions.last).display_content |
91 | end |
92 | |
93 | end |