Class: Microengine::AdminPage
- Inherits:
-
Object
- Object
- Microengine::AdminPage
- Defined in:
- lib/admin_page.rb
Overview
Admin interface
Instance Method Summary collapse
-
#deleter ⇒ Object
Show interface to delete page.
-
#editor ⇒ Object
Show interface to edit page.
-
#error(code) ⇒ Object
Error.
-
#initialize(http, path, admin) ⇒ AdminPage
constructor
A new instance of AdminPage.
-
#refresher ⇒ Object
Show interface to input password for refresh cache.
-
#untranslater ⇒ Object
Show interface to delete translation.
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 |
# File 'lib/admin_page.rb', line 23 def initialize(http, path, admin) @http = http @path = '/' + path @admin = admin @show_password = http.['password'].nil? 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
#deleter ⇒ Object
Show interface to delete page
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/admin_page.rb', line 99 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 |
#editor ⇒ Object
Show interface to edit page
52 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 |
# File 'lib/admin_page.rb', line 52 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
137 138 139 140 |
# File 'lib/admin_page.rb', line 137 def error(code) @code = code display 'error' end |
#refresher ⇒ Object
Show interface to input password for refresh cache
132 133 134 |
# File 'lib/admin_page.rb', line 132 def refresher display 'refresher' end |
#untranslater ⇒ Object
Show interface to delete translation
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/admin_page.rb', line 117 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 |