template-inheritance 0.2 → 0.3

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.
data/README.textile CHANGED
@@ -13,6 +13,16 @@ template = TemplateInheritance::Template.new("site/post.html.haml")
13
13
  template.render(post: post)
14
14
  </pre>
15
15
 
16
+ h2. In Padrino
17
+
18
+ <pre>
19
+ require "template-inheritance/adapters/padrino"
20
+
21
+ class Foo &amp; Padrino::Application
22
+ register TemplateInheritance::Rendering
23
+ end
24
+ </pre>
25
+
16
26
  h1. Haml Extensions
17
27
 
18
28
  <pre>
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require "template-inheritance"
4
+ require "padrino-core/application/rendering"
5
+
6
+ # TODO: It'd be nice to share the logger.
7
+ module TemplateInheritance
8
+ class Template
9
+ attr_accessor :padrino_views_directory
10
+ end
11
+
12
+ module TemplateHelpers
13
+ alias_method :_normalize_template_path, :normalize_template_path
14
+ def normalize_template_path(path)
15
+ full_path = File.join(template.padrino_views_directory, path)
16
+ _normalize_template_path(full_path)
17
+ end
18
+ end
19
+ end
20
+
21
+ module TemplateInheritance::Rendering
22
+ def self.registered(app)
23
+ app.helpers(self)
24
+ app.register(Padrino::Rendering)
25
+ end
26
+
27
+ # TODO: support options for Haml.
28
+ # NOTE: block does nothing.
29
+ # FIXME: locals doesn't work because we don't get them from Padrino.
30
+ include Module.new {
31
+ def render(_, path, options, locals, &block)
32
+ base_dir = options[:views] || settings.views || "./views"
33
+ fullpath = File.join(base_dir, path.to_s)
34
+ template = TemplateInheritance::Template.new(fullpath, self)
35
+ template.padrino_views_directory = base_dir
36
+ options && options.delete(:layout_engine)
37
+ options && options.delete(:layout)
38
+ template.render(locals)
39
+ end
40
+ }
41
+ end
@@ -1,8 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module TemplateInheritance
4
- SubtemplateNotFound = Class.new(StandardError)
5
-
6
4
  module TemplateHelpers
7
5
  def self.extended(scope)
8
6
  class << scope
@@ -103,8 +101,6 @@ module TemplateInheritance
103
101
  template = TemplateInheritance::Template.new(full_path, self) # self is scope
104
102
  self.template = original_template
105
103
  return template.render(context)
106
- rescue TemplateInheritance::TemplateNotFound.new(path)
107
- raise SubtemplateNotFound, "Template #{path} doesn't exist in #{full_path}"
108
104
  end
109
105
 
110
106
  # partial "products/list"
@@ -88,7 +88,7 @@ module TemplateInheritance
88
88
 
89
89
  # @since 0.0.2
90
90
  def render(context = Hash.new)
91
- raise TemplateNotFound.new("Template #{self.path} wasn't found in these paths: #{self.class.paths.inspect}") if self.fullpath.nil?
91
+ raise TemplateNotFound.new(self.path) if self.fullpath.nil?
92
92
  TemplateInheritance.logger.info("Rendering template #{self.path} with context keys #{context.keys.inspect}")
93
93
  self.scope.context = self.context = context # so we can access context in the scope object as well
94
94
  value = self.template.render(self.scope, context)
@@ -5,7 +5,7 @@ require "base64"
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "template-inheritance"
8
- s.version = "0.2"
8
+ s.version = "0.3"
9
9
  s.authors = ["Jakub Šťastný aka Botanicus"]
10
10
  s.homepage = "http://github.com/botanicus/template-inheritance"
11
11
  s.summary = ""
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: template-inheritance
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: "0.2"
5
+ version: "0.3"
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain:
12
- date: 2011-03-17 00:00:00 +00:00
12
+ date: 2011-05-19 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,7 @@ files:
52
52
  - example/site/base.html.haml
53
53
  - example/site/post.html.haml
54
54
  - lib/template-inheritance.rb
55
+ - lib/template-inheritance/adapters/padrino.rb
55
56
  - lib/template-inheritance/exts/haml.rb
56
57
  - lib/template-inheritance/exts/tilt.rb
57
58
  - lib/template-inheritance/helpers.rb