swee 0.0.1
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.
- checksums.yaml +7 -0
- data/README.md +212 -0
- data/Rakefile +4 -0
- data/bin/swee +38 -0
- data/doc/tmp.rb +77 -0
- data/lib/swee.rb +5 -0
- data/lib/swee/app_executor.rb +152 -0
- data/lib/swee/config.rb +118 -0
- data/lib/swee/connection.rb +48 -0
- data/lib/swee/controller.rb +158 -0
- data/lib/swee/controller_filter.rb +67 -0
- data/lib/swee/daemonize.rb +17 -0
- data/lib/swee/engine.rb +201 -0
- data/lib/swee/exception.rb +2 -0
- data/lib/swee/helper.rb +29 -0
- data/lib/swee/installer.rb +58 -0
- data/lib/swee/lodder.rb +92 -0
- data/lib/swee/middlewaves/common_logger.rb +29 -0
- data/lib/swee/middlewaves/content_length.rb +21 -0
- data/lib/swee/middlewaves/reloader.rb +24 -0
- data/lib/swee/patches/logger.rb +15 -0
- data/lib/swee/routes.rb +46 -0
- data/lib/swee/server.rb +298 -0
- data/lib/swee/support.rb +79 -0
- data/lib/swee/swee_logger.rb +59 -0
- data/lib/swee/thin/headers.rb +40 -0
- data/lib/swee/thin/request.rb +162 -0
- data/lib/swee/thin/response.rb +177 -0
- data/lib/swee/version.rb +3 -0
- data/lib/swee/view.rb +36 -0
- data/lib/template/config.rb +38 -0
- data/lib/template/controllers/HomeController.rb +11 -0
- data/lib/template/public/404.html +66 -0
- data/lib/template/routes.rb +11 -0
- data/lib/template/todo_config.rb +75 -0
- data/lib/template/views/home/index.erb +2 -0
- metadata +164 -0
data/lib/swee/version.rb
ADDED
data/lib/swee/view.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
module Swee
|
4
|
+
class View
|
5
|
+
include Helper
|
6
|
+
def initialize controller
|
7
|
+
@controller = controller
|
8
|
+
@config = Swee.config.app
|
9
|
+
get_binding
|
10
|
+
end
|
11
|
+
|
12
|
+
# 把controller 实变量绑定到 view 层
|
13
|
+
def get_binding
|
14
|
+
@controller.instance_variables.each do |v|
|
15
|
+
instance_variable_set v, @controller.instance_variable_get(v)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# 读取视图文件
|
20
|
+
# controller/action.erb
|
21
|
+
def create_view
|
22
|
+
erb = ::ERB.new(File.read(File.expand_path("views/#{@controller._name}/#{@controller.action_name}.erb", ENV["app_path"])))
|
23
|
+
erb.result(binding)
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
# 404页面
|
28
|
+
def render_404
|
29
|
+
cfg = Swee.config.app
|
30
|
+
body = ::ERB.new(File.read(File.expand_path(cfg["page404"], ENV["app_path"]))).result
|
31
|
+
headers = { "Content-Type" => "text/html; charset=utf8" }
|
32
|
+
[200,headers,[body]]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Swee
|
2
|
+
|
3
|
+
# 服务器配置
|
4
|
+
server_config do |cfg|
|
5
|
+
|
6
|
+
# 日志文件位置 => [日志文件, 文件数量, 文件大小]
|
7
|
+
cfg.log_file = [ "./logs/development.log", 10, 10240000 ]
|
8
|
+
|
9
|
+
# 日志等级
|
10
|
+
cfg.logger_level = :debug
|
11
|
+
|
12
|
+
# 重启模式
|
13
|
+
# :touch => 请配置 touch_file, 并指定 restart.txt 文件位置
|
14
|
+
# :pid => 请配置 pid_file, 并制定 pid 文件位置
|
15
|
+
cfg.restart_mode = :touch
|
16
|
+
cfg.touch_file = "./tmp/restart.txt"
|
17
|
+
cfg.pid_file = "./tmp/pid"
|
18
|
+
|
19
|
+
# 是否改变代码立刻reload(重载)
|
20
|
+
cfg.code_reload = true
|
21
|
+
|
22
|
+
# 最大连接数
|
23
|
+
cfg.max_connections = 1024
|
24
|
+
|
25
|
+
# 是否后台运行(守护进程模式)
|
26
|
+
cfg.run_background = false
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# 应用配置
|
31
|
+
app_config do |cfg|
|
32
|
+
|
33
|
+
# 配置 404 页面路径(相对于项目路径)
|
34
|
+
cfg.page404 = "./public/404.html"
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>页面不存在</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<div class="dialog">
|
59
|
+
<div>
|
60
|
+
<h1>抱歉,您访问的页面不存在</h1>
|
61
|
+
<p>也许您地址输入错误了或者当前地址已经被删除</p>
|
62
|
+
</div>
|
63
|
+
<p>请查看日志获取更多信息</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Swee
|
2
|
+
|
3
|
+
# 应用配置
|
4
|
+
app_config do |cfg|
|
5
|
+
cfg.time_zone = "Beijing"
|
6
|
+
cfg.default_locale = "zh-CN"
|
7
|
+
cfg.include_path = ["./initialize"]
|
8
|
+
cfg.email = {
|
9
|
+
domain: "xxx.xxx.com",
|
10
|
+
username: "xxxx",
|
11
|
+
password: "123456"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
# 服务器配置
|
16
|
+
server_config do |cfg|
|
17
|
+
|
18
|
+
# 处理请求方式
|
19
|
+
cfg.handle_request_mode = :event_loop
|
20
|
+
# cfg.handle_request_mode :thread
|
21
|
+
|
22
|
+
# 性能监控
|
23
|
+
cfg.performance_monitoring = true
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
app_plugin_cfg do |cfg|
|
30
|
+
cfg.user_system do |us|
|
31
|
+
us.password_enpty :md5 # md5 或 sha2
|
32
|
+
us.password_enpty_length 16 # 16位 或 32位
|
33
|
+
|
34
|
+
us.third_part_login_include :qq,
|
35
|
+
pid: "xxxxxxxxxxxx",
|
36
|
+
sid: "xxxxxxxxxxxx",
|
37
|
+
username: "xxxxxxxxxxxxxx"
|
38
|
+
|
39
|
+
us.third_part_login_include :weibo,
|
40
|
+
pid: "xxxxxxxxxxxx",
|
41
|
+
sid: "xxxxxxxxxxxx",
|
42
|
+
username: "xxxxxxxxxxxxxx"
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
cfg.uploader do |upl|
|
47
|
+
upl.image_pattern = /jpg|jpeg|gif|png|bmp/
|
48
|
+
upl.max_magabyte = 20
|
49
|
+
|
50
|
+
cut do |s|
|
51
|
+
s[:large] = { size: [1280,960], type: "#" }
|
52
|
+
s[:mid] = { size: [640,480], type: "#" }
|
53
|
+
s[:thumb] = [ size: [320,240], type: "#" }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
cfg.payments do |pm|
|
57
|
+
pm.pid = "xxxxxxxx"
|
58
|
+
pm.sid = "xxxxxxxx"
|
59
|
+
pm.email = "xxxxxxxxxxxxx"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# 数据库配置
|
64
|
+
database_config do |cfg|
|
65
|
+
cfg.adapter = :mysql2
|
66
|
+
cfg.database = :timeboxs_development
|
67
|
+
cfg.host = :localhost
|
68
|
+
cfg.username = :root
|
69
|
+
cfg.password = ""
|
70
|
+
cfg.encoding = :utf8
|
71
|
+
cfg.pool = 5
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "秀秀"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thin
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: "用ruby语言实现,自带轻量级的http服务器"
|
98
|
+
email:
|
99
|
+
- 177365340@qq.com
|
100
|
+
executables:
|
101
|
+
- swee
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/swee
|
108
|
+
- doc/tmp.rb
|
109
|
+
- lib/swee.rb
|
110
|
+
- lib/swee/app_executor.rb
|
111
|
+
- lib/swee/config.rb
|
112
|
+
- lib/swee/connection.rb
|
113
|
+
- lib/swee/controller.rb
|
114
|
+
- lib/swee/controller_filter.rb
|
115
|
+
- lib/swee/daemonize.rb
|
116
|
+
- lib/swee/engine.rb
|
117
|
+
- lib/swee/exception.rb
|
118
|
+
- lib/swee/helper.rb
|
119
|
+
- lib/swee/installer.rb
|
120
|
+
- lib/swee/lodder.rb
|
121
|
+
- lib/swee/middlewaves/common_logger.rb
|
122
|
+
- lib/swee/middlewaves/content_length.rb
|
123
|
+
- lib/swee/middlewaves/reloader.rb
|
124
|
+
- lib/swee/patches/logger.rb
|
125
|
+
- lib/swee/routes.rb
|
126
|
+
- lib/swee/server.rb
|
127
|
+
- lib/swee/support.rb
|
128
|
+
- lib/swee/swee_logger.rb
|
129
|
+
- lib/swee/thin/headers.rb
|
130
|
+
- lib/swee/thin/request.rb
|
131
|
+
- lib/swee/thin/response.rb
|
132
|
+
- lib/swee/version.rb
|
133
|
+
- lib/swee/view.rb
|
134
|
+
- lib/template/config.rb
|
135
|
+
- lib/template/controllers/HomeController.rb
|
136
|
+
- lib/template/public/404.html
|
137
|
+
- lib/template/routes.rb
|
138
|
+
- lib/template/todo_config.rb
|
139
|
+
- lib/template/views/home/index.erb
|
140
|
+
homepage: ''
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.9.2
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.2.2
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: swee是一个简单的web框架
|
164
|
+
test_files: []
|