microengine 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -2
- data/bin/microengine +4 -8
- data/lib/admin.rb +2 -2
- data/lib/admin_page.rb +4 -14
- data/lib/assambler.rb +5 -8
- data/lib/dispatcher.rb +6 -14
- data/lib/file_cache.rb +1 -1
- data/lib/http.rb +11 -35
- metadata +2 -2
data/Rakefile
CHANGED
data/bin/microengine
CHANGED
@@ -18,7 +18,7 @@ if '/' != path[-1..-1]
|
|
18
18
|
path += '/'
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
unless File.directory? path
|
22
22
|
begin
|
23
23
|
FileUtils.mkdir path
|
24
24
|
rescue
|
@@ -29,7 +29,7 @@ end
|
|
29
29
|
|
30
30
|
distr = File.dirname(__FILE__) + '/../'
|
31
31
|
|
32
|
-
|
32
|
+
unless File.exists? path + 'content/layout'
|
33
33
|
files = [
|
34
34
|
"config/*",
|
35
35
|
"content/**/*",
|
@@ -43,14 +43,10 @@ if not File.exists? path + 'content/layout'
|
|
43
43
|
Dir.glob(distr + pattern, File::FNM_DOTMATCH) do |file|
|
44
44
|
filename = path + file[distr.length..-1]
|
45
45
|
FileUtils.mkpath File.dirname(filename)
|
46
|
-
|
47
|
-
FileUtils.install file, filename
|
48
|
-
end
|
46
|
+
FileUtils.install file, filename unless File.directory? file
|
49
47
|
end
|
50
48
|
end
|
51
|
-
|
52
|
-
FileUtils.mkdir path + 'cache/'
|
53
|
-
end
|
49
|
+
FileUtils.mkdir path + 'cache/' unless File.directory? path + 'cache/'
|
54
50
|
|
55
51
|
FileUtils.chmod_R 0777, path + 'content/'
|
56
52
|
FileUtils.chmod 0777, path + 'cache/'
|
data/lib/admin.rb
CHANGED
@@ -59,7 +59,7 @@ module Microengine
|
|
59
59
|
end
|
60
60
|
|
61
61
|
if not blocked? http.ip and right? password
|
62
|
-
|
62
|
+
unless http.cookie['password']
|
63
63
|
http.set_cookie 'password', password
|
64
64
|
end
|
65
65
|
|
@@ -81,7 +81,7 @@ module Microengine
|
|
81
81
|
AdminPage.new(http, path, self).error(e.message)
|
82
82
|
end
|
83
83
|
else
|
84
|
-
|
84
|
+
http.set_cookie 'password', ''
|
85
85
|
block http.ip, 5
|
86
86
|
@access_logger.warn 'Wrong password from ' + http.ip
|
87
87
|
http.status = '403 Forbidden'
|
data/lib/admin_page.rb
CHANGED
@@ -55,7 +55,7 @@ module Microengine
|
|
55
55
|
return
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
unless File.exists? MICROENGINE_ROOT + "/layouts/#{@layout}/#{@lang}.yaml"
|
59
59
|
@old_lang = @lang
|
60
60
|
@lang = @admin.dispatcher.language(@http, @layout_langs)
|
61
61
|
error 'untranslated_layout'
|
@@ -77,27 +77,17 @@ module Microengine
|
|
77
77
|
layout_langs.push File.basename(lang, '.yaml')
|
78
78
|
end
|
79
79
|
untranslated = langs - layout_langs
|
80
|
-
|
81
|
-
@untranslated_layouts[layout] = untranslated
|
82
|
-
end
|
80
|
+
@untranslated_layouts[layout] = untranslated unless untranslated.empty?
|
83
81
|
end
|
84
82
|
|
85
83
|
if @http.post['body'].nil?
|
86
|
-
|
87
|
-
@body = IO.read MICROENGINE_ROOT + "/content#{@path}#{@lang}.body"
|
88
|
-
rescue
|
89
|
-
@body = ''
|
90
|
-
end
|
84
|
+
@body = IO.read MICROENGINE_ROOT + "/content#{@path}#{@lang}.body" rescue @body = ''
|
91
85
|
else
|
92
86
|
@body = @http.post['body']
|
93
87
|
end
|
94
88
|
|
95
89
|
if @http.post['header'].nil?
|
96
|
-
|
97
|
-
@header = IO.read MICROENGINE_ROOT + "/content#{@path}#{@lang}.header"
|
98
|
-
rescue
|
99
|
-
@header = ''
|
100
|
-
end
|
90
|
+
@header = IO.read MICROENGINE_ROOT + "/content#{@path}#{@lang}.header" rescue @header = ''
|
101
91
|
else
|
102
92
|
@header = @http.post['header']
|
103
93
|
end
|
data/lib/assambler.rb
CHANGED
@@ -32,7 +32,7 @@ module Microengine
|
|
32
32
|
@layouts = {}
|
33
33
|
|
34
34
|
begin
|
35
|
-
|
35
|
+
unless File.directory? MICROENGINE_ROOT + '/cache/'
|
36
36
|
FileUtils.mkdir MICROENGINE_ROOT + '/cache/'
|
37
37
|
end
|
38
38
|
FileUtils.rm_r Dir.glob(MICROENGINE_ROOT + '/cache/*')
|
@@ -108,7 +108,7 @@ module Microengine
|
|
108
108
|
def cache_dir(dir)
|
109
109
|
path = MICROENGINE_ROOT + '/content' + dir
|
110
110
|
cache = MICROENGINE_ROOT + '/cache' + dir
|
111
|
-
|
111
|
+
unless File.directory? cache
|
112
112
|
begin
|
113
113
|
Dir.mkdir cache
|
114
114
|
rescue
|
@@ -153,9 +153,8 @@ module Microengine
|
|
153
153
|
# Check name and layout
|
154
154
|
name = name.sub(/(^|\/)\.\.?/, '')
|
155
155
|
dir = MICROENGINE_ROOT + '/layouts/' + name + '/';
|
156
|
-
|
157
|
-
|
158
|
-
end
|
156
|
+
|
157
|
+
raise "Can't find layout #{name} ." unless File.directory?(dir) and File.exists? dir + 'layout.rhtml'
|
159
158
|
|
160
159
|
# Load layout
|
161
160
|
layout = {
|
@@ -165,9 +164,7 @@ module Microengine
|
|
165
164
|
# Load translation
|
166
165
|
Dir.glob(dir + '**.yaml') do |file|
|
167
166
|
lang = File.basename file, '.yaml'
|
168
|
-
if 'layout' == lang
|
169
|
-
next
|
170
|
-
end
|
167
|
+
next if 'layout' == lang
|
171
168
|
layout[lang] = load_translation(file)
|
172
169
|
end
|
173
170
|
layout
|
data/lib/dispatcher.rb
CHANGED
@@ -48,7 +48,7 @@ module Microengine
|
|
48
48
|
|
49
49
|
if spider? http.agent
|
50
50
|
# Search engine spiders (another i18n logic)
|
51
|
-
|
51
|
+
unless http.get['lang'].nil?
|
52
52
|
if langs.include? http.get['lang']
|
53
53
|
http << @cache.get(http.url, http.get['lang'])
|
54
54
|
request.finish
|
@@ -60,7 +60,7 @@ module Microengine
|
|
60
60
|
# Human visitor
|
61
61
|
if http.get['lang']
|
62
62
|
http.set_cookie 'lang', http.get['lang'], 30
|
63
|
-
|
63
|
+
unless langs.include? http.get['lang']
|
64
64
|
http.redirect http.url
|
65
65
|
request.finish
|
66
66
|
next
|
@@ -84,21 +84,15 @@ module Microengine
|
|
84
84
|
def language(http, available)
|
85
85
|
# Language selected manually
|
86
86
|
if not http.get['lang'].nil?
|
87
|
-
if available.include? http.get['lang']
|
88
|
-
return http.get['lang']
|
89
|
-
end
|
87
|
+
return http.get['lang'] if available.include? http.get['lang']
|
90
88
|
elsif http.cookie['lang']
|
91
|
-
if available.include? http.cookie['lang']
|
92
|
-
return http.cookie['lang']
|
93
|
-
end
|
89
|
+
return http.cookie['lang'] if available.include? http.cookie['lang']
|
94
90
|
end
|
95
91
|
|
96
92
|
# Select user language
|
97
93
|
http.langs.each do |lang|
|
98
94
|
lang.downcase!
|
99
|
-
if available.include? lang
|
100
|
-
return lang
|
101
|
-
end
|
95
|
+
return lang if available.include? lang
|
102
96
|
end
|
103
97
|
|
104
98
|
# Select any language
|
@@ -114,9 +108,7 @@ module Microengine
|
|
114
108
|
# Check HTTP_USER_AGENT value for search engine spiders
|
115
109
|
def spider?(agent)
|
116
110
|
@spiders.each do |spider|
|
117
|
-
if agent.include? spider
|
118
|
-
return true
|
119
|
-
end
|
111
|
+
return true if agent.include? spider
|
120
112
|
end
|
121
113
|
false
|
122
114
|
end
|
data/lib/file_cache.rb
CHANGED
data/lib/http.rb
CHANGED
@@ -48,9 +48,7 @@ module Microengine
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def post
|
51
|
-
if @post.nil?
|
52
|
-
@post = format_post @request.in
|
53
|
-
end
|
51
|
+
@post = format_post @request.in if @post.nil?
|
54
52
|
@post
|
55
53
|
end
|
56
54
|
|
@@ -66,9 +64,7 @@ module Microengine
|
|
66
64
|
|
67
65
|
# Send content to user
|
68
66
|
def << (content)
|
69
|
-
|
70
|
-
send_headers
|
71
|
-
end
|
67
|
+
send_headers unless header_sended?
|
72
68
|
@out.print content
|
73
69
|
end
|
74
70
|
|
@@ -85,16 +81,13 @@ module Microengine
|
|
85
81
|
|
86
82
|
# Set header
|
87
83
|
def header(name, value)
|
88
|
-
if header_sended?
|
89
|
-
Initializer.logger.warning 'Header already sended'
|
90
|
-
end
|
91
84
|
@headers << [name, value]
|
92
85
|
end
|
93
86
|
|
94
87
|
# Set cookie
|
95
88
|
def set_cookie(name, value, days=nil)
|
96
89
|
cookie = name + '=' + value + '; path=/'
|
97
|
-
|
90
|
+
unless days.nil?
|
98
91
|
time = Time.now + (days * 86400)
|
99
92
|
cookie += '; expires=' + time.gmtime.strftime('%a %d-%b-%Y %H:%M:S %Z')
|
100
93
|
end
|
@@ -111,13 +104,11 @@ module Microengine
|
|
111
104
|
|
112
105
|
# Format accept languages from string to array
|
113
106
|
def format_langs(langs)
|
114
|
-
if langs.nil? or
|
115
|
-
return []
|
116
|
-
end
|
107
|
+
return [] if langs.nil? or langs.empty?
|
117
108
|
langs = langs.split(',')
|
118
109
|
langs.map! do |lang|
|
119
110
|
index = lang.index(';')
|
120
|
-
|
111
|
+
unless index.nil?
|
121
112
|
lang[0...index]
|
122
113
|
else
|
123
114
|
lang
|
@@ -127,18 +118,12 @@ module Microengine
|
|
127
118
|
|
128
119
|
# Format GET variables in URI as array
|
129
120
|
def format_get(query)
|
130
|
-
if query.empty?
|
131
|
-
return {}
|
132
|
-
end
|
121
|
+
return {} if query.empty?
|
133
122
|
|
134
123
|
vars = {}
|
135
124
|
query = query.split('&').each do |var|
|
136
125
|
var = var.split('=')
|
137
|
-
|
138
|
-
vars[var[0]] = var[1]
|
139
|
-
else
|
140
|
-
vars[var[0]] = true
|
141
|
-
end
|
126
|
+
vars[var[0]] = var[1].nil? ? true : var[1]
|
142
127
|
end
|
143
128
|
vars
|
144
129
|
end
|
@@ -155,9 +140,7 @@ module Microengine
|
|
155
140
|
|
156
141
|
# Format cookies as array
|
157
142
|
def format_cookie(string)
|
158
|
-
if string.nil? or string.empty?
|
159
|
-
return {}
|
160
|
-
end
|
143
|
+
return {} if string.nil? or string.empty?
|
161
144
|
|
162
145
|
cookies = {}
|
163
146
|
string = string.split(';')
|
@@ -170,21 +153,14 @@ module Microengine
|
|
170
153
|
|
171
154
|
# Format POST variables
|
172
155
|
def format_post(input)
|
173
|
-
if 'application/x-www-form-urlencoded' != @env['CONTENT_TYPE']
|
174
|
-
return {}
|
175
|
-
end
|
176
|
-
|
156
|
+
return {} if 'application/x-www-form-urlencoded' != @env['CONTENT_TYPE']
|
177
157
|
post = input.read
|
178
|
-
if post.nil?
|
179
|
-
return {}
|
180
|
-
end
|
158
|
+
return {} if post.nil?
|
181
159
|
|
182
160
|
vars = {}
|
183
161
|
post.split('&').each do |var|
|
184
162
|
var = var.split '='
|
185
|
-
if var[1].nil?
|
186
|
-
var[1] = ''
|
187
|
-
end
|
163
|
+
var[1] = '' if var[1].nil?
|
188
164
|
vars[var[0]] = CGI.unescape(var[1].nil? ? '' : var[1])
|
189
165
|
end
|
190
166
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: microengine
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2008-02-
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2008-02-05 00:00:00 +03:00
|
8
8
|
summary: MicroEngine is a fast, simple and minimalistic site engine.
|
9
9
|
require_paths:
|
10
10
|
- lib
|