nekonote-framework 1.0.0.pre.beta3 → 1.0.0.pre.beta4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00eabea6fe9875a31c1e00c10bf8d5b69fd75df1504126ccecd9a45b0b53cc49
4
- data.tar.gz: 11f1a32532b1efcaebc1fda354b594d2730a94b2910f66141e6fac1e05a1398b
3
+ metadata.gz: 93b75ef49754ba2acb077f4e48561f052963a1003069aacb5ea5e25c3b63ad8c
4
+ data.tar.gz: 991045d68698d89d11998f3799ae5ba0c9a7e8d06f79ea0a5b9b93cfe382e477
5
5
  SHA512:
6
- metadata.gz: bd9e66323d6a3e68f6f36d408de30d2ce2dfc82ca1cc2e6f674821ea785551f2755c1070d0524bf6cae016f869d812c1e79ab5abf114a4f4b28551f00a7ae5d5
7
- data.tar.gz: 66c85acf1a1bfc53e618f203d21405e516a8d609a377bdb0bf09d9765b16245501129b46254cd9d8846451e44d7f8dc7c7398fe115093537c11ad0f657a8c454
6
+ metadata.gz: c5004e020a5d4c40ccbb99a41025eda8c894a71c597f1f6486d008ecd3390f7815485761f2e25bf4a02ff4d2d1deed37b0711cc23fa84902cea84a54f96db56a
7
+ data.tar.gz: fbd87c7eb9ca444e8ac5761a346ea4c7df3fe8290d570fa80d5376f6dc9db3c968216e93168a50b3c705b29fce981d9581a42d930027438edb05a20f10b72a08
data/README.md CHANGED
@@ -1,44 +1,43 @@
1
1
  # Nekonote Framework
2
-
3
- Nekonote Framework is a small web application framework that helps your web development.
2
+ Simple and Lightweight Ruby Framework for Web Development
4
3
 
5
4
  ## Features
6
5
 
7
6
  ### Simple
8
- "Simplicity" is one of most important things. Nekonote Framework is simple and easy to learn.
7
+ Nekonote Framework is simple and easy to learn.
9
8
 
10
9
  ### Lightweight
11
- Nekonote Framework is not full-stack framework. It's small and Lightweight.
10
+ It's not a kind of full-stack framework. Small and Lightweight.
12
11
 
13
12
  ### Rack-based
14
- Nekonote Framework can generate Rack application easily even if you are not familiar with Rack.
13
+ You can generate a Rack application easily.
15
14
 
16
15
  ### MVC
17
- Nekonote Framework is designed as Push-MVC based architecture.
16
+ It's Push-MVC based architecture.
18
17
 
19
- ### Application Structure
20
- It's possible to generate a structure of application by running nekonote command.
18
+ ### Structure
19
+ You can get started with a application structure.
21
20
 
22
- ### Sanitizing
23
- Nekonote Framework can sanitize HTTP request parameters as your expected.
21
+ ### Web Server
22
+ "nekonote" command can controll a web server.
24
23
 
25
- ### Strict Routes
26
- You can configure routes easily by the configuration files. You may set some rules to them.
24
+ ### Routing
25
+ You can define routes for your application in the configuration files.
27
26
 
28
- ### Error Pages
29
- You may configure routes for error pages by the configuration file.
27
+ ### Error Routes
28
+ You may define the routes for when some exceptional things happend.
30
29
 
31
- ### Separable Environments
32
- It's possible to separate the configuration files by environments.
30
+ ### Environments
31
+ You can configure environments for your application.
33
32
 
34
33
  ### GUI Debuger
35
- The GUI-based debugger can display exception details on your browser.
34
+ It can display exception's details on your browser.
36
35
 
37
- ### Multiprocess-safe Logger
38
- Nekonote Framework provides you safety logging. It's multiprocess-safety and thread-safety.
36
+ ### Logger
37
+ It provides you thread-safe logging.
39
38
 
