flame 4.0.6 → 4.0.7

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
  SHA1:
3
- metadata.gz: 7e3eff2ff95d66cad8d31d30b8938ee7f7936726
4
- data.tar.gz: c8b3793fab9614b8c710f71e01f22f2c25dde926
3
+ metadata.gz: 10ea7a8158cb464a542f980ccd107c59ba36d5b4
4
+ data.tar.gz: c93a1fb11b44d074c48aeb16e99fe8e29f3d807c
5
5
  SHA512:
6
- metadata.gz: 98e65d7b60f888c271b83e987b4cbf5c56a800f0fcf30678d29f1df5546d835194728656c9bcf0808ded1e278e897a116f90ead91899f05cde915cb1d053cff8
7
- data.tar.gz: 5d7e63b49ad424fa33d3319daaa585e038a0942cc633489a3d139f0557b59d035f1f4787b4459375713a42f2ac2e8791de020d4f05c3ff2165de4c7484c25bb6
6
+ metadata.gz: f971c4a0fa36f66472b062aa35ebf9258af56886aceb8cd965b43e94819c348ce2f870f5322f71c2abcc9dbc061d7e020f5145549920a1ae3edd018b1b348ace
7
+ data.tar.gz: f2c36b5da0332076131edb4829a1504931cbe092ef0f164124b2ba3a4e91b9d964882bde24bd7fb0108de726b1ff9e7861d7e2bbdf4e3a37f059dabc5d2c0f05
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  require 'tilt'
2
4
  require 'tilt/plain'
3
5
  require 'tilt/erb'
@@ -41,6 +43,10 @@ module Flame
41
43
  end
42
44
  end
43
45
 
46
+ def views_dir
47
+ @ctrl.config[:views_dir]
48
+ end
49
+
44
50
  using GorillaPatch::ModuleExt
45
51
 
46
52
  ## Compile file with Tilt engine
@@ -51,11 +57,12 @@ module Flame
51
57
 
52
58
  ## @todo Add `views_dir` for Application and Controller
53
59
  ## @todo Add `layout` method for Controller
54
- def find_file(path)
60
+ def find_file(path, layout: false)
55
61
  ## Get full filename
62
+ dirs = layout ? layout_dirs : controller_dirs
56
63
  Dir[File.join(
57
- @ctrl.config[:views_dir],
58
- "{#{controller_dirs.join(',')},}",
64
+ views_dir,
65
+ "{#{dirs.join(',')},}",
59
66
  "#{path}.*"
60
67
  )].uniq.find do |file|
61
68
  Tilt[file]
@@ -67,18 +74,25 @@ module Flame
67
74
  controller_dir_parts = @ctrl.class.underscore.split('/').map do |part|
68
75
  (part.split('_') - %w(controller controllers ctrl)).join('_')
69
76
  end
70
- controller_dir = controller_dir_parts.join('/')
71
- [controller_dir,
72
- controller_dir_parts[1..-1].join('/'),
73
- controller_dir_parts[1..-2].join('/'),
74
- controller_dir_parts.last]
77
+ controller_dir_parts.map.with_index do |_part, ind|
78
+ controller_dir_parts[ind..-1].join('/')
79
+ end
80
+ end
81
+
82
+ def layout_dirs
83
+ file_dir = Pathname.new(@filename).dirname
84
+ diff_path = file_dir.relative_path_from Pathname.new(views_dir)
85
+ diff_parts = diff_path.to_s.split('/')
86
+ diff_parts.map.with_index do |_part, ind|
87
+ diff_parts[0..-(ind + 1)].join('/')
88
+ end
75
89
  end
76
90
 
77
91
  ## Render the layout with template
78
92
  ## @param result [String] result of template rendering
79
93
  ## @param cache [Boolean] cache compiles or not
80
94
  def layout_render(result, cache: true)
81
- layout_file = find_file(@layout)
95
+ layout_file = find_file(@layout, layout: true)
82
96
  ## Compile layout to hash
83
97
  return result unless layout_file
84
98
  layout =
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flame
4
- VERSION = '4.0.6'.freeze
4
+ VERSION = '4.0.7'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flame
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.6
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-04 00:00:00.000000000 Z
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack