Permalink
Browse files

Make theme_park can take over handlers

  • Loading branch information...
1 parent 41685c0 commit 8e2ecc4e2a600e1fcb1b4bea38a4115d63910fcf @zires committed Mar 25, 2012
@@ -16,6 +16,10 @@
# ThemePark.setup do |config|
#
# config.root = '/themes'
+# config.handlers = :all # will load all handlers depends on your application.
+# # other options for handlers
+# # config.handlers = [:liquid] # only load .liquid
+# # config.handlers = [:erb, :haml] # only load .erb and .haml
# config.prefix = 'themes'
# config.images_path = ':root/:name/assets/images'
# config.javascripts_path = ':root/:name/assets/javascripts'
View
@@ -34,7 +34,7 @@ def self.setup
class << self
- delegate :base, :root, :base_root, :prefix, :to => :config
+ delegate :base, :root, :base_root, :prefix, :handlers, :to => :config
def config
@@config ||= ThemePark::Configuration.new
@@ -21,9 +21,14 @@ class Configuration
# The place contains images, javascripts, stylesheets, compiled files and view files.
attr_accessor :images_path, :javascripts_path, :stylesheets_path, :compiled_path, :views_path
+ # Handlers.
+ # In some scenes, we may want only one or several handlers.
+ attr_accessor :handlers
+
def initialize
# Default settings
@base = ''
+ @handlers = :all
@root = '/themes'
@prefix = 'themes'
@images_path = ':root/:name/assets/images'
@@ -1,5 +1,17 @@
# encoding: utf-8
module ThemePark
+
+ # For rails, we need to resolve the handlers.
+ def self.resolve_views_path(name)
+ views_path = self.views_path(name)
+ if ThemePark.handlers.to_s != 'all'
+ handers = ThemePark.handlers.to_a.join(',')
+ ActionView::FileSystemResolver.new(views_path, ":prefix/:action{.:locale,}{.:formats,}{.{#{handers}},}")
+ else
+ views_path
+ end
+ end
+
module Rails
module ActionController
extend ActiveSupport::Concern
@@ -12,7 +24,7 @@ module ClassMethods
# end
# ===
def theme(name, options = {})
- path = ThemePark.views_path(name)
+ path = ThemePark.resolve_views_path(name)
if options.empty?
prepend_view_path path
else
@@ -34,7 +46,7 @@ def theme(name, options = {})
# end
# ===
def theme(name)
- path = ThemePark.views_path(name)
+ path = ThemePark.resolve_views_path(name)
prepend_view_path path
end

0 comments on commit 8e2ecc4

Please sign in to comment.