40
- ### Liquid Template Engine
41
- Liquid is a well-known powerful template engine. Templates are rendered by Liquid.
39
+ Template Engine
40
+ The templating engine on Nekonote Framework is Liquid.
42
41
 
43
42
  ## Getting Started
44
43
 
@@ -13,11 +13,13 @@
13
13
  # custom: some value # unknown fields are not directive. It will be assigned into your templates.
14
14
 
15
15
  # ----------------------
16
- # Route Options
16
+ # routing options
17
17
  # ----------------------
18
18
  preference:
19
19
  path_as_regexp: false
20
20
  allow_dup_slash: false
21
+ template_file_extension: tpl
22
+ layout_file_extension: tpl
21
23
 
22
24
  # ----------------------
23
25
  # Routes
data/lib/nekonote/core.rb CHANGED
@@ -83,7 +83,7 @@ module Nekonote
83
83
 
84
84
  # load and initialize logger if it has been enabled
85
85
  def self.init_logger
86
- pref_logger = Preference.instance.get_logger true # don't use property cache
86
+ pref_logger = Preference.instance.get_logger
87
87
 
88
88
  if pref_logger['write_exception'] == true
89
89
  @@logger_write_exception = true
@@ -16,6 +16,7 @@ module Nekonote
16
16
  MSG_INVALID_FIELD = %(Invalid format field '%s' in '%s'.)
17
17
  MSG_MISSING_CONST = %(Not found such class or module or contant -> '%s'.)
18
18
  MSG_EMPTY_FILE_NOT_EMPTY = %('%s' is not empty. Failed to create an empty file.)
19
+ MSG_NOT_FOUND_DIRECTIVE = %('%s' directive is required in '%s')
19
20
 
20
21
  # write message as warning to log file if logging is enabled
21
22
  # @param string msg
@@ -32,8 +33,6 @@ module Nekonote
32
33
 
33
34
  # @param StandardError e
34
35
  def self.abort(e)
35
- logging_error e
36
-
37
36
  # if executed from cli do not throw exception
38
37
  if Nekonote.from_cli?
39
38
  warn "#{e.class}; =(-x-=;)" + $/
@@ -44,6 +43,9 @@ module Nekonote
44
43
  exit 1
45
44
  end
46
45
 
46
+ # logging when logger is enabled
47
+ logging_error e
48
+
47
49
  raise e
48
50
  end
49
51
 
@@ -4,8 +4,8 @@ module Nekonote
4
4
  MSG_WRONG_YAML_SYNTAX = %(The yaml file '%s' is invalid syntax.)
5
5
  MSG_MISSING_INCLUDE = %(No such field '%s' in %s.)
6
6
  MSG_INVALID_HANDLER_NAME = %(Handler class name '%s' is invalid.)
