Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Templates: remove :register_as from default_options, remove init meth…

…od, overwrite Templates::Tilt#default_mime_type
  • Loading branch information...
commit a88b6de64d1f79894ed9c8dd8eaf3d770a6a5527 1 parent 2706a7a
Daniel Mendler authored
10  lib/temple/mixins/template.rb
@@ -9,21 +9,17 @@ def compile(code, options)
9 9
         default_options[:engine].new(options).call(code)
10 10
       end
11 11
 
12  
-      def init
13  
-        # Overwrite this for class initialization
14  
-      end
15  
-
16  
-      def register_as(name)
  12
+      def register_as(*names)
17 13
         raise NotImplementedError
18 14
       end
19 15
 
20 16
       def create(engine, options)
  17
+        register_as = options.delete(:register_as)
21 18
         template = Class.new(self)
22 19
         template.disable_option_validator!
23 20
         template.default_options[:engine] = engine
24 21
         template.default_options.update(options)
25  
-        template.init
26  
-        template.register_as(options[:register_as]) if options[:register_as]
  22
+        template.register_as(*register_as) if register_as
27 23
         template
28 24
       end
29 25
     end
23  lib/temple/templates/rails.rb
@@ -14,13 +14,15 @@ class Rails < ActionView::TemplateHandler
14 14
         extend Mixins::Template
15 15
 
16 16
         def compile(template)
17  
-          self.class.compile(template.source,
18  
-                             ImmutableHash.new({ :file => template.identifier, :streaming => false },  # Overwrite option: No streaming support in Rails < 3.1
19  
-                                               self.class.default_options).without(:engine, :register_as))
  17
+          # Overwrite option: No streaming support in Rails < 3.1
  18
+          self.class.compile(template.source, ImmutableHash.new({ :file => template.identifier, :streaming => false },
  19
+                             self.class.default_options).without(:engine))
20 20
         end
21 21
 
22  
-        def self.register_as(name)
23  
-          ActionView::Template.register_template_handler name.to_sym, self
  22
+        def self.register_as(*names)
  23
+          names.each do |name|
  24
+            ActionView::Template.register_template_handler name.to_sym, self
  25
+          end
24 26
         end
25 27
       end
26 28
     else
@@ -28,17 +30,18 @@ class Rails
28 30
         extend Mixins::Template
29 31
 
30 32
         def call(template)
31  
-          self.class.compile(template.source,
32  
-                             ImmutableHash.new({ :file => template.identifier },
33  
-                                               self.class.default_options).without(:engine, :register_as))
  33
+          self.class.compile(template.source, ImmutableHash.new({ :file => template.identifier },
  34
+                             self.class.default_options).without(:engine))
34 35
         end
35 36
 
36 37
         def supports_streaming?
37 38
           self.class.default_options[:streaming]
38 39
         end
39 40
 
40  
-        def self.register_as(name)
41  
-          ActionView::Template.register_template_handler name.to_sym, new
  41
+        def self.register_as(*names)
  42
+          names.each do |name|
  43
+            ActionView::Template.register_template_handler name.to_sym, new
  44
+          end
42 45
         end
43 46
       end
44 47
     end
24  lib/temple/templates/tilt.rb
@@ -5,15 +5,25 @@ module Templates
5 5
     class Tilt < ::Tilt::Template
6 6
       extend Mixins::Template
7 7
 
  8
+      define_options :mime_type => 'text/html'
  9
+
  10
+      def self.default_mime_type
  11
+        default_options[:mime_type]
  12
+      end
  13
+
  14
+      def self.default_mime_type=(mime_type)
  15
+        default_options[:mime_type] = mime_type
  16
+      end
  17
+
8 18
       # Prepare Temple template
9 19
       #
10 20
       # Called immediately after template data is loaded.
11 21
       #
12 22
       # @return [void]
13 23
       def prepare
14  
-        @src = self.class.compile(data,
15  
-                                  ImmutableHash.new({ :file => eval_file, :streaming => false }, # Overwrite option: No streaming support in Tilt
16  
-                                                    options, self.class.default_options).without(:mime_type, :engine, :register_as))
  24
+        # Overwrite option: No streaming support in Tilt
  25
+        @src = self.class.compile(data, ImmutableHash.new({ :file => eval_file, :streaming => false },
  26
+                                  options, self.class.default_options).without(:mime_type, :engine))
17 27
       end
18 28
 
19 29
       # A string containing the (Ruby) source code for the template.
@@ -24,12 +34,8 @@ def precompiled_template(locals = {})
24 34
         @src
25 35
       end
26 36
 
27  
-      def self.init
28  
-        self.default_mime_type = default_options[:mime_type] || 'text/html'
29  
-      end
30  
-
31  
-      def self.register_as(name)
32  
-        ::Tilt.register name.to_s, self
  37
+      def self.register_as(*names)
  38
+        ::Tilt.register(self, *names.map(&:to_s))
33 39
       end
34 40
     end
35 41
   end

0 notes on commit a88b6de

Please sign in to comment.
Something went wrong with that request. Please try again.