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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e8590189de70e359db4f9bfa8a491bbafc1becc543460ffef6f3424c4d5a355
4
- data.tar.gz: 5c126bb0ea314fbd8393a76088f3b9abcc49b37f3db21780bba6c0998a8edf0e
3
+ metadata.gz: e5f37d86fafd6edc28102e4ad2b6ddbc2e7451d5bdaae8fddaf98d8e0014e23f
4
+ data.tar.gz: 51adff55ec9e987b9bcbd4422215fe7c1af36360610b4d6f00fe22b333b0311f
5
5
  SHA512:
6
- metadata.gz: a6af6b480387f047aaf6b0b951bee0d2b71bb5f6abe2aa36d33bb7acbd7ba851bca52c6f49fe0b438e41222093de9721d56adb346b70c090f480457bf0681bc1
7
- data.tar.gz: 8a14b10a3187236f5924c10c6c2c3dc2cfe5d8c3f774e5c8296f265d0124c5f821ed78e420ca0413e4750a7c72d3aa83ecaad97720e544bafbdafc5e9df095eb
6
+ metadata.gz: 933b166ee71a739536a3a10ea44a9bc600744b450d2bda6408a76da83949244b98a2e276fdb734941aacc1160d57de2108704f91e87a208a717aef8570007a0c
7
+ data.tar.gz: 207c81d0d37ca4dd7a2ad51ef11a2488b17ba30f9f034524a4f7d50935826f35a90c473f9ed7ec7432a2e0c48b7bcccebbd7ee5044d647c726f45fd0c6c176b9
@@ -18,8 +18,6 @@
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
23
21
 
24
22
  # ----------------------
25
23
  # Routes
@@ -28,6 +28,7 @@ bind "tcp://#{_host}:#{_port}"
28
28
  # }
29
29
 
30
30
  # Minimum to maximum number of threads to answer.
31
+ # @comment well actually, seems this number plus 6 threads exist ...
31
32
  threads 0, 16
32
33
 
33
34
  # The environment in which the rack's app will run.
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
@@ -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 = routing_options[FIELD_OPTION_TEMPLATE_EXT] || DEFAULT_OPTION_TEMPLATE_FILE_EXT
213
- @layout_file_extension = routing_options[FIELD_OPTION_LAYOUT_EXT] || DEFAULT_OPTION_LAYOUT_FILE_EXT
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-beta6).freeze
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?(@mapping) && @mapping.is_a?(Hash)
223
- @mapping.merge! list_cnv
224
+ if defined?(@assign_list) && @assign_list.is_a?(Hash)
225
+ @assign_list.merge! list_cnv
224
226
  else
225
- @mapping = list_cnv
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
- if @template_path.is_a? String
362
- liq_tpl_template = Liquid::Template.parse IO.read(@template_path)
363
- end
360
+ # parse data in template file
361
+ template_data = render_data_with_liquid(@template_path, @assign_list)
364
362
 
365
- if @layout_path.is_a? String
366
- liq_tpl_layout = Liquid::Template.parse IO.read(@layout_path)
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 and render template
370
- if liq_tpl_template.is_a? Liquid::Template
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
- # parse and render layout
377
- if liq_tpl_layout.is_a? Liquid::Template
378
- if content != nil
379
- # assgin tempalte for layout
380
- mapping = {
381
- 'content' => content
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 data
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.beta6
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 00:00:00.000000000 Z
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/tag_env_get.rb
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
@@ -1,12 +0,0 @@
1
- module Nekonote
2
- class TagEnvGet < Liquid::Tag
3
- def initialize(tag_name, val, parse_context)
4
- super
5
- @val = val.strip
6
- end
7
-
8
- def render(context)
9
- return Env.get @val
10
- end
11
- end
12
- end