wouter-views 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b356aaa50ae723d845020d7dadfc95464e03dddedeb5ef04a09992cf9c56e56
4
- data.tar.gz: 88ceeb64f8f33e41abc7075ce59daaa15ab11ed401c541f6caa9242d0d0d8a61
3
+ metadata.gz: 52f7636ecdb3cdf1d29fe825b53464e3506b89527a1833a3529b62dc4af124b1
4
+ data.tar.gz: 8e3b2b075d7c0ff1a5d683fbc7b8589d530795a4aa85dae1d24f5f6028910c5f
5
5
  SHA512:
6
- metadata.gz: d0f52189c54044d9cbcf9a887ca7a967faefd3a7a3b4102f2822a88788b8477cd1394c5a65d5f5c745cbb980109df18c88f53e062d29b63f8b193e261bde3eae
7
- data.tar.gz: c870c1ac14931cbd385660ddce16c3dbe36c6264ab4cf246c1b7ae583791e8edd510b1a10631cf769a1541285e7dfacb203fed5321edb29029ccba13317ea320
6
+ metadata.gz: 8de81eb26f3cd36e08ad46375910ec5767e6f2b63b738178cae804587c4c8bfc388ab49b65bcbf0ab66f7c4c1bc728a6487ec5abbbd56d4f501c89387c3c766a
7
+ data.tar.gz: 5db7cb838e4f3e27b03262653ed1723795eb6ed6c722135cbacc89b9a91bcd38756319fac49ec70f2e73323c3d1e4e1aec12bfe3567ad2c222914d9c1f819bbd
data/lib/wouter/views.rb CHANGED
@@ -6,48 +6,71 @@ class Wouter
6
6
  class Views
7
7
  class FileNotFound < StandardError; end
8
8
 
9
- def self.file_finder(dir, template, engine, bind)
10
- file_name = template.to_s + '.' + engine.to_s
11
- full_path = dir + '/' + file_name
9
+ class <<self
10
+ def file_finder(dir, template, engine, layout, bind)
11
+ template_full_path = full_path(template, dir, engine)
12
+ template_data = if Tilt.template_for(template_full_path)
13
+ Tilt.new(template_full_path).render(bind)
14
+ else
15
+ File.read(template_full_path)
16
+ end
12
17
 
13
- return Tilt.new(full_path).render(bind) if File.exists?(full_path)
14
-
15
- full_path = dir + '/' + template.to_s
16
-
17
- if Tilt.template_for(full_path)
18
- Tilt.new(full_path).render(bind)
19
- else
20
- if File.exists?(full_path)
21
- File.read(full_path)
18
+ if layout
19
+ layout_full_path = full_path(layout, dir, engine)
20
+ if Tilt.template_for(layout_full_path)
21
+ Tilt.new(layout_full_path).render(bind) { template_data }
22
+ else
23
+ File.read(layout_full_path) + template_data
24
+ end
22
25
  else
23
- raise FileNotFound, "could not find file: #{full_path}"
26
+ template_data
24
27
  end
25
28
  end
29
+
30
+ def full_path(file, dir, engine)
31
+ file_name = file.to_s + '.' + engine.to_s
32
+ full_path = dir + '/' + file_name
33
+
34
+ return full_path if File.exists?(full_path)
35
+
36
+ full_path = dir + '/' + file.to_s
37
+
38
+ return full_path if File.exists?(full_path)
39
+
40
+ raise FileNotFound, "cannot find file: '#{file}' in '#{dir}'"
41
+ end
26
42
  end
43
+
27
44
  end
28
45
  end
29
46
 
30
47
  class Wouter
31
48
  class <<self
32
- def render_template(template, bind = self, engine = nil, dir = nil)
49
+ def render_template(template, bind = self, engine = nil, dir = nil, layout = nil)
33
50
  dir = dir || config[:view_dir] || File.expand_path('./views')
34
51
  engine = engine || config[:view_engine] || :html
