Class: WikiService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWikiService

Returns a new instance of WikiService.



10
11
12
# File 'app/models/wiki_service.rb', line 10

def initialize
  @webs, @system = {}, {}
end

Instance Attribute Details

#systemObject (readonly)

Returns the value of attribute system.



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

def system
  @system
end

#websObject (readonly)

Returns the value of attribute webs.



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

def webs
  @webs
end

Instance Method Details

#authenticate(password) ⇒ Object



18
19
20
# File 'app/models/wiki_service.rb', line 18

def authenticate(password)
  password == (@system["password"] || "instiki")
end

#create_web(name, address, password = nil) ⇒ Object



27
28
29
# File 'app/models/wiki_service.rb', line 27

def create_web(name, address, password = nil)
  @webs[address] = Web.new(name, address, password) unless @webs[address]
end

#delete_bliki_entry(web_address, page_name) ⇒ Object

{{{



126
127
128
# File 'app/models/wiki_service.rb', line 126

def delete_bliki_entry(web_address, page_name) #{{{
  @webs[web_address].bliki.delete(page_name)
end

#delete_page(web_address, page_name) ⇒ Object

deletes a page from the web.



76
77
78
# File 'app/models/wiki_service.rb', line 76

def delete_page(web_address, page_name) #{{{
  @webs[web_address].pages.delete(page_name)
end

#read_bliki_entry(web_address, page_name) ⇒ Object

Bliki commands ————————————————————-



104
105
106
# File 'app/models/wiki_service.rb', line 104

def read_bliki_entry(web_address, page_name)
  @webs[web_address].bliki[page_name]
end

#read_page(web_address, page_name) ⇒ Object



49
50
51
# File 'app/models/wiki_service.rb', line 49

def read_page(web_address, page_name)
  @webs[web_address].pages[page_name]
end

#remove_orphaned_pages(web_address) ⇒ Object



71
72
73
# File 'app/models/wiki_service.rb', line 71

def remove_orphaned_pages(web_address)
  @webs[web_address].remove_pages(@webs[web_address].select.orphaned_pages)
end

#rename_page(web_address, old_page_name, new_page_name) ⇒ Object

renames a page in the web.



81
82
83
84
85
86
87
# File 'app/models/wiki_service.rb', line 81

def rename_page(web_address, old_page_name, new_page_name) #{{{
  web = @webs[web_address]
  page = web.pages.delete(old_page_name)
  page or raise "unknown page: #{old_page_name.to_s};; #{pages.keys.join(',')}"
  page.name = new_page_name
  web.pages[new_page_name] = page
end

#revise_bliki_entry(web_address, page_name, content, revised_on, author) ⇒ Object



114
115
116
117
118
# File 'app/models/wiki_service.rb', line 114

def revise_bliki_entry(web_address, page_name, content, revised_on, author)
  page = read_bliki_entry(web_address, page_name)
  page.revise(content, revised_on, author)
  page
end

#revise_page(web_address, page_name, content, revised_on, author) ⇒ Object



59
60
61
62
63
# File 'app/models/wiki_service.rb', line 59

def revise_page(web_address, page_name, content, revised_on, author)
  page = read_page(web_address, page_name)
  page.revise(content, revised_on, author)
  page
end

#rollback_bliki_entry(web_address, page_name, revision_number, created_at) ⇒ Object



120
121
122
123
124
# File 'app/models/wiki_service.rb', line 120

def rollback_bliki_entry(web_address, page_name, revision_number, created_at)
  page = read_bliki_entry(web_address, page_name)
  page.rollback(revision_number, created_at)
  page
end

#rollback_page(web_address, page_name, revision_number, created_at, author_id = nil) ⇒ Object



65
66
67
68
69
# File 'app/models/wiki_service.rb', line 65

def rollback_page(web_address, page_name, revision_number, created_at, author_id = nil)
  page = read_page(web_address, page_name)
  page.rollback(revision_number, created_at, author_id)
  page
end

#save_menu_pref(web, type, limit, content, category) ⇒ Object

}}}



89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/models/wiki_service.rb', line 89

def save_menu_pref(web, type, limit, content, category) #{{{
  web.menu_type = type
  web.menu_limit = limit
  web.menu_content = content
  web.menu_category = category
  if web.menu_type == 'user'
    # only calculate the rendered content once:
    web.rendered_menu = Page.new(
      web, 'menu', @params["content"], Time.now, ''
    ).revisions.last.display_content
  end
end

#setup(password, web_name, web_address) ⇒ Object



22
23
24
25
# File 'app/models/wiki_service.rb', line 22

def setup(password, web_name, web_address)
  @system["password"] = password
  create_web(web_name, web_address)
end

#setup?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/models/wiki_service.rb', line 14

def setup?
  !@system.empty?
end

#update_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false, password = nil, published = false, brackets_only = false, count_pages = false) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/wiki_service.rb', line 31

def update_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false, 
    password = nil, published = false, brackets_only = false, count_pages = false)
  if old_address != new_address
    @webs[new_address] = @webs[old_address]
    @webs.delete(old_address)
    @webs[new_address].address = new_address
  end
  
  web = @webs[new_address]
  web.refresh_revisions if settings_changed?(web, markup, safe_mode, brackets_only)
  
  web.name, web.markup, web.color, web.additional_style, web.safe_mode = 
    name, markup, color, additional_style, safe_mode
    
  web.password, web.published, web.brackets_only, web.count_pages =
    password, published, brackets_only, count_pages
end

#write_bliki_entry(web_address, page_name, content, written_on, author) ⇒ Object



108
109
110
111
112
# File 'app/models/wiki_service.rb', line 108

def write_bliki_entry(web_address, page_name, content, written_on, author)
  page = Page.new(@webs[web_address], page_name, content, written_on, author)
  @webs[web_address].add_bliki_entry(page)
  page
end

#write_page(web_address, page_name, content, written_on, author) ⇒ Object



53
54
55
56
57
# File 'app/models/wiki_service.rb', line 53

def write_page(web_address, page_name, content, written_on, author)
  page = Page.new(@webs[web_address], page_name, content, written_on, author)
  @webs[web_address].add_page(page)
  page
end