nekonote-framework 1.0.0.pre.beta6 → 1.0.0.pre.beta7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/structure/preference/development/route.yml +0 -2
- data/data/structure/preference/development/server/puma.rb +1 -0
- data/data/structure/template/partial/.gitkeep +0 -0
- data/lib/loader.rb +1 -1
- data/lib/nekonote/liquid/tag_partial.rb +30 -0
- data/lib/nekonote/preference.rb +2 -4
- data/lib/nekonote/spec.rb +1 -1
- data/lib/nekonote/view.rb +31 -35
- metadata +4 -3
- data/lib/nekonote/liquid/tag_env_get.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5f37d86fafd6edc28102e4ad2b6ddbc2e7451d5bdaae8fddaf98d8e0014e23f
|
4
|
+
data.tar.gz: 51adff55ec9e987b9bcbd4422215fe7c1af36360610b4d6f00fe22b333b0311f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 933b166ee71a739536a3a10ea44a9bc600744b450d2bda6408a76da83949244b98a2e276fdb734941aacc1160d57de2108704f91e87a208a717aef8570007a0c
|
7
|
+
data.tar.gz: 207c81d0d37ca4dd7a2ad51ef11a2488b17ba30f9f034524a4f7d50935826f35a90c473f9ed7ec7432a2e0c48b7bcccebbd7ee5044d647c726f45fd0c6c176b9
|
File without changes
|
data/lib/loader.rb
CHANGED
@@ -65,8 +65,8 @@ module Nekonote
|
|
65
65
|
{:class => :Setting, :file => 'setting'},
|
66
66
|
{:class => :PageCache, :file => 'page_cache'},
|
67
67
|
{:class => :View, :file => 'view'},
|
68
|
-
{:class => :TagEnvGet, :file => 'liquid/tag_env_get'},
|
69
68
|
{:class => :TagSettingGet, :file => 'liquid/tag_setting_get'},
|
69
|
+
{:class => :TagPartial, :file => 'liquid/tag_partial'},
|
70
70
|
{:class => :Request, :file => 'request'},
|
71
71
|
{:class => :Handler, :file => 'handler.rb'},
|
72
72
|
{:class => :Rackup, :file => 'rackup'},
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Nekonote
|
2
|
+
class TagPartial < Liquid::Tag
|
3
|
+
def initialize(tag_name, val, parse_context)
|
4
|
+
super
|
5
|
+
@filepath = val.strip
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(context)
|
9
|
+
# get assign list from Liquid::Context
|
10
|
+
assigns = {}
|
11
|
+
context.environments[0].each_pair do |k, v|
|
12
|
+
assigns[k] = v
|
13
|
+
end
|
14
|
+
|
15
|
+
# absolute path to the partial template
|
16
|
+
filepath = Nekonote.get_root + '/' + View::PATH_TO_PARTIAL + '/' + @filepath + '.tpl'
|
17
|
+
|
18
|
+
# read data and parse it and render it
|
19
|
+
data = ''
|
20
|
+
begin
|
21
|
+
liquid = Liquid::Template.parse IO.read(filepath)
|
22
|
+
data = liquid.render assigns
|
23
|
+
rescue => e
|
24
|
+
# ignore this exception
|
25
|
+
end
|
26
|
+
|
27
|
+
return data
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/nekonote/preference.rb
CHANGED
@@ -12,8 +12,6 @@ module Nekonote
|
|
12
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
15
|
|
18
16
|
# default values for routing options
|
19
17
|
DEFAULT_OPTION_ROUTE_REGEXP = false
|
@@ -209,8 +207,8 @@ module Nekonote
|
|
209
207
|
# true -> Nekonote::URLMapper, false -> :Rack::URLMap
|
210
208
|
@is_path_regexp = routing_options[FIELD_OPTION_ROUTE_REGEXP] || DEFAULT_OPTION_ROUTE_REGEXP
|
211
209
|
@is_allow_dup_slash = routing_options[FIELD_OPTION_ALLOW_DUP_SLASH] || DEFAULT_OPTION_ALLOW_DUP_SLASH
|
212
|
-
@template_file_extension =
|
213
|
-
@layout_file_extension =
|
210
|
+
@template_file_extension = DEFAULT_OPTION_TEMPLATE_FILE_EXT
|
211
|
+
@layout_file_extension = DEFAULT_OPTION_LAYOUT_FILE_EXT
|
214
212
|
|
215
213
|
# validation for file extension
|
216
214
|
if !@template_file_extension.is_a?(String) || @template_file_extension == ''
|
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-
|
3
|
+
VERSION = %(1.0.0-beta7).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
@@ -1,11 +1,12 @@
|
|
1
1
|
module Nekonote
|
2
2
|
# define original liquid tag
|
3
|
-
::Liquid::Template.register_tag 'env_get', TagEnvGet
|
4
3
|
::Liquid::Template.register_tag 'setting_get', TagSettingGet
|
4
|
+
::Liquid::Template.register_tag 'partial', TagPartial
|
5
5
|
|
6
6
|
class View
|
7
7
|
PATH_TO_TEMPLATE = 'template'
|
8
8
|
PATH_TO_LAYOUT = 'template/layout'
|
9
|
+
PATH_TO_PARTIAL = 'template/partial'
|
9
10
|
|
10
11
|
# accessor
|
11
12
|
attr_accessor :is_redirect
|
@@ -19,6 +20,7 @@ module Nekonote
|
|
19
20
|
:info_layout,
|
20
21
|
:info_page_cache_time
|
21
22
|
|
23
|
+
# Returns default response for error
|
22
24
|
# @return array
|
23
25
|
def self.get_default_error_response
|
24
26
|
return [
|
@@ -219,10 +221,10 @@ module Nekonote
|
|
219
221
|
list_cnv = {}
|
220
222
|
list.map {|pair| list_cnv[pair[0].to_s] = pair[1] }
|
221
223
|
|
222
|
-
if defined?(@
|
223
|
-
@
|
224
|
+
if defined?(@assign_list) && @assign_list.is_a?(Hash)
|
225
|
+
@assign_list.merge! list_cnv
|
224
226
|
else
|
225
|
-
@
|
227
|
+
@assign_list = list_cnv
|
226
228
|
end
|
227
229
|
end
|
228
230
|
|
@@ -354,47 +356,41 @@ module Nekonote
|
|
354
356
|
# @return string
|
355
357
|
private
|
356
358
|
def get_parsed
|
357
|
-
data = ''
|
358
|
-
liq_tpl_template = nil
|
359
|
-
liq_tpl_layout = nil
|
360
359
|
begin
|
361
|
-
|
362
|
-
|
363
|
-
end
|
360
|
+
# parse data in template file
|
361
|
+
template_data = render_data_with_liquid(@template_path, @assign_list)
|
364
362
|
|
365
|
-
if
|
366
|
-
|
363
|
+
# assign it into variable [content] if template was avalable
|
364
|
+
if template_data != nil
|
365
|
+
@assign_list['content'] = template_data
|
367
366
|
end
|
368
367
|
|
369
|
-
# parse
|
370
|
-
|
371
|
-
content = liq_tpl_template.render @mapping
|
372
|
-
else
|
373
|
-
content = nil
|
374
|
-
end
|
368
|
+
# parse data in layout file with template data
|
369
|
+
layout_data = render_data_with_liquid(@layout_path, @assign_list)
|
375
370
|
|
376
|
-
|
377
|
-
if
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
# and put it to @mapping
|
384
|
-
@mapping.merge! mapping
|
385
|
-
end
|
386
|
-
data = liq_tpl_layout.render @mapping
|
387
|
-
|
388
|
-
else
|
389
|
-
# if template data is available set it to data
|
390
|
-
data = content if content != nil
|
371
|
+
response_body = ''
|
372
|
+
if layout_data != nil
|
373
|
+
# just layout or with template
|
374
|
+
response_body = layout_data
|
375
|
+
elsif template_data != nil
|
376
|
+
# just template
|
377
|
+
response_body = template_data
|
391
378
|
end
|
392
|
-
|
393
379
|
rescue => e
|
394
380
|
raise ViewError, e.message
|
395
381
|
end
|
396
382
|
|
397
|
-
return
|
383
|
+
return response_body
|
384
|
+
end
|
385
|
+
|
386
|
+
# @param string filepath path to file
|
387
|
+
# @param hash assigns variables to assign
|
388
|
+
# @return Liquid::Template|nil
|
389
|
+
# @throw Exception
|
390
|
+
def render_data_with_liquid(filepath, assigns)
|
391
|
+
return nil if !filepath.is_a? String
|
392
|
+
liquid = Liquid::Template.parse IO.read(filepath)
|
393
|
+
return liquid.render assigns
|
398
394
|
end
|
399
395
|
end
|
400
396
|
end
|
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.
|
4
|
+
version: 1.0.0.pre.beta7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khotta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: color_echo
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- data/structure/template/error.tpl
|
71
71
|
- data/structure/template/layout/default.tpl
|
72
72
|
- data/structure/template/layout/error.tpl
|
73
|
+
- data/structure/template/partial/.gitkeep
|
73
74
|
- data/structure/template/welcome/index.tpl
|
74
75
|
- data/structure/tmp/pids/.gitkeep
|
75
76
|
- lib/loader.rb
|
@@ -87,7 +88,7 @@ files:
|
|
87
88
|
- lib/nekonote/exception/view_error.rb
|
88
89
|
- lib/nekonote/handler.rb
|
89
90
|
- lib/nekonote/handler/protected_methods.rb
|
90
|
-
- lib/nekonote/liquid/
|
91
|
+
- lib/nekonote/liquid/tag_partial.rb
|
91
92
|
- lib/nekonote/liquid/tag_setting_get.rb
|
92
93
|
- lib/nekonote/logger.rb
|
93
94
|
- lib/nekonote/page_cache.rb
|