35
- Wouter::Views.file_finder(dir, template, engine, bind)
52
+ layout = layout || config[:layout] || nil
53
+ Wouter::Views.file_finder(dir, template, engine, layout, bind)
36
54
  end
37
55
 
38
- def render_view(template, engine: nil, dir: nil)
39
- ViewWrap.new(template, engine, dir)
56
+ def render_view(template, engine: nil, dir: nil, layout: nil)
57
+ ViewWrap.new(template, engine, dir, layout)
40
58
  end
41
59
 
42
60
  def view_dir(dir = nil)
43
- config[:view_dir] = dir unless dir.nil?
61
+ config[:view_dir] = dir if dir
44
62
  config[:view_dir]
45
63
  end
46
64
 
47
65
  def view_engine(engine = nil)
48
- config[:view_engine] = engine unless engine.nil?
66
+ config[:view_engine] = engine if engine
49
67
  config[:view_engine]
50
68
  end
69
+
70
+ def view_layout(layout = nil)
71
+ config[:view_layout] = layout if layout
72
+ config[:view_layout]
73
+ end
51
74
  end
52
75
 
53
76
  class ViewEndpoint < Wouter::Endpoint
@@ -57,32 +80,35 @@ class Wouter
57
80
  end
58
81
 
59
82
  def respond
60
- render_view(@view[:template], engine: @view[:engine], dir: @view[:dir])
83
+ render_view(@view[:template], engine: @view[:engine], dir: @view[:dir], layout: @view[:layout])
61
84
  end
62
85
  end
63
86
 
64
87
  class ViewWrap
65
- def initialize(template, engine = nil, dir = nil)
88
+ def initialize(template, engine = nil, dir = nil, layout = nil)
66
89
  @template = template
67
90
  @engine = engine
68
91
  @dir = dir
92
+ @layout = layout
69
93
  end
70
94
 
71
95
  def call(env)
72
96
  env['wouter.view'] = {
73
97
  template: @template,
74
98
  engine: @engine,
75
- dir: @dir
99
+ dir: @dir,
100
+ layout: @layout
76
101
  }
77
102
  ViewEndpoint.call(env)
78
103
  end
79
104
  end
80
105
 
81
106
  class Endpoint
82
- def render_view(template, engine: nil, dir: nil)
107
+ def render_view(template, engine: nil, dir: nil, layout: nil)
83
108
  engine ||= config[:view_engine]
84
109
  dir ||= config[:view_dir]
85
- Wouter.render_template(template, self, engine, dir)
110
+ layout ||= config[:view_layout]
111
+ Wouter.render_template(template, self, engine, dir, layout)
86
112
  end
87
113
  end
88
114
  end
data/wouter-views.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'wouter-views'
5
5
  s.platform = Gem::Platform::RUBY
6
- s.version = '0.0.7'
6
+ s.version = '0.0.8'
7
7
  s.summary = 'View template support for Wouter web framework.'
8
8
  s.description = 'Adds view template support to the Wouter web framework.'
9
9
  s.authors = ['Robert Peterson']
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency 'rack-test', '~> 1.1'
23
23
  s.add_development_dependency 'rake', '~> 12.3'
24
24
  s.add_development_dependency 'slim', '~> 4.0', '>= 4.0.1'
25
+ s.add_development_dependency 'sass', '~> 3.7'
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wouter-views
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Peterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-21 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wouter
@@ -154,6 +154,20 @@ dependencies:
154
154
  - - ">="
155
155
  - !ruby/object:Gem::Version
156
156
  version: 4.0.1
157
+ - !ruby/object:Gem::Dependency
158
+ name: sass
159
+ requirement: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - "~>"
162
+ - !ruby/object:Gem::Version
163
+ version: '3.7'
164
+ type: :development
165
+ prerelease: false
166
+ version_requirements: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - "~>"
169
+ - !ruby/object:Gem::Version
170
+ version: '3.7'
157
171
  description: Adds view template support to the Wouter web framework.
158
172
  email: robertpeterson@gmail.com
159
173
  executables: []