nekonote-framework 1.0.0.pre.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +49 -0
  4. data/bin/nekonote +45 -0
  5. data/data/structure/Gemfile +25 -0
  6. data/data/structure/config.ru +14 -0
  7. data/data/structure/handler/base.rb +21 -0
  8. data/data/structure/handler/error.rb +35 -0
  9. data/data/structure/handler/welcome.rb +11 -0
  10. data/data/structure/lib/.gitkeep +0 -0
  11. data/data/structure/preference/development/logger.yml +62 -0
  12. data/data/structure/preference/development/middlewares.rb +152 -0
  13. data/data/structure/preference/development/public.yml +29 -0
  14. data/data/structure/preference/development/route.yml +30 -0
  15. data/data/structure/preference/development/route_error.yml +28 -0
  16. data/data/structure/preference/development/route_include.yml +22 -0
  17. data/data/structure/preference/development/server/puma.rb +63 -0
  18. data/data/structure/preference/development/setting/example.yml +40 -0
  19. data/data/structure/preference/development/setting/site.yml +3 -0
  20. data/data/structure/preference/development/setting/welcome.yml +7 -0
  21. data/data/structure/public/css/layout/common.css +11 -0
  22. data/data/structure/public/css/layout/default.css +3 -0
  23. data/data/structure/public/css/layout/error.css +3 -0
  24. data/data/structure/public/css/welcome.css +47 -0
  25. data/data/structure/public/favicon.ico +0 -0
  26. data/data/structure/public/img/.gitkeep +0 -0
  27. data/data/structure/public/img/logo.png +0 -0
  28. data/data/structure/public/js/.gitkeep +0 -0
  29. data/data/structure/static/layout/default.tpl +19 -0
  30. data/data/structure/static/layout/error.tpl +15 -0
  31. data/data/structure/static/sass/welcome.scss +52 -0
  32. data/data/structure/static/template/error.tpl +4 -0
  33. data/data/structure/static/template/welcome/index.tpl +26 -0
  34. data/data/structure/tmp/pids/.gitkeep +0 -0
  35. data/lib/loader.rb +83 -0
  36. data/lib/nekonote.rb +9 -0
  37. data/lib/nekonote/cli.rb +702 -0
  38. data/lib/nekonote/cmd_parser.rb +55 -0
  39. data/lib/nekonote/core.rb +116 -0
  40. data/lib/nekonote/env.rb +56 -0
  41. data/lib/nekonote/exception/cli_error.rb +34 -0
  42. data/lib/nekonote/exception/error.rb +75 -0
  43. data/lib/nekonote/exception/handler_error.rb +5 -0
  44. data/lib/nekonote/exception/logger_error.rb +8 -0
  45. data/lib/nekonote/exception/page_cache_error.rb +6 -0
  46. data/lib/nekonote/exception/preference_error.rb +11 -0
  47. data/lib/nekonote/exception/view_error.rb +7 -0
  48. data/lib/nekonote/handler.rb +274 -0
  49. data/lib/nekonote/handler/protected_methods.rb +119 -0
  50. data/lib/nekonote/liquid/tag_env_get.rb +12 -0
  51. data/lib/nekonote/liquid/tag_setting_get.rb +12 -0
  52. data/lib/nekonote/logger.rb +135 -0
  53. data/lib/nekonote/page_cache.rb +111 -0
  54. data/lib/nekonote/preference.rb +215 -0
  55. data/lib/nekonote/puma.rb +131 -0
  56. data/lib/nekonote/rack/rack_static.rb +17 -0
  57. data/lib/nekonote/rack/rack_static_file.rb +19 -0
  58. data/lib/nekonote/rack/url_mapper.rb +193 -0
  59. data/lib/nekonote/rackup.rb +319 -0
  60. data/lib/nekonote/request.rb +295 -0
  61. data/lib/nekonote/setting.rb +59 -0
  62. data/lib/nekonote/spec.rb +22 -0
  63. data/lib/nekonote/util/filer.rb +69 -0
  64. data/lib/nekonote/util/process.rb +43 -0
  65. data/lib/nekonote/view.rb +398 -0
  66. data/lib/nekonote/yaml_access.rb +60 -0
  67. metadata +144 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5de2cc68d527ef357666746ae5cc4423a2c2a0a3
4
+ data.tar.gz: 68348bd3c64514ea3738588c5678158fb07fe42f
5
+ SHA512:
6
+ metadata.gz: af4a645150d95e69f18663b56b31d0cb28c54187d1e286df35e9d89254e7295b40eb681b9fcc42dcbe34527be5912cff3c64aef9cf1b926ed2a8a8540de228c6
7
+ data.tar.gz: 441702f028749ca8df4b0d0770c66cde538f17ff52882d7803e61e23725e1d193cfcd1e67858a45edc4f3e560195c6518cf057b90c292121c9a88618833d4d3d
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Kazuya Hotta
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # Nekonote Framework
2
+
3
+ Nekonote Framework is a small web application framework that helps your web development.
4
+
5
+ ## Features
6
+
7
+ ### Simple
8
+ "Simplicity" is one of most important things. Nekonote Framework is simple and easy to learn.
9
+
10
+ ### Lightweight
11
+ Nekonote Framework is not full-stack framework. It's small and Lightweight.
12
+
13
+ ### Rack-based
14
+ Nekonote Framework can generate Rack application easily even if you are not familiar with Rack.
15
+
16
+ ### MVC
17
+ Nekonote Framework is designed as Push-MVC based architecture.
18
+
19
+ ### Application Structure
20
+ It's possible to generate a structure of application by running nekonote command.
21
+
22
+ ### Sanitizing
23
+ Nekonote Framework can sanitize HTTP request parameters as your expected.
24
+
25
+ ### Strict Routes
26
+ You can configure routes easily by the configuration files. You may set some rules to them.
27
+
28
+ ### Error Pages
29
+ You may configure routes for error pages by the configuration file.
30
+
31
+ ### Separable Environments
32
+ It's possible to separate the configuration files by environments.
33
+
34
+ ### GUI Debuger
35
+ The GUI-based debugger can display exception details on your browser.
36
+
37
+ ### Multiprocess-safe Logger
38
+ Nekonote Framework provides you safety logging. It's multiprocess-safety and thread-safety.
39
+
40
+ ### Liquid Template Engine
41
+ Liquid is a well-known powerful template engine. Templates are rendered by Liquid.
42
+
43
+ ## Getting Started
44
+
45
+ Please see [Getting Started](https://nekonote-framework.github.io/document/1.0.0-beta/getting-started.html) on the reference manual.
46
+
47
+ ## License
48
+
49
+ Nekonote Framework is friendly license and is released under the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ begin
5
+ require 'color_echo'
6
+ require 'nekonote'
7
+ rescue LoadError
8
+ # couldn't find them in LOAD_PATH
9
+ # installed via bundler? change LOAD_PATH to bundler
10
+ require 'bundler/setup'
11
+ require 'color_echo'
12
+ require 'nekonote'
13
+ end
14
+
15
+ rescue LoadError => e
16
+ warn 'LoadError: ' + $/ + %( #{e.message})
17
+ exit 1
18
+ end
19
+
20
+ begin
21
+ root = nil
22
+
23
+ # parse options
24
+ parser = Nekonote::CmdParser.new $*
25
+ if parser.version_option?
26
+ Nekonote::Cli.version
27
+
28
+ elsif parser.help_option?
29
+ Nekonote::Cli.usage
30
+
31
+ elsif parser.root_option?
32
+ root = parser.get_op_val_root
33
+ raise Nekonote::CLIError, 'Missing value with --root option.' if root == nil
34
+ end
35
+
36
+ options = {
37
+ :root => root
38
+ }
39
+
40
+ cmd, subcmd, val = parser.parse_un_options
41
+ Nekonote::Cli.new(cmd, subcmd, val, options).exec
42
+
43
+ rescue StandardError, ScriptError => e
44
+ Nekonote::Error.abort e
45
+ end
@@ -0,0 +1,25 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Nekonote Framework
4
+ # Copyright (c) 2017, Kazuya Hotta
5
+ # License https://github.com/khotta/Nekonote-Framework/blob/master/LICENSE
6
+ gem 'nekonote-framework', 'REPLACE_ME_TO_NEKONOTE_VERSION'
7
+ gem 'simple_rotate', '~> 1.2', '>= 1.2.0'
8
+ gem 'color_echo', '~> 3.1', '>= 3.1.1'
9
+
10
+ # Rack
11
+ # Copyright (c) 2007-2016 Christian Neukirchen <purl.org/net/chneukirchen>
12
+ # License https://github.com/rack/rack/blob/master/COPYING
13
+ gem 'rack', '~> 2.0', '>= 2.0.3'
14
+
15
+ # Liquid
16
+ # Copyright (c) 2005, 2006 Tobias Luetke
17
+ # License https://github.com/Shopify/liquid/blob/master/LICENSE
18
+ gem 'liquid', '~> 4.0', '>= 4.0.0'
19
+
20
+ # Puma
21
+ # Some code copyright (c) 2005, Zed Shaw
22
+ # Copyright (c) 2011, Evan Phoenix
23
+ # License https://github.com/puma/puma/blob/master/LICENSE
24
+ # Note: It seems that 'restart' doesn't work with 'bundler exec' in version 3.9.2
25
+ gem 'puma', '3.8.2'
@@ -0,0 +1,14 @@
1
+ # This is a configuration file about Rack which created automatically.
2
+ # You must NOT delete this file.
3
+
4
+ # for starting web server withouht 'nekonote server'
5
+ if !defined? Nekonote
6
+ require 'bundler/setup'
7
+ require 'nekonote'
8
+ end
9
+
10
+ # set-up your application
11
+ Nekonote.set_root File.expand_path(File.dirname(__FILE__)) if !Nekonote.has_root?
12
+ self.instance_exec &Nekonote::Rackup.instance.use_middlewares
13
+ self.instance_exec Nekonote::Preference.instance.get_public, &Nekonote::Rackup.instance.define_public_dir
14
+ self.instance_exec Nekonote::Preference.instance.get_route, &Nekonote::Rackup.instance.define_route
@@ -0,0 +1,21 @@
1
+ # BaseHandler class
2
+ #
3
+ # BaseHandler class is a mechanism for code reuse in each Handler classes.
4
+ # All Handler classes are supposed to be inherited from this class.
5
+
6
+ class BaseHandler < Nekonote::Handler
7
+ # This method will be executed at first
8
+ def __pre
9
+ end
10
+
11
+ # This method will be executed at last
12
+ def __post
13
+ if @custom_fields['page-title'].is_a? String
14
+ base = __setting_get :site, :title
15
+ if base != nil
16
+ list = {:title => "#{@custom_fields['page-title']} - #{base}"}
17
+ __assign list
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ class ErrorHandler < BaseHandler
2
+ def missing_route
3
+ @subject = 'Invalid URL'
4
+ @msg = 'The URL does not match any route'
5
+ @detail = %('#{Nekonote::Env.get :REQUEST_URI}' does not match any route.)
6
+ end
7
+
8
+ def wrong_http_method
9
+ @subject = 'Unacceptable HTTP method'
10
+ @msg = 'You have accessed with the unacceptable HTTP method.'
11
+ end
12
+
13
+ def fatal
14
+ @subject = 'Server Error'
15
+ @msg = 'You can not access this page temporary.'
16
+ end
17
+
18
+ def not_found
19
+ @subject = 'No such resource'
20
+ @msg = %('#{Nekonote::Env.get :REQUEST_URI}' was not found on the server.)
21
+ end
22
+
23
+ # It will be called at last
24
+ def __post
25
+ # assign values to templates
26
+ list = {}
27
+ list['subject'] = @subject if defined?(@subject)
28
+ list['msg'] = @msg if defined?(@msg)
29
+ list['detail'] = @detail if defined?(@detail)
30
+ __assign list
31
+
32
+ # change the response code to not 500 but 200
33
+ __set_code 200
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ class WelcomeHandler < BaseHandler
2
+ def index
3
+ variables = {
4
+ 'version' => Nekonote::VERSION,
5
+ 'description' => Nekonote::DESCRIPTION,
6
+ 'root' => Nekonote.get_root,
7
+ 'env' => Nekonote::Env.current
8
+ }
9
+ __assign variables
10
+ end
11
+ end
File without changes
@@ -0,0 +1,62 @@
1
+ # Logger Configuration
2
+
3
+ # false to disable
4
+ # true to enable
5
+ enabled: true
6
+
7
+ # Path to a logfile which is supposed to be written log messages.
8
+ # e.g. log/%s.log
9
+ logfile: log/%s.log
10
+
11
+ # Configures if the logger writes the exception details to the log file when some exception raised.
12
+ write_exception: true
13
+
14
+ # Log message format
15
+ # log:
16
+ # Configures a log message format.
17
+ # datetime:
18
+ # The date format for the variable $DATE in ‘log’ directive.
19
+ format:
20
+ log: "$DATE [$LEVEL] $LOG"
21
+ datetime: "%a %d %b %H:%M:%S"
22
+
23
+ # Sets from which log severity levels are should be reported to the log file.
24
+ threshold: debug
25
+
26
+ # The default log severity level for log messages
27
+ default_log_level: info
28
+
29
+ # Sets the threshold to rotate log files.
30
+ limit: 1G
31
+
32
+ # Sets the maximum number of old log files.
33
+ # 0 to keeping all old log files.
34
+ keep: 0
35
+
36
+ # Configures if old log files are compressed when rotation is done.
37
+ # enabled:
38
+ # false to disabled
39
+ # true to enabled
40
+ # level:
41
+ # Compression level for gzip.
42
+ compress:
43
+ enabled: false
44
+ level: 6
45
+
46
+ # false to log messages are written to only log files.
47
+ # true to log messages are written to stdout as well.
48
+ with_stdout: false
49
+
50
+ # false to the warning messsages are ignored.
51
+ # ture to the warning messages are written to the log files.
52
+ verbose: true
53
+
54
+ # When this directive is set ‘true’, the logger can be multi-processes safe
55
+ psync: true
56
+
57
+ # Program will wait for this seconds after rotation was done.
58
+ sleeptime: 0.1
59
+
60
+ # false to disbale flushing buffered data after writing a log message to the log file.
61
+ # true to enable flushing buffered data.
62
+ flush: true
@@ -0,0 +1,152 @@
1
+ # You may add any configurations of Rack middlewares here.
2
+ # Please prepend underscore to beginning of your variable name to avoid naming conficts.
3
+ # Some configuration are listed by default. You may set them enabling or disbaling.
4
+ #
5
+ # --------------------------------------------------------------------------
6
+ # Rack::Reloader
7
+ # It reloads modified files without restarting nor reloading the web server.
8
+ # --------------------------------------------------------------------------
9
+ _cooldown = 10
10
+ use Rack::Reloader, _cooldown
11
+
12
+ # -------------------------------------------------------------------------------------------------
13
+ # Rack::ShowExceptions
14
+ # A GUI based debugger. It's won't work when 'fatal' route is set in route_error.yml.
15
+ # You are supposed to DISABLE this function on production environment for security reason.
16
+ # -------------------------------------------------------------------------------------------------
17
+ use Rack::ShowExceptions
18
+
19
+ # -------------------------------------------
20
+ # Rack::Auth::Basic
21
+ # It provides Basic access authentication.
22
+ # -------------------------------------------
23
+ =begin
24
+ _realm = 'Here is secret zone'
25
+ _username = 'username_here'
26
+ _passwd = 'password_here'
27
+ use Rack::Auth::Basic, _realm do |username, passwd|
28
+ username == _username && passwd == _passwd
29
+ end
30
+ =end
31
+
32
+ # --------------------------------------------
33
+ # Rack::Auth::Digest::MD5
34
+ # It provides Digest access authentication.
35
+ # --------------------------------------------
36
+ =begin
37
+ _realm = 'Here is secret zone'
38
+ _opaque = 'replace_me' # this is supposed to be set to a long random string
39
+ _username = 'username_here'
40
+ _passwd = 'password_here'
41
+ _pw = {_username => _passwd}
42
+ use Rack::Auth::Digest::MD5, _realm, _opaque do |username|
43
+ _pw[username]
44
+ end
45
+ =end
46
+
47
+ # ==========================
48
+ # Preferences for Session Management
49
+ # ==========================
50
+ _key = 'rack.session'
51
+ _domain = nil
52
+ _path = '/'
53
+ _expire_after = 3600
54
+ _secure = false
55
+ _httponly = false
56
+ _sidbits = 128
57
+
58
+ _session_options = {
59
+ :key => _key,
60
+ :domain => _domain,
61
+ :path => _path,
62
+ :expire_after => _expire_after,
63
+ :secure => _secure,
64
+ :httponly => _httponly,
65
+ :sidbits => _sidbits
66
+ }
67
+ _session_options[:domain] = _domain if _domain != nil
68
+
69
+ # ---------------------------------------------------------------------
70
+ # Rack::Session::Cookie
71
+ # It provides cookie based simple session management.
72
+ # ---------------------------------------------------------------------
73
+ # use Rack::Session::Cookie, _session_options
74
+
75
+ # --------------------------------------------------------------------------------------
76
+ # Rack::Session::Pool
77
+ # It provides property-based session management.
78
+ # --------------------------------------------------------------------------------------
79
+ =begin
80
+ _drop = false
81
+ _session_pool_options = {
82
+ :drop => _drop
83
+ }
84
+ use Rack::Session::Pool, _session_options.merge(_session_pool_options)
85
+ =end
86
+
87
+ # ----------------------------------------------------------------------------------
88
+ # Rack::Session::Dalli
89
+ # It provides memcached based session management.
90
+ # You must add 'dalli' to your Gemefile and typing bundle install to use it.
91
+ # ----------------------------------------------------------------------------------
92
+ =begin
93
+ _servers = ['127.0.0.1:11211'] # you may add any number of servers by comma
94
+ _connection_pooling = false
95
+
96
+ # options for dalli client
97
+ _namespace = 'nekonote.session'
98
+ _failover = true
99
+ _threadsafe = true
100
+ _expires_in = 0
101
+ _compress = false
102
+ _dalli_client_options = {
103
+ :namespace => _namespace,
104
+ :failover => _failover,
105
+ :threadsafe => _threadsafe,
106
+ :expires_in => _expires_in,
107
+ :compress => _compress
108
+ }
109
+
110
+ # options for connection pooling
111
+ # they will work when connection pooling is enbaled
112
+ _size = 5
113
+ _timeout = 5
114
+ _dalli_pool_options = {
115
+ :size => _size,
116
+ :timeout => _timeout
117
+ }
118
+
119
+ # setup dalli
120
+ require 'dalli'
121
+
122
+ if _connection_pooling
123
+ # enable connection pooling
124
+ _dalli_client = ::Dalli::Client.new _servers, _dalli_client_options
125
+ _cache = ::ConnectionPool::Wrapper.new(_pool_options) {_dalli_client}
126
+ else
127
+ # disable connection pooling
128
+ _cache = ::Dalli::Client.new _servers, _dalli_client_options
129
+ end
130
+
131
+ _dalli_options = {
132
+ :cache => _cache
133
+ }
134
+ use Rack::Session::Dalli, _session_options.merge(_dalli_options)
135
+ =end
136
+
137
+ # -----------------------------------------------------------------------------------------
138
+ # Rack::Access
139
+ # It provides access restrcition based on IP address.
140
+ # You must add 'rack-contrib' to your Gemefile and typing bundle install to use it.
141
+ # -----------------------------------------------------------------------------------------
142
+ # Restricting access by IP addresses.
143
+ # Note: You may append subnet mask to a IP address.
144
+ # Note: You may specify any number of ipmasks by comma.
145
+ =begin
146
+ _rules = {
147
+ # '/location' => ['ipmasks' ,...]
148
+ '/' => ['127.0.0.1'] #,...
149
+ }
150
+ require 'rack/contrib'
151
+ use Rack::Access, _rules
152
+ =end