Class: Web
- Inherits:
-
Object
- Object
- Web
- Defined in:
- app/models/web.rb
Instance Attribute Summary collapse
-
#additional_style ⇒ Object
Returns the value of attribute additional_style.
-
#address ⇒ Object
Returns the value of attribute address.
-
#allow_uploads ⇒ Object
Returns the value of attribute allow_uploads.
-
#brackets_only ⇒ Object
Returns the value of attribute brackets_only.
-
#color ⇒ Object
Returns the value of attribute color.
-
#count_pages ⇒ Object
Returns the value of attribute count_pages.
-
#markup ⇒ Object
Returns the value of attribute markup.
-
#max_upload_size ⇒ Object
Returns the value of attribute max_upload_size.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#password ⇒ Object
Returns the value of attribute password.
-
#published ⇒ Object
Returns the value of attribute published.
-
#safe_mode ⇒ Object
Returns the value of attribute safe_mode.
Instance Method Summary collapse
- #add_page(page) ⇒ Object
- #authors ⇒ Object
- #categories ⇒ Object
- #has_file?(name) ⇒ Boolean
- #has_page?(name) ⇒ Boolean
-
#initialize(parent_wiki, name, address, password = nil) ⇒ Web
constructor
A new instance of Web.
- #make_file_link(mode, name, text, base_url) ⇒ Object
-
#make_link(name, text = nil, options = {}) ⇒ Object
Create a link for the given page name and link text based on the render mode in options and whether the page exists in the this web.
- #make_page_link(mode, name, text, base_url) ⇒ Object
- #make_pic_link(mode, name, text, base_url) ⇒ Object
-
#refresh_pages_with_references(page_name) ⇒ Object
Clears the display cache for all the pages with references to.
- #refresh_revisions ⇒ Object
- #remove_pages(pages_to_be_removed) ⇒ Object
- #revised_on ⇒ Object
- #select(&condition) ⇒ Object
-
#wiki ⇒ Object
This ensures compatibility with 0.9 storages.
Constructor Details
#initialize(parent_wiki, name, address, password = nil) ⇒ Web
Returns a new instance of Web.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/web.rb', line 14 def initialize(parent_wiki, name, address, password = nil) self.address = address @wiki, @name, @password = parent_wiki, name, password # default values @markup = :textile @color = '008B26' @safe_mode = false @pages = {} @allow_uploads = true @additional_style = nil @published = false @brackets_only = false @count_pages = false @allow_uploads = true @max_upload_size = 100 end |
Instance Attribute Details
#additional_style ⇒ Object
Returns the value of attribute additional_style.
9 10 11 |
# File 'app/models/web.rb', line 9 def additional_style @additional_style end |
#address ⇒ Object
Returns the value of attribute address.
12 13 14 |
# File 'app/models/web.rb', line 12 def address @address end |
#allow_uploads ⇒ Object
Returns the value of attribute allow_uploads.
9 10 11 |
# File 'app/models/web.rb', line 9 def allow_uploads @allow_uploads end |
#brackets_only ⇒ Object
Returns the value of attribute brackets_only.
9 10 11 |
# File 'app/models/web.rb', line 9 def brackets_only @brackets_only end |
#color ⇒ Object
Returns the value of attribute color.
8 9 10 |
# File 'app/models/web.rb', line 8 def color @color end |
#count_pages ⇒ Object
Returns the value of attribute count_pages.
9 10 11 |
# File 'app/models/web.rb', line 9 def count_pages @count_pages end |
#markup ⇒ Object
Returns the value of attribute markup.
8 9 10 |
# File 'app/models/web.rb', line 8 def markup @markup end |
#max_upload_size ⇒ Object
Returns the value of attribute max_upload_size.
10 11 12 |
# File 'app/models/web.rb', line 10 def max_upload_size @max_upload_size end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'app/models/web.rb', line 8 def name @name end |
#pages ⇒ Object
Returns the value of attribute pages.
8 9 10 |
# File 'app/models/web.rb', line 8 def pages @pages end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'app/models/web.rb', line 8 def password @password end |
#published ⇒ Object
Returns the value of attribute published.
9 10 11 |
# File 'app/models/web.rb', line 9 def published @published end |
#safe_mode ⇒ Object
Returns the value of attribute safe_mode.
8 9 10 |
# File 'app/models/web.rb', line 8 def safe_mode @safe_mode end |
Instance Method Details
#add_page(page) ⇒ Object
32 33 34 |
# File 'app/models/web.rb', line 32 def add_page(page) @pages[page.name] = page end |
#authors ⇒ Object
43 44 45 |
# File 'app/models/web.rb', line 43 def select. end |
#categories ⇒ Object
47 48 49 |
# File 'app/models/web.rb', line 47 def categories select.map { |page| page.categories }.flatten.uniq.sort end |
#has_file?(name) ⇒ Boolean
55 56 57 |
# File 'app/models/web.rb', line 55 def has_file?(name) wiki.file_yard(self).has_file?(name) end |
#has_page?(name) ⇒ Boolean
51 52 53 |
# File 'app/models/web.rb', line 51 def has_page?(name) pages[name] end |
#make_file_link(mode, name, text, base_url) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/web.rb', line 59 def make_file_link(mode, name, text, base_url) link = CGI.escape(name) case mode when :export if has_file?(name) then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>" else "<span class=\"newWikiWord\">#{text}</span>" end when :publish if has_file?(name) then "<a class=\"existingWikiWord\" href=\"#{base_url}/published/#{link}\">#{text}</a>" else "<span class=\"newWikiWord\">#{text}</span>" end else if has_file?(name) "<a class=\"existingWikiWord\" href=\"#{base_url}/file/#{link}\">#{text}</a>" else "<span class=\"newWikiWord\">#{text}<a href=\"#{base_url}/file/#{link}\">?</a></span>" end end end |
#make_link(name, text = nil, options = {}) ⇒ Object
Create a link for the given page name and link text based on the render mode in options and whether the page exists in the this web. The links a relative, and will work only if displayed on another WikiPage. It should not be used in menus, templates and such - instead, use link_to_page helper
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/web.rb', line 82 def make_link(name, text = nil, = {}) text = CGI.escapeHTML(text || WikiWords.separate(name)) mode = [:mode] || :show base_url = [:base_url] || '..' link_type = [:link_type] || :show case link_type.to_sym when :show make_page_link(mode, name, text, base_url) when :file make_file_link(mode, name, text, base_url) when :pic make_pic_link(mode, name, text, base_url) else raise "Unknown link type: #{link_type}" end end |
#make_page_link(mode, name, text, base_url) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/models/web.rb', line 99 def make_page_link(mode, name, text, base_url) link = CGI.escape(name) case mode.to_sym when :export if has_page?(name) then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>} else %{<span class="newWikiWord">#{text}</span>} end when :publish if has_page?(name) then %{<a class="existingWikiWord" href="#{base_url}/published/#{link}">#{text}</a>} else %{<span class="newWikiWord">#{text}</span>} end else if has_page?(name) %{<a class="existingWikiWord" href="#{base_url}/show/#{link}">#{text}</a>} else %{<span class="newWikiWord">#{text}<a href="#{base_url}/show/#{link}">?</a></span>} end end end |
#make_pic_link(mode, name, text, base_url) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/web.rb', line 117 def make_pic_link(mode, name, text, base_url) link = CGI.escape(name) case mode.to_sym when :export if has_file?(name) then %{<img alt="#{text}" src="#{link}" />} else %{<img alt="#{text}" src="no image" />} end when :publish if has_file?(name) then %{<img alt="#{text}" src="#{link}" />} else %{<span class="newWikiWord">#{text}</span>} end else if has_file?(name) then %{<img alt="#{text}" src="#{base_url}/pic/#{link}" />} else %{<span class="newWikiWord">#{text}<a href="#{base_url}/pic/#{link}">?</a></span>} end end end |
#refresh_pages_with_references(page_name) ⇒ Object
Clears the display cache for all the pages with references to
137 138 139 140 141 |
# File 'app/models/web.rb', line 137 def refresh_pages_with_references(page_name) select.pages_that_reference(page_name).each { |page| page.revisions.each { |revision| revision.clear_display_cache } } end |
#refresh_revisions ⇒ Object
143 144 145 |
# File 'app/models/web.rb', line 143 def refresh_revisions select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } } end |
#remove_pages(pages_to_be_removed) ⇒ Object
147 148 149 |
# File 'app/models/web.rb', line 147 def remove_pages(pages_to_be_removed) pages.delete_if { |page_name, page| pages_to_be_removed.include?(page) } end |
#revised_on ⇒ Object
151 152 153 |
# File 'app/models/web.rb', line 151 def revised_on select.most_recent_revision end |
#select(&condition) ⇒ Object
155 156 157 |
# File 'app/models/web.rb', line 155 def select(&condition) PageSet.new(self, @pages.values, condition) end |
#wiki ⇒ Object
This ensures compatibility with 0.9 storages
160 161 162 |
# File 'app/models/web.rb', line 160 def wiki @wiki ||= WikiService.instance end |