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.



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

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

Instance Attribute Details

#default_webObject

Returns the value of attribute default_web.



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

def default_web
  @default_web
end

#systemObject (readonly)

Returns the value of attribute system.



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

def system
  @system
end

#websObject (readonly)

Returns the value of attribute webs.



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

def webs
  @webs
end

Instance Method Details

#authenticate(password) ⇒ Object



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

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

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



33
34
35
# File 'app/models/wiki_service.rb', line 33

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

{{{



159
160
161
# File 'app/models/wiki_service.rb', line 159

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.



102
103
104
# File 'app/models/wiki_service.rb', line 102

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 ————————————————————-



137
138
139
# File 'app/models/wiki_service.rb', line 137

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

#read_page(web_address, page_name) ⇒ Object



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

def read_page(web_address, page_name)
  web = @webs[web_address]
  web ? web.pages[page_name] : nil
end

#remove_orphaned_pages(web_address) ⇒ Object



95
96
97
# File 'app/models/wiki_service.rb', line 95

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.



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

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}; #{web.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



147
148
149
150
151
# File 'app/models/wiki_service.rb', line 147

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, edit_type) ⇒ Object



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

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

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



153
154
155
156
157
# File 'app/models/wiki_service.rb', line 153

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



89
90
91
92
93
# File 'app/models/wiki_service.rb', line 89

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_address, type, limit, content, category, author) ⇒ Object

Menu commands ————————————————————–



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/models/wiki_service.rb', line 117

def save_menu_pref(web_address, type, limit, content, category, author) #{{{
  web = @webs[web_address]
  web.menu_type              = type
  web.menu_limit             = limit
  web.menu_category          = category

  if Page === web.menu_content
    web.menu_content.revise( 
      content, Time.now, '', author 
    )
  else
    # Protect old Pimki storages.
    web.menu_content = Page.new(
      web, 'menu', content, Time.now, ''
    )
  end
end

#setup(password, web_name, web_address) ⇒ Object



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

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

#setup?Boolean

Returns:

  • (Boolean)


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

def setup?
  !@system.empty?
end

#update_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false, password = nil, published = false, default_to_published = false, brackets_only = false, count_pages = false, mind_map_size = "7,7", symbols_map = nil, links_map = nil, snapshots_interval = 1, enable_dclick_edit = nil, enable_menu = true, check_pass_on_edit = false, prog = nil, graph_type = nil, missing = nil, show_authors = nil, show_leaves = nil, selected_categories = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/wiki_service.rb', line 37

def update_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false, 
    password = nil, published = false, default_to_published = false, brackets_only = false,
    count_pages = false, mind_map_size="7,7", symbols_map=nil, links_map=nil,
    snapshots_interval = 1,
    enable_dclick_edit=nil, enable_menu=true, check_pass_on_edit=false,
    prog=nil, graph_type=nil, missing=nil, show_authors=nil, show_leaves=nil, selected_categories=nil) 

  if old_address != new_address
    @webs[new_address] = @webs[old_address]
    @webs.delete(old_address)
    @webs[new_address].address = new_address
  end

  self.class.snapshot_interval_hours = snapshots_interval
  
  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.default_to_published, web.brackets_only, web.count_pages =
    password, published, default_to_published, brackets_only, count_pages
    
  web.enable_dclick_edit, web.enable_menu, web.check_pass_on_edit = enable_dclick_edit, enable_menu, check_pass_on_edit
  
  web.mind_map_size, web.mm_prog, web.mm_graph_type, web.mm_show_missing =
    mind_map_size, prog, graph_type, missing

  web.mm_show_authors, web.mm_show_leaves, web.mm_selected_categories = 
    show_authors, show_leaves, selected_categories
  
  web.symbols_map, web.links_map = symbols_map, links_map
end

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



141
142
143
144
145
# File 'app/models/wiki_service.rb', line 141

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



77
78
79
80
81
# File 'app/models/wiki_service.rb', line 77

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