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
All below getters know their default values.
- #color ⇒ Object
- #count_pages ⇒ Object
- #markup ⇒ Object
- #max_upload_size ⇒ Object
-
#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(name, content, created_at, author) ⇒ 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
-
#set_compatible_defaults ⇒ Object
Explicitly sets value of some web attributes to defaults, unless they are already set.
- #wiki ⇒ Object
Constructor Details
#initialize(parent_wiki, name, address, password = nil) ⇒ Web
Returns a new instance of Web.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/web.rb', line 15 def initialize(parent_wiki, name, address, password = nil) self.address = address @wiki, @name, @password = parent_wiki, name, password set_compatible_defaults @pages = {} @allow_uploads = true @additional_style = nil @published = false @count_pages = false @allow_uploads = true 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.
10 11 12 |
# File 'app/models/web.rb', line 10 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
All below getters know their default values. This is necessary to ensure compatibility with 0.9 storages, where they were not defined.
40 |
# File 'app/models/web.rb', line 40 def brackets_only() @brackets_only || false end |
#color ⇒ Object
41 |
# File 'app/models/web.rb', line 41 def color() @color ||= '008B26' end |
#count_pages ⇒ Object
42 |
# File 'app/models/web.rb', line 42 def count_pages() @count_pages || false end |
#markup ⇒ Object
43 |
# File 'app/models/web.rb', line 43 def markup() @markup ||= :textile end |
#max_upload_size ⇒ Object
44 |
# File 'app/models/web.rb', line 44 def max_upload_size() @max_upload_size || 100; 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(name, content, created_at, author) ⇒ Object
47 48 49 50 51 |
# File 'app/models/web.rb', line 47 def add_page(name, content, created_at, ) page = Page.new(self, name) page.revise(content, created_at, ) @pages[page.name] = page end |
#authors ⇒ Object
60 61 62 |
# File 'app/models/web.rb', line 60 def select. end |
#categories ⇒ Object
64 65 66 |
# File 'app/models/web.rb', line 64 def categories select.map { |page| page.categories }.flatten.uniq.sort end |
#has_file?(name) ⇒ Boolean
72 73 74 |
# File 'app/models/web.rb', line 72 def has_file?(name) wiki.file_yard(self).has_file?(name) end |
#has_page?(name) ⇒ Boolean
68 69 70 |
# File 'app/models/web.rb', line 68 def has_page?(name) pages[name] end |
#make_file_link(mode, name, text, base_url) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/web.rb', line 76 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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/web.rb', line 99 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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/web.rb', line 116 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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/models/web.rb', line 134 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
150 151 152 153 154 |
# File 'app/models/web.rb', line 150 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
156 157 158 |
# File 'app/models/web.rb', line 156 def refresh_revisions select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } } end |
#remove_pages(pages_to_be_removed) ⇒ Object
160 161 162 |
# File 'app/models/web.rb', line 160 def remove_pages(pages_to_be_removed) pages.delete_if { |page_name, page| pages_to_be_removed.include?(page) } end |
#revised_on ⇒ Object
164 165 166 |
# File 'app/models/web.rb', line 164 def revised_on select.most_recent_revision end |
#select(&condition) ⇒ Object
168 169 170 |
# File 'app/models/web.rb', line 168 def select(&condition) PageSet.new(self, @pages.values, condition) end |
#set_compatible_defaults ⇒ Object
Explicitly sets value of some web attributes to defaults, unless they are already set
30 31 32 33 34 35 36 37 |
# File 'app/models/web.rb', line 30 def set_compatible_defaults @markup = markup() @color = color() @safe_mode = safe_mode() @brackets_only = brackets_only() @max_upload_size = max_upload_size() @wiki = wiki end |
#wiki ⇒ Object
45 |
# File 'app/models/web.rb', line 45 def wiki() @wiki ||= WikiService.instance; end |