Sha256: 002d79878f032d99b1c3dd593345104f8680d1f1962cff6a6d6565fba704ffbc
Contents?: true
Size: 1.99 KB
Versions: 1
Compression:
Stored size: 1.99 KB
Contents
module ThemesOnRails class ActionController attr_reader :theme_name class << self def apply_theme(controller_class, theme, options={}) filter_method = before_filter_method(options) options = options.slice(:only, :except) # set layout controller_class.class_eval do define_method :layout_from_theme do theme_instance.theme_name end define_method :theme_instance do @theme_instance ||= ThemesOnRails::ActionController.new(self, theme) end private :layout_from_theme, :theme_instance layout :layout_from_theme, options end controller_class.send(filter_method, options) do |controller| # prepend view path controller.prepend_view_path theme_instance.theme_view_path # liquid file system Liquid::Template.file_system = Liquid::Rails::FileSystem.new(theme_instance.theme_view_path) if defined?(Liquid::Rails) end end private def before_filter_method(options) case Rails::VERSION::MAJOR when 3 options.delete(:prepend) ? :prepend_before_filter : :before_filter when 4 options.delete(:prepend) ? :prepend_before_action : :before_action end end end def initialize(controller, theme) @controller = controller @theme_name = _theme_name(theme) end def theme_view_path "#{prefix_path}/#{@theme_name}/views" end def prefix_path "#{Rails.root}/app/themes" end private def _theme_name(theme) case theme when String then theme when Proc then theme.call(@controller).to_s when Symbol then @controller.respond_to?(theme, true) ? @controller.send(theme).to_s : theme.to_s else raise ArgumentError, "String, Proc, or Symbol, expected for `theme'; you passed #{theme.inspect}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
themes_on_rails-0.3.1 | lib/themes_on_rails/action_controller.rb |