Class: Web

Inherits:
Object
  • Object
show all
Defined in:
app/models/web.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, address, password = nil) ⇒ Web

Returns a new instance of Web.



11
12
13
14
# File 'app/models/web.rb', line 11

def initialize(name, address, password = nil)
  @name, @address, @password, @safe_mode = name, address, password, false
  @pages = {}
end

Instance Attribute Details

#additional_styleObject

Returns the value of attribute additional_style.



9
10
11
# File 'app/models/web.rb', line 9

def additional_style
  @additional_style
end

#addressObject

Returns the value of attribute address.



8
9
10
# File 'app/models/web.rb', line 8

def address
  @address
end

#brackets_onlyObject

Returns the value of attribute brackets_only.



9
10
11
# File 'app/models/web.rb', line 9

def brackets_only
  @brackets_only
end

#colorObject

Returns the value of attribute color.



9
10
11
# File 'app/models/web.rb', line 9

def color
  @color
end

#count_pagesObject

Returns the value of attribute count_pages.



9
10
11
# File 'app/models/web.rb', line 9

def count_pages
  @count_pages
end

#markupObject

Default values



74
75
76
# File 'app/models/web.rb', line 74

def markup
  @markup
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'app/models/web.rb', line 8

def name
  @name
end

#pagesObject

Returns the value of attribute pages.



8
9
10
# File 'app/models/web.rb', line 8

def pages
  @pages
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'app/models/web.rb', line 8

def password
  @password
end

#publishedObject

Returns the value of attribute published.



9
10
11
# File 'app/models/web.rb', line 9

def published
  @published
end

#safe_modeObject

Returns the value of attribute safe_mode.



9
10
11
# File 'app/models/web.rb', line 9

def safe_mode
  @safe_mode
end

Instance Method Details

#add_page(page) ⇒ Object



16
17
18
# File 'app/models/web.rb', line 16

def add_page(page)
  @pages[page.name] = page
end

#authorsObject



32
33
34
# File 'app/models/web.rb', line 32

def authors 
  select.authors 
end

#categoriesObject



36
37
38
# File 'app/models/web.rb', line 36

def categories
  select.map { |page| page.categories }.flatten.uniq.sort
end

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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/web.rb', line 43

def make_link(name, text = nil, options = {})
  page = pages[name]
  text = text || WikiWords.separate(name)
  link = CGI.escape(name)
  
  case options[:mode]
    when :export
      if page then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
      else "<span class=\"newWikiWord\">#{text}</span>" end
    when :publish
      if page then "<a class=\"existingWikiWord\" href=\"../show/#{link}\">#{text}</a>"
      else "<span class=\"newWikiWord\">#{text}</span>" end
    else
      if page then "<a class=\"existingWikiWord\" href=\"../show/#{link}\">#{text}</a>"
      else "<span class=\"newWikiWord\">#{text}<a href=\"../show/#{link}\">?</a></span>" end
  end
end

#refresh_pages_with_references(page_name) ⇒ Object

Clears the display cache for all the pages with references to



63
64
65
66
67
# File 'app/models/web.rb', line 63

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_revisionsObject



69
70
71
# File 'app/models/web.rb', line 69

def refresh_revisions
  select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } }
end

#remove_pages(pages_to_be_removed) ⇒ Object



20
21
22
# File 'app/models/web.rb', line 20

def remove_pages(pages_to_be_removed)
  pages.delete_if { |page_name, page| pages_to_be_removed.include?(page) }
end

#revised_onObject



28
29
30
# File 'app/models/web.rb', line 28

def revised_on
  select.most_recent_revision
end

#select(&accept) ⇒ Object



24
25
26
# File 'app/models/web.rb', line 24

def select(&accept)
  PageSet.new(self, @pages.values, accept)
end