jeanine 0.2.0 → 0.3.0

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
- SHA1:
3
- metadata.gz: a9120ffa8994858a7560330fa0afbe1bf18e2f94
4
- data.tar.gz: fd326e260cc8c90a5b70b8b8ad4a1cd5b0b9869a
2
+ SHA256:
3
+ metadata.gz: 0ec0b02b10f6cbf4e488db86b4bff6a5bb2f81184448dcdc8d431aa650ce8b64
4
+ data.tar.gz: 0d3408a137162c82388e86a3fcb74b5f14bf07e18cd0581866b4b027f29aa3ba
5
5
  SHA512:
6
- metadata.gz: 8b11b5b73abed4a7df44caf5a7b53ad6d2d52616fc23658e8c0d864239c0dc7b3fdfb6837c6d611f593944ad2518d92cc9af945ec3185a7bdfd783f913c3309c
7
- data.tar.gz: 2ca9b7d2196c08e57bda6f983cfb0a1da71c06772bb6b42b76deb0aa941d5cb454eef4041d9834f8b3eeea9644d5a86b22e48de5f6b951a32e39481d9ac631a4
6
+ metadata.gz: 1b5a6e3c6d7202516b24bd68c8573885195041d6c8f5a756de96792cd66681b2f2802904e65fd8b07b95bf180d84c3b15ccbc1bcb9809a0b31d1a443810cd1d1
7
+ data.tar.gz: 4d907b99574cf1b2bf9e2fd7a76523d680c767f79f1565f41ac1474fde345929a8eab329c01c915523a7cd707daa1fc5dd0a43e1cabd6c7cd276601f2bc6d2a1
@@ -8,6 +8,9 @@ require 'jeanine/app'
8
8
  require 'tilt'
9
9
 
10
10
  module Jeanine
11
+ def self.view_paths
12
+ @_view_paths ||= Set.new(["views"])
13
+ end
11
14
  def self.tilt_cache
12
15
  @title_cache ||= Tilt::Cache.new
13
16
  end
@@ -6,17 +6,22 @@ require 'jeanine/response'
6
6
  require 'jeanine/renderer'
7
7
  require 'jeanine/routing'
8
8
  require 'jeanine/session'
9
+ require 'jeanine/view_paths'
9
10
 
10
11
  module Jeanine
11
12
  class App
12
13
  include Session
14
+ include Rescuing
13
15
  include Routing::Evaluation
16
+
14
17
  attr_reader :request, :response
15
18
 
16
19
  class << self
17
20
  include Callbacks
18
21
  include Routing::DSL
19
22
  include Rescuing
23
+ include ViewPaths
24
+
20
25
  alias :_new :new
21
26
  def new(*args, &block)
22
27
  initialize!
@@ -41,8 +46,6 @@ module Jeanine
41
46
  end
42
47
  end
43
48
 
44
- include Rescuing
45
-
46
49
  def call(env)
47
50
  begin
48
51
  @env = env
@@ -9,14 +9,6 @@ module Jeanine
9
9
  }
10
10
  end
11
11
 
12
- def _register_callback(type, paths = [], &block)
13
- if paths == []
14
- _callbacks["#{type}_all".to_sym] << { block: block }
15
- else
16
- _callbacks[type] << { paths: paths, block: block }
17
- end
18
- end
19
-
20
12
  def before(*paths, &block)
21
13
  _register_callback(:before, paths, &block)
22
14
  end
@@ -24,5 +16,14 @@ module Jeanine
24
16
  def after(*paths, &block)
25
17
  _register_callback(:after, paths, &block)
26
18
  end
19
+
20
+ private
21
+ def _register_callback(type, paths = [], &block)
22
+ if paths == []
23
+ _callbacks["#{type}_all".to_sym] << { block: block }
24
+ else
25
+ _callbacks[type] << { paths: paths, block: block }
26
+ end
27
+ end
27
28
  end
28
29
  end
@@ -1,7 +1,9 @@
1
+ require 'rack'
2
+
1
3
  module Jeanine
2
4
  class Mimes
3
5
  MimeTypeNotFound = Class.new(StandardError)
4
- MIME_TYPES_INVERTED = Rack::Mime::MIME_TYPES.invert
6
+ MIME_TYPES_INVERTED = ::Rack::Mime::MIME_TYPES.invert
5
7
 
6
8
  def self.load!
7
9
  register(:json, Rack::Mime::MIME_TYPES[".json"])
@@ -81,6 +81,16 @@ module Jeanine
81
81
  Thread.current[:tilt_cache] ||= Tilt::Cache.new
82
82
  end
83
83
 
84
+ def find_template!(template)
85
+ Jeanine.view_paths.to_a.each do |path|
86
+ template_with_path = "#{path}/#{template}"
87
+ if File.exist?(template_with_path)
88
+ return template_with_path
89
+ end
90
+ end
91
+ raise "Template not found in view paths. Looking for #{template} in #{Jeanine.view_paths.to_a.join(', ')}"
92
+ end
93
+
84
94
  def html(engine, template_name, options = {}, locals = {}, &block)
85
95
  locals = options.delete(:locals) || locals || {}
86
96
  layout = options[:layout]
@@ -94,6 +104,7 @@ module Jeanine
94
104
  unless layout.include?("layouts/")
95
105
  layout = "layouts/#{layout}"
96
106
  end
107
+ layout = find_template!(layout)
97
108
  options = options.merge(layout: false, scope: scope)
98
109
  catch(:layout_missing) { return html(engine, layout, options, locals) { output } }
99
110
  end
@@ -104,7 +115,8 @@ module Jeanine
104
115
  Tilt::Cache.new.fetch engine, template_name, options do
105
116
  template = Tilt[engine]
106
117
  raise "Template engine not found: #{engine}" if template.nil?
107
- template.new("views/#{template_name}", options)
118
+ template_name = find_template!(template_name)
119
+ template.new(template_name, options)
108
120
  end
109
121
  end
110
122
 
@@ -34,7 +34,7 @@ module Jeanine
34
34
  while index < matches.captures.size
35
35
  param = route[:params][index]
36
36
  @request.params[param] = matches.captures[index]
37
- if index == match.captures.size
37
+ if index == matches.captures.size
38
38
  @request.params[param].gsub!(@request.format)
39
39
  end
40
40
  index += 1
@@ -1,3 +1,3 @@
1
1
  module Jeanine
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,7 @@
1
+ module Jeanine
2
+ module ViewPaths
3
+ def append_view_path(path)
4
+ Jeanine.view_paths << path
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeanine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -53,7 +53,35 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - ">="
@@ -96,6 +124,7 @@ files:
96
124
  - lib/jeanine/session.rb
97
125
  - lib/jeanine/version.rb
98
126
  - lib/jeanine/view.rb
127
+ - lib/jeanine/view_paths.rb
99
128
  homepage: https://github.com/joshmn/jeanine
100
129
  licenses:
101
130
  - MIT
@@ -118,8 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
147
  - !ruby/object:Gem::Version
119
148
  version: '0'
120
149
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.6.14.3
150
+ rubygems_version: 3.0.3
123
151
  signing_key:
124
152
  specification_version: 4
125
153
  summary: A framework.