7
- MSG_DUPLICATE_PATH = %(There is the duplicate path in %s. Values of 'path' directive are supposed to be uniq.)
8
- MSG_EVAL_MIDDLEWARES = %(Unable to evaluate '%s' because there's something wrong.)
7
+ MSG_DUPLICATE_PATH = %(There is the duplicate path in %s. Values of 'path' directive are supposed to be unique.)
8
+ MSG_EVAL_MIDDLEWARES = %(Failed to run '%s')
9
9
  MSG_FAILED_INI_HANDLER = %(Failed to make a %s class object.)
10
10
  end
11
11
  end
@@ -8,10 +8,18 @@ module Nekonote
8
8
  # for route.yml
9
9
  FIELD_ROUTE_INCLUDE = 'include'
10
10
 
11
- # for route options
12
- FIELD_OPTION_ROUTE = 'preference'
11
+ # routing options
12
+ FIELD_ROUTING_OPTIONS = 'preference'
13
13
  FIELD_OPTION_ROUTE_REGEXP = 'path_as_regexp'
14
14
  FIELD_OPTION_ALLOW_DUP_SLASH = 'allow_dup_slash'
15
+ FIELD_OPTION_TEMPLATE_EXT = 'template_file_extension'
16
+ FIELD_OPTION_LAYOUT_EXT = 'layout_file_extension'
17
+
18
+ # default values for routing options
19
+ DEFAULT_OPTION_ROUTE_REGEXP = false
20
+ DEFAULT_OPTION_ALLOW_DUP_SLASH = false
21
+ DEFAULT_OPTION_TEMPLATE_FILE_EXT = 'tpl'
22
+ DEFAULT_OPTION_LAYOUT_FILE_EXT = 'tpl'
15
23
 
16
24
  # for route_error.yml
17
25
  FIELD_ROUTE_ERR_MISSING_ROUTE = 'missing_route'
@@ -63,8 +71,7 @@ module Nekonote
63
71
  :path_logger_yml
64
72
 
65
73
  def initialize
66
- env = Nekonote.get_env
67
- path = Nekonote.get_root_path + YamlAccess::DIR_PREFERENCE + "/#{env}/"
74
+ path = Nekonote.get_root_path + YamlAccess::DIR_PREFERENCE + "/#{Nekonote.get_env}/"
68
75
 
69
76
  @path_route_yml = path + 'route.yml'
70
77
  @path_route_include_yml = path + 'route_include.yml'
@@ -73,132 +80,139 @@ module Nekonote
73
80
  @path_middlewares_rb = path + 'middlewares.rb'
74
81
  @path_logger_yml = path + 'logger.yml'
75
82
 
76
- @parsed_route_yml = nil
77
- @parsed_route_include_yml = nil
78
- @parsed_route_error_yml = nil
79
- @parsed_public_yml = nil
80
- @parsed_mw_yml = nil
81
- @parsed_logger_yml = nil
82
-
83
- # in route.yml
84
- @is_path_regexp = nil
85
- @is_allow_dup_slash = nil
86
-
87
- # in middleware.yml
83
+ # check if GUI debugger is on? this value will be set from rackup
88
84
  @is_enabled_show_exceptions = nil
89
85
 
90
- # check there are required yaml files
86
+ # check if config.ru and route.yml exists
91
87
  if !Util::Filer.available_file? 'config.ru'
92
88
  msg = Error::MSG_MISSING_RACKUP% @@root_path + $/
93
89
  msg += Error::SPACE + Error::MSG_WRONG_ROOT
94
90
  raise Error, msg
95
- end
96
-
97
- if !Util::Filer.available_file? @path_route_yml
91
+ elsif !Util::Filer.available_file? @path_route_yml
98
92
  raise PreferenceError, Error::MSG_MISSING_FILE% @path_route_yml
99
93
  end
100
- end
101
-
102
- # @param string field
103
- # @return bool
104
- public
105
- def has_error_route?(field)
106
- pref = get_route_error
107
94
 
108
- # missing route_error.yml
109
- if pref == nil
110
- Error.warning "Missing a file which for error routes #{@path_route_error_yml}."
111
- return false
112
- end
113
-
114
- return pref[field].is_a?(Hash) && pref[field][FIELD_ROUTE_HANDLER].is_a?(String)
95
+ # read preferences from configuration files
96
+ init_pref
115
97
  end
116
98
 
117
- # @param bool fresh
118
- # @return hash or exit from program
99
+ # @return hash
100
+ # @throws PreferenceError
119
101
  public
120
- def get_route(fresh = false)
121
- if !@parsed_route_yml.is_a?(Hash) || fresh
122
- @parsed_route_yml = YamlAccess::get_parsed_route @path_route_yml
123
- if @parsed_route_yml.size == 0
124
- raise PreferenceError, PreferenceError::MSG_EMPTY_YAML% @path_route_yml
125
- end
126
- end
102
+ def get_route
127
103
  return @parsed_route_yml
128
104
  end
129
105
 
130
- # @param bool fresh
131
106
  # @return hash
132
107
  public
133
- def get_route_include(fresh = false)
134
- if !@parsed_route_include_yml.is_a?(Hash) || fresh
135
- @parsed_route_include_yml = YamlAccess::get_parsed @path_route_include_yml
136
- end
108
+ def get_route_include
137
109
  return @parsed_route_include_yml
138
110
  end
139
111
 
140
- # @param bool fresh
141
112
  # @return hash
142
113
  public
143
- def get_route_error(fresh = false)
144
- if !@parsed_route_error_yml.is_a?(Hash) || fresh
145
- @parsed_route_error_yml = YamlAccess::get_parsed @path_route_error_yml
146
- end
114
+ def get_route_error
147
115
  return @parsed_route_error_yml
148
116
  end
149
117
 
150
- # @param bool fresh
151
118
  # @return hash
152
119
  public
153
- def get_public(fresh = false)
154
- if !@parsed_public_yml.is_a?(Hash) || fresh
155
- @parsed_public_yml = YamlAccess::get_parsed @path_public_yml
156
- end
120
+ def get_public
157
121
  return @parsed_public_yml
158
122
  end
159
123
 
160
- # @param bool fresh
161
124
  # @return hash
162
125
  public
163
- def get_logger(fresh = false)
164
- if !@parsed_logger_yml.is_a?(Hash) || fresh
165
- @parsed_logger_yml = YamlAccess::get_parsed @path_logger_yml
166
- end
126
+ def get_logger
167
127
  return @parsed_logger_yml
168
128
  end
169
129
 
170
- # @param bool fresh
130
+ # @param string field
171
131
  # @return bool
172
132
  public
173
- def is_path_regexp?(fresh = false)
174
- if @is_path_regexp == nil || fresh
175
- pref = YamlAccess::get_parsed @path_route_yml
176
-
177
- if pref[FIELD_OPTION_ROUTE].is_a?(Hash) \
178
- && (pref[FIELD_OPTION_ROUTE][FIELD_OPTION_ROUTE_REGEXP] == true || pref[FIELD_OPTION_ROUTE][FIELD_OPTION_ROUTE_REGEXP] == 1)
179
- @is_path_regexp = true # using Nekonote::URLMapper
180
- else
181
- @is_path_regexp = false # using ::Rack::URLMap
182
- end
133
+ def has_error_route?(field)
134
+ # not found route_error.yml just return false, error pages is not required
135
+ if @parsed_route_error_yml == nil
136
+ return false
183
137
  end
184
138
 
139
+ return @parsed_route_error_yml.is_a?(Hash) && @parsed_route_error_yml[field][FIELD_ROUTE_HANDLER].is_a?(String)
140
+ end
141
+
142
+ # @return bool
143
+ public
144
+ def is_path_regexp?
185
145
  return @is_path_regexp
186
146
  end
187
147
 
188
- # @param bool fresh
189
148
  # @return bool
190
149
  public
191
- def is_allow_dup_slash?(fresh = false)
192
- if @is_allow_dup_slash == nil || fresh
193
- pref = YamlAccess::get_parsed @path_route_yml
194
- if pref[FIELD_OPTION_ROUTE].is_a?(Hash) && pref[FIELD_OPTION_ROUTE][FIELD_OPTION_ALLOW_DUP_SLASH] != nil
195
- @is_allow_dup_slash = pref[FIELD_OPTION_ROUTE][FIELD_OPTION_ALLOW_DUP_SLASH]
196
- else
197
- @is_allow_dup_slash = false
198
- end
150
+ def is_allow_dup_slash?
151
+ return @is_allow_dup_slash
152
+ end
153
+
154
+ # @return string
155
+ public
156
+ def get_template_file_extension
157
+ return @template_file_extension
158
+ end
159
+
160
+ # @return string
161
+ public
162
+ def get_layout_file_extension
163
+ return @layout_file_extension
164
+ end
165
+
166
+ # initialize preferences
167
+ public
168
+ def init_pref
169
+ @parsed_route_yml = YamlAccess::get_parsed_route @path_route_yml
170
+ @parsed_route_include_yml = YamlAccess::get_parsed @path_route_include_yml
171
+ @parsed_route_error_yml = YamlAccess::get_parsed @path_route_error_yml
172
+ @parsed_public_yml = YamlAccess::get_parsed @path_public_yml
173
+ @parsed_logger_yml = YamlAccess::get_parsed @path_logger_yml
174
+
175
+ # check if found available route
176
+ if @parsed_route_yml.size == 0
177
+ raise PreferenceError, PreferenceError::MSG_EMPTY_YAML% @path_route_yml
199
178
  end
200
179
 
201
- return @is_allow_dup_slash
180
+ # set route options
181
+ init_routing_options
182
+ end
183
+
184
+ # initialize routing options
185
+ public
186
+ def init_routing_options
187
+ @is_path_regexp = nil
188
+ @is_allow_dup_slash = nil
189
+ @template_file_extension = nil
190
+ @layout_file_extension = nil
191
+
192
+ # read route.yml
193
+ pref = YamlAccess::get_parsed @path_route_yml
194
+
195
+ # not found but already it's checked though
196
+ return if !pref.is_a?(Hash)
197
+
198
+ routing_options = pref['preference']
199
+
200
+ # not found routing options to default
201
+ return if !routing_options.is_a?(Hash)
202
+
203
+ # set value to property
204
+ # true -> Nekonote::URLMapper, false -> :Rack::URLMap
205
+ @is_path_regexp = routing_options[FIELD_OPTION_ROUTE_REGEXP] || DEFAULT_OPTION_ROUTE_REGEXP
206
+ @is_allow_dup_slash = routing_options[FIELD_OPTION_ALLOW_DUP_SLASH] || DEFAULT_OPTION_ALLOW_DUP_SLASH
207
+ @template_file_extension = routing_options[FIELD_OPTION_TEMPLATE_EXT] || DEFAULT_OPTION_TEMPLATE_FILE_EXT
208
+ @layout_file_extension = routing_options[FIELD_OPTION_LAYOUT_EXT] || DEFAULT_OPTION_LAYOUT_FILE_EXT
209
+
210
+ # validation for file extension
211
+ if !@template_file_extension.is_a?(String) || @template_file_extension == ''
212
+ raise PreferenceError, Error::MSG_WRONG_TYPE% [FIELD_OPTION_TEMPLATE_EXT, 'String']
213
+ elsif !@layout_file_extension.is_a?(String) || @layout_file_extension == ''
214
+ raise PreferenceError, Error::MSG_WRONG_TYPE% [FIELD_OPTION_LAYOUT_EXT, 'String']
215
+ end
202
216
  end
203
217
 
204
218
  # @param array info information about route
@@ -149,8 +149,10 @@ module Nekonote
149
149
  # evaluate middlewares.rb as Ruby codes
150
150
  path = Preference.instance.path_middlewares_rb
151
151
  begin
152
+ # run middlewares.rb
152
153
  instance_eval IO.read path
153
154
  rescue => e
155
+ # when the web server deamonized it will be output into log/puma.stderr.log
154
156
  warn <<EOS
155
157
  #{PreferenceError::MSG_EVAL_MIDDLEWARES% path}
156
158
 
@@ -300,8 +302,8 @@ EOS
300
302
  # set app
301
303
  begin
302
304
  routes[info[Preference::FIELD_ROUTE_PATH].strip] = Object.const_get(handler).new(info)
303
- rescue NameError
304
- raise PreferenceError, PreferenceError::MSG_FAILED_INI_HANDLER% info[Preference::FIELD_ROUTE_HANDLER]
305
+ rescue NameError => e
306
+ Error.abort e
305
307
  end
306
308
 
307
309
  paths << path
data/lib/nekonote/spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Nekonote
2
2
  LIBS_NAME = %(nekonote-framework).freeze
3
- VERSION = %(1.0.0-beta3).freeze
3
+ VERSION = %(1.0.0-beta4).freeze
4
4
  HOMEPAGE = %(https://nekonote-framework.github.io).freeze
5
5
  SUMMARY = %(Simple and Lightweight Ruby Framework for Web Development).freeze
6
6
  DESCRIPTION = %(Nekonote Framework is a small web application framework that helps your web development.).freeze
data/lib/nekonote/view.rb CHANGED
@@ -122,13 +122,12 @@ module Nekonote
122
122
  # if nil is given for layout and/or template, No template and/or layout will be used
123
123
  if @template_path != nil && !Util::Filer.available_file?(@template_path)
124
124
  raise ViewError, ViewError::MSG_MISSING_TEMPLATE_FILE% @template_path
125
- end
126
125
 
127
- if @layout_path != nil && !Util::Filer.available_file?(@layout_path)
126
+ elsif @layout_path != nil && !Util::Filer.available_file?(@layout_path)
128
127
  raise ViewError, ViewError::MSG_MISSING_LAYOUT_FILE% @layout_path
129
128
  end
130
129
 
131
- @response.write get_parsed(@template_path, @layout_path)
130
+ @response.write get_parsed
132
131
  end
133
132
 
134
133
  # @param string|symbol subject
@@ -313,14 +312,16 @@ module Nekonote
313
312
  # @return string absolute path
314
313
  private
315
314
  def get_template_path(template)
316
- return Nekonote.get_root_path + PATH_TO_TEMPLATE + '/' + template + '.tpl'
315
+ ext = Preference.instance.get_template_file_extension
316
+ return "#{Nekonote.get_root_path}#{PATH_TO_TEMPLATE}/#{template}.#{ext}"
317
317
  end
318
318
 
319
319
  # @param string layout relative path to layout file
320
320
  # @return string absolute path
321
321
  private
322
322
  def get_layout_path(layout)
323
- return Nekonote.get_root_path + PATH_TO_LAYOUT + '/' + layout + '.tpl'
323
+ ext = Preference.instance.get_layout_file_extension
324
+ return "#{Nekonote.get_root_path}#{PATH_TO_LAYOUT}/#{layout}.#{ext}"
324
325
  end
325
326
 
326
327
  # Returns template path for the default when it was found and available
@@ -390,21 +391,19 @@ module Nekonote
390
391
  end
391
392
  end
392
393
 
393
- # @param string|nil template_path
394
- # @param string|nil layout_path
395
394
  # @return string
396
395
  private
397
- def get_parsed(template_path = nil, layout_path = nil)
396
+ def get_parsed
398
397
  data = ''
399
398
  liq_tpl_template = nil
400
399
  liq_tpl_layout = nil
401
400
  begin
402
- if template_path.is_a? String
403
- liq_tpl_template = Liquid::Template.parse IO.read(template_path)
401
+ if @template_path.is_a? String
402
+ liq_tpl_template = Liquid::Template.parse IO.read(@template_path)
404
403
  end
405
404
 
406
- if layout_path.is_a? String
407
- liq_tpl_layout = Liquid::Template.parse IO.read(layout_path)
405
+ if @layout_path.is_a? String
406
+ liq_tpl_layout = Liquid::Template.parse IO.read(@layout_path)
408
407
  end
409
408
 
410
409
  # parse and render template
@@ -23,6 +23,7 @@ module Nekonote
23
23
 
24
24
  # Returns the parsed routing information
25
25
  # @param string path
26
+ # @return hash
26
27
  def self.get_parsed_route(path)
27
28
  if !Util::Filer.available_file? path
28
29
  return nil
@@ -34,7 +35,7 @@ module Nekonote
34
35
  route_list = []
35
36
  ast.root.children.each_with_index do |node, index|
36
37
  cnt = index / 2
37
- if node.is_a?(Psych::Nodes::Scalar) && node.value != Preference::FIELD_OPTION_ROUTE
38
+ if node.is_a?(Psych::Nodes::Scalar) && node.value != Preference::FIELD_ROUTING_OPTIONS
38
39
  route_list[cnt] = {Preference::FIELD_ROUTE_HANDLER => node.value}
39
40
  elsif node.is_a? Psych::Nodes::Mapping
40
41
  if route_list[cnt].is_a? Hash
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nekonote-framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta3
4
+ version: 1.0.0.pre.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - khotta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-05 00:00:00.000000000 Z
11
+ date: 2018-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: color_echo