Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make theme_park can take over handlers

  • Loading branch information...
commit 8e2ecc4e2a600e1fcb1b4bea38a4115d63910fcf 1 parent 41685c0
Thierry Zires authored March 25, 2012
4  lib/generators/templates/theme_park.rb
@@ -16,6 +16,10 @@
16 16
 # ThemePark.setup do |config|
17 17
 #   
18 18
 #   config.root             = '/themes'
  19
+#   config.handlers         = :all           # will load all handlers depends on your application.
  20
+#   # other options for handlers
  21
+#   # config.handlers       = [:liquid]      # only load .liquid
  22
+#   # config.handlers       = [:erb, :haml]  # only load .erb and .haml
19 23
 #   config.prefix           = 'themes'
20 24
 #   config.images_path      = ':root/:name/assets/images'
21 25
 #   config.javascripts_path = ':root/:name/assets/javascripts'
2  lib/theme_park.rb
@@ -34,7 +34,7 @@ def self.setup
34 34
 
35 35
   class << self
36 36
 
37  
-    delegate :base, :root, :base_root, :prefix, :to => :config
  37
+    delegate :base, :root, :base_root, :prefix, :handlers, :to => :config
38 38
 
39 39
     def config
40 40
       @@config ||= ThemePark::Configuration.new
5  lib/theme_park/configuration.rb
@@ -21,9 +21,14 @@ class Configuration
21 21
     # The place contains images, javascripts, stylesheets, compiled files and view files.
22 22
     attr_accessor :images_path, :javascripts_path, :stylesheets_path, :compiled_path, :views_path
23 23
 
  24
+    # Handlers.
  25
+    # In some scenes, we may want only one or several handlers.
  26
+    attr_accessor :handlers
  27
+
24 28
     def initialize
25 29
       # Default settings
26 30
       @base             = ''
  31
+      @handlers         = :all
27 32
       @root             = '/themes'
28 33
       @prefix           = 'themes'
29 34
       @images_path      = ':root/:name/assets/images'
16  lib/theme_park/rails/action_controller.rb
... ...
@@ -1,5 +1,17 @@
1 1
 # encoding: utf-8
2 2
 module ThemePark
  3
+
  4
+  # For rails, we need to resolve the handlers.
  5
+  def self.resolve_views_path(name)
  6
+    views_path = self.views_path(name)
  7
+    if ThemePark.handlers.to_s != 'all'
  8
+      handers = ThemePark.handlers.to_a.join(',')
  9
+      ActionView::FileSystemResolver.new(views_path, ":prefix/:action{.:locale,}{.:formats,}{.{#{handers}},}")
  10
+    else
  11
+      views_path
  12
+    end
  13
+  end
  14
+
3 15
   module Rails
4 16
     module ActionController
5 17
       extend ActiveSupport::Concern
@@ -12,7 +24,7 @@ module ClassMethods
12 24
         # end
13 25
         # ===
14 26
         def theme(name, options = {})
15  
-          path = ThemePark.views_path(name)
  27
+          path = ThemePark.resolve_views_path(name)
16 28
           if options.empty?
17 29
             prepend_view_path path
18 30
           else
@@ -34,7 +46,7 @@ def theme(name, options = {})
34 46
       # end
35 47
       # ===
36 48
       def theme(name)
37  
-        path = ThemePark.views_path(name)
  49
+        path = ThemePark.resolve_views_path(name)
38 50
         prepend_view_path path
39 51
       end
40 52
       

0 notes on commit 8e2ecc4

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