Class: Microengine::AdminPage

Inherits:
Object
  • Object
show all
Defined in:
lib/admin_page.rb

Overview

Admin interface

Instance Method Summary collapse

Constructor Details

#initialize(http, path, admin) ⇒ AdminPage

Returns a new instance of AdminPage.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/admin_page.rb', line 23

def initialize(http, path, admin)
  @http = http
  @path = '/' + path
  @admin = admin
  password = http.cookie['password']
  @show_password = password.nil? or password.empty?
  
  if not @http.post['layout'].nil?
    @layout = @http.post['default_layout']
  elsif '/admin/refresh/' == http.url
    @layout = @admin.config['default_layout']
  elsif File.exists? MICROENGINE_ROOT + "/content#{@path}layout"
    begin
      @layout = IO.read MICROENGINE_ROOT + "/content#{@path}layout"
    rescue
      @layout = @admin.config['default_layout']
    end
  else
    @layout = @admin.config['default_layout']
  end
  @layout_langs = []
  Dir.glob(MICROENGINE_ROOT + "/layouts/#{@layout}/*.yaml") do |lang|
    @layout_langs.push File.basename(lang, '.yaml')
  end
  
  @lang = language
  load_translation
end

Instance Method Details

#deleterObject

Show interface to delete page



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/admin_page.rb', line 100

def deleter
  if '/admin/' == @path[0..6]
    error 'admin_subdir'
    return
  end
  if @admin.cache.langs[@path].nil?
    @admin.dispatcher.not_found @http
    return
  end
  if ['/404/', '/403/', '/'].include? @path
    error 'delete_system'
    return
  end
  @body = IO.read MICROENGINE_ROOT + "/content#{@path}#{@lang}.body"
  display 'deleter'
end

#editorObject

Show interface to edit page



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/admin_page.rb', line 53

def editor
  if '/admin/' == @path[0..6]
    error 'admin_subdir'
    return
  end
  
  unless File.exists? MICROENGINE_ROOT + "/layouts/#{@layout}/#{@lang}.yaml"
    @old_lang = @lang
    @lang = @admin.dispatcher.language(@http, @layout_langs)
    error 'untranslated_layout'
    return
  end
  
  @layouts = []
  @untranslated_layouts = {}
  if @admin.cache.langs[@path].nil?
    langs = [@lang]
  else
    langs = @admin.cache.langs[@path] + [@lang]
  end
  Dir.glob(MICROENGINE_ROOT + '/layouts/*/layout.rhtml') do |file|
    layout = file.split('/')[-2]
    @layouts.push layout
    layout_langs = []
    Dir.glob(MICROENGINE_ROOT + "/layouts/#{layout}/*.yaml") do |lang|
      layout_langs.push File.basename(lang, '.yaml')
    end
    untranslated = langs - layout_langs
    @untranslated_layouts[layout] = untranslated unless untranslated.empty?
  end
  
  if @http.post['body'].nil?
    @body = IO.read MICROENGINE_ROOT + "/content#{@path}#{@lang}.body" rescue @body = ''
  else
    @body = @http.post['body']
  end
  
  if @http.post['header'].nil?
    @header = IO.read MICROENGINE_ROOT + "/content#{@path}#{@lang}.header" rescue @header = ''
  else
    @header = @http.post['header']
  end
  
  display 'editor'
end

#error(code) ⇒ Object

Error



138
139
140
141
# File 'lib/admin_page.rb', line 138

def error(code)
  @code = code
  display 'error'
end

#refresherObject

Show interface to input password for refresh cache



133
134
135
# File 'lib/admin_page.rb', line 133

def refresher
  display 'refresher'
end

#untranslaterObject

Show interface to delete translation



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/admin_page.rb', line 118

def untranslater
  if '/admin/' == @path[0..6]
    error 'admin_subdir'
    return
  end
  if @admin.cache.langs[@path].nil?
    @admin.dispatcher.not_found @http
    return
  end
  
  @body = IO.read MICROENGINE_ROOT + "/content#{@path}#{@lang}.body"
  display 'untranslater'
end